|
|
@ -33,6 +33,7 @@ GameScreen::GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, std::map
|
|
|
|
void GameScreen::reset() {
|
|
|
|
void GameScreen::reset() {
|
|
|
|
ship.set_sprite(sprites["Ship"]);
|
|
|
|
ship.set_sprite(sprites["Ship"]);
|
|
|
|
ship.reset_pos(SCREEN_W / 2, SCREEN_H / 8);
|
|
|
|
ship.reset_pos(SCREEN_W / 2, SCREEN_H / 8);
|
|
|
|
|
|
|
|
max_bullets = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//If a sample needs to be played while it is still being played, it will be stopped first.
|
|
|
|
//If a sample needs to be played while it is still being played, it will be stopped first.
|
|
|
@ -66,6 +67,7 @@ void GameScreen::run(ALLEGRO_FONT* font) {
|
|
|
|
ALLEGRO_EVENT ev;
|
|
|
|
ALLEGRO_EVENT ev;
|
|
|
|
al_wait_for_event(event_queue, &ev);
|
|
|
|
al_wait_for_event(event_queue, &ev);
|
|
|
|
if (ev.type == ALLEGRO_EVENT_TIMER) { //Check per frame
|
|
|
|
if (ev.type == ALLEGRO_EVENT_TIMER) { //Check per frame
|
|
|
|
|
|
|
|
//Ship Movement
|
|
|
|
if (keys[KEYUP]) {
|
|
|
|
if (keys[KEYUP]) {
|
|
|
|
if (keys[KEYRIGHT]) {
|
|
|
|
if (keys[KEYRIGHT]) {
|
|
|
|
ship.move(UR);
|
|
|
|
ship.move(UR);
|
|
|
@ -95,6 +97,13 @@ void GameScreen::run(ALLEGRO_FONT* font) {
|
|
|
|
ship.move(R);
|
|
|
|
ship.move(R);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Firing
|
|
|
|
|
|
|
|
if (keys[KEYSPACE]) {
|
|
|
|
|
|
|
|
if (bullets.size() < max_bullets) {
|
|
|
|
|
|
|
|
bullets.push_back(ship.fire());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Global refresh
|
|
|
|
//Global refresh
|
|
|
|
al_clear_to_color(al_map_rgb(0, 0, 0));
|
|
|
|
al_clear_to_color(al_map_rgb(0, 0, 0));
|
|
|
|
redraw(font);
|
|
|
|
redraw(font);
|
|
|
@ -177,6 +186,19 @@ void GameScreen::run(ALLEGRO_FONT* font) {
|
|
|
|
//Redraw all elements of the screen
|
|
|
|
//Redraw all elements of the screen
|
|
|
|
void GameScreen::redraw(ALLEGRO_FONT* font) {
|
|
|
|
void GameScreen::redraw(ALLEGRO_FONT* font) {
|
|
|
|
ship.draw();
|
|
|
|
ship.draw();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<int> unload;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < bullets.size(); i++) {
|
|
|
|
|
|
|
|
if (bullets.at(i).oob) {
|
|
|
|
|
|
|
|
unload.push_back(i);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bullets.at(i).move(U);
|
|
|
|
|
|
|
|
bullets.at(i).draw();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < unload.size(); i++) {
|
|
|
|
|
|
|
|
int x = unload.at(i);
|
|
|
|
|
|
|
|
bullets.erase(bullets.begin() + x);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GameScreen::back() {
|
|
|
|
void GameScreen::back() {
|
|
|
|