Пример #1
0
void Astroid::update(sf::Time * delta_time) {
	Entity::update();
	setXVelocity(cos(getAngle() * kDegreesToRadians) * delta_time->asSeconds());
	setYVelocity(cos(getAngle() * kDegreesToRadians) * delta_time->asSeconds());

	move(getXVelocity(), getYVelocity());
}
Пример #2
0
// If Star moved off screen, move back to far right.
void Star::out() {
  WorldManager &world_manager = WorldManager::getInstance();
  Position pos(world_manager.getBoundary().getHorizontal() + random()%20,
	       random() % world_manager.getBoundary().getVertical());
  setPosition(pos);
  setXVelocity(-1.0 / (random()%10 + 1));
}
Пример #3
0
Saucer::Saucer() {
  df::LogManager &log_manager = df::LogManager::getInstance();
  df::ResourceManager &resource_manager = df::ResourceManager::getInstance();
  df::WorldManager &world_manager = df::WorldManager::getInstance();

  // Setup "saucer" sprite.
  df::Sprite *p_temp_sprite = resource_manager.getSprite("saucer");
  if (!p_temp_sprite) {
    log_manager.writeLog("Saucer::Saucer(): Warning! Sprite '%s' not found",
			 "saucer");
  } else {
    setSprite(p_temp_sprite);
    setSpriteSlowdown(4);
  }

  // Set object type.
  setType("Saucer");

  // Set speed in horizontal direction.
  setXVelocity(-0.25); // 1 space left every 4 frames

  // Move Saucer to start location.
  moveToStart();
  // Register interest in "nuke" event.
  registerInterest(NUKE_EVENT);
  Role &role = Role::getInstance();
  if(role.isHost()) {
    Role &role = Role::getInstance();
    role.registerSyncObj(this);
  }
}
Пример #4
0
Saucer::Saucer()
{
    // Dragonfly managers needed for this method.
    df::LogManager &log_manager = df::LogManager::getInstance();
    df::ResourceManager &resource_manager = df::ResourceManager::getInstance();
    df::WorldManager &world_manager = df::WorldManager::getInstance();

    // Setup "saucer" sprite.
    df::Sprite *p_temp_sprite = resource_manager.getSprite("saucer");
    if (!p_temp_sprite) {
        log_manager.writeLog("Saucer::Saucer(): Warning! Sprite '%s' not found", "saucer");
    } else {
        setSprite(p_temp_sprite);
        setSpriteSlowdown(4);		
    }

    // Set object type.
    setType("Saucer");

    // Set speed in horizontal direction.
    setXVelocity(-0.25); // 1 space left every 4 frames

    /*
    // Set starting location in the middle of window.
    int world_horiz = world_manager.getBoundary().getHorizontal();
    int world_vert = world_manager.getBoundary().getVertical();
    df::Position pos(world_horiz/2, world_vert/2);
    setPosition(pos);*/

    moveToStart();
}
Пример #5
0
void Ghost::move_to_hero() {
	WorldManager &wm = WorldManager::getInstance();
	Position pos = getPosition();

	if (abs(pos.getX() - hero_pos.getX()) > abs(pos.getY() - hero_pos.getY())) {
		if (pos.getX() > hero_pos.getX()) {
			setXVelocity(-GHOST_VELOCITY);
		} else if (pos.getX() < hero_pos.getX()) {
			setXVelocity(GHOST_VELOCITY);
		}
	} else if (pos.getY() > hero_pos.getY()) {
		setYVelocity(-GHOST_VELOCITY);
	} else {
		setYVelocity(GHOST_VELOCITY);
	}
}
Пример #6
0
// overloaded constructor to take in initial velocity and position
Ball::Ball(float xVelocity, float yVelocity, df::Position pos){
	setType("Ball");
	setXVelocity(xVelocity);
	setYVelocity(yVelocity);
	setSolidness(df::HARD);
	setPosition(pos);
}
Пример #7
0
Shell::Shell()
{
	setKillsBottom(true);
	setKillsSide(true);
	setKillsTop(false);
	setPoints(0);
	setXVelocity(2.0);
	setYVelocity(0.0);
}
Пример #8
0
Mushroom::Mushroom()
{
	setKillsBottom(false);
	setKillsSide(false);
	setKillsTop(false);
	setPoints(0);
	setXVelocity(2.0);
	setYVelocity(0.0);
}
Пример #9
0
Star::Star()
{
	setKillsBottom(false);
	setKillsSide(false);
	setKillsTop(false);
	setPoints(0);
	setXVelocity(2.0);
	setYVelocity(0.0);
}
Пример #10
0
EnemyFireball::EnemyFireball()
{
	setKillsBottom(true);
	setKillsSide(true);
	setKillsTop(true);
	setPoints(0);
	setXVelocity(0.0);
	setYVelocity(0.0);
}
Пример #11
0
Star::Star() {
  setType("Star");
  setSolidness(SPECTRAL);
  setXVelocity(-1.0 / (random()%10 + 1));
  setAltitude(0);	// Make them in the background.
  WorldManager &world_manager = WorldManager::getInstance();
  Position pos(random()%world_manager.getBoundary().getHorizontal(),
	       random()%world_manager.getBoundary().getVertical());
  setPosition(pos);
}
Пример #12
0
void Star::out(){
	df::WorldManager &world_manager = df::WorldManager::getInstance();

	setXVelocity((float)(-1.0 / (rand() % 10 + 1)));
	df::Position newPos(
		world_manager.getBoundary().getHorizontal() + 1,
		rand()%world_manager.getBoundary().getVertical());

	setPosition(newPos);
}
Пример #13
0
Star::Star() {
	setType("Star");
	setSolidness(df::SPECTRAL);
	setXVelocity((float)(-1.0 / (rand() % 10 + 1)));
	setAltitude(0);
	df::WorldManager &world_manager = df::WorldManager::getInstance();
	df::Position pos(rand() % world_manager.getBoundary().getHorizontal(),
		rand() % world_manager.getBoundary().getVertical());
	setPosition(pos);
}
Пример #14
0
Wall::Wall(){
	pos = Position(0,0);
	this->setPosition(pos);
	setXVelocity(0.5);
	ResourceManager &rm = ResourceManager::getInstance();
	Sprite *p_temp_sprite;
	p_temp_sprite = rm.getSprite("bullet");
	setSprite(p_temp_sprite);


}
Пример #15
0
Plant::Plant()
{
	setKillsBottom(true);
	setKillsSide(true);
	setKillsTop(true);
	setPoints(0);
	setXVelocity(0.0);
	setYVelocity(1.0);
    count_ = 720;
    sprite();
}
Пример #16
0
Turtle::Turtle()
{
	setKillsBottom(true);
	setKillsSide(true);
	setKillsTop(false);
	setPoints(0);
	setXVelocity(-0.5);
	setYVelocity(0.0);
    
    sprite();
    
    }
