76388/Actor.cpp
#include "Actor.h"
#include "StudentWorld.h"
using namespace std;
Actor::Actor( StudentWorld* world, int imageID, int startX, int startY, int startDirection, double size, int depth,
bool alive, int health, bool avoidanceWorthy, int yVel, int xVel )
: GraphObject(imageID, startX, startY, startDirection, size, depth),
m_world(world), m_alive(alive), m_health(health), m_avoidanceWorthy(avoidanceWorthy),
m_yVel(yVel), m_xVel(xVel)
{
}
void Actor::doSomething()
{
if (! isAlive())
{
return;
}
doSomethingSpecializedA();
moveActor();
doSomethingSpecializedB();
}
void Actor::moveActor()
{
int vert_speed = getYVelocity() - getWorld()->getRacer()->getYVelocity();
int horiz_speed = getXVelocity();
double new_y = getY() + vert_speed;
double new_x = getX() + horiz_speed;
moveTo(new_x, new_y);
if (getY() < 0 || getX() < 0 || getX() > VIEW_WIDTH || getY() > VIEW_HEIGHT)
{
setAliveSatus(false);
return;
}
}
void Actor::damageActor(int soundHurt, int soundDead, int direction, int damage)
{
changeHealth(damage);
if(getHealth() <= 0)
{
setAliveSatus(false);
getWorld()->playSound(soundDead);
specializedDamageA();
}
setDirection(direction);
getWorld()->playSound(soundHurt);
specializedDamageB();
}
GhostRacer::GhostRacer( StudentWorld* world, int imageID, int startX, int startY, int startDirection, double size, int depth,
bool alive, int health, bool avoidanceWorthy, int yVel, int xVel,
int sprays )
: Actor(world, imageID, startX, startY, startDirection, size, depth, alive, health, avoidanceWorthy, yVel, xVel),
m_sprays(sprays)
{
}
void GhostRacer::doSomethingSpecializedA()
{
int ch;
if (getX() <= LEFT_EDGE)
{
if (getDirection() > FACING_STRAIGHT)
damageActor(SOUND_VEHICLE_CRASH, SOUND_PLAYER_DIE, FACING_STRAIGHT - INCREMENT_DIR, HP_LOSS_HIT_EDGE);
}
else if (getX() >= RIGHT_EDGE)
{
if (getDirection() < FACING_STRAIGHT)
damageActor(SOUND_VEHICLE_CRASH, SOUND_PLAYER_DIE, FACING_STRAIGHT + INCREMENT_DIR, HP_LOSS_HIT_EDGE);
}
else if (getWorld()->getKey(ch))
{
switch (ch)
{
case KEY_PRESS_SPACE:
if (getSprays() >= 1)
{
}
break;
case KEY_PRESS_LEFT:
if (getDirection() < FACING_STRAIGHT + 3 * INCREMENT_DIR)
setDirection(getDirection() + INCREMENT_DIR);
break;
case KEY_PRESS_RIGHT:
if (getDirection() > FACING_STRAIGHT - 3 * INCREMENT_DIR)
setDirection(getDirection() - INCREMENT_DIR);
break;
case KEY_PRESS_UP:
if (getYVelocity() < MAX_RACER_VEL)
changeYVel(1);
break;
case KEY_PRESS_DOWN:
if (getYVelocity() > MIN_RACER_VEL)
changeYVel(-1);
break;
}
}
}
void GhostRacer::moveActor()
{
double max_shift_per_tick = 4.0;
double direction = degreesToRad(getDirection());
double delta_x = cos(direction) * max_shift_per_tick;
double cur_x = getX();
double cur_y = getY();
moveTo(cur_x + delta_x, cur_y);
}
BorderLine::BorderLine( StudentWorld* world, int imageID, int startX, int startY, int startDirection, double size, int depth,
bool alive, int health, bool avoidanceWorthy, int yVel, int xVel )
: Actor(world, imageID, startX, startY, startDirection, size, depth, alive, health, avoidanceWorthy, yVel, xVel)
{
}
Pedestrian::Pedestrian( StudentWorld* world, int startX, int startY, int imageID, int startDirection, double size, int depth,
bool alive, int health, bool avoidanceWorthy, int yVel, int xVel, int movePlan )
: Actor(world, imageID, startX, startY, startDirection, size, depth, alive, health, avoidanceWorthy, yVel, xVel),
m_movePlan(movePlan)
{
}
void Pedestrian::doSomethingSpecializedA()
{
if (getWorld()->doesOverlap(this, getWorld()->getRacer()))
{
setAliveSatus(false);
getWorld()->getRacer()->setAliveSatus(false);
return;
}
}
void Pedestrian::doSomethingSpecializedB()
{
changeMovePlan(-1);
if (getMovePlan() > 0)
{
return;
}
const int nSpeeds = 6;
const int possibleXVels[nSpeeds] = { -3, -2, -1, 1, 2, 3 };
int randIndex = randInt(0, nSpeeds - 1);
setXVelocity(possibleXVels[randIndex]);
setMovePlan(randInt(4, 32));
if (getXVelocity() < 0)
{
setDirection(180);
}
else if (getXVelocity() > 0)
{
setDirection(0);
}
}
ZombiePedestrian::ZombiePedestrian( StudentWorld* world, int startX, int startY, int imageID, int startDirection, double size, int depth,
bool alive, int health, bool avoidanceWorthy, int yVel, int xVel, int movePlan, int nextGrunt )
: Pedestrian(world, startX, startY, imageID, startDirection, size, depth, alive, health, avoidanceWorthy, yVel, xVel, movePlan),
m_tickToNextGrunt(nextGrunt)
{
}
76388/GameController.cpp
#include "freeglut.h"
#include "GameController.h"
#include "GameWorld.h"
#include "GameConstants.h"
#include "GraphObject.h"
#include "SoundFX.h"
#include "SpriteManager.h"
#include
#include