Snakeling: A snake clone

Description

A snake clone for Arduboy With 3 levels of difficulty.

Instructions

Eat apples, to score points and grow bigger. do not crash into walls, do not your own tail.

Download

Download an updated version on Github.

13 Likes

Nice one :slight_smile: What would be the next game?

I am prototyping a platforming game based on “life of pixel” that might be next :blush:

dragula96 or game factory ? :wink:

3 Likes

Hi dragula96!

Really nice example! I just have one question to your code - sorry I am a C++ n00b.

What is the reason you use the bitwise operator | in your collision check and not || ?

void checkCollision() {
  if (x < 0 | x > width - unitSize | y > height - unitSize | y < 0) {  ... gameover = true; }

I understand the general idea of bitwise operators ( like 0 | 1 leads to 1 or 0 & 1 to 0 …) but I don’t get their “advantage” in the if-clause? (All I see is you are checking four cases, if one is true then you set gamover to true).

Many thanks and best regards!

Hi computermouse256!

Please correct me if I’m wrong, but I think, that each comparison returns a TRUE or FALSE. So the bitwise operators works, but the boolean operaters || would be faster.

Robert

good question, i used | and it worked, so i just left it like that, i never went back to try and optimize the code.

while single or is valid double || can be faster as only one condition needs to be evaluated true for the branch to be taken where the other requires the entire line to be evaluated before determining if the branch is taken. Either way it’s somewhat CPU/compiler dependent and the gains wont be very noticeable. Still it’s generally better/wiser to use double then single as it’s cleaner and leads to less possible ambiguity issues or your code being improperly converted.

It might be worth looking up the difference between bitwise vs logical operators in C/C++ standard.

-edit-
For the more complex people, yes there are times when bitwise is faster. It just comes down to knowing what you’re doing and what you expect from your code.

Using double is generally better than single, but using double then single is a total waste. You don’t need to do both. :wink:

I don’t know what i’m doing. I’m more of the “if it aint broke dont fix it type of guy” :smile:

1 Like

So I compiled the game but when I upload it nothing happens. Works with other games but not this one.

Looks cool! I just watched a video about the Arduboy and the guy said if someone made a “snake” game he would download it in a second. I can try to find the video and link it if you want. :slightly_smiling:

1 Like

I’m getting this too. When I compile it also gives me low memory warnings? Maybe that’s it?

Please check the official list posted on the forums, it’s likely this game hasn’t been updated to work on the production hardware.

Ill port this to the retail version in a few weeks

I played it just fine on my retail arduboy already?

It doesnt work for me.

1 Like

Hey @RamonML,

Could you describe a little bit more about what happened when you tried to load and run the game? Was there any error message the game output? Was it like anyone else’s above?

I can load properly the sketch, no error message, but the screen get black.
I have an Arduboy 1.0.

Thanks for your reply and sorry about my english.

Try this one out :smiley: https://codebender.cc/sketch:292546