void initialize_pong_game(){ unsigned i; clear_screen(); for (i=0;i<ROW_SIZE;i++){ video_buffer[i+TOP_BORDER*ROW_SIZE]=0xff; video_buffer[i+ROW_SIZE*BOTTOM_BORDER]=0xff; } for (i=TOP_BORDER+1;i<(BOTTOM_BORDER-1);i++){ if (i&1) video_buffer[ROW_SIZE*i+3]=1u; } running=0; score[LEFT_PLAYER]=0; score[RIGHT_PLAYER]=0; server=winner; winner=NO_WINNER; paddle[LEFT_PLAYER]=read_pot(LEFT_PLAYER)+TOP_BORDER; paddle[RIGHT_PLAYER]=read_pot(RIGHT_PLAYER)+TOP_BORDER; if (server==LEFT_PLAYER){ ball.x=LEFT_BORDER+1; ball.y=paddle[LEFT_PLAYER]+1; }else{ ball.x=RIGHT_BORDER-1; ball.y=paddle[RIGHT_PLAYER]+1; } ball.dx=0; ball.dy=0; write_score(LEFT_PLAYER,score[LEFT_PLAYER]); write_score(RIGHT_PLAYER,score[RIGHT_PLAYER]); draw_paddle(LEFT_PLAYER,WHITE); draw_paddle(RIGHT_PLAYER,WHITE); plot(ball.x,ball.y,WHITE); srand(frame_cntr); }//f()
// le joueur a manquer la balle // mettre à jour le pointage // faire entendre le son associé // player est le joueur qui a manqué la balle. void ball_missed(int player){ plot(ball.x,ball.y,INVERT); sound_miss(); plot(ball.x,ball.y,INVERT); ball.dx=0; ball.dy=0; if (player==LEFT_PLAYER){ score[RIGHT_PLAYER]++; write_score(RIGHT_PLAYER,score[RIGHT_PLAYER]); if (score[RIGHT_PLAYER]==WIN_SCORE){ game_over(); return; } ball.x=RIGHT_BORDER-1; ball.y=paddle[RIGHT_PLAYER]+1; server=RIGHT_PLAYER; }else{ score[LEFT_PLAYER]++; write_score(LEFT_PLAYER,score[LEFT_PLAYER]); if (score[LEFT_PLAYER]==WIN_SCORE){ game_over(); return; } ball.x=LEFT_BORDER+1; ball.y=paddle[LEFT_PLAYER]+1; server=LEFT_PLAYER; } plot(ball.x,ball.y,WHITE); wait_service(); }//f()
void reset_scores() { int i=0; for(i=0;i<10;++i) { strcpy(score[i].name,"NO NAME"); score[i].score = 0; } write_score(score); }
static t_bunny_response bunny_vellement(void *my_data) { t_data *data = my_data; // blit_everything(data); data->loop += ABS(data->speed / 4); // manage_core(data); write_score(data->champ[0].score / 10, data->pix, data->font); data->speed = 10 + (data->champ[0].score < 0 ? 0 : data->champ[0].score / 15000); data->font_pos.y += data->speed; if (data->font_pos.y < HEIGHT) { data->pos.x = 0; data->pos.y = 0; data->pos.y = data->font_pos.y - HEIGHT; bunny_blit(&data->win->buffer, &data->newpix->clipable, &data->pos); // bunny_blit(&data->win->buffer, &data->pix->clipable, &data->font_pos); } printf("lol\n"); bunny_display(data->win); return (GO_ON); }
void game_over(hero tux){ int poradie; char tmp[756]; SDL_Color text_color = {255, 255, 255}; SDL_Rect text_rect; SDL_Surface *text_surface; SDL_FillRect(gd->screen.surface, NULL, 0); poradie = write_score(tux.score); if(poradie<0) printf("%s\n", gd->lang.write_score); else if(poradie == 6) printf("%s\n", gd->lang.score_state); else printf("%s %d. %s\n", gd->lang.you_got, poradie, gd->lang.place); sprintf(tmp, "%s %d", gd->lang.score, tux.score); text_surface = TTF_RenderUTF8_Blended(gd->font, tmp, text_color); text_rect.x = gd->screen.width/2; text_rect.y = gd->screen.height/2; SDL_BlitSurface(text_surface, NULL, gd->screen.surface, &text_rect); SDL_FreeSurface(text_surface); SDL_Flip(gd->screen.surface); SDL_Delay(2000); }
t_game showGameOver(t_game game) { game.Gscreen = loadTexture( "/../../../images/background/main_menu.png", game.Grenderer ); game.begin.surface_play = TTF_RenderText_Solid(game.text.font, "GAME OVER", game.text.color); game.begin.play_with_2 = SDL_CreateTextureFromSurface(game.Grenderer, game.begin.surface_play); game.begin.play_with_2_position = init_position(135, 180, 180, 500); SDL_Delay(50); game.begin.state = 1; if (game.Gplayer1.lives == -1) { write_score(game, game.Gplayer1); game = init_player(game); } set_hscore(&game, get_hscore(hscore_path())); render_hscore(&(game.text), game.Grenderer); render_score(&(game.Gplayer1), game.text, game.Grenderer); renderEnd(game); return (game); }
void add_score(char *name, long int scoreVal) { SCORES temp; int i=0; int addition_point; for(i=0;i<10;++i) { if(score[i].score<scoreVal) { addition_point = i; } } for(i=addition_point;i<9;++i) { temp = score[i+1]; score[i+1] = score[i]; } strcpy(score[addition_point].name,name); score[addition_point].score =scoreVal; write_score(score); }