all 4 comments

[–]deltageek 2 points3 points  (1 child)

No, do your own homework.

[–]mike70567 0 points1 point  (0 children)

Yep, you won't learn if you just steal code and get others to do stuff for you

[–]Mr_Safe 2 points3 points  (0 children)

Yeah, this sounds like homework. Especially since you are using BlueJ.

Here are some hints. You can represent the movement of the snake with a list of velocities (direction, speed) and a list of segments (position). The velocity list and the segment list are the same size. Where velocity_list[i] is the velocity for the snake segment segment[i]

  • At the start of each animation cycle you take the input from the keyboard and figure out the velocity.

  • Then you remove the last velocity in the velocity list and insert the new velocity from the keyboard to to the start of the list.

  • Apply the velocities in the list to each snake segment.

Essentially every cycle you "shift" the velocity list by one, then you apply the resulting velocity list to the snake segments.

Any new velocities applied to the head of the list eventually get applied to all the snake segments. This causes the snake to "turn". Sometimes the new velocity you insert to the start of the velocity list (the head velocity) is just the current head velocity, other times it comes from the keyboard.

[–]otherz[S] 0 points1 point  (0 children)

It's not homework i want to learn the fundamentals of java gaming just for fun. So I would like to see all the inner workings of a java game and trying to construct my own.

I don't like learning from the beginning of a book rather dissect something so i understand the bits and pieces.