Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finished extracting Entity from Avatar. Fixed movement bug. Added the…

… font to the repository.
  • Loading branch information...
commit 019ab07d4ef976b83b4b687f2034acfc4b87b565 1 parent 3d5647b
namaste authored
View
BIN  soylent/GoD/Resources/zrnic___.ttf
Binary file not shown
View
33 soylent/GoD/avatar.h
@@ -15,43 +15,24 @@ class Avatar : public Entity
Avatar(cpSpace *space, cpBody *body, cpShape *shape)
: Entity(space, body, shape)
{
- thrust = 900.0;
+ thrust = 900.0f;
uFrict = 0.03f;
}
~Avatar() {}
- /*void Update()
- {
- ApplyFriction();
- }*/
-
void Thrust(cpVect dir)
{
+ //***this should be replaced with a more sophisticated function which just resets the thrust force
cpBodyResetForces(myBody);
+
+ thrustForce = cpvmult(cpvnormalize(dir), thrust);
if(cpvlength(dir) != 0) {
- Move(cpvmult(cpvnormalize(dir), thrust));
- //cpBodyApplyForce(myBody, cpvmult(cpvnormalize(dir), thrust), cpvzero);
+ cpBodyApplyForce(myBody, thrustForce, cpvzero);
}
}
private:
- /*cpBody* myBody;
- cpFloat thrust;
- cpFloat uFrict;*/
-
- /*void ApplyFriction()
- {
- cpVect vel = myBody->v;
- cpVect dir = cpvnormalize(cpvneg(vel));
- cpFloat mag = cpvlength(vel) * uFrict;
-
- if(mag != 0) Move(cpvmult(dir, mag));
- }*/
-
- /*void Move(cpVect force)
- {
- cpBodyApplyImpulse(myBody, force, cpvzero);
- }*/
+ cpVect thrustForce;
};
@@ -73,7 +54,7 @@ class Thrust_Command : public Input_Command
void handle(SDL_Event *e)
{
- bool keydown = e->type == SDL_KEYDOWN;
+ bool keydown = (e->type == SDL_KEYDOWN);
SDLKey key = e->key.keysym.sym;
if(key == events[0].key.keysym.sym) {//up
View
9 soylent/GoD/entity.h
@@ -1,8 +1,11 @@
#ifndef __ENTITY_H__
#define __ENTITY_H__
+#include <iostream>
+
#include "chipmunk.h"
+//An entity is an object with a shape and body which exists in a space. It applies friction to itself.
class Entity
{
public:
@@ -13,7 +16,7 @@ class Entity
cpSpaceAddBody(space, myBody);
cpSpaceAddShape(space, shape);
- thrust = 900.0;
+ thrust = 900.0f;
uFrict = 0.03f;
}
~Entity() {}
@@ -34,10 +37,10 @@ class Entity
cpVect dir = cpvnormalize(cpvneg(vel));
cpFloat mag = cpvlength(vel) * uFrict;
- if(mag != 0) Move(cpvmult(dir, mag));
+ if(mag != 0) Impulse(cpvmult(dir, mag));
}
- void Move(cpVect force)
+ void Impulse(cpVect force)
{
cpBodyApplyImpulse(myBody, force, cpvzero);
}
View
5 soylent/GoD/main.cpp
@@ -3,6 +3,7 @@
#include <math.h>
#include <iostream>
#include <vector>
+#include <list>
#ifdef WIN32
#include <windows.h>
@@ -28,6 +29,7 @@ cpSpace *space;
cpBody *staticBody;
Avatar *avatar;
+Entity **entities;
Input_Manager *inputManager;
FTFont *font;
@@ -102,6 +104,7 @@ void setup()
// shape = cpCircleShapeNew(body, 10.0, cpvzero);
shape->e = 0.0f; shape->u = 0.04f;
cpSpaceAddShape(space, shape);
+
}
//Avatar
@@ -275,7 +278,7 @@ void draw()
cpSpaceHashEach(space->activeShapes, &drawObject, NULL);
cpSpaceHashEach(space->staticShapes, &drawObject, NULL);
- glColor3f(0.0, 0.0, 0.0);
+ glColor3f(0.0f, 0.0f, 1.0f);
glLoadIdentity();
glTranslatef(-SCREEN_WIDTH/2.1f, -SCREEN_HEIGHT/2.1f, 0.0f);
std::string text;
Please sign in to comment.
Something went wrong with that request. Please try again.