Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.geom.Point;
- import net.flashpunk.Entity;
- import net.flashpunk.graphics.Spritemap;
- // gamer is a classs fo a game entity, controlled either
- // by local player, remote player or AI or nothing
- public class Gamer extends Entity
- {
- // variables
- public var vx:Number = 0; // velocity
- public var vy:Number = 0;
- public var jumps:uint = max_jumps; // jumps performed
- // properties
- public var speed:Number = 8.0; // max velocity
- public var acc:Number = .2; // ecceleration
- public var decc:Number = .98; // brakes
- public var max_jumps:uint = 2; // x-iple jump
- public var jumprate:Number = -12.0; // how high
- public var bumprate:Number = 0.0; // wallfallbump rate
- public var antigravity:Number = 1.0; // parachuting
- public var fly:Boolean = false; // disregard for gravity
- public var stationary:Boolean = false; // disregard for everything
- public var manual:Boolean = false; // disregard for input()
- static public var gravity:Number = .3; // gravity
- // BUTTONS
- static public const UP:uint = 0x01;
- static public const DOWN:uint = 0x02;
- static public const LEFT:uint = 0x04;
- static public const RIGHT:uint = 0x08;
- static public const SHOOT:uint = 0x10;
- static public const JUMP:uint = 0x20;
- static public const SHIT:uint = 0x40;
- static public const FUCK:uint = 0x80;
- static public const MULTIJUMP:uint = 0x100;
- public function Gamer(x:Number,y:Number)
- {
- this.x = x;
- this.y = y;
- }
- // this return buttonpress bitmask, least 8 bits:
- // 0 - UP
- // 1 - DOWN
- // 2 - LEFT
- // 3 - RIGHT
- // 4 - SHOOT
- // 5 - JUMP
- // 6 - SOMETHING ELSE
- // 7 - SOMETHING ELSER
- public function input():uint
- {
- // please overload
- return 0;
- }
- override public function update():void
- {
- // if it doesn't move then... well it doesn't!
- if (stationary) return;
- // if not controlled manually (by code) we check input
- if (!manual)
- {
- // get keys!
- var keys:uint = input();
- // check left/right!
- if (keys & LEFT) vx -= acc;
- if (keys & RIGHT) vx += acc;
- // if flying, then not jumping :P
- if (fly)
- {
- if (keys & UP) vy -= acc;
- if (keys & DOWN) vy += acc;
- } else {
- // else, totally jumping :P
- if ((keys & JUMP) && jumps)
- {
- vy = jumprate;
- jumps--;
- }
- }
- }
- // collision detection assumes all objects initially do not collide
- // gravitizing
- vy += gravity * antigravity;
- // friction
- vx *= decc;
- // ground / head collision
- if (collide("level", x, y + vy))
- {
- if (vy < 0) // goes up
- {
- // hit the ceiling
- vy = 0;// -vy * bumprate;
- } else { // falling or standing
- // landed, we bump if necessary
- jumps = 0;
- vy = -vy * bumprate;
- jumps = max_jumps;
- }
- }
- // side level collision
- // please note the double collision check
- if (collide("level", x+vx, y) || collide("level", x+vx, y+vy))
- {
- if (vx < 0) // goes up
- {
- } else { // falling or standing
- }
- // bump if necessary (or stop)
- vx = -vx * bumprate;
- }
- // apply velocity!
- x += vx;
- y += vy;
- // it's as simple as that!
- }
- }
- }
Add Comment
Please, Sign In to add comment