Exemplo n.º 1
0
/*********************************************
* CALLBACK
* The main interaction loop of the engine.
* This gets called from OpenGL.  It give us our
* interface pointer (where we get our events from)
* as well as a void pointer which we know is our
* game class.
*********************************************/
void callBack(const Interface *pUI, void *p)
{
	// we know the void pointer is our game class so
	// cast it into the game class.
	Gun *pGun = (Gun *)p;

	// check the paddle
	pGun->move(pUI->isUp(), pUI->isDown());

	// draw it
	pGun->draw();
}
Exemplo n.º 2
0
void Player::draw() {
	Image::draw();
	Item* activeItem = inventory->getActiveItem()->getItem();
	if (activeItem->getItemType() == Item::Equipable) {
		Gun* gun = (Gun*)activeItem;
		gun->draw();
	}
	OSD::instance()->addLine("Player is at (" + std::to_string(topLeft.x) + ", " + std::to_string(topLeft.y) + ") Can Jump: " + std::to_string(canJump) + " | Can Fall: " + std::to_string(canFall) + " | Jumping: " + std::to_string(jumping) + " | Falling: " + std::to_string(falling));
	OSD::instance()->addLine("(" + std::to_string(int(topLeft.x)) + ", " + std::to_string(int(topLeft.y)) + ") ---- (" + std::to_string(int(topRight.x)) + ", " + std::to_string(int(topRight.y)) + ")");
	OSD::instance()->addLine("     |     ----     |  ");
	OSD::instance()->addLine("(" + std::to_string(int(bottomLeft.x)) + ", " + std::to_string(int(bottomRight.y)) + ") ---- (" + std::to_string(int(bottomRight.x)) + ", " + std::to_string(int(bottomRight.y)) + ")");

}
Exemplo n.º 3
0
int main()
{
	init();

	resetTicks();

	bool end = false;
	list<Thing*>::iterator it;

	Gun *gun = new Gun();
	Scoreboard *sb = new Scoreboard();

	level = 4.0;
	int prev_button = 0;

	while(!end)
	{
		if (ticks > 0)
		{
			while(ticks-- > 0)
			{
				if (randomFloat(0, 48 - level) < 1.0)
				{
					if (randomInt(0, 15) == 0)
						world.push_back(new Bonus(randomInt(20, 620), level * randomFloat(0.99, 1.05)));
					else
						world.push_back(new Baddie(randomInt(20, 620), level * randomFloat(0.99, 1.05)));
				}

				for(it = world.begin(); it != world.end(); it++)
					(*it)->update();

				for(it = world.begin(); it != world.end();)
				{
					if (!(*it)->isAlive())
					{
						delete (*it);
						it = world.erase(it);
					}
					else
					{
						it++;
					}
				}
				gun->update();

				if (key[KEY_ESC])
				{
					end = true;
				}
				end |= (hp <= 0);

				level += 0.0012;

				if ((mouse_b == 1) && (mouse_b != prev_button) && (ammo > 0))
				{
					ammo--;
					for(it = world.begin(); it != world.end(); it++)
						(*it)->shootAt(mouse_x, mouse_y);
				}
				if ((mouse_b == 2) && (mouse_b != prev_button))
				{
					ammo = 6;
					score -= 250;
				}

				prev_button = mouse_b;
			}
		}

		clear_bitmap(buffer);
		for(it = world.begin(); it != world.end(); it++)
			(*it)->draw();
		gun->draw();
		sb->draw();

		blit(buffer, screen, 0, 0, 0, 0, 640, 480);
	}

	clear_bitmap(screen);
	textprintf_centre_ex(screen, font, 320, 220, makecol(255, 0, 0), -1, "G A M E    O V E R");
	textprintf_centre_ex(screen, font, 320, 240, makecol(255, 255, 255), -1, "Final score: %d", score);
	textprintf_centre_ex(screen, font, 320, 260, makecol(255, 255, 0), -1, "Press both mouse buttons to exit");

	while (mouse_b);
	while (mouse_b != 3);

	destroy();
}