This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

mathisdewitte
mathisdewitte presents ...

2017/12/1

space soldiers

MOVE AND TURN: use the keyboard arrows
SHOOT: use the space bar to shoot when you have to destroy a ufo or an asteroid.
LIVES: you have 4 lives

1724 views / 694 in the last 7 days

Tags: None

Your browser is ignoring the <APPLET> tag.
Hi. how did you code the random enemies coming from the right side? can i know? thank you
mathisdewittemathisdewitte

2017/12/8

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); } } }
mathisdewittemathisdewitte

2017/12/8

for the start of the game you must give the coordinates to the editor of myWorld.
mathisdewittemathisdewitte

2017/12/8

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)

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.