Hey guys i need help with this assignment at school. Im in year 9 and for the assignment we have to make a two player game on greenfoot.
What i really need help with is collision detection. I am a beginner so i dont know much code but some basics so this collision detection is a real problem for me.
So what my game is ment to be is a simple two player game with a white background and two fist facing each other. Player1 is on the left side at the end and player two the complete opposite (on the right side). There is a face in the middle of the background with the fists pointing at it. The face is KimJongUn (just to let you know). there is ment two be two counters one above Player1 and two above player2. and there is ment to be a timmer ant the top middle of the background witch i havnt done yet. and the aim of the game is who can hit KimJongUn the most times in 30 seconds. who ever gets the most hits wins. and the controls are simple. Player1's controls = UpKey(upwardsarrow) and player2's is the "w" button. but the problem is when i press up for player 1 it only go's half way through KimJongUn and stops and does not count towards the counter. and the game stops.
so what i need help with is the collision from the fist and kimjongun to stop when it hits him and bounce back to its starting position.
HERE is the code i have for player1 and please help me with this:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Player1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player1 extends Animal
{
private Counter counter;
public Player1(Counter pointCounter)
{
counter=pointCounter;
}
public void act()
{
checkKeys();
}
/**
* Act - do whatever the Player1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void checkKeys()
{
if (Greenfoot.isKeyDown("up") )
{
move(75);
}
if (getX()>400) setLocation(400, getY());
}
private Player1 getIntersectingPlayer1()
{
return (Player1) getOneIntersectingObject(Player1.class);
}
}
Please tell me what to do and show the code to fix it.
I need help with in today and the 27th of april 2016 because my assignment is due a couple of days after that
Thanks guys :).

