1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class Space extends World { int x; int y; GreenfootImage background; /** * Constructor for objects of class MyWorld. * */ public Space() { // Create a new world with 1600x1200 cells with a cell size of 1x1 pixels. super ( 1600 , 1200 , 1 ); x = getWidth()/ 2 ; y = getHeight()/ 2 ; addObject( new Rocket(),getWidth()/ 2 ,getHeight()/ 2 ); addEnemy(); addBack(); } public void addEnemy() { int x1 = 1600 / 8 ; for ( int i = 0 ;i<= 1600 ;i=i+x1) { addObject( new enemy1(), 200 +x1, 30 ); } } public void addBack() { if ( enemy1. class == null ) { addEnemy(); } } } |

