-
Notifications
You must be signed in to change notification settings - Fork 0
/
debris.m
56 lines (43 loc) · 1.24 KB
/
debris.m
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
% Authors: Alejandro R. Mosteo, Danilo Tardioli, Eduardo Montijano
% Copyright 2018-9999 Monmostar
% Licensed under GPLv3 https://www.gnu.org/licenses/gpl-3.0.en.html
%
classdef debris < i_body & i_drawable
properties
vx, vy
vx_max = 20
vy_max = 40
ay = 25
h % Drawer
end
methods(Static)
function list = create(n, x, y)
% Create a bunch of debris at a point, returned as horizontal list
list = cell(1, n);
for i=1:n
list{i} = debris(x, y);
end
end
end
methods
function this = debris(x, y)
this.h = drawer();
this.x = x;
this.y = y;
this.vx = (rand - 0.5)*this.vx_max;
this.vy = rand*this.vy_max;
end
function draw(this, axis, scale)
this.h.plot(axis, this.x*scale, this.y*scale, 'Color', [0 0 0], 'Marker', '.');
end
function done = update(this, period)
this.x = this.x + this.vx*period;
if abs(this.x) > saudefense.W/2
this.vx = -this.vx;
end
this.y = this.y + this.vy*period;
this.vy = this.vy - this.ay*period;
done = this.y < 0 || abs(this.x) > saudefense.W/1.5;
end
end
end