1. Ball falls through Screen[SOLVED]
- Posted by Icy_Viking Oct 03, 2022
- 833 views
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()
2. Re: Ball falls through Screen[SOLVED]
- Posted by irv Oct 04, 2022
- 795 views
enum x,y -- will help, but I still prefer dot notation.
3. Re: Ball falls through Screen[SOLVED]
- Posted by Icy_Viking Oct 04, 2022
- 749 views
enum x,y -- will help, but I still prefer dot notation.
Thanks for the tip. I prefer dot notation as well.
4. Re: Ball falls through Screen[SOLVED]
- Posted by petelomax Oct 05, 2022
- 722 views
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.
5. Re: Ball falls through Screen[SOLVED]
- Posted by euphoric (admin) Oct 05, 2022
- 813 views
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.
6. Re: Ball falls through Screen[SOLVED]
- Posted by Icy_Viking Oct 05, 2022
- 696 views
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.
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.
7. Re: Ball falls through Screen[SOLVED]
- Posted by ghaberek (admin) Oct 05, 2022
- 701 views
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.
-Greg
8. Re: Ball falls through Screen[SOLVED]
- Posted by irv Oct 06, 2022
- 642 views
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
9. Re: Ball falls through Screen[SOLVED]
- Posted by ghaberek (admin) Oct 06, 2022
- 679 views
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.
-Greg
10. Re: Ball falls through Screen[SOLVED]
- Posted by euphoric (admin) Oct 06, 2022
- 658 views
Have y'all ever heard of lodash?
11. Re: Ball falls through Screen[SOLVED]
- Posted by ghaberek (admin) Oct 06, 2022
- 667 views
Have y'all ever heard of lodash?
(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
12. Re: Ball falls through Screen[SOLVED]
- Posted by irv Oct 06, 2022
- 623 views
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
13. Re: Ball falls through Screen[SOLVED]
- Posted by ghaberek (admin) Oct 07, 2022
- 597 views
Just for fun, let's write a working program with emojis:
Probably best to just replace all the keywords with emoji.
ðŸ 🇠😀 🔤Hello World!🔤â—ï¸ ðŸ‰
-Greg
14. Re: Ball falls through Screen[SOLVED]
- Posted by irv Oct 07, 2022
- 590 views
🗣ï¸ðŸ¥§ï¸
3.14159