1. Bouncing Ball?
- Posted by David Roach <roachd_76 at YAHOO.COM> May 11, 2000
- 478 views
Could someone give me an idea as to how to get a ball to bounce around the screen in Windows. Everything I try just doesn't seem to work. Thanks Dave
2. Re: Bouncing Ball?
- Posted by simulat <simulat at INTERGATE.BC.CA> May 11, 2000
- 448 views
Umm - - - my Mom always said if I bounced a ball on a Window I'd break it. Maybe that's your problem. It's easy to do in dos. Bye Martin ----- Original Message ----- From: David Roach <roachd_76 at YAHOO.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Wednesday, May 10, 2000 11:02 PM Subject: Bouncing Ball? > Could someone give me an idea as to how to get a ball to bounce around the > screen in Windows. Everything I try just doesn't seem to work. > Thanks > > Dave >
3. Re: Bouncing Ball?
- Posted by David Roach <roachd_76 at YAHOO.COM> May 11, 2000
- 446 views
I don't buy that for a second. I just can't figure out a routine( I guess that's what you'd call it) for this. Why would it be so hard to do in Windows? All you are doing is dealing with coordinates and angles. Simple stuff. Just for the like of me I can't figure it out. I think I have gon brain. Dead.
4. Re: Bouncing Ball?
- Posted by David Cuny <dcuny at LANSET.COM> May 12, 2000
- 472 views
David Roach wrote: > Could someone give me an idea as to how to get a ball > to bounce around the screen in Windows. Everything I > try just doesn't seem to work. I wasn't sure which you wanted, so here are two: one that bounces in a window, and the other that bounces in the window screen. Note that the first on really should use double buffering. Hope this helps! -- David Cuny -- VERSION 1: BOUNCES IN WINDOW -- include win32lib.ew constant Win = create( Window, "Bounce Demo", 0, Default, Default, 200, 100, 0 ), BallSize = 20, -- size of ball BallRate = 2 -- smoothness of motion integer x, y, dx, dy -- ball initial position x = 0 y = 0 -- ball initial vector dx = rand(3)*BallRate dy = rand(3)*BallRate -- tick early and often setTimer( Win, 1, 1 ) procedure Tick( integer timer ) sequence size -- move ball x += dx y += dy -- get window size size = getClientRect( Win ) -- hit top or bottom? if x < size[1] then -- don't go past top x = size[1] -- change direction dx = rand(3)*BallRate elsif x+BallSize > size[3] then -- don't go past bottom x = size[3]-BallSize -- change direction dx = -rand(3)*BallRate end if -- hit left or right? if y < size[2] then -- don't go past left y = size[2] -- change direction dy = rand(3)*BallRate elsif y+BallSize > size[4] then -- don't go past right y = size[4]-BallSize -- change direction dy = -rand(3)*BallRate end if -- erase window repaintWindow( Win ) -- draw ball drawEllipse( Win, True, x, y, x+BallSize, y+BallSize ) end procedure onTimer[Win] = routine_id("Tick") WinMain( Win, Normal ) -- VERSION 2: BOUNCES IN SCREEN include win32lib.ew constant Win = create( Window, "Bounce Demo", 0, Default, Default, 200, 100, 0 ), Pix = create( Pixmap, "", 0, 0, 0, BallSize, BallSize, 0 ), BallSize = 20, -- size of ball BallRate = 2 -- smoothness of motion integer x, y, dx, dy -- ball initial position x = 0 y = 0 -- copy area behind ball bitBlt( Pix, 0, 0, Screen, x, y, BallSize, BallSize, SRCCOPY ) -- ball initial vector dx = rand(3)*BallRate dy = rand(3)*BallRate -- tick early and often setTimer( Win, 1, 1 ) procedure Tick( integer timer ) sequence size -- restore area behind ball copyBlt( Screen, x, y, Pix ) -- move ball x += dx y += dy -- get window size size = getSize( Screen ) -- hit top or bottom? if x < size[1] then -- don't go past top x = size[1] -- change direction dx = rand(3)*BallRate elsif x+BallSize > size[3] then -- don't go past bottom x = size[3]-BallSize -- change direction dx = -rand(3)*BallRate end if -- hit left or right? if y < size[2] then -- don't go past left y = size[2] -- change direction dy = rand(3)*BallRate elsif y+BallSize > size[4] then -- don't go past right y = size[4]-BallSize -- change direction dy = -rand(3)*BallRate end if -- copy area ball will cover bitBlt( Pix, 0, 0, Screen, x, y, BallSize, BallSize, SRCCOPY ) -- draw ball drawEllipse( Screen, True, x, y, x+BallSize, y+BallSize ) end procedure onTimer[Win] = routine_id("Tick") WinMain( Win, Normal )