Пример #17
0
int ExampleObject::eventHandler(Event *p_event)
{
	auto& gameManager = GameManager::getInstance();
	auto& logManager = LogManager::getInstance();
	auto& worldManager = WorldManager::getInstance();

	if (p_event->getType() == DF_STEP_EVENT)
	{
		logManager.writeLog("ExampleObject: Step Event processed.\n");

		if (getPosition().getX() == 30)
		{
			//gameManager.setGameOver();
			logManager.writeLog("ExampleObject: X position reached 30. Requested to end game.\n");
		}
	}
	else if (p_event->getType() == DF_OUT_EVENT)
	{
		logManager.writeLog("ExampleObject: Out Event processed.\n");
		setPosition(Position(40, getPosition().getY()));
	}
	else if (p_event->getType() == DF_KEYBOARD_EVENT)
	{
		logManager.writeLog("ExampleObject: Keyboard Event processed.\n");
		EventKeyboard *p_keyboard_event = static_cast <EventKeyboard *> (p_event);
		switch (p_keyboard_event->getKey())
		{
		case KEY_RIGHT:		// up arrow
			setXVelocity(abs(getXVelocity()));
			break;
		case KEY_LEFT:		// down arrow
			setXVelocity(-abs(getXVelocity()));
			break;
		};
		return 1;
	}

	return 0;
}
Пример #18
0
void
KbfxPlasmaCanvasItem::advance ( int phase )
{
	if ( phase == 0 )
	{
		setXVelocity ( 0 );
		setYVelocity ( yVelocity () * 1 - 0.001 );
	}
	else
	{
		move ( x () + xVelocity (), y () + yVelocity () );
	}
}
Пример #19
0
void Platform::step(EventStep *p_s)
{
	// move left and right

	if (move_countdown < 0)
	{

		setXVelocity(getXVelocity() * -1);
		setYVelocity(getYVelocity() * -1);
		move_countdown = 50;
	}

	move_countdown--;
}
Пример #20
0
// Handle event (default is to ignore everything).
// Return 0 if ignored, else 1 if handled.
int Bus::eventHandler(df::Event *p_e){
	
	// if out of bounds then end game
	if (p_e->getType() == DF_OUT_EVENT){
		df::GameManager::getInstance().setGameOver();
		return 1;
	}

	// if the space key is pressed then set the velocity of the bus to start moving
	else if (p_e->getType() == df::DF_KEYBOARD_EVENT && ((df::EventKeyboard *) p_e)->getKeyboardAction() == df::EventKeyboardAction::KEY_PRESSED && ((df::EventKeyboard *) p_e)->getKey() == df::Input::SPACE){
		setXVelocity(-0.1);
		return 1;
	}
	return 0;
}
Пример #21
0
Bullet::Bullet(Position hero_pos, int velocityX, int velocityY, int typee) {

	// Set object properties.
	setType("Bullet");
	setXVelocity(velocityX);// move 1 space right every frame
	setYVelocity(velocityY);
	type = typee;
	auto& resMgr = ResourceManager::getInstance();
	if (type == 1)
	{
		setSprite(resMgr.getSprite("bullet1"));
	}
	else if (type == 2)
	{
		setSprite(resMgr.getSprite("bullet-left"));
	}
	else if (type == 3)
	{
		setSprite(resMgr.getSprite("bullet-right"));
	}

	setSpriteSlowdown(4);
	// Set object type.
	setBox(Box(Position(0, 0), getSprite()->getWidth(), getSprite()->getHeight()));
	Position pos1;

	// Set starting location, based on hero's position passed in.
	if (velocityY == 0)
	{

		Position pos(hero_pos.getX() + 3 * velocityX, hero_pos.getY());
		pos1 = pos;
	}
	if (velocityX == 0 )
	{
		Position pos(hero_pos.getX(), hero_pos.getY() + 3 * velocityY);
		pos1 = pos;
	}
	
  
  setPosition(pos1);
}
Пример #22
0
Platform::Platform()
{
	setType("Platform");
	isItThick = false;
	size = 50;
	setSolidness(HARD);
	setXVelocity(0.0);
	setYVelocity(0.0);
	setAltitude(3);	// Make them in the background.
	WorldManager &world_manager = WorldManager::getInstance();
	//Position pos(random() % world_manager.getBoundary().getHorizontal(),
	//	random() % world_manager.getBoundary().getVertical());
	Position pos(0, 15);
	setPosition(pos);
	height = 5;
	setBox(Box(Position(), size, height));
	thecolor = rand() % 7;



}
Пример #23
0
Platform::Platform(bool thickness, int sizee, int heightt, int x, int y, float x_speed, float y_speed)
{
	setType("Platform");
	isItThick = thickness;
	size = sizee;
	setSolidness(HARD);
	setXVelocity(x_speed);
	move_countdown = 10;
	setYVelocity(y_speed);
	setAltitude(3);	// Make them in the background.
	WorldManager &world_manager = WorldManager::getInstance();
	//Position pos(random() % world_manager.getBoundary().getHorizontal(),
	//	random() % world_manager.getBoundary().getVertical());
	Position pos(x, y);
	setPosition(pos);
	height = heightt;
	setBox(Box(Position(), size, height));
	thecolor = rand() % 7;



}
void EnemyTank::step() {
    // Fire countdown.
    fire_countdown--;
    if (fire_countdown < 0)
        fire_countdown = 0;

    // Move countdown.
    move_countdown--;
    if (move_countdown < 0)
        move_countdown = 0;

    //Move towards player
    if (getPosition().getX() < player->getPosition().getX()) {
        move(1);
    }
    else if (getPosition().getX() > player->getPosition().getX()) {
        move(-1);
    }
    else {
        setXVelocity(0);
    }
}
Пример #25
0
Saucer::Saucer()
{
	LogManager &log_manager = LogManager::getInstance();
	auto& resMgr = ResourceManager::getInstance();

	setSprite(resMgr.getSprite("saucer"));
	// Set object type.
	setType("Saucer");
	setBox(Box(Position(0, 0), getSprite()->getWidth(), getSprite()->getHeight()));

	// Set speed in vertical direction.
	setXVelocity(-0.25);		// 1 space every 4 frames
	setSpriteSlowdown(4);
	moveToStart();



#ifdef REGISTER
	// Register interest in "nuke" event.
	registerInterest(NUKE_EVENT);
#endif 
}
Пример #26
0
Bullet::Bullet(Position hero_pos, int velocityX) {

	// Set object properties.
	setType("Bullet");
	setXVelocity(velocityX);// move 1 space right every frame
	//setYVelocity(velocityY);
	type = 0;
	auto& resMgr = ResourceManager::getInstance();
	setSprite(resMgr.getSprite("bullet"));
	setSpriteSlowdown(4);
	// Set object type.
	setBox(Box(Position(0, 0), getSprite()->getWidth(), getSprite()->getHeight()));

	// Set starting location, based on hero's position passed in.
	//if (velocityY == 0 && velocityX != 0)
		Position pos(hero_pos.getX() + 3 * velocityX, hero_pos.getY());
	//if (velocityY != 0 && velocityX == 0)
	//	Position pos(hero_pos.getX(), hero_pos.getY() + 3 * velocityY);
	//if (velocityY != 0 && velocityX != 0)
	//	Position pos(hero_pos.getX() + 3 * velocityX, hero_pos.getY() + 3 * velocityY);

	setPosition(pos);
}
Пример #27
0
void BallConfigItem::addParameter(std::string name, double value)
{
    if (name == "xCoordinate") {
        setXCoordinate(value);
    } else if (name == "yCoordinate") {
        setYCoordinate(value);
    } else if (name == "radius") {
        setRadius(value);
    } else if (name == "xVelocity") {
        setXVelocity(value);
    } else if (name == "yVelocity") {
        setYVelocity(value);
    } else if (name == "colorHue") {
        if (value < 0 || value > 1) {
            std::cout << "Hue value out of bounds [0,1] when creating a ball." << std::endl;
            exit(0);
        }
        setHue(value);
    } else {
        // Unrecognised parameter.
        std::cout << "Unrecognised parameter when creating a ball: " + name << std::endl;
        exit(0);
    }
}
Пример #28
0
void GLObject::setVelocity(GLfloat vx, GLfloat vy, GLfloat vz)
{
	setXVelocity(vx);
	setYVelocity(vy);
	setZVelocity(vz);
}