/src/Pixel.cpp
#include "Pixel.h"
//#include <stdlib.h>
#include <GLES/gl.h>
#include "SDL.h"
Pixel::Pixel(SDL_Surface* screen) {
this->x = (rand() / (float)RAND_MAX) * screen->w;
this->y = (rand() / (float)RAND_MAX) * screen->h;
this->vx = (rand() / (float)RAND_MAX) * 10.0 - 5.0;
this->vy = (rand() / (float)RAND_MAX) * 10.0 - 5.0;
this->lastupdate = SDL_GetTicks();
}
Pixel::~Pixel(void) {
}
void Pixel::accel(float x, float y) {
this->vx += x;
if (this->vx > 100.0)
this->vx = 100.0;
else if (this->vx < -100.0)
this->vx = -100.0;
this->vy += y;
if (this->vy > 100.0)
this->vy = 100.0;
else if (this->vy < -100.0)
this->vy = -100.0;
}
void Pixel::update() {
Uint32 now = SDL_GetTicks();
float dt = (now - this->lastupdate) / 75.0;
if (dt < 1000) { // If we're running less than 1FPS, don't bother updating.
this->x += this->vx * dt;
this->y += this->vy * dt;
}
this->lastupdate = now;
}
void Pixel::draw(GLfloat *vertices) {
vertices[0] = this->x;
vertices[1] = this->y;
vertices[3] = this->x - this->vx / 4.0f;
vertices[4] = this->y - this->vy / 4.0f;
}