Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ig.module(
- 'game.entities.player'
- )
- .requires(
- 'impact.entity'
- )
- .defines(function () {
- EntityPlayer = ig.Entity.extend({
- collides: ig.Entity.COLLIDES.PASSIVE,
- // Hitbox size and offset, fine tuned for good collisions
- size: {x: 6, y: 22},
- offset: {x: 2, y: 0},
- maxVel: {x: 50, y: 400},
- friction: {x: 300, y: 0},
- animSheet: new ig.AnimationSheet('media/player.png', 10, 22),
- init: function (x, y, settings) {
- this.parent(x, y, settings);
- // Add the animations
- this.addAnim('idle', 1, [0]);
- this.addAnim('run', 0.1, [1,2,3,4]);
- this.addAnim('idleRun', 1, [1]);
- },
- accelGround: 200,
- accelAir: 100,
- jump: 90,
- flipped: false,
- update: function () {
- // Slower acceleration if in the air
- var accel = this.standing? this.accelGround : this.accelAir;
- if (ig.input.state('left')) {
- this.accel.x = -accel;
- this.flipped = true;
- } else if (ig.input.state('right')) {
- this.accel.x = accel;
- this.flipped = false;
- } else {
- this.accel.x = 0;
- }
- if (ig.input.pressed('jump') && this.standing) {
- this.vel.y = -this.jump;
- }
- // Handle animations
- if (this.vel.x != 0) {
- this.currentAnim = this.anims.run;
- } else {
- this.currentAnim = this.anims.idle;
- }
- this.currentAnim.flip.x = this.flipped;
- this.parent();
- },
- collideWith: function (other, axis) {
- console.log('hey');
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement