Hey
I really could use some help! I am trying to program a new game that is similar to Mario Kart and I am almost finished. but I am experiencing some problems and troubles. firstly, I want that whenever a player arrives at the finishing line it stops the movement and a little sound plays in the background. Honestly, I am very new to programming and I don't really know much about it yet. though I still have to complete this school project... Oh and don't mind my English I am not a native :)
Here is what I have now:
public void act()
{
// Ergänzen Sie Ihren Quelltext hier...
int lDirection = this.getRotation();
if (this.canMove())
{
switch(lDirection)
{
case 0 :
this.setLocation(getX()+ 1, getY());
break;
case 90 :
this.setLocation(getX(), getY()+1);
break;
case 180 :
this.setLocation(getX()-1, getY());
break;
case 270 :
this.setLocation(getX(), getY()-1);
break;
}
Greenfoot.delay(1);
}
else
{
System.out.println("Vorbei :(");
}
}
public boolean canMove()
{
if (this.getRotation() == 0 && this.getX() == this.getWorld().getWidth()-1)
{
return false;
}
if (this.getRotation() == 90 && this.getY() == this.getWorld().getHeight()-1)
{
return false;
}
if (this.getRotation() == 180 && this.getX() == 0)
{
return false;
}
if (this.getRotation() == 270 && this.getY() == 0)
{
return false;
}
return true;
}
public void drive(){
while (this.canMove()){
act();
race();
}
}
public void race(){
if (Greenfoot.isKeyDown("Left"))
{
setRotation(180);
drive();
}
if (Greenfoot.isKeyDown("Down"))
{
setRotation(90);
drive();
}
if (Greenfoot.isKeyDown("Up"))
{
setRotation(270);
drive();
}
if (Greenfoot.isKeyDown("Right"))
{
setRotation(0);
drive();
}
}
}