This game is supposed to be an excersize for learning programmers. It doesn't make sense to give away the code, but I've freely described how it works due to the number of comments/pms on how this and some of my other programs are made. I did this with just the knowledge of the case studies available online and a bit of Googling, so you should be able to as well.
This is a quick Snake game I wrote in under an hour. It's Yoshi themed- Yoshi is followed by its eggs. If you let it step on on egg or walk off the grid, it's game over. Eat the food (still rocks in this version, will update later) and gain an egg.
Code Walkthrough (- means carrot, those characters just aren't allowed.):
SnakeWorld-Actor- extends World-Actor-
public SnakeWorld(Yoshi, grid){
call super, then assign Yoshi or its location to a private variable.
}
public boolean keyPressed(str, loc){
Send Yoshi a setdirection method based on the controls of your choice (I have A, S, D, W, others like arrows and others like keypad).
Always return true on a keypress in GridWorld
}
public static newFood(){
place a sweet in any random empy location
}
Yoshi extends Bug
Yoshi(){super();}
void act(){
check if the location it's looking at is VALID, then if it is EMPTY. If so, move forward and create a new egg where it was previously at. If it is not empty but there is food, increment Yoshi's counter. If not, remove Yoshi from the game and let the world clear itself.
}
public getCount(){
return the number of times Yoshi ate food
}
Egg extends Rock(){
void act(){
increment age. if age is greater than getCount of Yoshi, remove the egg from the grid.
}
That goes so fast o.o
bumrang 9 months ago
@bumrang Its because hypercam speeds up videos. It's not really that fast, but that bar on the bottom can change the speed to be faster than in the video.
1232121212321212 9 months ago