forked from giladaya/arduino-particle-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle_Std.cpp
44 lines (36 loc) · 962 Bytes
/
Particle_Std.cpp
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
/*
* Copyright (C) 2013 Gilad Dayagi. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
/*
* Particle_Std.cpp - standard particle, dies when out of bounds
*/
#include "Particle_Std.h"
signed char Particle_Std::ax = 0;
signed char Particle_Std::ay = 0;
Particle_Std::Particle_Std()
{
isAlive = false;
}
void Particle_Std::update(void)
{
//age
ttl--;
//apply acceleration
vx = min(vx+ax, PS_MAX_X);
vy = min(vy+ay, PS_MAX_Y);
//apply velocity
unsigned int newX, newY;
newX = x + vx;
newY = y + vy;
if(ttl == 0 || newX < 0 || newX > PS_MAX_X || newY < 0 || newY > PS_MAX_Y) {
isAlive = false;
} else {
x = (byte)newX;
y = (byte)newY;
}
}