This is the alpha version of the completed game. There still remain some bugs that will need to be ironed out. Note that double buffering is not currently implemented for all objects on screen (at present, only the player and the mushrooms collection implement it). As a result, there is a noticable flickering of the spider, scorpion and centipede objects
I think the only thing worth going into detail about is the structure of the centipede class:
Attributes|_ x position (int)
|_ y position (int)
|_ diameter (int)
|_ isHit (boolean) //goes high when a segment is hit
|_ allBlobsDead (boolean) //goes high when all segments are dead (at which point, the player progresses to the next level)
|_ centipedeBug[] (Centipede) //array that stores centipede's "blobs"
|_ n (int) //length of centipede
Functions|_ Centipede[] generate(int n) //creates a centipede array of length 'n'
|_ void checkCollision(Centipede currentBlob) //constantly checks for any collisions between the centipede and the mushrooms on the screen
|_ void run() //loops as long as the centipede thread is alive performing all the movement and collision detection operations
It's important to note that with my design, and there might be better ways of doing this, each segment in the centipede is independant and only linked to the other segments via the array collection. This means that each segment's isFlag can go to 'true' when it is hit, and then it can either be removed or transformed into a mushroom or whatever.
Here is an outline of how checkCollision() works:
CODE
Loop i=0 to length of centipede[]
currentBlob=centipede[i]
Loop i=0 to length of mushrooms[]
Get Mushroom object at mushrooms[i]
if currentBlob.xPosition or currentblob.yPos overlap mushroom[i].xPosition or mushroom[i].yPosition
if mushroom is poisoned
drop to bottom of screen
end if
if mushroom is not poisoned
switch direction
end if
end if
Loop
Loop
A working demo can be found at:
http://www.cyberiapc.com/java/centipede/8/...8/Centipede.htmNote: For the same reason I couldn't get the previous versions up, this one seems to be loading too slowly in the context of a browser, making the game virtually unplayable.