Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ig.module(
- 'game.entities.Player'
- )
- .requires(
- 'impact.entity',
- 'game.entities.SavePoint'
- )
- .defines(function() {
- EntityPlayer = ig.Entity.extend({
- collides: ig.Entity.COLLIDES.ACTIVE,
- type : ig.Entity.TYPE.A,
- checkAgainst : ig.Entity.B,
- framerate: 0.1,
- size: {x: 16, y: 16},
- zIndex: 10,
- lastInput: null,
- // Load an animation sheet
- animUp: new ig.AnimationSheet('media/link/up.png', 16, 24),
- animDown: new ig.AnimationSheet('media/link/down.png', 16, 24),
- animRight: new ig.AnimationSheet('media/link/right.png', 16, 24),
- animSwordDown: new ig.AnimationSheet('media/link/sworddown.png', 34, 34),
- animSwordUp: new ig.AnimationSheet('media/link/swordup.png', 36, 36),
- animSwordRight: new ig.AnimationSheet('media/link/swordright.png', 36, 36),
- //game play
- health : 3,
- init: function(x, y, settings) {
- this.parent(x, y, settings);
- this.anims.up = new ig.Animation(this.animUp, this.framerate, [0, 1, 2, 3, 4, 5, 6, 7]);
- this.anims.down = new ig.Animation(this.animDown, this.framerate, [0, 1, 2, 3, 4, 5, 6]);
- this.anims.right = new ig.Animation(this.animRight, this.framerate, [0, 1, 2, 3, 4, 5]);
- this.anims.idleDown = new ig.Animation(this.animDown, this.framerate, [3]);
- this.anims.idleRight = new ig.Animation(this.animRight, this.framerate, [3]);
- this.anims.idleUp = new ig.Animation(this.animUp, this.framerate, [3]);
- this.anims.swordDown = new ig.Animation(this.animSwordDown, 0.1, [0, 1, 2, 3, 4, 5]);
- this.anims.swordUp = new ig.Animation(this.animSwordUp, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8]);
- this.anims.swordRight = new ig.Animation(this.animSwordRight, this.framerate, [0, 1, 2, 3, 4, 5, 6, 7, 8]);
- self = this;
- },
- update: function() {
- // This method is called for every frame on each entity.
- // React to input, or compute the entity's AI here.
- moving = 0;
- if (ig.input.state('sword1'))
- {
- if(this.lastInput){
- if(this.lastInput = ig.input.state('down')){
- }else if (true) {
- }
- }else{
- console.log("pas de last input");
- }
- };
- // si up ou down ET rien d'autre on stocke la valeur.
- // objectif : garder l'animation précédente pour qu'en diagonale, le personnage ne soit pas toujours à droite ou à gauche en animation s'il a commencé par haut ou bas
- if ((ig.input.state('up1') || ig.input.state('down1')) && !ig.input.state('left1') && !ig.input.state('right1')) {
- this.lastInput = ig.input.state('down1') ? 'down1' : 'up1';
- }
- if ((ig.input.state('left1') || ig.input.state('right1')) && !ig.input.state('up1') && !ig.input.state('down1'))
- this.lastInput = ig.input.state('left1') ? 'left1' : 'right1';
- // si haut + bas ou droite + gauche : stop animation.
- if (ig.input.state('up1') && ig.input.state('down1')) {
- moving = 0;
- this.vel.y = 0;
- }
- if (ig.input.state('left1') && ig.input.state('right1')) {
- moving = 0;
- this.vel.x = 0;
- }
- // gestion des cas d'input
- if (ig.input.state('up1') && !ig.input.state('down1')) {
- moving = 1;
- this.vel.y = -100;
- this.currentAnim = this.anims.up;
- }
- if (ig.input.state('down1') && !ig.input.state('up1')) {
- moving = 1;
- this.vel.y = 100;
- this.currentAnim = this.anims.down;
- }
- if (ig.input.state('left1') && !ig.input.state('right1')) {
- moving = 1;
- this.vel.x = -100;
- // conservation de la dernière direction
- if (this.lastInput != 'left1' && this.lastInput != 'right1' && (ig.input.state('up1') || ig.input.state('down1')))
- if (ig.input.state('up1'))
- this.currentAnim = this.anims.up;
- else
- this.currentAnim = this.anims.down;
- else
- this.currentAnim = this.anims.right;
- }
- if (ig.input.state('right1') && !ig.input.state('left1')) {
- moving = 1;
- this.vel.x = 100;
- // conservation de la dernière direction
- if (this.lastInput != 'left1' && this.lastInput != 'right1' && (ig.input.state('up1') || ig.input.state('down1')))
- if (ig.input.state('up1'))
- this.currentAnim = this.anims.up;
- else
- this.currentAnim = this.anims.down;
- else
- this.currentAnim = this.anims.right;
- }
- if (!ig.input.state('left1') && !ig.input.state('right1'))
- this.vel.x = 0;
- if (!ig.input.state('up1') && !ig.input.state('down1'))
- this.vel.y = 0;
- // trouvé ici : http://gmc.yoyogames.com/index.php?showtopic=547900
- // calcul de la vitesse en diagonale
- if (this.vel.x != 0 && this.vel.y != 0)
- {
- this.vel.x = this.vel.x / Math.sqrt(2);
- this.vel.y = this.vel.y / Math.sqrt(2);
- }
- // si on bouge pas, on conserve la dernière direction regardée par le personnage
- if (!moving) {
- switch (this.lastInput) {
- case 'left1':
- case 'right1':
- this.currentAnim = this.anims.idleRight;
- break;
- case 'up1':
- this.currentAnim = this.anims.idleUp;
- break;
- default:
- this.currentAnim = this.anims.idleDown;
- break;
- }
- }
- // animation de gauche = flip(animation de droite)
- if (this.vel.x < 0 || (!moving && this.lastInput == 'left1'))
- this.currentAnim.flip.x = true;
- else
- this.currentAnim.flip.x = false;
- // Call the parent update() method to move the entity
- // according to its physics
- this.parent();
- },
- check: function(other){
- if(other instanceOf EntitySavePoint){
- console.log('save');
- }
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement