Ember

Game()

Jun 25th, 2011
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // A pong game using no objects
  2.  
  3. //Initialize
  4. time = current_time;
  5. time_previous = time;
  6. ball_x = room_width/2;
  7. ball_y = room_height/2;
  8. ball_direction = choose(45,135,225,315);
  9. p1_x = 16;
  10. p2_x = room_width-16;
  11. p1_y = 0;//room_height/2;
  12. p2_y = room_height/2;
  13. p1_h = 32;
  14. p2_h = 32;
  15. frames = 60;
  16. started = false;
  17.  
  18. draw_set_color(c_white);
  19.  
  20. //Main loop
  21. while(1)
  22. {
  23.     //Update timing
  24.     time_previous = time;
  25.     time = current_time;
  26.    
  27.     //Sleep until next frame
  28.     sleep((1000/frames)-(time-time_previous));    
  29.    
  30.     //Handle the keyboard stuff and mouse stuff and stuff
  31.     io_handle();
  32.    
  33.     //Update quit and what-not
  34.     if keyboard_check_released(vk_escape) {break; game_end();}
  35.     if started = false if keyboard_check_pressed(vk_space) {started = true;}
  36.    
  37.     //Update Player
  38.     p2_y = mouse_y;
  39.     if p2_y > room_height-(p2_h/2) {p2_y = room_height-(p2_h/2);}
  40.     if p2_y < p2_h/2 {p2_y = p2_h/2;}
  41.    
  42.     //Update AI
  43.     p1_y += (ball_y-p1_y)/32;
  44.    
  45.     //Update Ball
  46.     if started
  47.     {
  48.         ball_x += lengthdir_x(ball_speed,ball_direction);
  49.         ball_y += lengthdir_y(ball_speed,ball_direction);
  50.        
  51.         //if ball_x-16 < p1_x and (ball_y < p1_y+p1_h // still writing this line
  52.     }
  53.    
  54.     //Draw stuff
  55.     draw_clear(c_black);
  56.     // draw_rectangle(0,p1_y-p1_h,p1_x,,false); // still writing this line
  57.     draw_rectangle(p2_x,p2_y-p2_h,room_width,p2_y+p2_h,false);
  58.     draw_rectangle(ball_x-16,ball_y-16,ball_x+16,ball_y+16,false);
  59.     screen_refresh();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment