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({
- animSheet: new ig.AnimationSheet( 'media/player.png', 16, 16 ),
- size: {x: 16, y: 16},
- offset: {x: 0, y: 0},
- flip: false,
- maxVel: {x: 100, y: 150},
- friction: {x: 600, y: 0},
- accelGround: 400,
- accelAir: 200,
- jump: 200,
- init: function( x, y, settings ) {
- this.parent( x, y, settings );
- this.addAnim( 'idle', 1, [0, 4] );
- this.addAnim( 'walk', 1, [1] );
- this.addAnim( 'jump', 1, [2] );
- this.addAnim( 'fall', 1, [3] );
- //Camera
- ig.game.player = this;
- },
- update: function() {
- var accel = this.standing ? this.accelGround : this.accelAir;
- if( ig.input.state('left') ) {
- this.accel.x = -accel;
- this.flip = true;
- }else if( ig.input.state('right') ) {
- this.accel.x = accel;
- this.flip = false;
- }else{
- this.accel.x = 0;
- }
- if( this.standing && ig.input.pressed('jump') ) {
- this.vel.y = -this.jump;
- }
- if( ig.input.pressed('shoot') ) {
- var mx = (ig.input.mouse.x + ig.game.screen.x);
- var my = (ig.input.mouse.y + ig.game.screen.y);
- var r = Math.atan2(my-this.pos.y, mx-this.pos.x);
- ig.game.spawnEntity( EntityBullet, this.pos.x, this.pos.y, {flip:this.flip} );
- }
- //Animations
- if( this.vel.y < 0) {
- this.currentAnim = this.anims.jump;
- }else if( this.vel.y > 0 ) {
- this.currentAnim = this.anims.fall;
- }else if( this.vel.x != 0 ) {
- this.currentAnim = this.anims.walk;
- }else{
- this.currentAnim = this.anims.idle;
- }
- this.parent();
- },
- });
- EntityBullet = ig.Entity.extend({
- animSheet: new ig.AnimationSheet( 'media/bullet.png', 5, 3 ),
- size: {x: 5, y: 3},
- maxVel: {x: 200, y: 0},
- //Collision type.
- type: ig.Entity.TYPE.NONE,
- checkAgainst: ig.Entity.TYPE.B,
- collides: ig.Entity.COLLIDES.PASSIVE,
- init: function( x, y, settings ) {
- this.parent( x + (settings.flip ? -4 : 8) , y+8, settings );
- var vely = Math.sin(this.angle) * this.desiredVel; //.desiredVel is just the velocity I would want if we were going in a straight line directly out of the right of the player. I just put it as a property of the entity since I refer to it in multiple locations
- var velx = Math.cos(this.angle) * this.desiredVel;
- this.maxVel.x = this.vel.x = this.accel.x = 100;
- this.maxVel.y = this.vel.y = this.accel.y = 100;
- this.vel.x = this.accel.x = (settings.flip ? -this.maxVel.x : this.maxVel.x);
- this.addAnim( 'idle', 0.2, [0] );
- },
- handleMovementTrace: function( res ) {
- this.parent( res );
- if( res.collision.x || res.collision.y ){
- this.kill();
- }
- },
- check: function( other ) {
- other.recieveDamage( 3, this );
- this.kill();
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement