/* * draw_players * * Draw the players on the screen. * * Parameters: teams - Contains a link to all the players on the pitch. * players_per_team - Used to iterate over the player array. * animation_handler - Contains information on the animations used * for the players. */ void draw_players(TEAM *teams[], int players_per_team, ANIMATION_HANDLER *animation_handler) { /* * Local Variables. */ int ii; for (ii = 0; ii < players_per_team; ii++) { draw_player(teams[0]->players[ii], animation_handler); draw_player(teams[1]->players[ii], animation_handler); } }
int main(int argc, char** argv) { #ifndef TARGET_ESC64 //disable line-buffering on stdin struct termios old_tio, new_tio; assert(!tcgetattr(STDIN_FILENO, &old_tio)); new_tio = old_tio; new_tio.c_lflag &= (~ICANON & ~ECHO); assert(!tcsetattr(STDIN_FILENO, TCSANOW, &new_tio)); #endif for(;;) { fputs("\x1B[2J\x1B[H\x1B[?25l", stdout); //clear screen, cursor to home, cursor invis player1.pos.x = 16; player2.pos.x = 60; //initialize / generate gen_terrain(); init_player(&player1); init_player(&player2); curPlayer = &player1; //draw draw_static(); draw_terrain(); draw_player(&player1); draw_player(&player2); draw_stats(&player1); draw_stats(&player2); while(player1.hull > 0 && player2.hull > 0) { if(player_input()) { break; } TERM_DRAWSTR(MSG_X, MSG_Y + 1, "shot fired"); shoot(); curPlayer = curPlayer == &player1 ? &player2 : &player1; } } #ifndef TARGET_ESC64 //restore old settings line-buffering settings //tcsetattr(STDIN_FILENO, TCSANOW, &old_tio); #endif //return 0; }
void ram(void) { while(1) { if (!screen_intro()){ setTextColor(0xff,0x00); return; } game.rokets = 3; game.level = 1; game.score = 0; init_game(); screen_level(); while (game.rokets>=0) { ////checkISP(); lcdFill(0x00); check_end(); move_ufo(); move_shot(); move_shots(); move_player(); move_enemy(); draw_score(); draw_ufo(); draw_bunker(); draw_player(); draw_enemy(); draw_shots(); // draw_status(); lcdDisplay(); delayms(12); } if (!screen_gameover()) setTextColor(0xff,0x00); return; } }
void draw_game(t_game *game, SDL_Renderer *ren) { AfficherMap(game->maps,game->background,ren); draw_player(game->player, ren); }
// 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); }
void ram(void) { splash_scene(); long frame_count = 0; init_game(); while(1) { frame_count++; lcdFill(0); update_platforms(frame_count); move_player(frame_count); draw_platforms(); draw_player(); draw_hud(); blink_led(); lcdDisplay(); if(!game.running) { if(!gameover_scene()){ delayms_queue_plus(10,1); return; } init_game(); } delayms_queue_plus(24,0); } }
void finish_attack(int left) { if (left) { game_state.left_img = 3; game_state.right_img = 4; } else { game_state.left_img = 4; game_state.right_img = 3; } draw_player(); }
void update_player() { if (gm != GM_MULTIPLAYER) return; game_state.attack_cnt--; if (!game_state.attack_cnt) { game_state.attack_cnt = 32; if (!game_state.left_img) game_state.left_img = game_state.right_img = 1; else game_state.left_img = game_state.right_img = 0; draw_player(); } }
void start_attack(int left) { game_state.attack_cnt = 75; if (left) { game_state.left_img = 3; game_state.right_img = 2; } else { game_state.left_img = 2; game_state.right_img = 3; } draw_player(); }
bool render_game() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mat4 t = ident; draw_maps(t); draw_player(); draw_actors(); draw_ui(); return true; }
void draw(SDL_Surface *screen, int *mouse_x, int *mouse_y, struct Player *p, SDL_Surface *text, TTF_Font *font, SDL_Color color, int sv_msg, SDL_Surface *save_message) { draw_background(screen); draw_all_tiles(screen); draw_text(p, screen, text, font, color); if(sv_msg) { draw_save_msg(p, screen, save_message, font, color); } draw_player(screen, p); draw_cursor(screen, mouse_x, mouse_y); SDL_Flip(screen); SDL_Delay(1); }
void game_loop() { while (game_running) { // do things update_keys(); handle_input(); // draw things blank_screen(&renderer); draw_player(); SDL_RenderPresent(renderer); // keep things at a normal pace SDL_Delay(10); } }
/** Completely draws the screen during game. * * The usleep() function interrupts the program for 'n' microseconds. * It was difficult to get a stable value for the game progression. * * @note This is the main function of this file because it shows * logically how the process of drawing the screen sould be */ void engine_show_screen () { draw_background (); draw_borders (); draw_fruit (); draw_player (); draw_fruit_bonus(); draw_score (); usleep (REFRESH_DELAY); refresh(); }
void draw_world(){ for (int i = 0; i < MAP_WIDTH; ++i){ for (int j = 0; j < MAP_HEIGHT; ++j){ if (NULL != get_sprite_ptr(i,j)){ draw_player(get_sprite_ptr(i,j)); } else { printf("%c ", get_map_value(i,j)); } } printf("\n"); } printf("\n"); }
static void draw_battle_field( BATTLE *battle ) { BATTLE_ACTOR *ba; for (ba = (BATTLE_ACTOR *) LIST_HEAD(&battle->battleList); ba != NULL; ba = (BATTLE_ACTOR *) LIST_NEXT(&ba->listNode) ) { draw_player(ba->player, battle->world); } }
int16_t player_hit(Player* player, int16_t x, int16_t y) { if( x < player->pos.x || x >= player->pos.x + 3 || y < player->pos.y || y >= player->pos.y + 2) { return 0; } explosion(x, y); draw_player(player); player->hull -= SHOT_DAMAGE; draw_stats(player); term_setpos(MSG_X, MSG_Y + 1); printstr("hit player "); printch(player->id); return 1; }
void draw_world(world* game_world, screen* out) { for (int i = 0; i < game_world->height; i++) { for (int j = 0; j < game_world->width; j++) { set_pixel(i, j, '0', out); } } for (int i = 0; i < game_world->num_walls; i++) { point wall = game_world->walls[i]; set_pixel(wall.y, wall.x, '1', out); } draw_player(game_world->game_player, out); draw_collectible(game_world->pellet, out); }
void draw_world(world_data* world, ne::transform3f view) { ne::set_texture(assets.textures.tileset); for (auto& i : world->chunks) { if (!chunk_in_view(view, &i.second)) { continue; } render_tile_chunk(&i.second); draw_tile_chunk(&i.second); } for (auto& i : world->chunks) { if (!chunk_in_view(view, &i.second)) { continue; } draw_chests(&i.second.chests); draw_warps(&i.second.warps); draw_npcs(&i.second.npcs); } draw_monsters(&world->monsters); draw_player(&world->player); for (auto& i : world->attacks) { if (i.attack_type = ATTACK_NORMAL_ARROW) { ne::set_drawing_shape(0); ne::set_model_matrix(&i.area); ne::set_texture(assets.textures.weapons.arrow); ne::draw_vertices(); } } if (ne::is_key_down(KEY_1)) { for (auto& i : world->monsters) { draw_entity_collision(&i); } for (auto& i : world->chunks) { if (!chunk_in_view(view, &i.second)) { continue; } for (auto& j : i.second.chests) { draw_entity_collision(&j); } } draw_entity_collision(&world->player); } }
/* * Update the global |player| struct based on displacement from keyboard * interrupts, and re-draw the player's avatar if needed. */ void update_player_position(void) { int displacement = get_new_displacement(); if (displacement == 0) { return; } int prev_x_coord = player.x_coord; player.x_coord += displacement; if (player.x_coord >= WIDTH - 1) { player.x_coord = WIDTH - 1; win = 1; } else if (player.x_coord < 0) { player.x_coord = 0; } draw_player(); erase_player_at_prev_position(prev_x_coord, player.y_coord); }
/* This is the entry-point for the game! */ void c_start(void) { // Initialize video, interrupt, timer, and keyboard subsystems init_video(); init_interrupts(); init_timer(); init_keyboard(); // Initialize game state init_player(); init_guns(); win = 0; draw_world(); draw_player(); enable_interrupts(); mainloop(); }
void draw_world(void) { int i; int j; i = 0; poll_msg(); while (i < g_shm.size) { j = 0; while (j < g_shm.size) { draw_player(i, j); j += 1; } i += 1; } }
/** * draw_area: * * Draw the game area with its players and their cards */ void draw_area(void) { gint i; cairo_t *cr; player *player; GdkRectangle rect = { 0, 0, gskat.area->allocation.width, gskat.area->allocation.height }; gdk_window_begin_paint_rect(gskat.area->window, &rect); cr = gdk_cairo_create(gskat.area->window); draw_table(gskat.area, cr); if (gskat.skat) draw_cards(gskat.skat, cr); if (gskat.table) draw_cards(gskat.table, cr); if (gskat.players) { for (i=0; i<3; ++i) { player = gskat.players[i]; draw_cards(player->cards, cr); draw_player(player, cr); } } /* draw bid values during provoke phase only */ if (gskat.state >= PROVOKE1 && gskat.state <= PROVOKE4 && get_prop_bool("provoke_values")) draw_provoke_value(cr); cairo_destroy(cr); gdk_window_end_paint(gskat.area->window); }
void check_draw(char *tmp) { if (my_strcmp(tmp, "linemate") == 0) draw_stone(1); if (my_strcmp(tmp, "deraumere") == 0) draw_stone(2); if (my_strcmp(tmp, "sibur") == 0) draw_stone(3); if (my_strcmp(tmp, "mendiane") == 0) draw_stone(4); if (my_strcmp(tmp, "phiras") == 0) draw_stone(5); if (my_strcmp(tmp, "thystame") == 0) draw_stone(6); if (my_strcmp(tmp, "nourriture") == 0) draw_food(); if (my_strcmp(tmp, "player") == 0) draw_player(); }
void draw_game(void) { switch(state) { case GAME_STATE_WORLD : draw_world(game_world); draw_player(game_player, game_world); break; case GAME_STATE_MENU : draw_menu(10, 10); break; case GAME_STATE_MAP : draw_scanner(game_scanner, game_world, 10, 10, game_player->x, game_player->y); break; case GAME_STATE_STATUS : draw_actor_status(10, 10, game_player->h); break; case GAME_STATE_BATTLE : draw_world(game_world); draw_battle(game_battle); break; default : break; } }
//display function void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //setup view glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //set the camera(3 posibilities 0 - up, 1 - first person, 2 - third person) camera.render(cam, player_x, player_y, player_r, lab_size_x > lab_size_y ? lab_size_x : lab_size_y); //draw all the objects draw_labirinth(l, lab_size_x, lab_size_y); draw_portal(); draw_player(); //swap buffers glutSwapBuffers(); }
//------------------------------ // Drawing functions //------------------------------ void draw_everything() { // Fill the screen with black SDL_FillRect(screen,NULL, 0x000000); // Draw background draw_background(); // Draw the title screen if(gamestate_title == true) draw_titlescreen(); else { // Draw the game objects if(gamestate_over == false) draw_player(); draw_enemies(); draw_explosions(); draw_lasers(); draw_info(); draw_statustext(); } }
void init_video(void) { char * datas = ((char*) PROGRAM_BASE_ADDR); datas += 100000; datas -= 512; assets = (Game_Assets*)datas; //color_screen(0x3f); // write_string_position(5, "wowowow", 5, 5); // write_string_position(5, hu, 5, 15); // write_string_position(5, katana, 5, 25); draw_bullet(6, 11, 15, 5); draw_player(15, 35); draw_enemy(0, 15, 55); draw_enemy(1, 15, 70); /* TODO: Do any video display initialization you might want to do, such * as clearing the screen, initializing static variable state, etc. */ // Clear Screen - not yet debugged. // clearScreen(); #if 0 //TEST~nico~~ #if 0 write_string_offset(RED, string, 10); #endif // TEST 2~~nico~~~~ color_pixel(RED, 50); color_pixel(BLUE, 52); color_pixel(YELLOW, 54); color_pixel(WHITE, 210); color_pixel(GREEN, 212); color_pixel(CYAN, 214); #endif }
int main (void) { /* initialize the game. */ setup_allegro (MODE, WIDTH, HEIGHT, 16); setup_bmps(); setup_player(); scrollx = 0; scrolly = 0; currentmap = (MAP*)malloc (sizeof (MAP)); currentmap->initflag = 1; currentmap->idnumber = TCA_13; map_handler(); while (!key[KEY_ESC]) { get_input(); move_player(); scroll_window(); animate_player(); map_event_handler(); map_handler(); draw_player(); blit (scrollbmp, bufferbmp, scrollx, scrolly, 0, 0, WIDTH-1, HEIGHT-1); print_scroll_debug_messages(); print_player_debug_messages(); acquire_screen(); blit (bufferbmp, screen, 0, 0, 0, 0, WIDTH-1, HEIGHT-1); release_screen(); rest (20); } destroy_bmps(); allegro_exit(); return 0; }
/** * Runs the game. */ Result gameplay() { Result result = NONE; Ball new_ball; bool collision = false; int round = 2; char round_msg[28]; while(!gameover) { handle_window_resizing(); // react to player input if (input_player == PLAYER_QUIT) { gameover = true; result = QUIT; } if (input_player == PLAYER_PAUSE) { continue; } if (input_player == PLAYER_UP && inside_borders(player.y + 1)) { player.y++; input_player = 0x00; } if (input_player == PLAYER_DOWN && inside_borders(player.y - 1)) { player.y--; input_player = 0x00; } // react to computer AI if (input_computer == COMP_UP && inside_borders(computer.y + 1)){ computer.y++; } if (input_computer == COMP_DOWN && inside_borders(computer.y - 1)){ computer.y--; } getmaxyx(field, field_size.y, field_size.x); // collision detection new_ball = next_move(); int new_x = (int)new_ball.x; int new_y = (int)new_ball.y; // ball hits player or computer // left side if ((new_x == player.x && new_y == player.y - 1) || (new_x == computer.x && new_y == computer.y - 1)) { new_ball.y_d = new_edge_speed(new_ball.y_d); new_ball.x_d *= -1; collision = true; round++; } // middle else if ((new_x == player.x && new_y == player.y) || (new_x == computer.x && new_y == computer.y)) { int pos = new_ball.y_d > 0; new_ball.y_d = MID_SPEED; if(pos) new_ball.y_d *= -1; new_ball.x_d *= -1; collision = true; round++; } // right side else if ((new_x == player.x && new_y == player.y + 1) || (new_x == computer.x && new_y == computer.y + 1)) { new_ball.y_d = new_edge_speed(new_ball.y_d); new_ball.x_d *= -1; collision = true; round++; } // player failed else if (new_x <= player.x) { gameover = true; collision = true; result = LOOSE; } // computer failed else if(new_x >= computer.x) { gameover = true; collision = true; result = WIN; } // bottom and top borders else if (new_y >= field_size.y -1 || new_y <= 0) { new_ball.y_d *= -1; collision = true; } // draw new window content wclear(info); wclear(field); draw_window(info,"Info", false); sprintf(round_msg, "round: %d - next: %s",round/2, round%2?"Player":"Computer"); mvwprintw(info,1,2,round_msg); draw_window(field,"Pong", true); // only draw new position if no collision occured if (collision && !gameover) mvwprintw(field,ball.y,ball.x,BALL); else mvwprintw(field,new_ball.y,new_ball.x,BALL); draw_player(); draw_computer(); wrefresh(info); wrefresh(field); // set new ball position ball = new_ball; collision = false; usleep(DELAY); } return result; }
int main(void) { PlayerState player_state_0, player_state_1; SDL_Event event; SDL_Renderer *renderer; SDL_Window *window; double current_time_s, last_tick_time_s; unsigned int frequency_divider_counter, player_move_frequency_divider; unsigned int current_time, last_time; SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO); SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_WIDTH, 0, &window, &renderer); SDL_SetWindowTitle(window, "asdw: move red | jkli: move blue | space: move faster | esc: restart | q: quit"); main_loop: init_state( &player_state_0, &player_state_1, &last_tick_time_s, &frequency_divider_counter, &player_move_frequency_divider ); while (1) { while (SDL_PollEvent(&event) == 1) { if (event.type == SDL_QUIT) { goto quit; } else if (event.type == SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_ESCAPE: goto main_loop; case SDLK_q: goto quit; default: break; } } } const Uint8 *keystate = SDL_GetKeyboardState(NULL); if (keystate[SDL_SCANCODE_SPACE]) { player_move_frequency_divider = FAST_FREQUENCY_DIVIDER; } else { player_move_frequency_divider = NORMAL_FREQUENCY_DIVIDER; } /* Player 0. */ player_state_0.speed_x = 0; player_state_0.speed_y = 0; if (keystate[SDL_SCANCODE_A]) { player_state_0.speed_x = -1; } if (keystate[SDL_SCANCODE_D]) { player_state_0.speed_x = 1; } if (keystate[SDL_SCANCODE_W]) { player_state_0.speed_y = -1; } if (keystate[SDL_SCANCODE_S]) { player_state_0.speed_y = 1; } /* Player 1. */ player_state_1.speed_x = 0; player_state_1.speed_y = 0; if (keystate[SDL_SCANCODE_J]) { player_state_1.speed_x = -1; } if (keystate[SDL_SCANCODE_L]) { player_state_1.speed_x = 1; } if (keystate[SDL_SCANCODE_I]) { player_state_1.speed_y = -1; } if (keystate[SDL_SCANCODE_K]) { player_state_1.speed_y = 1; } current_time = SDL_GetTicks(); current_time_s = current_time / 1000.0; if (current_time != last_time) { if (current_time_s - last_tick_time_s > FASTEST_TICK_PERIOD_S) { /* Draw world. */ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); draw_player( &player_state_0, renderer, 255, 0, 0 ); draw_player( &player_state_1, renderer, 0, 0, 255 ); SDL_RenderPresent(renderer); /* Update state. */ if (frequency_divider_counter % GRAVITY_FREQUENCY_DIVIDER == 0) { player_state_0.speed_y += 1; player_state_1.speed_y += 1; } if (frequency_divider_counter % player_move_frequency_divider == 0) { update_player(&player_state_0); update_player(&player_state_1); } /* Update time tracking. */ last_tick_time_s = current_time_s; frequency_divider_counter++; if (frequency_divider_counter == MCD_FREQUENCY_DIVIDER) frequency_divider_counter = 0; /* Ticks per second. Equls 1 / FASTEST_TICK_PERIOD_S if no processing is done. */ common_fps_update_and_print(); } } last_time = current_time; } quit: SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); return EXIT_SUCCESS; }