Original date:2022-10-03 18:11:55 Edited by: Icy_Viking Subject: Ball falls through Screen[SOLVED]

Hi all,

I recently made the bouncing ball example from Raylib using Greg's Euphoria version of FFI. However, as soon as the program starts, the ball doesn't bounce off the screen, it just falls through.

EDIT: Nvm, I figured it out. I'll be pushing it to the examples section of the fork I made.

This FFI has been great, its not perfect, but it works and has made wrapping libraries easier. Ideally, it would be much better to have ballPos.x instead of ballPos[1], but hey we're making progress!

include raylib.e 
atom width = 800 
atom height = 600 
procedure main() 
 InitWindow(width,height,"Bouncing Ball") 
 sequence ballPos = {GetScreenWidth() / 2.0, GetScreenHeight() / 2.0} 
 sequence ballSpeed = {5.0, 4.0} 
 atom ballRadius = 20.0 
 integer paused = 0 
 integer framesCount = 0 
 while not WindowShouldClose() do 
 if IsKeyPressed(KEY_SPACE) and paused = 0  then 
 	paused = 1 
 	elsif IsKeyPressed(KEY_SPACE) and paused = 1 then 
 		paused = 0 
 end if 
 if paused = 0 then 
 	ballPos[1] += ballSpeed[1] --[1] is x 
 	ballPos[2] += ballSpeed[2] --[2] is y 
	if ballPos[1] >= GetScreenWidth() - ballRadius or ballPos[1] <= ballRadius then 
		ballSpeed[1] *= -1.0 --Forgot to add - in front of the 1.0 
	elsif ballPos[2] >= GetScreenHeight() - ballRadius or ballPos[2] <= ballRadius then 
		ballSpeed[2] *= -1.0 
		framesCount += 1 
	end if 
 end if 
  if paused = 1 then 
 	DrawText("Paused",GetScreenWidth() / 2,GetScreenHeight() / 2,50,LIGHTGRAY) 
 end if 
 end while 
end procedure 
Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu