-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.as
87 lines (73 loc) · 1.75 KB
/
Player.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package{
import org.flixel.*;
public class Player extends FlxSprite{
[Embed (source = "assets/player.png")] private var sprite:Class;
[Embed (source="assets/jump.mp3")] private var jump:Class;
private var _speed:int = 400;
private var _bullets:FlxGroup;
public var can_shoot:Boolean = false;
private var a:FlxSound;
public function Player(X:Number,Y:Number,bullets:FlxGroup):void{
super(X,Y);
loadGraphic(sprite,true,true,28,43);
addAnimation('stand',[0]);
addAnimation('run',[1,2,3,4,5,6],10);
width = 16;
height = 32;
offset.x=6;
offset.y = 4;
//Max speeds
maxVelocity.x = 150;
maxVelocity.y = 200;
//Gravity
acceleration.y = 400;
//acceleration.x = 100;
//Friction
drag.x = 300;
//Initial right facing
facing = RIGHT;
//Allow collisions
solid = true;
a = new FlxSound;
a.loadEmbedded(jump);
health=2;
_bullets = bullets;
}
override public function update():void{
if(FlxG.keys.LEFT){
play('run');
facing = LEFT;
//velocity.x -= _speed * FlxG.elapsed;
acceleration.x = -600;
}
else if (FlxG.keys.RIGHT){
play('run');
facing = RIGHT;
//velocity.x += _speed * FlxG.elapsed;
acceleration.x = 600;
}
else{
acceleration.x = 0;
if(velocity.x==0){
play('stand');
}
}
if (FlxG.keys.UP && (this.touching&DOWN)){
velocity.y-= 200;
a.play();
}
if (FlxG.keys.justPressed("SPACE") && can_shoot){
a.play();
_bullets.add(new Bullet(x,y,facing));
can_shoot = false;
var t:FlxTimer = new FlxTimer();
t.start(0.5,1,function(t:FlxTimer):void{can_shoot = true;})
}
super.update();
}
override public function hurt(Damage:Number):void{
flicker(1);
super.hurt(Damage);
}
}
}