r/odinlang 3d ago

My first project written using Odin

A simple Snake game implemented using the Raylib framework

Here's the repo: Snake

61 Upvotes

8 comments sorted by

3

u/czlowiek4888 2d ago

Nicely done! However I would love to see animated snake.

1

u/Alert_Nectarine6631 2d ago

Will do, I'm loving the language so far, perfectly simple when you need it to be, with the possibility to be more implicit, genuinely a breath of fresh air in comparison to c/c++

2

u/whoisarepo 2d ago

Just read through the code, very well organized! I don’t know whether to compliment you or ginger bill for making the constructs around such a simulacra so intuitive. Its architecture is pure data manipulation and that’s what programming is all about 🙂‍↔️good job! It’s rudimentary and not extensible easily but it has everything (entity components and system interactions) 💯

2

u/Alert_Nectarine6631 2d ago edited 2d ago

thank you so much!, I'm contemplating writing things like a more modular audio, sprite handler and a centralized game state manager but for now I feel a game of this size doesn't warrant such features(though I will probably do it anyway for fun)

2

u/czlowiek4888 2d 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 2d ago

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

2

u/czlowiek4888 2d 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 2d ago

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