Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 1376 times)
0 Members and 1 Guest are viewing this topic.
Offline Swattkidd7

Junior Member





« Posted 2011-12-24 10: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: 264
Projects: 2


I'm the King!


« Reply #1 - Posted 2011-12-24 12: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 Member


Medals: 7



« Reply #2 - Posted 2011-12-24 15: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
Online h3ckboy
« Reply #3 - Posted 2011-12-24 19: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: 264
Projects: 2


I'm the King!


« Reply #4 - Posted 2011-12-24 20: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 Member





« Reply #5 - Posted 2011-12-24 22: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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (77 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (119 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (178 views)
2013-05-12 17:10:36

kutucuk (178 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.077 seconds with 21 queries.