Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A pong game using no objects
- //Initialize
- time = current_time;
- time_previous = time;
- ball_x = room_width/2;
- ball_y = room_height/2;
- ball_direction = choose(45,135,225,315);
- p1_x = 16;
- p2_x = room_width-16;
- p1_y = 0;//room_height/2;
- p2_y = room_height/2;
- p1_h = 32;
- p2_h = 32;
- frames = 60;
- started = false;
- draw_set_color(c_white);
- //Main loop
- while(1)
- {
- //Update timing
- time_previous = time;
- time = current_time;
- //Sleep until next frame
- sleep((1000/frames)-(time-time_previous));
- //Handle the keyboard stuff and mouse stuff and stuff
- io_handle();
- //Update quit and what-not
- if keyboard_check_released(vk_escape) {break; game_end();}
- if started = false if keyboard_check_pressed(vk_space) {started = true;}
- //Update Player
- p2_y = mouse_y;
- if p2_y > room_height-(p2_h/2) {p2_y = room_height-(p2_h/2);}
- if p2_y < p2_h/2 {p2_y = p2_h/2;}
- //Update AI
- p1_y += (ball_y-p1_y)/32;
- //Update Ball
- if started
- {
- ball_x += lengthdir_x(ball_speed,ball_direction);
- ball_y += lengthdir_y(ball_speed,ball_direction);
- //if ball_x-16 < p1_x and (ball_y < p1_y+p1_h // still writing this line
- }
- //Draw stuff
- draw_clear(c_black);
- // draw_rectangle(0,p1_y-p1_h,p1_x,,false); // still writing this line
- draw_rectangle(p2_x,p2_y-p2_h,room_width,p2_y+p2_h,false);
- draw_rectangle(ball_x-16,ball_y-16,ball_x+16,ball_y+16,false);
- screen_refresh();
- }
Advertisement
Add Comment
Please, Sign In to add comment