-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.as
71 lines (55 loc) · 1.32 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
package Vortex
{
import Framework.FG;
import Framework.FSprite;
import Framework.Shapes.FCircle;
import Framework.Maths.FVec;
import Framework.Maths.FPoint;
import Framework.Maths.FMath;
public class Player extends FSprite
{
private var radius:int;
private var moveSpeed:int;
public function Player()
{
super(FG.mouse.x, FG.mouse.y);
}
override public function Create():void
{
super.Create();
radius = 2;
moveSpeed = 30;
collision = new FCircle(x, y, radius);
}
override public function Update():void
{
var temp:FVec = new FVec(FG.mouse.x - x - (radius/2), FG.mouse.y - y - (radius/2));
// Enforce the player speed limit
if(temp.Mag() > moveSpeed)
{
temp.Normalize();
temp.Mult(moveSpeed);
}
// Rotation calculation
var adj:Number = FG.mouse.x - x;
var opp:Number = FG.mouse.y - y;
var rot:Number = FMath.RadiansToDegrees(Math.atan(opp / adj));
rotation = rot;
// Velocity squish!
scaleX = 1 + Math.abs(temp.x/(moveSpeed/4));
scaleY = 1 - Math.abs(temp.x/(moveSpeed*2));
// Update collision model and the location
x += temp.x;
y += temp.y;
super.Update();
}
override public function Draw():void
{
graphics.clear();
graphics.beginFill(0);
graphics.drawCircle(0,0,radius);
graphics.endFill();
draws = false;
}
}
}