/// ***** Constructors/Destructors *****
GravityWell::GravityWell(const Vector2& pos)
- : position(pos)
+ : m_position(pos)
{
}
const Vector2& pos = e->positionRaw();
float mass = e->m_mass;
- Vector2 delta = position - pos;
+ Vector2 delta = m_position - pos;
float sqrDist = delta.sqrLength();
Vector2 acc(0,0);
void GravityWell::setPosition(const Vector2& pos)
{
- position = pos;
+ m_position = pos;
}
void setPosition(const Vector2&);
private:
- Vector2 position;
+ Vector2 m_position;
};
#endif // GRAVITYWELL_H
void Ball::draw() const
{
- graphics::drawCircle(m_radius, position, m_color);
+ graphics::drawCircle(m_radius, m_position, m_color);
}
float Ball::getRadius() const
/// ***** Constructors/Destructors *****
Entity::Entity(const Vector2& pos)
- : position(pos), velocity(0,0)
+ : m_position(pos), m_velocity(0,0)
{
}
const Vector2& Entity::positionRaw() const
{
- return position;
+ return m_position;
}
const Vector2& Entity::velocityRaw() const
{
- return velocity;
+ return m_velocity;
}
const Vector2& velocityRaw() const;
protected:
- Vector2 position;
- Vector2 velocity;
+ Vector2 m_position;
+ Vector2 m_velocity;
};
#endif // ENTITY_H
m_lifeTime -= time_step;
m_isDead = m_lifeTime <= 0;
}
- position += velocity * time_step;
+ m_position += m_velocity * time_step;
}
void PhysicsEntity::update(float time_step)
{
- position = positionAt(time_step);
- velocity = velocityAt(time_step);
+ m_position = positionAt(time_step);
+ m_velocity = velocityAt(time_step);
m_force *= 0;
}
Vector2 PhysicsEntity::positionAt(float time_step) const
{
- Vector2 newPosition = position;
- Vector2 newVelocity = velocity;
+ Vector2 newPosition = m_position;
+ Vector2 newVelocity = m_velocity;
Vector2 newForce = m_force;
newPosition += effect::positionDelta(this, time_step);
Vector2 PhysicsEntity::velocityAt(float time_step) const
{
Vector2 newForce = m_force;
- Vector2 newVelocity = velocity;
+ Vector2 newVelocity = m_velocity;
newForce += effect::forceDelta(this, time_step);
newVelocity += effect::velocityDelta(this, time_step);
void PhysicsEntity::applyForce(const Vector2& force)
{
- applyForce(force, position);
+ applyForce(force, m_position);
}
void PhysicsEntity::applyForce(const Vector2& force, const Vector2& /*at*/)
{
void PhysicsEntity::applyImpulse(const Vector2& impulse)
{
- applyImpulse(impulse, position);
+ applyImpulse(impulse, m_position);
}
void PhysicsEntity::applyImpulse(const Vector2& impulse, const Vector2& /*at*/)
{
- velocity += impulse;
+ m_velocity += impulse;
}
void PhysicsEntity::applyNudge(const Vector2& vecPush)
{
- position += vecPush;
+ m_position += vecPush;
}
/// ***** Constructors/Destructors *****
Point::Point(const Vector2& org, bool canDie)
- : Particle(org, canDie), radius(2)
+ : Particle(org, canDie), m_radius(2)
{
}
Point::Point(const Vector2& org, float life_time)
- : Particle(org, life_time), radius(2)
+ : Particle(org, life_time), m_radius(2)
{
}
virtual void draw();
protected:
- float radius;
+ float m_radius;
// color
};
virtual void update(float);
protected:
- float radius;
+ float m_radius;
// color
};
void input::init()
{
+ // default all keys to released
for(int i=0; i< keySize; i++)
+ {
keyState[i] = isR;
+ }
}
void input::clean()
{
{
SDL_Event event;
- for(int i=0; i< keySize; i++)
+ for(int i=0; i < keySize; i++)
{
- if(keyState[i] == wasR)
- keyState[i] = isR;
- else if(keyState[i] == wasP)
- keyState[i] = isP;
+ State newKeyState;
+
+ switch(keyState[i])
+ {
+ case isR: newKeyState = isR; break;
+ case wasR: newKeyState = isR; break;
+ case isP: newKeyState = isP; break;
+ case wasP: newKeyState = isP; break;
+ default: DASSERT(false); return;
+ }
+
+ keyState[i] = newKeyState;
}
while(0 < SDL_PeepEvents(&event, 1, SDL_GETEVENT, eventMask))
{
switch(event.type)
{
- case SDL_KEYUP:
- keyState[event.key.keysym.sym] = wasR;
- break;
- case SDL_KEYDOWN:
- keyState[event.key.keysym.sym] = wasP;
- break;
- case SDL_QUIT:
- keyState[key::end] = wasR;
- break;
- default:
- break;
+ case SDL_KEYUP:
+ keyState[event.key.keysym.sym] = wasR;
+ break;
+ case SDL_KEYDOWN:
+ keyState[event.key.keysym.sym] = wasP;
+ break;
+ case SDL_QUIT:
+ // HACK: simulate an SDL_QUIT event as an ESC key press
+ keyState[key::end] = wasR;
+ break;
+ default:
+ break; // somthing I don't care about
}
}
}