1 decade ago by spacelime
Hello!
I've started working on a game and the only problem so far is that the entity is "jumping" through the ceiling when coming to the end of a sloping tunnel. Also if letting go of the keys it will slide into the wall. You can test it out here:
http://diggers2.cloudcontrolapp.com/
Use keys 'a', 'w', and 'd' for moving.
Here is the code for the entity. I've not done anything particular to cause this as far as I can tell...
I've started working on a game and the only problem so far is that the entity is "jumping" through the ceiling when coming to the end of a sloping tunnel. Also if letting go of the keys it will slide into the wall. You can test it out here:
http://diggers2.cloudcontrolapp.com/
Use keys 'a', 'w', and 'd' for moving.
Here is the code for the entity. I've not done anything particular to cause this as far as I can tell...
EntityPlayer = ig.Entity.extend({ size: {x: 8, y: 10}, offset: {x: 2, y: 6}, direction: 1, messagebox: "", type: ig.Entity.TYPE.A, nettimer: 10, name: "player", gamename: 'player' + Math.floor(Math.random()*999), messageboxtimer: 200, speed:100, jump: 500, soundJump: new Audio("media/jump.ogg"), ismove: 0, checkAgainst: ig.Entity.TYPE.NONE, collides: ig.Entity.COLLIDES.PASSIVE, animSheet: new ig.AnimationSheet( 'media/player.png', 12, 16 ), init: function( x, y, settings ) { this.parent( x, y, settings ); // Add the animations this.addAnim( 'idleup', 0.1, [10] ); this.addAnim( 'idledown', 0.1, [1] ); this.addAnim( 'idleleft', 0.27, [0,1,2] ); this.addAnim( 'idleright', 0.27, [3,4,5] ); this.addAnim( 'up', .21, [9,10,11] ); this.addAnim( 'down', .21, [0,1,2] ); this.addAnim( 'left', .21, [6,7,8] ); this.addAnim( 'right', .21, [9,10,11] ); this.addAnim( 'jump', .21, [9,10,11] ); //socket.emit('initializeplayer', this.gamename); }, update: function() { socket.emit('initializeplayer', this.gamename); // Dig if( ig.input.state('space')) { if( ig.input.state('right') && (ig.game.backgroundMaps[0].getTile( this.pos.x+14, this.pos.y+8 ) == 2)) { ig.game.backgroundMaps[0].setTile( this.pos.x+14, this.pos.y+8, 3); ig.game.collisionMap.setTile( this.pos.x+14, this.pos.y+8, 0 ); } else if( ig.input.state('left') && (ig.game.backgroundMaps[0].getTile( this.pos.x-8, this.pos.y+8 ) == 2)) { ig.game.backgroundMaps[0].setTile( this.pos.x-2, this.pos.y+8, 3); ig.game.collisionMap.setTile( this.pos.x-2, this.pos.y+8, 0 ); } else if( ig.input.state('down') && (ig.game.backgroundMaps[0].getTile( this.pos.x+8, this.pos.y+24 ) == 2)) { ig.game.backgroundMaps[0].setTile( this.pos.x+8, this.pos.y+24, 3); ig.game.collisionMap.setTile( this.pos.x+8, this.pos.y+24, 0 ); } } // move left or right // if( ig.input.state('left') && ismove != 1 && ismove != 2 && ismove != 4) { this.vel.x = -this.speed; if(ismove == 0) { socket.emit('recievedata', 'a' ,this.gamename); } ismove = 3; this.direction = 3; this.currentAnim = this.anims.left; } else if( ig.input.state('right') && ismove != 1 && ismove != 3 && ismove != 4) { this.vel.x = +this.speed; if(ismove == 0) { socket.emit('recievedata', 'd' ,this.gamename); var t = ig.game.collisionMap.getTile( this.pos.x, this.pos.y+20 ); if( t != 0 ) { } } ismove = 2; this.direction = 2; this.currentAnim = this.anims.right; } else { if(ismove != 0) { socket.emit('recievedata', 'releaseKey' ,this.gamename); } this.vel.x = 0; ismove = 0; } ///////////////////////animate///////////// if( this.vel.y < 0 ) { this.currentAnim = this.anims.up; currentanimation = 1; } else if( this.vel.y > 0 ) { this.currentAnim = this.anims.down; currentanimation = 2; } else if( this.vel.x > 0 ) { this.currentAnim = this.anims.right; currentanimation = 4; } else if( this.vel.x < 0 ) { this.currentAnim = this.anims.left; currentanimation = 3; } else { if( this.direction == 4 ) { this.currentAnim = this.anims.idledown; currentanimation = 6; } if( this.direction == 3 ) { this.currentAnim = this.anims.idleleft; currentanimation = 7; } if( this.direction == 2 ) { this.currentAnim = this.anims.idleright; currentanimation = 8; } if( this.direction == 1 ) { this.currentAnim = this.anims.idleup; currentanimation = 5; } } // jump if( this.standing && ig.input.pressed('up')) { this.vel.y = -this.jump; socket.emit('recievedata', 'w' ,this.gamename); if (window.chrome) this.soundJump.load(); this.soundJump.play(); } this.parent(); } });