I'm quite new in the programming world and I came across a problem I couldn't solve myself. I wanted to create a 2 player tank game where they have to fight each other. I also wanted to have some blocks the players can't pass through, but i don't l know how to add them.
Here is my code for Player1:
public class Player1 extends Player
{
public Player1()
{
setImage("Blue.png");
getImage().scale(40,40);
}
public void act()
{
moveAround();
isTouchingBlock();
}
private void moveAround()
{
if(Greenfoot.isKeyDown("w"))
{
move(2);
}
if(Greenfoot.isKeyDown("a"))
{
setRotation(getRotation()-2);
}
if(Greenfoot.isKeyDown("s"))
{
move(-2);
}
if(Greenfoot.isKeyDown("d"))
{
setRotation(getRotation()+2);
}
}
public void isTouchingBlock()
{
if(isTouching(Stein.class))
{
setLocation(getX(), getY());
}
}
}
Stein.class is my block that shouldn't be passed. There is nothing in that code yet.
I'd appreciate every help.
Thanks!