Click here to Skip to main content
15,897,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone can anyone tell me that how can i start the basic animation in java using its any package. I want to make my own snake game which means he eats his food and grows.

Suggestion required.
Thanks,
Akkywadhwa
Posted

This is not about animation.

You need to repaint the Field the snake is running on. repainting it every time you change something. Repainting it every time you add an apple or stone(? - where those in there?).

You can pass arguments to your Component that specify the snake and the obsticales:

Java
public class PanelPlayGround extends JPanel{

 private Snake oSnake;
 private Obesticales oObsticales;

 public PanelPlayGround(final Snake oSnake, final Obsticales oObsticales){
   super():
   setSnake(oSnake);
   setObsticales(oObsticales);
   ignition();
 }

 private void ignition(){
   // let the fun begin
 }

 public void renewPanel(final Snake oNewSnake, final Obsticales oNewObsticales){
   setSnake(oNewSnake);
   setObsticales(oNewObsticales);
   this.dolayout(); // to repaint the Jpanel
 }

}


The Object Snake contains basically a list of x/y-values to specify which fields of the grid are occupied by the snake.
The Object Obsticales contains a List of Obstical.
Obstical contains one x/y value and one Enum ObsticalType.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900