Blind fix for Pre bugs
[swarmPDK.git] / src / Pixel.cpp
1 #include "Pixel.h"
2 //#include <stdlib.h>
3 #include <GLES/gl.h>
4 #include "SDL.h"
5
6 Pixel::Pixel(SDL_Surface* screen) {
7         this->x = (rand() / (float)RAND_MAX) * screen->w;
8         this->y = (rand() / (float)RAND_MAX) * screen->h;
9         this->vx = (rand() / (float)RAND_MAX) * 10.0 - 5.0;
10         this->vy = (rand() / (float)RAND_MAX) * 10.0 - 5.0;
11         this->lastupdate = SDL_GetTicks();
12 }
13
14 Pixel::~Pixel(void) {
15 }
16
17 void Pixel::accel(float x, float y) {
18         this->vx += x;
19         if (this->vx > 100.0)
20                 this->vx = 100.0;
21         else if (this->vx < -100.0)
22                 this->vx = -100.0;
23         this->vy += y;
24         if (this->vy > 100.0)
25                 this->vy = 100.0;
26         else if (this->vy < -100.0)
27                 this->vy = -100.0;
28 }
29
30 void Pixel::update() {
31         Uint32 now = SDL_GetTicks();
32         float dt = (now - this->lastupdate) / 75.0;
33         if (dt < 1000) {   // If we're running less than 1FPS, don't bother updating.
34                 this->x += this->vx * dt;
35                 this->y += this->vy * dt;
36         }
37         this->lastupdate = now;
38 }
39
40 void Pixel::draw(GLfloat *vertices) {
41         vertices[0] = this->x;
42         vertices[1] = this->y;
43         vertices[3] = this->x - this->vx / 4.0f;
44         vertices[4] = this->y - this->vy / 4.0f;
45 }