the speed is a negative number because it moves backwards on the x-axis
the speed is a positive number if it moves forwards on the x-axis (to the right)
use setLocation and give the editor your coordinates, here is the code of the asteroids:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.Random;
/**
* Write a description of class meteoriet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class meteoriet extends Actor
{
Random r = new Random();
private int speed = -2;
/**
* Act - do whatever the meteoriet wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(speed);
if (this.isAtEdge()) {
this.setLocation(550, r.nextInt(50)+100);
speed = speed-1;
}
Actor raket = this.getOneIntersectingObject(raket.class);
if (raket != null) {
//(this.getWorldOfType(MyWorld.class)).getHealthbar().loseHealth();
Healthbar Hb = (this.getWorldOfType(MyWorld.class)).getHealthbar();
Hb.loseHealth();
this.setLocation(550, r.nextInt(50)+100);
if (Hb.Health==0)
{ (this.getWorldOfType(MyWorld.class)).einde_spel();
this.getWorld().removeObject(raket);
World myWorld = getWorld();
Game_over gameover = new Game_over();
myWorld.addObject(gameover, myWorld.getWidth()/2,200);}
}// Add your action code here.
Actor a = this.getOneIntersectingObject(Laser.class);
if (a != null) {
// this.getWorld().removeObject(this);
this.setLocation(550, r.nextInt(300)+50);
}
}
}
2017/12/8
space soldiers
2017/12/8
space soldiers
2017/12/8
space soldiers