Android Question Snake Game

Douglas Farias

Expert
Licensed User
Longtime User
How the best way to start snake game?
can someonse give sugestions about?
 

sorex

Expert
Licensed User
Longtime User
I would first create a new folder for the project.

Is it the 80s style of snake game you want?
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
I would first create a new folder for the project.
This is a good start i make this

Is it the 80s style of snake game you want?
Yes

what better way to do this game for someone who is starting programming?
what the best way to make this game easy?
what libs to make this easy *-*
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
you don't need any libs besides the core ones.

do you want it smooth or with snakeblock movement? the second one should be easier.
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
you don't need any libs besides the core ones.
do you want it smooth or with snakeblock movement? the second one should be easier.
can you give examples? in english i dont understand google dont help me now xD
i think snakeblock movement.
snakeblock movement = timer movimentation?
the more easy *-*
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
shortly summerized...

you just need an array that represents your blocky screen.

there you place/erase blocks as you move around.

randomly place the food you need to eat.

check boundaries, food & tail block collision and that's about it.
 
Upvote 0

strat

Active Member
Licensed User
Longtime User
Sorry, I can't write code now so I'll try to explain the principal of a snake movement.

At first, snake should be simple. It may have three square blocks that created by imageview objects.

All block must have own coordinates to move apart from other blocks.

Place snake's block at the left side of the screen and move them from left to right.

When snake come to middle of the screen, suppose that we pressed the up button. Or try to move to upper side. All parts should go upper when they come true place. So you should calculate all blocks coordinates.

If it gave an idea, you can start make three coloured blocks and try to change its left and top coordinates by code.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
just to check if my theory was right I coded a snake game in about 3 hours this morning.

it contains the basic movements, apple placement, collision checks with apple/tail/walls (walls not present at the moment), snake growing, and scoring.

it all fits in 200 lines and with "all" I literaly mean everything which is the declaration of the variables/views, activity start/resume, button events etc included.

and it only requires the core library.


so it should'nt be too hard to make it that's why I will not give the source as you won't learn anything by just copy/pasting code,
you have to live in in how the game works and try to code it like that.

if you're stuck just ask for help and we'll try to help you out.
 

Attachments

  • snake_poc.gif
    8.8 KB · Views: 299
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
shortly summerized...

you just need an array that represents your blocky screen.

there you place/erase blocks as you move around.

randomly place the food you need to eat.

check boundaries, food & tail block collision and that's about it.


Thats a great start. But for a more "professional" game, use the same logic but use libGDX and some nice sprites.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
thrust me, libGDX is overkill for such game. you'll end up writing more code than needed and most logic is outside libgdx anyway.

as I said you don't need any extra library for this even when you want to make it look pretty.
you can make ugly crap games with gdx too you know if you suck at coding libGdx won't help much either.

now it's a 112K apk (which is still too much for what it is but that's the B4A core which has a lot of usefull features included already),
with libGdx it's probably 2.5Mb while you're not using 1% of its features.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…