-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMathStudent.as
60 lines (50 loc) · 1.11 KB
/
MathStudent.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
package{
import org.flixel.*;
public class MathStudent extends FlxSprite {
[Embed(source="assets/math.png")] private var sprite:Class;
private var _target:FlxObject;
public function MathStudent(X:Number,Y:Number,target:FlxObject=null){
super(X,Y);
loadGraphic(sprite,true,true,28,43);
addAnimation('run',[0,1,2,3],10);
play('run');
width = 16;
height = 32;
offset.x=6;
offset.y = 4;
//Max speeds
maxVelocity.x = 200;
maxVelocity.y = 200;
//Gravity
acceleration.y = 400;
//acceleration.x = 100;
//Friction
drag.x = 300;
//Initial right facing
facing = RIGHT;
//Allow collisions
solid = true;
health=1;
_target = target;
}
override public function update():void{
if (_target == null || !_target.alive || (_target.flickering && onScreen())){
facing = LEFT;
velocity.x = -150;
}
else if (onScreen()){
if (_target.x < x){
facing = LEFT;
velocity.x = -100;
}
else if (_target.x > x){
facing = RIGHT;
velocity.x = 100;
}
if (_target.y < y && touching&DOWN){
velocity.y = -70;
}
}
}
}
}