Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // == purpose functions ==
- function ball_distx(box_x)
- return box_x-ball_x
- end
- function ball_disty(box_y)
- return box_y-ball_y
- end
- function inrange(num,min,max)
- if num >= min and num <= max then
- flip()
- return true
- else
- return false
- end
- end
- [ . . . ]
- // == the update function ==
- function _update60()
- [ . . . ]
- // move the ball based on the set speed
- ball_x+=ball_dx*ball_speed
- ball_y+=ball_dy*ball_speed
- // if the ball is beyond the right/bottom of the screen...
- if ball_x>115 or ball_y>127
- // ...or the top/left...
- or ball_x<5 or ball_y<2
- then
- // reverse the direction
- ball_dx = -ball_dx
- ball_dy = -ball_dy
- ball_ang = rnd(4)
- // play the ball hit sound sound
- end
- // ball collision
- if ball_disty(110) == 0 and ball_distx(pad_x) >= -4 and ball_distx(pad_x) <= 4 then
- // context: pad_dir is the direction the paddle is facing, which is controlled either by the Z and X buttons or by what direction the paddle is moving in
- if pad_dir == 0 then
- ball_dx = -1
- ball_dy = -1
- end
- if pad_dir == 1 then
- ball_dx = 0
- ball_dy = -1
- end
- if pad_dir == 2 then
- ball_dx = 1
- ball_dy = -1
- end
- //ball_speed += .1
- end
- end
- // == the draw function ==
- function _draw()
- // clear the screen
- cls()
- // print any test variables
- print(ball_distx(pad_x),20,0,7)
- print(ball_disty(110),50,0,7)
- [ . . . ]
- // draw the ball
- spr(ball_spr,ball_x,ball_y)
- // draw the paddle
- spr(pad_spr,pad_x,110)
- // ball animation
- mn = ball_disty(110)
- if inrange(ball_distx(pad_x),-4,4) then
- if inrange(mn,-1,1) then ball_spr = pad_spr end
- if inrange(mn,-2,2) then ball_spr = 18 end
- if inrange(mn,-3,3) then ball_spr = 17 end
- if inrange(mn,-4,4) then ball_spr = 0 end
- else
- if ball_x==112 or ball_x==8 then flip() flip() ball_spr=0 end
- if ball_x==113 or ball_x==7 then flip() flip() ball_spr=1 end
- if ball_x==114 or ball_x==6 then flip() flip() ball_spr=2 end
- if ball_x==115 or ball_x==5 then flip() flip() ball_spr=3 end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment