1. 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!

My Github fork: https://github.com/gAndy50/libffi-euphoria

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 
  
 SetTargetFPS(60) 
  
 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 
 
	else 
		framesCount += 1 
	end if 
 end if 
  
 BeginDrawing() 
  
 ClearBackground(RAYWHITE) 
  
 DrawCircleV(ballPos,ballRadius,MAROON) 
  
 DrawFPS(1,1) 
 
  if paused = 1 then 
 	DrawText("Paused",GetScreenWidth() / 2,GetScreenHeight() / 2,50,LIGHTGRAY) 
 end if 
  
 EndDrawing() 
 	 
 end while 
  
 CloseWindow() 
	 
end procedure 
 
main() 
new topic     » topic index » view message » categorize

2. Re: Ball falls through Screen[SOLVED]

enum x,y -- will help, but I still prefer dot notation. 
new topic     » goto parent     » topic index » view message » categorize

3. Re: Ball falls through Screen[SOLVED]

irv said...
enum x,y -- will help, but I still prefer dot notation. 

Thanks for the tip. I prefer dot notation as well.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Ball falls through Screen[SOLVED]

Icy_Viking said...
irv said...
enum x,y -- will help, but I still prefer dot notation. 

Thanks for the tip. I prefer dot notation as well.

Here's an older version of that demo, better than either [] or dot notation imo.

include Euraylib.ew 
 
atom width = 800, height = 450 
 
InitWindow(width,height,"Bouncing Ball") 
 
atom ball_x = width/2, 
     ball_y = height/2, 
     ball_speed_x = 5.0, 
     ball_speed_y = 4.0, 
     ball_radius = 20 
 
integer paused = 0, 
        frameCounter = 0 
 
SetTargetFPS(60) 
 
constant black = #00000000, 
         green = #FF00FF00, 
           red = #FF0000FF 
 
while not WindowShouldClose() do 
 
    if IsKeyPressed(KEY_SPACE) then 
        paused = not paused 
    end if 
     
    if paused = 0 then 
        ball_x += ball_speed_x 
        ball_y += ball_speed_y 
         
        if ball_x >= width - ball_radius 
        or ball_x <= ball_radius then 
            ball_speed_x *= -1.0 
        end if 
        if ball_y >= height - ball_radius 
        or ball_y <= ball_radius then 
            ball_speed_y *= -1.0 
        end if 
    end if 
    frameCounter += 1 
     
    BeginDrawing() 
     
    ClearBackground(black) 
     
    DrawCircleV(ball_x,ball_y,ball_radius,red) 
     
    if paused = 1  and frameCounter / 30 then 
        DrawText("PAUSED",1,20,30,green) 
    end if 
     
    DrawFPS(1,1) 
     
    EndDrawing() 
     
end while 
 
CloseWindow() 

The only thing dot notation even slightly makes sense for me is intellisense lookup, but that's a fairly weak argument:
after keying in ball_ you should get the same set of "sub-fields", and showing an intellisense for bal of balance/ball/balloney
rather than them plus all k+l+m sub-fields is something it could do with underscore notation anyway, plus (potentially and
somthing of a minor issue) all in a single intellisense lookup rather than forcing two.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Ball falls through Screen[SOLVED]

petelomax said...

The only thing dot notation even slightly makes sense for me is intellisense lookup... something it could do with underscore notation anyway...

The period is way easier to type than the underscore. grin

new topic     » goto parent     » topic index » view message » categorize

6. Re: Ball falls through Screen[SOLVED]

euphoric said...
petelomax said...

The only thing dot notation even slightly makes sense for me is intellisense lookup... something it could do with underscore notation anyway...

The period is way easier to type than the underscore. grin

I agree with euphoric, dot notation is easier to type. For me, dot noation along with intellisense makes it easier to keep track of variables.

new topic     » goto parent     » topic index » view message » categorize

7. Re: Ball falls through Screen[SOLVED]

An underscore is part of the identifier while a dot provides a lexical break between identifiers. This is important to having a parser provide proper classes with methods, properties, inheritance, etc.

Heck, an underscore itself is a valid identifier, so if you created an object named "_" of a class with a property named "_" which then had a method named "_" you could write _._._() as valid code. grin

-Greg

new topic     » goto parent     » topic index » view message » categorize

8. Re: Ball falls through Screen[SOLVED]

There's a function in EuGTK named _()

-- Nifty shortcut - thanks to Greg Haberek 
-- usage: _("MyFunk") 
-- allows using local functions without call_back(routine_id()) and scope issues. 
 
export function _(sequence name, atom rid = routine_id(name)) 
 if rid > 0 then 
    return call_back(rid) 
 end if 
 return 0 
end function 

There's also (in EuGTK) the ability to name objects and user-defined data pretty much anyway you wish:

object win = create(GtkWindow,"name=_") 
set("_","data","_",42) -- create a data item named "_" for the window named "_" with a value of 42 
settings:Save(ini,"_._",42) -- and save or restore to/from an ini file by object.name 
new topic     » goto parent     » topic index » view message » categorize

9. Re: Ball falls through Screen[SOLVED]

irv said...

There's a function in EuGTK named _()

-- Nifty shortcut - thanks to Greg Haberek 
-- usage: _("MyFunk") 
-- allows using local functions without call_back(routine_id()) and scope issues. 
 
export function _(sequence name, atom rid = routine_id(name)) 
 if rid > 0 then 
    return call_back(rid) 
 end if 
 return 0 
end function 

I was using this as shorthand for allocate_string() but once I get libffi implemented I'll have string support baked into the backend.

public function _( sequence string, integer cleanup=TRUE ) 
    return allocate_string( string, cleanup ) 
end function 

I had originally gotten the idea from wxWidgets, which uses a _() macro for translating strings.

https://docs.wxwidgets.org/stable/group__group__funcmacro__string.html#ga8a02b8875a521df57263a9e6f090f2d0

-Greg

new topic     » goto parent     » topic index » view message » categorize

10. Re: Ball falls through Screen[SOLVED]

Have y'all ever heard of lodash? grin

new topic     » goto parent     » topic index » view message » categorize

11. Re: Ball falls through Screen[SOLVED]

euphoric said...

Have y'all ever heard of lodash? grin

(Not to be confused with Lode Vandevenne aka lodev.) That looks like it's just jQuery's $() with a different shorthand character.

Current trend is to eschew any particular JavaScript "framework" as modern browsers typically include all the DOM parsing and whatnot one needs out of the box.

Of course the corollary to that is "and then use WebAssembly" which makes it 10x harder to debug your client-side code since it's all distilled down to byte code.

-Greg

new topic     » goto parent     » topic index » view message » categorize

12. Re: Ball falls through Screen[SOLVED]

Just for fun, let's write a working program with emojis:

include GtkEngine.e 
 
constant 
  win = create(GtkWindow,"name=🈴️;border=10;$destroy=Quit"), 
  pan = create(GtkBox,"name=🍱️;orientation=vertical"), 
  box = create(GtkButtonBox,"name=📥️"), 
  btn1 = create(GtkButton,"🚮️","Quit"), 
  btn2 = create(GtkButton,"👍","response","😀️") 
  set(btn1,"name","☝️") 
  set(btn2,"name","✌️️") 
   
  add("🈴️","🍱️") 
  add("📥️","☝️") 
  add("📥️","✌️️") 
  pack("🍱️","📥️") 
   
  show_all("🈴️") 
  main() 
   
  global function response(atom ctl, object x) 
    return Info(,,x) -- popup with smiley face 
  end function 
new topic     » goto parent     » topic index » view message » categorize

13. Re: Ball falls through Screen[SOLVED]

irv said...

Just for fun, let's write a working program with emojis:

Probably best to just replace all the keywords with emoji.

🏁 🍇 
  😀 🔤Hello World!🔤❗️ 
🍉 

-Greg

new topic     » goto parent     » topic index » view message » categorize

14. Re: Ball falls through Screen[SOLVED]

🗣️🥧️
3.14159

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu