Skip to content

Commit

Permalink
Basic acceleration for Actor.
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrignol committed Apr 11, 2014
1 parent b3bcf03 commit 0adda9f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Actor.cpp
Expand Up @@ -7,11 +7,19 @@ Actor::Actor(){
this->width = 0;
this->height = 0;
this->velocity = 0;
this->maxVelocity = 0;
this->acceleration = 0;
this->name = "unknown";
}


void Actor::move(float elapsedMs) {
//acceleration
this->velocity *= this->acceleration;

if (this->velocity > this->maxVelocity) {
this->velocity = this->maxVelocity;
}

float elapsedSec = elapsedMs / 1000;
float move = this->velocity * elapsedSec;
Expand Down
2 changes: 2 additions & 0 deletions src/Actor.h
Expand Up @@ -12,6 +12,8 @@ class Actor {
int height;

int velocity; //in pixels per second
int maxVelocity;
float acceleration;

std::string name;

Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Expand Up @@ -20,7 +20,9 @@ int main( int argc, char* args[] )
hero->height = 158;
hero->x = 0;
hero->y = (WINDOW_HEIGHT/2) - hero->height/2;
hero->velocity = 100;
hero->velocity = 10;
hero->maxVelocity = 300;
hero->acceleration = 1.2;

Sdl2Renderer * renderer = new Sdl2Renderer("Incrementalist step 2", WINDOW_WIDTH, WINDOW_HEIGHT);

Expand Down

0 comments on commit 0adda9f

Please sign in to comment.