add redirector

This commit is contained in:
Juraj Michalek
2015-12-25 19:20:10 +01:00
parent f349981c4e
commit 0d5cfc9368
2 changed files with 40 additions and 8 deletions

View File

@@ -19,18 +19,30 @@ state.create = function() {
this.tilemap = new Kiwi.GameObjects.Tilemap.TileMap(this, 'tilemap', this.textures.base); this.tilemap = new Kiwi.GameObjects.Tilemap.TileMap(this, 'tilemap', this.textures.base);
this.character = new Kiwi.GameObjects.Sprite(this, this.textures.character, 2*64, 64); this.character = new Kiwi.GameObjects.Sprite(this, this.textures.character, 2*64 - 8, 64 - 8);
this.character.box.hitbox = new Kiwi.Geom.Rectangle( 20, 20, 50, 50 ); this.character.box.hitbox = new Kiwi.Geom.Rectangle( 20, 20, 50, 50 );
this.character.physics = this.character.components.add( new Kiwi.Components.ArcadePhysics( this.character, this.character.box ) ); this.character.physics = this.character.components.add( new Kiwi.Components.ArcadePhysics( this.character, this.character.box ) );
this.character.physics.acceleration.y = 0; this.character.physics.acceleration.y = 0;
this.character.physics.maxVelocity.y = 140; this.character.physics.maxVelocity.y = 140;
this.character.animation.add('walking', [ 0, 1 ], 0.2, true); this.character.animation.add('walking', [ 0, 1 ], 0.2, true);
this.character.animation.add('idle', [ 2, 3, 4, 5 ], 0.2, false, false); this.character.animation.add('idle', [ 2, 3, 4, 5, 4, 3 ], 0.2, true);
this.redirector = new Kiwi.GameObjects.Sprite(this, this.textures.character, 2*64 - 8, 3*64 - 8);
this.redirector.box.hitbox = new Kiwi.Geom.Rectangle( 20, 20, 50, 50 );
this.redirector2 = new Kiwi.GameObjects.Sprite(this, this.textures.character, 6*64 - 8, 3*64 - 8);
this.redirector2.box.hitbox = new Kiwi.Geom.Rectangle( 20, 20, 50, 50 );
// Ground layer
this.addChild(this.tilemap.layers[0]); this.addChild(this.tilemap.layers[0]);
this.addChild(this.character); this.addChild(this.character);
this.addChild(this.redirector);
this.addChild(this.redirector2);
// Walls layer
this.addChild(this.tilemap.layers[1]); this.addChild(this.tilemap.layers[1]);
@@ -69,6 +81,9 @@ state.create = function() {
// this.myButton.input.onOut.add( this.buttonOut, this ); // this.myButton.input.onOut.add( this.buttonOut, this );
} }
state.velocityX = 64;
state.velocityY = 64;
state.buttonPressed = function() { state.buttonPressed = function() {
this.myButton.y = 55; this.myButton.y = 55;
} }
@@ -76,12 +91,18 @@ state.buttonPressed = function() {
state.buttonReleased = function() { state.buttonReleased = function() {
this.myButton.y = 50; this.myButton.y = 50;
this.myButton.text = 'THANK YOU :)'; this.myButton.text = 'THANK YOU :)';
this.resetCharacter();
}
state.resetCharacter = function () {
this.character.physics.velocity.x = 0; this.character.physics.velocity.x = 0;
this.character.physics.velocity.y = 0; this.character.physics.velocity.y = 0;
this.character.x = 2*64 - 8;
this.character.y = 64 - 8;
} }
state.activateScene = function () { state.activateScene = function () {
this.character.physics.velocity.y = 40; this.character.physics.velocity.y = this.velocityY;
} }
state.update = function () { state.update = function () {
@@ -109,6 +130,17 @@ state.updateCharacterAnimation = function () {
//Resolve collisions between the character and the first layer. //Resolve collisions between the character and the first layer.
state.checkCollision = function () { state.checkCollision = function () {
this.tilemap.layers[1].physics.overlapsTiles( this.character, true ); this.tilemap.layers[1].physics.overlapsTiles( this.character, true );
if ((this.character.physics.velocity.x == 0) && (this.character.physics.velocity.y == 0)) {
return;
}
if (this.character.box.bounds.intersects( this.redirector.box.bounds )) {
this.character.physics.velocity.x = this.velocityX;
} else if (this.character.box.bounds.intersects( this.redirector2.box.bounds )) {
this.character.physics.velocity.y = this.velocityY;
}
} }
state.updateCharacterMovement = function () { state.updateCharacterMovement = function () {
@@ -116,11 +148,11 @@ state.updateCharacterMovement = function () {
//Move the player/character //Move the player/character
if ( this.leftPressed ) { if ( this.leftPressed ) {
this.character.scaleX = -1; this.character.scaleX = -1;
this.character.physics.velocity.x = -40; this.character.physics.velocity.x = -this.velocityX;
} else if ( this.rightPressed ) { } else if ( this.rightPressed ) {
this.character.scaleX = 1; this.character.scaleX = 1;
this.character.physics.velocity.x = 40; this.character.physics.velocity.x = this.velocityY;
} }
} }

View File

@@ -22,7 +22,7 @@
"x":0, "x":0,
"y":0 "y":0
}], }],
"nextobjectid":1, "nextobjectid":4,
"orientation":"orthogonal", "orientation":"orthogonal",
"properties": "properties":
{ {