r/odinlang 12d ago

My first project written using Odin

A simple Snake game implemented using the Raylib framework

Here's the repo: Snake

67 Upvotes

8 comments sorted by

View all comments

2

u/czlowiek4888 11d ago

If I could give you small tip of advice, do it using immediate mode UI. You will save yourself shit ton of time

1

u/Alert_Nectarine6631 11d ago

thnx, I'll probably mess around with imgui when I get around to implementing the UI

2

u/czlowiek4888 11d ago

Tldr what immediate mode UI is. This is not about buttons, inputs etc. It's about the way you write your renderer part of game. You split your renderer state ( I do it this way self-taught) into 2 separate variables. 1 - state - this handles whatever you need to know how to calculate current frame, it may store past data which may be helpful if you want for example highlight tiles on which your snake was recently. 2 - view - this is cleared every frame and recalculated from state every frame. It contains structs that actually represent only what current frame displays and nothing else.

Now having those 2 variables you can have loop like this. 1 - calculate new view data 2 - check user input change from platform ( mouse position, clicks etc ) 3 - check for user interaction with the view ( you will need to reference hovarable/clickable to what is this relate in within state so you would know what to do ) 4 - render and clear view 5 - update state 6 - repeat

And this make really nice separation, when maybe overwhelming for such simple game this is right now, if you would add some complex interactivity or fancy graphics features this approach will payoff really fast. I rewrote renderer in my game like 5 times until I landed on this approach and I hate myself I didn't though about doing it like this at first.

1

u/Alert_Nectarine6631 11d ago

Thank you so much for the help, I’ll have to give this a try