// Render the entire screen // (in the right order) void render() { // Lock video surface (if needed) if (SDL_MUSTLOCK(screen)) if (SDL_LockSurface(screen) < 0) return; // Draw game objects to the screen draw_walls(screen, wal); draw_player(screen, &plr); draw_bots(screen, bot); draw_bullets(screen, bul); // Health bar int y, x; x = DISPLAY_WIDTH - 10 - plr.max_hp; for (y = DISPLAY_HEIGHT - 20; y < DISPLAY_HEIGHT - 10; y++) { put_line(screen, x, y, x + plr.hp, y, HEALTH_COLOR_GOOD); put_line(screen, x + plr.hp, y, DISPLAY_WIDTH - 10, y, HEALTH_COLOR_BAD); } // Unlock screen (if needed) if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); // Tell SDL to update the whole screen SDL_UpdateRect(screen, 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT); }
uint32_t tank8_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { set_pens(); m_tilemap->draw(screen, bitmap, cliprect, 0, 0); draw_sprites(bitmap, cliprect); draw_bullets(bitmap, cliprect); return 0; }
bool zodiack_state::screen_update( screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect ) { for (int i = 0; i < 32; i++) tilemap_set_scrolly(m_fg_tilemap, i, m_attributeram[i * 2]); tilemap_draw(&bitmap, &cliprect, m_bg_tilemap, 0, 0); tilemap_draw(&bitmap, &cliprect, m_fg_tilemap, 0, 0); draw_bullets(&bitmap, &cliprect); draw_sprites(&bitmap, &cliprect); return 0; }
void episode_game::draw() { glColor3f(1.f,1.f,1.f); _background.draw(); //glEnable(GL_BLEND); //glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); //glShadeModel(GL_FLAT); draw_enemies(); draw_main_character(); draw_bullets(); // draw explosions for(auto it = _explosions.begin(); it!=_explosions.end();++it) { (*it)->draw(); } if(_character_explosion!=NULL) { _character_explosion->draw(); } // bomb if(_bomb!=NULL) { _bomb->draw(); } //glDisable(GL_BLEND); // energy _energy->draw(); }
/* draws the entire view */ void draw_view() { int SCREEN_W = al_get_display_width(); int SCREEN_H = al_get_display_height(); int (*project)(float *f, int *i, int c); int r, g, b; ALLEGRO_COLOR c; int i, n, x, y; float point[6]; int ipoint[6]; al_clear_to_color(makecol(0, 0, 0)); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE, al_map_rgba_f(1, 1, 1, 1)); for (i=0; i<4; i++) { view_left = viewinfo[i].pos[0] * SCREEN_W; view_top = viewinfo[i].pos[1] * SCREEN_H; view_right = viewinfo[i].pos[2] * SCREEN_W; view_bottom = viewinfo[i].pos[3] * SCREEN_H; if ((view_right > view_left) && (view_bottom > view_top) && (view_right > 0) && (view_bottom > 0) && (view_left < SCREEN_W) && (view_top < SCREEN_H)) { switch (i) { case 0: /* flat projection, green */ project = project_flat; r = 0; g = 255; b = 0; break; case 1: /* spherical coordinates, yellow */ project = project_spherical; r = 255; g = 255; b = 0; break; case 2: /* inside a tube, blue */ project = project_tube; r = 0; g = 0; b = 255; break; case 3: /* surface of cylinder, red */ project = project_cylinder; r = 255; g = 0; b = 0; break; default: /* oops! */ assert(FALSE); return; } if (!no_grid) { c = makecol(r/5, g/5, b/5); n = (low_detail) ? 8 : 16; for (x=0; x<=n; x++) { for (y=0; y<=n; y++) { point[0] = (float)x / n; point[1] = (float)y / n; point[2] = (float)(x+1) / n; point[3] = (float)y / n; point[4] = (float)x / n; point[5] = (float)(y+1) / n; if (project(point, ipoint, 6)) { if (x < n) line(ipoint[0], ipoint[1], ipoint[2], ipoint[3], c); if ((y < n) && ((x < n) || (i == 0))) line(ipoint[0], ipoint[1], ipoint[4], ipoint[5], c); } } } } draw_player(r, g, b, project); draw_badguys(r, g, b, project); draw_bullets(r, g, b, project); draw_explode(r, g, b, project); } } solid_mode(); draw_message(); textprintf(font, 4, 4, makecol(128, 128, 128), "Lives: %d", lives); textprintf(font, 4, 16, makecol(128, 128, 128), "Score: %d", score); textprintf(font, 4, 28, makecol(128, 128, 128), "Hiscore: %d", get_hiscore()); al_flip_display(); }
void draw_ship() { draw_bullets(); draw_sprite( ship.current ); }
//Main program int main() { /* Initialize SDL’s video system and check for errors */ if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } /* Make sure SDL_Quit gets called when the program exits! */ atexit(SDL_Quit); /*set window title*/ SDL_WM_SetCaption("Essi Invaders", "P"); /* Attempt to set a 800x600 8 bit color video mode */ screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 8, SDL_DOUBLEBUF ); if (screen == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; } //load images load_image("titlescreen.bmp", &title_screen, magenta); load_image("cmap.bmp", &cmap, magenta); load_image("target1.bmp", &invaders_img[0], magenta); load_image("target2.bmp", &invaders_img[1], magenta); load_image("target3.bmp", &invaders_img[2], magenta); load_image("target4.bmp", &invaders_img[3], magenta); load_image("target5.bmp", &invaders_img[4], magenta); load_image("target6.bmp", &invaders_img[5], magenta); load_image("target7.bmp", &invaders_img[6], magenta); load_image("target8.bmp", &invaders_img[7], magenta); load_image("target9.bmp", &invaders_img[8], magenta); load_image("target10.bmp", &invaders_img[9], magenta); load_image("target11.bmp", &invaders_img[10], magenta); load_image("target12.bmp", &invaders_img[11], magenta); load_image("spaceship.bmp", &player_img, magenta); load_image("essi.bmp", &logo_img, magenta); load_image("saucer.bmp", &saucer_img, magenta); load_image("gameover.bmp", &game_over_img, magenta); load_image("damage.bmp", &damage_img, lime); load_image("damagetop.bmp", &damage_top_img, lime); Uint32 next_game_tick = SDL_GetTicks(); int sleep = 0; Uint8 *keystate = 0; int quit = 0; SDL_Event event; init_score(); init_bases(); init_misil(); init_invaders(); init_player(); init_saucer(); init_bullets(bullets, P_BULLETS); init_bullets(enemy_bullets, E_BULLETS); state = menu; title_time = SDL_GetTicks(); /* Animation */ while (quit == 0) { /* Grab a snapshot of the keyboard. */ keystate = SDL_GetKeyState(NULL); while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: switch( event.key.keysym.sym ) { //exit out of game loop if escape is pressed case SDLK_ESCAPE: quit = 1; break; case SDLK_SPACE: if (state == menu) { state = game; } else if (state == game){ player_shoot(); saucer_ai(); } else if (state == game_over) { init_invaders(); init_bases(); init_score(); init_player(); state = game; match = -1; } break; default: break; } break; case SDL_KEYUP: switch( event.key.keysym.sym ) { case SDLK_UP: move_misil(up); break; case SDLK_DOWN: move_misil(down); break; default: break; } } } draw_background(); if (state == menu) { char s[] = "Press SPACEBAR to start"; SDL_Rect src[60]; int i; if (title_time + 2000 < SDL_GetTicks()) { src[0].x = (SCREEN_WIDTH/100)*30; //Yellow Background of Space Invaders src[0].y = 40; src[0].w = 440; src[0].h = 230; SDL_FillRect(screen, &src[0], 248); } else { int y = 0; for (i = 0; i < 60; i++) { src[i].x = 0; src[i].y = y; src[i].w = SCREEN_WIDTH; src[i].h = 10; SDL_FillRect(screen, &src[i], 227); y += 10; } for (i = 0; i < 60; i++) { SDL_FillRect(screen, &src[i], rand() % 255); } } draw_title_screen(); draw_string(s, (SCREEN_WIDTH / 2) - (strlen(s) * 10), 500); } else if (state == game) { //move player if (keystate[SDLK_LEFT]) { move_player(left); } if (keystate[SDLK_RIGHT]) { move_player(right); } draw_hud(); draw_player(); draw_bases(); draw_invaders(); draw_saucer(); draw_serviceProjectMatch(match); draw_bullets(bullets, P_BULLETS); draw_bullets(enemy_bullets, E_BULLETS); enemy_hit_collision(); player_hit_collision(); enemy_base_collision(); saucer_hit_collision(); bullet_base_collision(enemy_bullets, E_BULLETS, 1); bullet_base_collision(bullets, P_BULLETS, 0); enemy_player_collision(); move_invaders(invaders.speed); move_saucer(); movenemy_bullets(bullets, P_BULLETS, -30); movenemy_bullets(enemy_bullets, E_BULLETS, 15); calculate_level(); enemy_ai(); game_over_ai(); pause_game(); } else if (state == game_over) { draw_hud(); draw_player(); draw_bases(); draw_invaders(); draw_saucer(); draw_bullets(bullets, P_BULLETS); draw_bullets(enemy_bullets, E_BULLETS); draw_game_over(); } else if (state == pause) { draw_hud(); draw_player(); draw_bases(); draw_invaders(); draw_saucer(); draw_bullets(bullets, P_BULLETS); draw_bullets(enemy_bullets, E_BULLETS); pause_game(); } /* Ask SDL to update the entire screen. */ SDL_Flip(screen); next_game_tick += 1000 / 30; sleep = next_game_tick - SDL_GetTicks(); if( sleep >= 0 ) { SDL_Delay(sleep); } } return 0; }
void tank8_state::screen_eof_tank8(screen_device &screen, bool state) { // on falling edge if (!state) { int x; int y; const rectangle &visarea = m_screen->visible_area(); m_tilemap->draw(screen, m_helper1, visarea, 0, 0); m_helper2.fill(8, visarea); m_helper3.fill(8, visarea); draw_sprites(m_helper2, visarea); draw_bullets(m_helper3, visarea); for (y = visarea.min_y; y <= visarea.max_y; y++) { int _state = 0; const UINT16* p1 = &m_helper1.pix16(y); const UINT16* p2 = &m_helper2.pix16(y); const UINT16* p3 = &m_helper3.pix16(y); if ((m_screen->frame_number() ^ y) & 1) continue; /* video display is interlaced */ for (x = visarea.min_x; x <= visarea.max_x; x++) { UINT8 index; /* neither wall nor mine */ if ((p1[x] != 0x11) && (p1[x] != 0x13)) { _state = 0; continue; } /* neither tank nor bullet */ if ((p2[x] == 8) && (p3[x] == 8)) { _state = 0; continue; } /* bullets cannot hit mines */ if ((p3[x] != 8) && (p1[x] == 0x13)) { _state = 0; continue; } if (_state) continue; if (p3[x] != 8) { index = ((p3[x] & ~0x01) >> 1) | 0x18; if (1) index |= 0x20; if (0) index |= 0x40; if (1) index |= 0x80; } else { int sprite_num = (p2[x] & ~0x01) >> 1; index = sprite_num | 0x10; if (p1[x] == 0x11) index |= 0x20; if (y - get_y_pos(sprite_num) >= 8) index |= 0x40; /* collision on bottom side */ if (x - get_x_pos(sprite_num) >= 8) index |= 0x80; /* collision on right side */ } timer_set(screen.time_until_pos(y, x), TIMER_COLLISION, index); _state = 1; }
//funkce pro kresleni void draw_game() { float t; draw_stars(); draw_enemies(); draw_bullets(); draw_particles(); draw_bonuses(); //mod pro koncovy screen hry if (playerdead) { //smesovani barev glEnable(GL_BLEND); //vyber blendovaci funkce glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //zesednuti pozadi glColor4f(0, 0, 0, 0.6); glBegin(GL_QUADS); glVertex2f(-250, -350); glVertex2f(250, -350); glVertex2f(250, 350); glVertex2f(-250, 350); glEnd(); glDisable(GL_BLEND); //kresleni statistik hry na konci hry glPushMatrix(); glTranslatef(-240, 0, 0); glScalef(18, 18, 0); glColor3f(0, 1, 0); glPushMatrix(); glTranslatef(2, 5, 0); glScalef(4, 4, 0); draw_string("GAME OVER"); glColor3f(1, 1, 1); glTranslatef(0.03, 0.03, 0); draw_string("GAME OVER"); glPopMatrix(); draw_string("LEVEL"); glTranslatef(3.5, 0, 0); draw_int(level); glTranslatef(-3.5, -1, 0); draw_string("SCORE"); glTranslatef(3.5, 0, 0); draw_int(score); glTranslatef(-3.5, -5, 0); glPushMatrix(); glTranslatef(0.3, -4, 0); glScalef(2, 2, 0); glColor3f(0, 1, 0); draw_string("PRESS FIRE TO RESTART"); glPopMatrix(); glPopMatrix(); } else { //statistika hry v levem spodnim rohu glPushMatrix(); glTranslatef(-240, -305, 0); glScalef(18, 18, 1); glColor3f(0, 1, 0); draw_string("POWER"); glTranslatef(3.5, 0, 0); draw_int(plevel); glTranslatef(-3.5, -1, 0); draw_string("LEVEL"); glTranslatef(3.5, 0, 0); draw_int(level); glTranslatef(-3.5, -1, 0); draw_string("SCORE"); glTranslatef(3.5, 0, 0); draw_int(score); glPopMatrix(); glTranslatef(posx, posy, 0); //raketka glBegin(GL_TRIANGLES); glColor3f(0, 0, 1); glVertex2f(-20, -10); glColor3f(0.5, 0.5, 1); glVertex2f(0, 0); glVertex2f(0, 50); glVertex2f(0, 50); glVertex2f(0, 0); glColor3f(0, 0, 1); glVertex2f(20, -10); glColor3f(1, 0, 0); glVertex2f(0, 0); glColor3f(1, 1, 0); glVertex2f(-2.5, -6); glVertex2f(2.5, -6); glEnd(); //pokud hrac sebere stitovy bonus if (shieldtimer>0) { //poslednich 5 vterin stit blika if (shieldtimer<5) t=sinf(shieldtimer*20); else t=1; glColor3f(0.3*t*t, 0.3*t*t, 0.6*t*t); //nakresleni trojuhelnikoveho stitu glBegin(GL_LINE_LOOP); glVertex2f(0, 55); glVertex2f(-25, -15); glVertex2f(25, -15); glEnd(); } } }