diff --git a/index.html b/index.html
index bc7825a..32d047e 100644
--- a/index.html
+++ b/index.html
@@ -19,18 +19,30 @@ state.create = function() {
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.box.hitbox = new Kiwi.Geom.Rectangle( 20, 20, 50, 50 );
+ 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.physics = this.character.components.add( new Kiwi.Components.ArcadePhysics( this.character, this.character.box ) );
this.character.physics.acceleration.y = 0;
this.character.physics.maxVelocity.y = 140;
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.character);
+
+ this.addChild(this.redirector);
+ this.addChild(this.redirector2);
+
+ // Walls layer
this.addChild(this.tilemap.layers[1]);
@@ -69,6 +81,9 @@ state.create = function() {
// this.myButton.input.onOut.add( this.buttonOut, this );
}
+state.velocityX = 64;
+state.velocityY = 64;
+
state.buttonPressed = function() {
this.myButton.y = 55;
}
@@ -76,12 +91,18 @@ state.buttonPressed = function() {
state.buttonReleased = function() {
this.myButton.y = 50;
this.myButton.text = 'THANK YOU :)';
+ this.resetCharacter();
+}
+
+state.resetCharacter = function () {
this.character.physics.velocity.x = 0;
this.character.physics.velocity.y = 0;
+ this.character.x = 2*64 - 8;
+ this.character.y = 64 - 8;
}
state.activateScene = function () {
- this.character.physics.velocity.y = 40;
+ this.character.physics.velocity.y = this.velocityY;
}
state.update = function () {
@@ -109,6 +130,17 @@ state.updateCharacterAnimation = function () {
//Resolve collisions between the character and the first layer.
state.checkCollision = function () {
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 () {
@@ -116,13 +148,13 @@ state.updateCharacterMovement = function () {
//Move the player/character
if ( this.leftPressed ) {
this.character.scaleX = -1;
- this.character.physics.velocity.x = -40;
+ this.character.physics.velocity.x = -this.velocityX;
} else if ( this.rightPressed ) {
this.character.scaleX = 1;
- this.character.physics.velocity.x = 40;
+ this.character.physics.velocity.x = this.velocityY;
}
-
+
}
diff --git a/tilemap.json b/tilemap.json
index a7752fa..697b39f 100644
--- a/tilemap.json
+++ b/tilemap.json
@@ -22,7 +22,7 @@
"x":0,
"y":0
}],
- "nextobjectid":1,
+ "nextobjectid":4,
"orientation":"orthogonal",
"properties":
{