-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFriction2.hx
36 lines (31 loc) · 792 Bytes
/
Friction2.hx
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
import openfl.display.Sprite;
import openfl.display.StageAlign;
import openfl.display.StageScaleMode;
import openfl.events.Event;
class Friction2 extends Sprite {
private var ball:Ball;
private var vx:Float = 0;
private var vy:Float = 0;
private var friction:Float = 0.9;
public function new() {
super();
init();
}
private function init():Void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
ball = new Ball();
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight / 2;
vx = Math.random() * 10 - 5;
vy = Math.random() * 10 - 5;
addChild(ball);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):Void {
vx *= friction;
vy *= friction;
ball.x += vx;
ball.y += vy;
}
}