From 0adda9f95dc14e81d414313fcd810a6c0cc53303 Mon Sep 17 00:00:00 2001 From: Nicolas Brignol Date: Fri, 11 Apr 2014 13:28:08 +0200 Subject: [PATCH] Basic acceleration for Actor. --- src/Actor.cpp | 8 ++++++++ src/Actor.h | 2 ++ src/main.cpp | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Actor.cpp b/src/Actor.cpp index 6714cc8..f229b94 100644 --- a/src/Actor.cpp +++ b/src/Actor.cpp @@ -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; diff --git a/src/Actor.h b/src/Actor.h index 1eea308..a8304e9 100644 --- a/src/Actor.h +++ b/src/Actor.h @@ -12,6 +12,8 @@ class Actor { int height; int velocity; //in pixels per second + int maxVelocity; + float acceleration; std::string name; diff --git a/src/main.cpp b/src/main.cpp index 61de555..dd61e06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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);