static void app(t_game *game) { t_level *current; init_glfw(game); current = game->levels; while (current) { load_level(game, current); while (!glfwWindowShouldClose(game->window) && !game->win) { update_time(game); if (game->started && !game->paused) { do_gl_stuff(game); move_ball(game); check_collision(game); draw_stuff(game); check_game_state(game); glfwSwapBuffers(game->window); usleep(12500); } glfwPollEvents(); usleep(100); } current = current->next; } }
static void idle() { currentTime = glutGet(GLUT_ELAPSED_TIME); timeInterval = currentTime - previousTime; if(timeInterval > 16){ glutPostRedisplay(); previousTime = currentTime; elapsedInSecond += timeInterval; if(action){ move_ball(); angle+=1; } } if(elapsedInSecond > 1000){ fps = frame_count; frame_count = 0; elapsedInSecond = 0; } sprintf(fps_vertices, "FPS: %d || Vertices: %d", fps, totalVerts); }
void Paddle::move(){ if(right_pressed){ move_right(); } else{ if (left_pressed){ move_left(); } } move_ball(); }
// au départ c'est le joueur de gauche qui a le service // il doit déplacer sa raquette pour lancer la balle. // la balle part avec un angle pointant vers le haut // ou le bas en fonction de la direction du // déplacement de la raquette. void play_pong(){ wait_service(); running=1; while (running){ move_paddle(LEFT_PLAYER); move_paddle(RIGHT_PLAYER); move_ball(); frame_sync(); frame_delay(1); } }//f()
int main(void) { WDTCTL = WDTPW | WDTHOLD; ball_t pongball = ball(50,50,50,30,5); while (1) { pongball = move_ball(pongball); } return 0; }
void content(t_env *env) { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, WIDTH, HEIGHT, 0.0f, 0.0f, 1.0f); key_hook(env); move_ball(env); draw(env); score(env); }
static void move_balls (ModeInfo *mi) /* for great justice */ { lavalite_configuration *bp = &bps[MI_SCREEN(mi)]; int i; for (i = 0; i < bp->nballs; i++) { metaball *b = &bp->balls[i]; if (b->alive_p) move_ball (mi, b); } clamp_balls (mi); }
int main(int argc, char *argv[]) { int serverport; char *serveraddr; if (argc >= 3) { serveraddr = argv[1]; serverport = atoi(argv[2]); } else { puts("Usage: ping [server] [port]"); exit(0); } unsigned int seed = time(NULL); srandom(seed); SLEEPT = 125000; user1_serving = 1; user1_serving_now = 1; user_served = 0; init_curses(); init_game(); netset(serverport, serveraddr); redraw(); serve(); while (!end) { redraw(); userctl(getch()); peersync(); move_ball(); redraw(); usleep(SLEEPT); } end_curses(); return 0; }
//Basically, move the ball and paddle around a bit... //For a background... void update_background(struct Ball* ball, struct Paddle* paddle, int max_x, int max_y) { move_ball(ball); if (((ball->y + 1) > max_y) || (ball->y < 0)) ball->vy = -ball->vy; if ((ball->x > max_x) || (ball->x < 0)) ball->vx = -ball->vx; //Move paddle towards ball switch (ball_in_paddle(ball, paddle)) { case 0: break; case 1: if (ball->vx < 0) move_paddle_dir(paddle , UP); break; case -1: if (ball->vx < 0) move_paddle_dir(paddle, DOWN); break; } }
void key_press(unsigned char key, int x, int y) { switch (key) { case 's': /* start game */ if (game_over) { game_over = 0; move_ball(current_game); if(BALL_NUMBER == 2) move_ball_2(current_game); } break; case 'r': /* reset game */ // current_game++; misses = 0; ball_x_pos = INITIAL_BALL_X_POS ; ball_y_pos = INITIAL_BALL_Y_POS ; ball_x1_pos = INITIAL_BALL_X_POS ; ball_y1_pos = INITIAL_BALL_Y_POS ; paddle_y_pos = INITIAL_PADDLE_Y_POS; ball_trajectory = INITIAL_BALL_ANGLE ; game_over = 1; ball_state = 0; ball_1_state = 1; BALL_NUMBER = 1; glutPostRedisplay(); break; case 'd': if(BALL_NUMBER == 1) { BALL_NUMBER++; move_ball_2(current_game); } break; case ESCAPE: /* exit the program...normal termination. */ exit(0); } }
/* Bring a ball into play, and re-randomize its values. */ static void reset_ball (ModeInfo *mi, metaball *b) { /* lavalite_configuration *bp = &bps[MI_SCREEN(mi)]; */ b->r = 0.00001; b->R = 0.12 + bellrand(0.10); b->pos_r = bellrand (0.9); b->pos_th = frand(M_PI*2); b->z = 0; b->dr = bellrand(TILT); b->dz = CONVECTION; b->leader = 0; if (!b->alive_p) b->alive_p = True; move_ball (mi, b); }
int do_ball(t_ole *t) { int i; if (t->state == 0) { i = 0; usleep(NB_BALL * 4000 + 20000); draw_init(t); while (i < NB_BALL) { move_ball(t, i); i = i + 1; } expose(t); } else if (t->state == 1) { t->state = 2; usleep(1000000); } }
int main(int argc, char* argv[]) { Box scene; /* The box that all balls will bounce inside. */ Ball balls[MAX_BALLS]; int balls_len = 1; /* The number of balls we will actually use. */ int i; /* Did the user specify the number of balls to use? */ if (argc > 1) { int user_len = atoi(argv[1]); /* Keep the number of balls in the valid range. */ balls_len = max(1, min(user_len, MAX_BALLS)); } srandom(time(0)); for (i = 0; i < balls_len; i++) { balls[i].xpos = random() % MAX_XPOS + 1; balls[i].xdir = random() % 2 == 0 ? 1 : -1; balls[i].ypos = random() % MAX_YPOS + 1; balls[i].ydir = random() % 2 == 0 ? 1 : -1; balls[i].printable = 'o'; } init_box(&scene); while (1) { draw_scene(&scene); /* Move all the balls in the scene to their new positions. */ for (i = 0; i < balls_len; i++) move_ball(&balls[i], &scene); /* A delay of 66 will give us about 15 frames per second. */ delay(66); } return 0; }
/* Called whenever a ball is lost, either by it falling off the bottom of the * screen, or the player pressing the "suicide key". */ void lost_ball(nbstate *state) { /* Decrement the balls count and if there are none left: */ if(!state->numballs--) { /* Go to the "game lost" state and update the high score if * appropriate: */ state->state = STATE_GAMELOST; /* Update the high score and save it if necessary: */ save_hiscore(state); /* This could probably be done better by just drawing the * splash- set_level_active() redraws the entire game area: */ set_level_active(state); return; } /* Erase the balls line at the top of the screen: */ draw_background(state, 0, state->scores.h, state->canvaswidth, state->ball.s->h + (BALLS_BORDER * 2)); /* Draw the balls again, but with one less than there was before: */ draw_balls(state); /* Copy the balls row to the output window: */ draw_canvas(state, 0, state->scores.h, state->canvaswidth, state->ball.s->h + (BALLS_BORDER * 2)); /* Park the new ball and erase the old one: */ park_ball(state); move_ball(state); /* Redraw the bat. This is a bit of a hack because sometimes when the * ball falls below the top of the bat on its way to the bottom of the * screen it can clip the bat and erase a bit of it. This redraws the * bat to hide that: */ draw_bat(state); /* Copy the redrawn bat to the output window: */ draw_canvas(state, state->batx - (state->batwidths[state->bat] / 2), state->canvasheight - state->batheight, state->batwidths[state->bat], state->batheight); }
int play_game(struct Game* game) { clear(); refresh(); WINDOW* win = newwin(game->height, game->width, INFO_WIN_HEIGHT, 0); WINDOW* info_win = newwin(INFO_WIN_HEIGHT, game->width, 0, 0); Timer* timer = sgl_timer_new(); //int ball_vx = EASY_BALL_VX; //int ball_vy = EASY_BALL_VY; //FIX THIS ^^^ struct Ball* ball = make_ball(game->width/2, game->height/2, .2, .075); struct Paddle* paddle1 = make_paddle(1, game->height/2, 5, game->sensitivity); struct Paddle* paddle2 = make_paddle(game->width-2, game->height/2, 5, game->sensitivity); //Used for checking where paddles are going to be... struct Paddle check_pad; int ai_wait = 0; int ai_wait_time = 0; switch (game->difficulty){ case 1: ai_wait_time = EASY_AI_WAIT; break; case 2: ai_wait_time = MEDIUM_AI_WAIT; break; case 3: ai_wait_time = HARD_AI_WAIT; break; } int key; int game_won = 0; char* pause_message = "PAUSED"; //Use this for any printing, etc. char* tmp_str = malloc(sizeof(char) * MAX_STRING_LENGTH); while ((key = getch()) != 'q'){ switch (key) { case ERR:break;//Ignore this key... case 'm': if (game->sound) game->sound = 0; else game->sound = 1; break; case 'p': if (game->paused){ game->paused = 0; erase_rect(win, game->max_height / 3, game->max_width / 2 - strlen(pause_message), strlen(pause_message), 1); } else { game->paused = 1; mvwaddstr(win, game->max_height / 3, game->max_width / 2 - strlen(pause_message), pause_message); } break; case 'w': if (game->paused || game_won) break; if (game->p1_aictrl) break;//The AI is controlling this paddle, so don't let player move it... check_pad = move_paddle_dir_f(*paddle1, UP); if (check_pad.y + paddle1->vel < 0){ move_paddle_xy(paddle1, paddle1->x, game->height - paddle1->width); }else { move_paddle_dir(paddle1, UP); } break; case 's': if (game->paused || game_won) break; if (game->p1_aictrl) break;//The AI is controlling this paddle, so don't let player move it... check_pad = move_paddle_dir_f(*paddle1, UP); if ((paddle1->y + paddle1->vel + paddle1->width) > game->height){ move_paddle_xy(paddle1, paddle1->x, 0); }else { move_paddle_dir(paddle1, DOWN); } break; case KEY_UP: if (game->paused || game_won) break; if (game->p2_aictrl) break;//The AI is controlling this paddle, so don't let player move it... check_pad = move_paddle_dir_f(*paddle2, UP); if ((check_pad.y + paddle2->vel) < 0){ move_paddle_xy(paddle2, paddle2->x, game->height - paddle2->width); }else { move_paddle_dir(paddle2, UP); } break; case KEY_DOWN: if (game->paused || game_won) break; if (game->p2_aictrl) break;//The AI is controlling this paddle, so don't let player move it... check_pad = move_paddle_dir_f(*paddle2, DOWN); if (((check_pad.y + check_pad.width) - paddle2->vel) > game->height){ move_paddle_xy(paddle2, paddle2->x, 0); }else { move_paddle_dir(paddle2, DOWN); } break; default: if (game_won){ clear(); refresh(); return 0; } break; } //AI Checks whether it has the ball and then moves if (ai_wait > ai_wait_time){ if (game->p1_aictrl && ball->vx < 0){ switch (ball_in_paddle(ball, paddle1)) { case 0: break; case 1: move_paddle_dir(paddle1, UP); break; case -1: move_paddle_dir(paddle1, DOWN); break; } }else if (game->p2_aictrl && ball->vx > 0){ switch (ball_in_paddle(ball, paddle2)) { case 0: break; case 1: move_paddle_dir(paddle2, UP); break; case -1: move_paddle_dir(paddle2, DOWN); break; } } ai_wait = 0; } if ((sgl_timer_elapsed_milliseconds(timer) > TICKS) && !(game->paused || game_won)){ sgl_timer_reset(timer); ai_wait++; //Ball has collided with paddle1 if ((ball->x <= paddle1->x) && ball_intersect_paddle(ball, paddle1)){ if (game->sound) fbeep(660, 10); //Move the ball 1 forward from paddle, this paddle is on left move_ball_xy(ball, paddle1->x + 1, ball->y); //Flip the ball's direction ball->vx = -ball->vx; float prcnt = collision_dist_prcnt(ball, paddle1); float vxi = (1 - prcnt) * EASY_BALL_V_INC; float vyi = prcnt * EASY_BALL_V_INC; ball->vx = sign(ball->vx) * (fabsf(ball->vx) + vxi); ball->vy = sign(ball->vy) * (fabsf(ball->vy) + vyi); } else if (ball->x <= paddle1->x){ if (game->sound) fbeep(550, 20); //Increase score... game->p2_score++; ball->vx = EASY_BALL_VX; ball->vy = EASY_BALL_VY; move_ball_xy(ball, game->width / 2, game->height / 2); } //Ball has collided with paddle2 if ((ball->x >= paddle2->x) && ball_intersect_paddle(ball, paddle2)){ fbeep(660, 10); //Move the ball 1 back from the paddle, this paddle is the one on right... move_ball_xy(ball, paddle2->x - 1, ball->y); ball->vx = -ball->vx; float prcnt = collision_dist_prcnt(ball, paddle2); float vxi = (1 - prcnt) * EASY_BALL_V_INC; float vyi = prcnt * EASY_BALL_V_INC; ball->vx = sign(ball->vx) * (fabsf(ball->vx) + vxi); ball->vy = sign(ball->vy) * (fabsf(ball->vy) + vyi); } else if (ball->x >= paddle2->x){ if (game->sound) fbeep(550, 20); game->p1_score++; ball->vx = -(EASY_BALL_VX); ball->vy = EASY_BALL_VY; move_ball_xy(ball, game->width / 2, game->height / 2); } //We need to erase it _now_ because??? erase_ball(win, ball); if ((ball->y + 1 > game->height - 1) || (ball->y < 1)) ball->vy = -ball->vy; move_ball(ball); } if (game->p1_score == game->max_score){ game_won = 1; snprintf(tmp_str, MAX_STRING_LENGTH, "%s Wins!", game->p1_name); mvwaddstr(win, game->max_height / 3, game->max_width / 2 - strlen(tmp_str), tmp_str); }else if (game->p2_score == game->max_score){ game_won = 1; snprintf(tmp_str, MAX_STRING_LENGTH, "%s Wins!", game->p2_name); mvwaddstr(win, game->max_height / 3, game->max_width / 2 - strlen(tmp_str), tmp_str); } erase_draw_ball(win, ball, RED); erase_draw_paddle(win, paddle1, BLUE); erase_draw_paddle(win, paddle2, GREEN); //Display some info box(info_win, 0 , 0); box(win, 0, 0); snprintf(tmp_str, MAX_STRING_LENGTH, "%s: %d", game->p1_name, game->p1_score); mvwaddstr(info_win, 1, 1, tmp_str); snprintf(tmp_str, MAX_STRING_LENGTH, "%s: %d", game->p2_name, game->p2_score); mvwaddstr(info_win, 1, game->width - strlen(tmp_str) - 1, tmp_str); wrefresh(info_win); wrefresh(win); refresh(); } clear(); refresh(); return 0; }
void game() { uint8_t i; clear(); column[0] = 0x18; column[7] = 0x18; sw1=0; sw2=0; score1=0; score2=0; uint8_t btn1 = 0, btn2 = 0, btn3 = 0, btn4 = 0; uint8_t counter = 0; uint8_t counter2 = 0; uint8_t c1=column[0],c2=column[7]; initBall(); for(;;) { /////////////////////////////// ///////////Button Read///////// btn1 = readButton(1); btn2 = readButton(2); btn3 = readButton(3); btn4 = readButton(4); if(counter>PSPEED) { if (btn1) { if((column[7] << 1) <=192) c2=column[7] = column[7] << 1; } if (btn2) { if((column[7] >> 1) >= 3) c2=column[7] = column[7] >> 1; } if (btn3) { if((column[0] << 1) <=192) c1=column[0] = column[0] << 1; } if (btn4) { if((column[0] >> 1) >= 3) c1=column[0] = column[0] >> 1; } counter=0; } counter++; //////////////////////////// //////////////////////////// //////////////////////// ////////Score Update//// if(score1>9 || score2>9) { score1=0; score2=0; update_score(score1,score2); } //////////////////////// //////////////////////// for(i=1; i<nrCol-1; i++) column[i]=0; //column[7]=c2; //column[0]=c1; /////////////////////// ////////Ball movement// if(counter2>BSPEED) { move_ball(); counter2=0; } counter2++; ////////////////////// ////////////////////// display(column); } }
int main(int argc, char *argv[]) { //sgenrand(time(NULL)); int k, curr_pos, check; int chunk; /* Repeat experiment in chunks. */ srand(SEED); printf("# Info: $Header: /home/ma/p/pruess/.cvsroot/manna_range/dmitry_20151021/manna_stack_clean_edited.c,v 1.2 2015/10/21 11:37:00 pruess Exp $\n"); preamble(argc, argv); PRINT_PARAM(SEED, "%lu"); PRINT_PARAM(LENGTH, "%lu"); PRINT_PARAM(DROP_LOCATION, "%lu"); PRINT_PARAM(total_malloced, "%lli"); printf("# Info: Expected avalanche size: <s>(x) = 1+(1/2) (<s>(x+1)+<s>(x-1)), BC <s>(0)=0, <s>(L+1)=0, solved by <s>(x)=(L+1-x)x/2.\n"); printf("# Info: Here L=LENGTH=%lu and x=DROP_LOCATION+1=%lu, so expect %g\n", LENGTH, DROP_LOCATION+1, ((double)(DROP_LOCATION+1))*((double)(LENGTH-DROP_LOCATION))/2.); for (chunk=1; ((chunk<=NUM_CHUNKS) || (NUM_CHUNKS<0)); chunk++) { MOMENTS_INIT(size); for (drop = 0; drop < N_ROLLS; drop++) { // big droppping cycle size=0; /* printf("(%i.)", drop); for(k = 0; k<LENGTH; k++) { printf("\%i", lattice[k]); } printf("\n"); */ #if (1) if(check_cell(DROP_LOCATION) == 0) { lattice[DROP_LOCATION] = 1; } else { stack_push(DROP_LOCATION); stack_push(DROP_LOCATION); lattice[DROP_LOCATION] = 0; } /* If validated, optimse by turning stack operations into macros, * optime random number drawing (rather than having doubles in the tree * have integers there and draw an integer to compare against), * optimise the shuffling of particles. * * I have added MOMENT macros for size. */ while(stack_used != 0) { curr_pos = stack_pop(); /* This code with the "check" looks clumsy. I suppose * you are "following through" topplings? I would think * there is no point doing this later. Anyway, we validate * this code and take it from there. */ do { curr_pos = move_ball(curr_pos); if(curr_pos >= LENGTH || curr_pos < 0) { check = 0 ; } /* Why not just "else" instead of the "if"? */ if(curr_pos < LENGTH && curr_pos >= 0) { check = check_cell(curr_pos); if (check == 1) { stack_push(curr_pos); } else { check = 0; } } }while(check != 0); }/* end of while(stack_used != 0) look */ #endif #if (0) { int npos; #define PUSH(a) stack[stack_used++]=(a) #define POP(a) (a)=stack[--stack_used] if (lattice[DROP_LOCATION]++==1) { PUSH(DROP_LOCATION); while(stack_used) { size++; POP(curr_pos); do { lattice[curr_pos]-=2; npos=curr_pos+ ( (rand()>RAND_MAX/2) ? 1 : -1); if ((npos>=0) && (npos<LENGTH)) { if (lattice[npos]++==1) {PUSH(npos);} } if ((npos>=0) && (npos<LENGTH)) { if (lattice[npos]++==1) {PUSH(npos);} } } while (lattice[curr_pos]>1); } } } #endif //printf("size is %i\n", size); MOMENTS(size,size); } /* end of iterations loop */ MOMENTS_OUT(size); } /* chunk */ }
int main() { SDL_Surface *temp; /* 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); /* Attempt to set a 640x480 8 bit color video mode */ screen = SDL_SetVideoMode(640, 480, 8,SDL_DOUBLEBUF); if (screen == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; } //load the numbermap image strip of 10 number 64px * 64px temp = SDL_LoadBMP("numbermap.bmp"); if (temp == NULL) { printf("Unable to load numbermap.bmp.\n"); return 1; } /* Set the numbermaps colorkey. */ Uint32 colorkey = SDL_MapRGB(temp->format, 255, 0, 255); SDL_SetColorKey(temp, SDL_SRCCOLORKEY, colorkey); //convert the numbermaps surface to the same type as the screen numbermap = SDL_DisplayFormat(temp); if (numbermap == NULL) { printf("Unable to convert bitmap.\n"); return 1; } SDL_FreeSurface(temp); //load the numbermap image strip of 10 number 64px * 64px temp = SDL_LoadBMP("title.bmp"); if (temp == NULL) { printf("Unable to load numbermap.bmp.\n"); return 1; } /* Set the numbermaps colorkey. */ SDL_SetColorKey(temp, SDL_SRCCOLORKEY, colorkey); //convert the numbermaps surface to the same type as the screen title = SDL_DisplayFormat(temp); if (numbermap == NULL) { printf("Unable to convert bitmap.\n"); return 1; } SDL_FreeSurface(temp); //load the numbermap image strip of 10 number 64px * 64px temp = SDL_LoadBMP("gameover.bmp"); if (temp == NULL) { printf("Unable to load gameover.bmp.\n"); return 1; } //convert the end surface to the same type as the screen end = SDL_DisplayFormat(temp); if (end == NULL) { printf("Unable to convert bitmap.\n"); return 1; } SDL_FreeSurface(temp); /* Initialize the ball position data. */ init_ball(); int quit = 0; int state = 0; Uint8 *keystate = 0; Uint32 next_game_tick = SDL_GetTicks(); int sleep = 0; int r = 0; /* Animate */ while (quit == 0) { /* Update SDL's internal input state information. */ SDL_PumpEvents(); /* Grab a snapshot of the keyboard. */ keystate = SDL_GetKeyState(NULL); /* Respond to input. */ if (keystate[SDLK_ESCAPE]) { quit = 1; } if (keystate[SDLK_DOWN]) { move_paddle(0); } if (keystate[SDLK_UP]) { move_paddle(1); } //draw the background draw_background(); //display main menu if (state == 0 ) { if (keystate[SDLK_SPACE]) { state = 1; } //draw menu draw_menu(); //display gameover } else if (state == 2) { if (keystate[SDLK_SPACE]) { state = 0; //delay for a little bit so the space bar press dosnt get triggered twice //while the main menu is showing SDL_Delay(500); } if (r == 1) { //if player 1 is AI if player 1 was human display the return value of r not 3 draw_game_over(3); } else { //display gameover draw_game_over(r); } //display the game } else if (state == 1){ //check score r = check_score(); if (r == 1) { state = 2; } else if (r == 2){ state = 2; } //paddle ai movement move_paddle_ai(); /* Move the balls for the next frame. */ move_ball(); //draw net draw_net(); //draw paddles draw_paddle(); /* Put the ball on the screen. */ draw_ball(); //draw the score draw_player_0_score(); //draw the score draw_player_1_score(); } /* Ask SDL to update the entire screen. */ SDL_Flip(screen); next_game_tick += 1000 / 60; sleep = next_game_tick - SDL_GetTicks(); if( sleep >= 0 ) { SDL_Delay(sleep); } } return 0; }
void main() { restart: #ifdef JOYSTICK hit_border(); #ifndef LOMEM #if defined(MSX) || defined(SVI) || defined(SC3000) || defined(EINSTEIN) msx_text(); #endif #ifdef SPECTRUM #ifdef ZX81 hrg_off(); zx_colour(112); #endif #endif printf("%c",12); printf("\n CHOOSE YOUR JOYSTICK INTERFACE\n\n"); for (k=0 ; k!=GAME_DEVICES; k++) printf(" %u - %s\n\n",k+1,joystick_type[k]); stick=0; while ((stick<1) || (stick>GAME_DEVICES)) { stick=getk()-48; } #else stick=1; #endif #endif #ifdef SPECTRUM #ifdef ZX81 hrg_on(); zx_colour(112); #endif #endif #ifdef CLOCK srand(clock()); #endif tt=-1; #ifdef ZX81 #if (spritesize == 2) speed=500; #else speed=300; #endif #else #ifdef C128 #else speed=300; #endif #endif start_level: #ifdef ZX81 speed-=100; #else speed-=200; #endif tt++; t=0; p=1; clg(); hit_border(); #ifdef LAMBDA zx_border (INK_CYAN); zx_colour(112); #endif for (m=1; m<=4; m+=2) for (n=0; n<=30; n+=2) { putsprite(spr_or,(n*spritesize),((m+3)*spritesizeh),brick_l); putsprite(spr_or,((n+1)*spritesize),((m+3)*spritesizeh),brick_r); putsprite(spr_or,(n*spritesize),((m+4)*spritesizeh),brick_r); putsprite(spr_or,((n+1)*spritesize),((m+4)*spritesizeh),brick_l); #if (spritesize == 8) #ifdef SPECTRUM #ifdef ZX81 *zx_cyx2aaddr(m+3,n) = m<<4; *zx_cyx2aaddr(m+3,n+1) = m<<4; *zx_cyx2aaddr(m+4,n) = (m+1)<<4; *zx_cyx2aaddr(m+4,n+1) = (m+1)<<4; #else *zx_cyx2aaddr(m+3,n) = m<<3; *zx_cyx2aaddr(m+3,n+1) = m<<3; *zx_cyx2aaddr(m+4,n) = (m+1)<<3; *zx_cyx2aaddr(m+4,n+1) = (m+1)<<3; #endif #endif #endif #ifdef LAMBDA *zx_cyx2aaddr(m+3,n) = m<<4; *zx_cyx2aaddr(m+3,n+1) = m<<4; *zx_cyx2aaddr(m+4,n) = (m+1)<<4; *zx_cyx2aaddr(m+4,n+1) = (m+1)<<4; #endif #if defined(MSX) || defined(SVI) || defined(SC3000) || defined(MTX) || defined(EINSTEIN) #if (spritesize == 8) set_attr(m+3,n,((m+1)<<1)|0x10); set_attr(m+3,n+1,((m+1)<<1)|0x10); set_attr(m+4,n,(m<<1)|0x10); set_attr(m+4,n+1,(m<<1)|0x10); #endif #endif } for (n=0; n<=30; n+=2) { putsprite(spr_or,(n*spritesize),((m+3)*spritesizeh),brick_l); putsprite(spr_or,((n+1)*spritesize),((m+3)*spritesizeh),brick_r); #if (spritesize == 8) #ifdef SPECTRUM #ifdef ZX81 *zx_cyx2aaddr(m+3,n) = 6<<4; *zx_cyx2aaddr(m+3,n+1) = 6<<4; #else *zx_cyx2aaddr(m+3,n) = 6<<3; *zx_cyx2aaddr(m+3,n+1) = 6<<3; #endif #endif #endif #ifdef LAMBDA *zx_cyx2aaddr(m+3,n) = 6<<4; *zx_cyx2aaddr(m+3,n+1) = 6<<4; #endif #if defined(MSX) || defined(SVI) || defined(SC3000) || defined(MTX) || defined(EINSTEIN) #if (spritesize == 8) set_attr(m+3,n,LIGHT_YELLOW|0x10); set_attr(m+3,n+1,LIGHT_YELLOW|0x10); #endif #endif } u=0; v=0; a=14; t=0; w=0; for (r=0; r<=6; r++) { m=10; n=8+rand()%15; p=0; a=13; #if (spritesize == 2) putsprite(spr_or,(a*spritesize),(21*spritesizeh)-1,paddle); #else putsprite(spr_or,(a*spritesize),(21*spritesizeh),paddle); #endif #ifndef LOMEM for (i=0; i<=6; i++) { putsprite (spr_and, (24+i)*spritesize, 23*spritesizeh, ball); if (i>r) putsprite (spr_or, (24+i)*spritesize, 23*spritesizeh, ball); } #endif g=200; /* Let's show where the ball stars before the dance begins */ putsprite(spr_or,(n*spritesize),(m*spritesizeh),ball); hit_border(); #ifdef SOUND for (i=1; i<14; i++) { bit_synth(4, 199+i, 200+i, 239+i, 240+i); putsprite(spr_xor,(n*spritesize),(m*spritesizeh),ball); } bit_synth(9, 255, 254, 253, 252); #endif putsprite(spr_and,(n*spritesize),(m*spritesizeh),ball); while (m <= 20) { /* delay */ do_delay(); move_ball(); /* total score count is 574 */ if (t>=573) goto start_level; if (u==20) putsprite(spr_and,(v*spritesize),(u*spritesizeh),bounce); else putsprite(spr_and,(v*spritesize),(u*spritesizeh),ball); /* Intermediate step to move the ball smoothly */ putsprite(spr_xor,(((n+v)*spritesize)>>1),(((m+u)*spritesizeh)>>1),ball); do_delay(); putsprite(spr_xor,(((n+v)*spritesize)>>1),(((m+u)*spritesizeh)>>1),ball); u=m; v=n; if (m==20) putsprite(spr_or,(n*spritesize),(m*spritesizeh),bounce); else putsprite(spr_or,(n*spritesize),(m*spritesizeh),ball); /* #ifdef SOUND bit_click(); #endif */ #ifdef JOYSTICK if (joystick(stick) & MOVE_LEFT) { move_left(); if (joystick(stick) & MOVE_FIRE) move_left(); } if (joystick(stick) & MOVE_RIGHT) { move_right(); if (joystick(stick) & MOVE_FIRE) move_right(); } #else k=getk(); switch (k) { case '2': move_left(); break case '1': move_left(); move_left(); break; case '9': move_right(); break; case '0': move_right(); move_right(); break; } #endif } /* ball is lost */ #if (spritesize == 2) putsprite(spr_and,(a*spritesize),(21*spritesizeh)-1,paddle); #else putsprite(spr_and,(a*spritesize),(21*spritesizeh),paddle); #endif } #ifdef ZX81 #if (spritesize == 2) #asm ld a,$1e ld i,a #endasm #endif #endif #ifndef LOMEM #ifdef BANNERS putsprite(spr_or,40,(12*spritesizeh),scorebanner); sprintf (scoretxt,"%05u",tt*1000+t); k=0; for (i=0; i<5; i++) { putsprite (spr_or, 140+i+k, 12*spritesizeh+7, &bigdigit[(scoretxt[i]-48)*38]); if (scoretxt[i]=='1') k+=5; else k+=14; } #else printf("%c\n\n Score: %u ",12,tt*1000+t); #endif #endif /* return (tt*1000+t); */ #ifdef SOUND bit_fx2(5); #endif while (getk()) {} while (!getk()) {} goto restart; }
int main(){ __dpmi_meminfo v_ram; char *bas = enter_graphics(MODE_640X480,&v_ram); create_static_sprite(gif_arkanoid,bas,280,240); delay(3*1000); create_static_sprite(novo_jogo, bas, 280, 240); //menu create_static_sprite(sair_jogo, bas, 280, 270); play_sound(10); //plays a sound delay(10*1000); leave_graphics(v_ram); enter_graphics(MODE_640X480,&v_ram); create_static_sprite(framev, bas, 0, 7); create_static_sprite(framev, bas, 633, 7); create_static_sprite(frameh, bas, 0, 0); create_static_sprite(frameh, bas, 0, 473); create_static_sprite(pic_brick1, bas, 580, 10); create_static_sprite(pic_brick2, bas, 540, 10); create_static_sprite(pic_brick3, bas, 500, 10); create_static_sprite(pic_brick4, bas, 460, 10); create_static_sprite(pic_brick1, bas, 420, 10); create_static_sprite(pic_brick2, bas, 380, 10); create_static_sprite(pic_brick3, bas, 340, 10); create_static_sprite(pic_brick4, bas, 300, 10); create_static_sprite(pic_brick1, bas, 260, 10); create_static_sprite(pic_brick2, bas, 220, 10); create_static_sprite(pic_brick3, bas, 180, 10); create_static_sprite(pic_brick4, bas, 140, 10); create_static_sprite(pic_brick1, bas, 100, 10); create_static_sprite(pic_brick2, bas, 60, 10); create_static_sprite(pic_brick3, bas, 20, 10); create_static_sprite(pic_brick4, bas, 580, 40); create_static_sprite(pic_brick1, bas, 540, 40); create_static_sprite(pic_brick2, bas, 500, 40); create_static_sprite(pic_brick3, bas, 460, 40); create_static_sprite(pic_brick4, bas, 420, 40); create_static_sprite(pic_brick1, bas, 380, 40); create_static_sprite(pic_brick2, bas, 340, 40); create_static_sprite(pic_brick3, bas, 300, 40); create_static_sprite(pic_brick4, bas, 260, 40); create_static_sprite(pic_brick1, bas, 220, 40); create_static_sprite(pic_brick2, bas, 180, 40); create_static_sprite(pic_brick3, bas, 140, 40); create_static_sprite(pic_brick4, bas, 100, 40); create_static_sprite(pic_brick1, bas, 60, 40); create_static_sprite(pic_brick2, bas, 20, 40); create_static_sprite(pic_brick3, bas, 580, 70); create_static_sprite(pic_brick4, bas, 540, 70); create_static_sprite(pic_brick1, bas, 500, 70); create_static_sprite(pic_brick2, bas, 460, 70); create_static_sprite(pic_brick3, bas, 420, 70); create_static_sprite(pic_brick4, bas, 380, 70); create_static_sprite(pic_brick1, bas, 340, 70); create_static_sprite(pic_brick2, bas, 300, 70); create_static_sprite(pic_brick3, bas, 260, 70); create_static_sprite(pic_brick4, bas, 220, 70); create_static_sprite(pic_brick1, bas, 180, 70); create_static_sprite(pic_brick2, bas, 140, 70); create_static_sprite(pic_brick3, bas, 100, 70); create_static_sprite(pic_brick4, bas, 60, 70); create_static_sprite(pic_brick1, bas, 20, 70); create_static_sprite(pic_brick2, bas, 580, 100); create_static_sprite(pic_brick3, bas, 540, 100); create_static_sprite(pic_brick4, bas, 500, 100); create_static_sprite(pic_brick1, bas, 460, 100); create_static_sprite(pic_brick2, bas, 420, 100); create_static_sprite(pic_brick3, bas, 380, 100); create_static_sprite(pic_brick4, bas, 340, 100); create_static_sprite(pic_brick1, bas, 300, 100); create_static_sprite(pic_brick2, bas, 260, 100); create_static_sprite(pic_brick3, bas, 220, 100); create_static_sprite(pic_brick4, bas, 180, 100); create_static_sprite(pic_brick1, bas, 140, 100); create_static_sprite(pic_brick2, bas, 100, 100); create_static_sprite(pic_brick3, bas, 60, 100); create_static_sprite(pic_brick4, bas, 20, 100); Sprite* bola = create_sprite_racket(pic_ball, bas); Sprite* raquete = create_sprite_racket(pic_racket, bas); play_sound(9); if(raquete == NULL) return 1; raquete->x = 271; raquete->y = 450; raquete->xspeed = 10; if(bola == NULL) return 1; bola->x = 320; bola->y = 440; bola->xspeed = 5; bola->yspeed = 5; set_kbd_isr(&prev_isr); while(1){ delete_sprite(bola, bas); delete_sprite(raquete, bas); unsigned char c = keyPress(); if(c==0x01) break; if(c==0x4d){ if(raquete->x + raquete->xspeed < 578) raquete->x = raquete->x +raquete->xspeed; }else if(c == 0x4b){ if(raquete->x + raquete->xspeed > 21) raquete->x = raquete->x - raquete->xspeed; } draw_sprite(raquete,bas); draw_sprite(bola, bas); move_ball(bola, raquete, bas); delay(50); } restore_isr(KBD_IRQ,& prev_isr); leave_graphics(v_ram); //sai do modo grafico return 0; }
int main(int player, int n, int dificuldade) { char tela[ALTURA][LARGURA]; Bola b; Raquete r1, r2; int dir, pause = 0; Score s; int i, j; if (n != 1) { inicia(tela, &b, &r1, &r2, &s, 0); } else if (player == 2 && dificuldade == 0) { inicia(tela, &b, &r1, &r2, &s, player); while (1) { COORD cord; cord.X = 0; cord.Y = 0; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cord); desenha_tela(tela, &r1, &r2, &s); if (_kbhit()) { dir = _getch(); while (dir == 'p' && pause == 0) { pause(); SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cord); desenha_tela(tela, &r1, &r2, &s); dir = _getch(); if (dir == 'p') { unpause(); pause++; } else { dir = 'p'; } } pause = 0; dirRaquetes(tela, &r1, dir, &r2); } move_ball(tela, &b, &r1, &r2, &s); } return 0; } else if (player == 1 && (dificuldade == 1 || dificuldade == 2)) { inicia(tela, &b, &r1, &r2, &s, player); while (1) { COORD cord; cord.X = 0; cord.Y = 0; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cord); desenha_tela(tela, &r1, &r2, &s); if (_kbhit()) { dir = _getch(); while (dir == 'p' && pause == 0) { pause(); SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cord); desenha_tela(tela, &r1, &r2, &s); dir = _getch(); if (dir == 'p') { unpause(); pause++; } else { dir = 'p'; } } pause = 0; dirRaquetes_1Player(tela, &r1, dir); } move_ball(tela, &b, &r1, &r2, &s); move_raquetePC(tela, &b, &r2, &r1, dificuldade); } return 0; } else if (player == 3 && dificuldade == 0) { inicia(tela, &b, &r1, &r2, &s, player); while (1) { COORD cord; cord.X = 0; cord.Y = 0; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cord); desenha_tela(tela, &r1, &r2, &s); if (_kbhit()) { dir = _getch(); if (dir == ESC) { exit(0); } while (dir == 'p' && pause == 0) { pause(); SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cord); desenha_tela(tela, &r1, &r2, &s); dir = _getch(); if (dir == 'p') { unpause(); pause++; } else { dir = 'p'; } } pause = 0; } move_ball(tela, &b, &r1, &r2, &s); move_raquetePC(tela, &b, &r2, &r1, dificuldade); } return 0; } }
/* Check if the ball will collide with something if it is moved to the * specified coordinates. If so, the direction is changed and 1 is returned * to indicate that the caller should recalculate the new coordinates and * try again. If there was no collision it returns 0. If something exceptional * happens (eg. the last brick is destroyed or the last ball is lost) it * returns 2 to indicate that the caller should give up trying to move the * ball. */ int check_ball_collision(nbstate *state, coords *c) { int i, bc; grid *g = state->grid; /* Check for a collision with the top of the game area: */ if(c->y < state->ball.s->h + (2 * BALLS_BORDER) + state->scores.h) { /* Bounce the ball back down and ask the caller to try again: */ state->ball.d = normalise_angle(M_PI - state->ball.d); return 1; } /* Check for a collision with the bottom of the game area: */ if(c->y > state->canvasheight - state->ball.s->h) { /* If the solidfloor cheat is active, bounce the ball back up * and ask the caller to try again: */ if(state->flags.sf) { state->ball.d = normalise_angle(M_PI - state->ball.d); return 1; } else { /* Otherwise destroy the ball, move the new ball to * the parked position (park_ball() is called by * lost_ball()) and ask the caller to give up trying * to move the ball: */ lost_ball(state); move_ball(state); return 2; } } /* Check for a collision with the left hand side of the game area: */ if(c->x < 0) { /* Bounce the ball back and ask the caller to try again: */ state->ball.d = normalise_angle((2 * M_PI) - state->ball.d); return 1; } /* Check for a collision with the right hand side of the game area: */ if(c->x > state->canvaswidth - state->ball.s->w) { /* Bounce the ball back and ask the caller to try again: */ state->ball.d = normalise_angle((2 * M_PI) - state->ball.d); return 1; } /* Check for a collision with the bat: */ if(c->y > state->canvasheight - state->batheight - state->ball.s->h && c->x > state->batx - (state->batwidths[state->bat] / 2) - state->ball.s->w && c->x < state->batx + (state->batwidths[state->bat] / 2)) { /* If the collision happened with the side of the bat instead * of the top, we don't care so just tell the caller there * was no collision: */ if(state->ball.y > state->canvasheight - state->batheight - state->ball.s->h) return 0; /* If the StickyBat power-up is active, park the ball: */ if(state->powertimes.stickybat) { park_ball(state); move_ball(state); return 2; } else { /* Otherwise bounce it back up and ask the caller to * try again: */ state->ball.d = normalise_angle(((c->x + (state->ball.s->w / 2) - state->batx) / state->batwidths[state->bat] / 2) * M_PI); return 1; } } /* Check for collisions with the bricks: */ bc = 0; /* No collisions have happened yet. */ /* For each brick in the grid: */ for(i = 0; i < state->width * state->height; i++) { /* If there is a brick in this grid position and the ball * intersects it: */ if(g->b && c->y + state->ball.s->h > g->y && c->y < g->y + state->brickheight && c->x + state->ball.s->w > g->x && c->x < g->x + state->brickwidth) { /* Perform the brick collision actions, and if * something exceptional happens (ie. we destroy the * last brick), return straight away asking the caller * to give up trying to move the ball: */ if(brick_collision(state, g)) return 2; /* Unless the NoBounce cheat is active, bounce the * ball off the brick. Only do this on the first brick * collision we find. */ if(!state->flags.nb && !bc) { bc = 1; /* Bounce off the left face: */ if(state->ball.x + state->ball.s->w < g->x) { state->ball.d = normalise_angle((2 * M_PI) - state->ball.d); /* Bounce off the right face: */ } else if(state->ball.x >= g->x + state->brickwidth) { state->ball.d = normalise_angle((2 * M_PI) - state->ball.d); /* Bounce off the upper face: */ } else if(state->ball.y + state->ball.s->h < g->y) { state->ball.d = normalise_angle(M_PI - state->ball.d); /* Bounce off the lower face: */ } else if(state->ball.y >= g->y + state->brickheight) { state->ball.d = normalise_angle(M_PI - state->ball.d); } else { /* This shouldn't happen, but I don't * trust the above algorithm 100%. */ debug_printf ("Internal error: " "couldn't figure out brick " "collision face\n"); } } } g++; /* Increment to the next grid position. */ } /* If a brick collision occured, ask the caller to try again: */ if(bc) return 1; return 0; /* Otherwise tell the caller that no collision occured. */ }