Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  I have lost my mind - Snake Game Design  (Read 1806 times)
0 Members and 1 Guest are viewing this topic.
Offline Swattkidd7

Junior Devvie





« Posted 2011-12-24 09:00:52 »

Recently I have been working on a bunch of random projects, havent completed anything and they have ranged from top down shooters, asteroids style games, match 3 games etc. So I decided to screw all the complicated designs and just make a complete snake game real quick, however I then realized I HAVE NO IDEA how to properly design a snake game.

I know there is no "right" way to design it but I cant even figure out any way to do it. The way I have been trying to do it is without a grid just using bounding boxes for collisions and having the snake move at a fixed distance every couple of frames or so. Why would I need a grid?

My current design is working, but it seems like its stupid. It is basically a Snake which is made up of a list of Body parts, each update I save the head's old position, update the head, and then loop through each of the Body parts from the end of the list to the front and set each body part to the location of the one next to it, and if its the first element in the array I set it to the "old head" position. It works but seems sloppy or hacked together.

But anyways, how would you guys design this seemingly simple game?
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2011-12-24 11:30:42 »

My first ever snake game, I used an ArrayList of Points. Every time the snake moves, I add a new Point for the new head and remove the last Point. However I don't remove the last point when capturing the apple Smiley
Also the easiest way is to not think about pixels when doing this, just think about your data. You only convert to screen coordinates when rendering. So if you have a grid of 20x20, each point would have an x and y between 0 and 19.

Good luck Smiley

Offline dah01

Junior Devvie


Medals: 7



« Reply #2 - Posted 2011-12-24 14:41:57 »

@ra4king I was thinking about how to do this last night and really couldn't conceptualize this. Until reading your comment. That really does seem like the way to do it.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #3 - Posted 2011-12-24 18:50:41 »

@ra4king ahh, thats actually pretty smart. I was helping some kid out in my programming class, and I did it the way dah01 did it with saving prev locations. but at the time I was more worried about making the stupid thing work in checkboxes (I was using VBA >.<)
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2011-12-24 19:12:01 »

Yeah I remember thinking about it and then suddenly getting that moment of inspiration.
Here is the snake game if you're interested Smiley

Offline Swattkidd7

Junior Devvie





« Reply #5 - Posted 2011-12-24 21:16:16 »

My first ever snake game, I used an ArrayList of Points. Every time the snake moves, I add a new Point for the new head and remove the last Point. However I don't remove the last point when capturing the apple Smiley
Also the easiest way is to not think about pixels when doing this, just think about your data. You only convert to screen coordinates when rendering. So if you have a grid of 20x20, each point would have an x and y between 0 and 19.

Good luck Smiley

Haha much cleaner than the chain reaction idea, I knew there was a simpler way, thanks! Its always nice to see what other people think to clear your brain a bit haha
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (33 views)
2014-11-23 00:13:56

xFryIx (73 views)
2014-11-14 00:34:49

digdugdiggy (52 views)
2014-11-13 09:11:50

digdugdiggy (46 views)
2014-11-13 09:10:15

digdugdiggy (40 views)
2014-11-13 09:09:33

kovacsa (65 views)
2014-11-08 07:57:14

TehJavaDev (69 views)
2014-11-04 10:04:50

BurntPizza (67 views)
2014-11-04 06:54:52

moogie (82 views)
2014-11-03 18:22:04

CopyableCougar4 (82 views)
2014-11-02 11:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-10 10:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-03 10:36:02

List of Learning Resources
by Longor1996
2014-08-16 22:40:00

List of Learning Resources
by SilverTiger
2014-08-06 07:33:27

Resources for WIP games
by CogWheelz
2014-08-02 04:20:17

Resources for WIP games
by CogWheelz
2014-08-02 04:19:50

List of Learning Resources
by SilverTiger
2014-08-01 04:29:50

List of Learning Resources
by SilverTiger
2014-08-01 04:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!