| Forum Home > Turing > Ball to wall collision using whatdotcolor | ||
|---|---|---|
|
Moderator Posts: 5 |
"Traditional" pong games check collision to see if the x and y cordinates of the ball of less than zero or greater than the max value of that length. This is another way to do it, via whatdotcolor. It checks to see if the next pixel is a certain color. Of course, using this method you must have solid color objects and no jpeg, bmps etc. View.Set ("graphics: max, max") View.Set ("offscreenonly")
var x, y, vx, vy : int := 1 var rad : int := 10
x := maxx div 2 y := maxy div 2
loop cls Draw.Box (0, 0, maxx, maxy, black) Draw.FillOval (x, y, rad, rad, blue) View.Update
x := x + vx % add velocities y := y + vy
delay (5) % check if the ball move offscreen by detecting if the next pixel is black % the black box is drawn as a boarder, if the next pixel is black % you know you are about to go offscreen, so reverse the velocity
if View.WhatDotColor (x, y + rad) = black then vy *= -1 elsif View.WhatDotColor (x, y - rad) = black then vy *= -1 end if if View.WhatDotColor (x + rad, y) = black then vx *= -1 elsif View.WhatDotColor (x - rad, y) = black then vx *= -1 end if end loop
| |
|
-- - Stanley
| ||