-
-
Save unstoppablecarl/4780144 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ig.module ( | |
'game.entities.Player' | |
) | |
.requires( | |
'impact.entity', | |
'impact.game', | |
'impact.font' | |
) | |
.defines(function(){ | |
var ismove = 0; | |
var speed = 100; | |
var steps = 0; | |
/************************* | |
Main local Player | |
*************************/ | |
EntityPlayer = ig.Entity.extend({ | |
size: {x: 24, y: 46}, | |
direction: 1, | |
type: ig.Entity.TYPE.A, | |
nettimer: 10, | |
name: "player", | |
gamename: name, | |
playername : name, | |
font: new ig.Font( 'media/font.png' ), | |
checkAgainst: ig.Entity.TYPE.B, // Collision related | |
collides: ig.Entity.COLLIDES.ACTIVE, // Collision related | |
animSheet: new ig.AnimationSheet( 'media/player.png', 24, 46 ), | |
init: function( x, y, settings ) { | |
this.parent( x, y, settings ); | |
/* | |
Player specs | |
*/ | |
this.strenght = 0; | |
this.agility = 0; | |
this.level = 5; | |
/* | |
Player ressources | |
*/ | |
this.ressources_gold = 0; | |
/* | |
Animation | |
*/ | |
currentanimation = ''; | |
this.addAnim( 'up', .21, [9,10,11] ); | |
this.addAnim( 'down', .12, [0,1,2,3,4,5,6,7] ); | |
this.addAnim( 'left', .12, [37,36,35,34,33,32,31,30] ); | |
this.addAnim( 'right', .12, [20,21,22,23,24,25,26,27] ); | |
this.addAnim( 'idleup', 1.1, [10,11,12,13] ); | |
this.addAnim( 'idledown', 1.1, [10,11,12,13] ); | |
this.addAnim( 'idleleft', 1.1, [10,11,12,13] ); | |
this.addAnim( 'idleright', 1.1, [10,11,12,13] ); | |
}, | |
update: function() { | |
/* | |
Movements | |
*/ | |
if( ig.input.state('left') && ismove != 1 && ismove != 2 && ismove != 4) { | |
this.vel.x = -speed; | |
ismove = 3; | |
this.direction = 3; | |
} | |
else if( ig.input.state('right') && ismove != 1 && ismove != 3 && ismove != 4) { | |
this.vel.x = +speed; | |
ismove = 2; | |
this.direction = 2; | |
} | |
else if( ig.input.state('up') && ismove != 3 && ismove != 2 && ismove != 4) { | |
this.vel.y = -speed; | |
ismove = 1; | |
this.direction = 1; | |
} | |
else if( ig.input.state('down') && ismove != 1 && ismove != 2 && ismove != 3) { | |
this.vel.y = +speed; | |
ismove = 4; | |
this.direction = 4; | |
} | |
else { | |
this.vel.x = 0; | |
this.vel.y = 0; | |
ismove = 0; | |
} | |
} | |
this.parent(); | |
} | |
draw: function(){ | |
// do normal draw first so the text is over top of it | |
this.parent(); | |
// width of text | |
var width = this.font.widthForString(this.playerName), | |
//how far up to move text from top of entity | |
yOffset = -20; | |
//draw font | |
this.font.draw( text || this.text, | |
ig.system.getDrawPos( this.pos.x - ig.game.screen.x - width/2 + this.size.x/2), | |
ig.system.getDrawPos( this.pos.y - ig.game.screen.y + yOffset), | |
ig.Font.ALIGN.CENTER ); | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment