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_xspeed = choose(-2,2);
- ball_yspeed = choose(-1,1);
- //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;
- p1_s = 0;
- p2_s = 0;
- frames = 60;
- started = false;
- f_game = font_add("Fixedsys",8,false,false,0,255);
- f_ball = font_add("Fixedsys",32,false,false,0,255);
- fade = 1;
- draw_set_color(c_white);
- draw_set_halign(fa_center);
- draw_set_valign(fa_middle);
- //Sound
- if file_exists("C:\Windows\Media\Speech Misrecognition.wav") {s_hit = sound_add("C:\Windows\Media\Speech Misrecognition.wav",0,1); sounds = true;}
- else if file_exists("C:\Windows\Media\Windows Information Bar.wav") {s_hit = sound_add("C:\Windows\Media\Windows Information Bar.wav",0,1); sounds = true;}
- else sounds = false;
- //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) or mouse_check_button(mb_left) {started = true; ball_xspeed = choose(-2,2); ball_yspeed = choose(-1,1);}
- if fade > 0.01 fade *= 0.95; else fade = 0;
- //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
- if ((p2_s-p1_s) != 4 and (p2_s-p1_s) != 0) p1_y += (ball_y-p1_y)/(32-((p2_s-p1_s)*8));
- if (p2_s-p1_s) = 0 p1_y += (ball_y-p1_y)/32;
- if (p2_s-p1_s) = 4 p1_y += (ball_y-p1_y);
- //Update Ball
- if started
- {
- ball_x += ball_xspeed;//lengthdir_x(ball_speed,ball_direction);
- ball_y += ball_yspeed;//lengthdir_y(ball_speed,ball_direction);
- //Enemy paddle
- if ball_x-8 <= p1_x and (ball_y-8 <= p1_y+p1_h and ball_y+8 >= p1_y-p1_h) and ball_xspeed < 0
- {
- ball_xspeed *= -1.025;
- ball_yspeed *= 1.1;
- if sounds sound_play(s_hit);
- }
- //Enemy goal
- if ball_x-8 <= 0
- {
- started = false;
- ball_x = room_width/2;
- ball_y = room_height/2;
- p2_s += 1;
- fade = 1;
- }
- //Player paddle
- if ball_x+8 >= p2_x and (ball_y-8 <= p2_y+p2_h and ball_y+8 >= p2_y-p2_h) and ball_xspeed > 0
- {
- ball_xspeed *= -1.025;
- ball_yspeed *= 1.025;
- if sounds sound_play(s_hit);
- }
- //Player goal
- if ball_x+8 >= room_width
- {
- started = false;
- ball_x = room_width/2;
- ball_y = room_height/2;
- p1_s += 1;
- fade = 1;
- }
- //Room bounds
- if ball_y+8 >= room_height or ball_y-8 <= 0
- {
- ball_yspeed *= -1.025;
- ball_yspeed *= 1.025;
- if sounds sound_play(s_hit);
- }
- }
- //Draw stuff
- draw_clear(merge_color(c_black,c_white,fade));
- draw_rectangle(0,p1_y-p1_h,p1_x,p1_y+p1_h,false);
- draw_rectangle(p2_x,p2_y-p2_h,room_width,p2_y+p2_h,false);
- draw_rectangle(ball_x-8,ball_y-8,ball_x+8,ball_y+8,false);
- draw_set_font(f_game);
- if !started draw_text(room_width/2,room_height/2-32,"Press <Spacebar> to start");
- draw_text(32,4,p1_s);
- draw_text(room_width-32,4,p2_s);
- draw_set_font(f_ball);
- if started draw_text(room_width/2,room_height/2,abs(ball_xspeed));
- screen_refresh();
- }
Advertisement
Add Comment
Please, Sign In to add comment