-
Notifications
You must be signed in to change notification settings - Fork 1
/
StartGame.java
54 lines (43 loc) · 1.5 KB
/
StartGame.java
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
51
52
53
54
import greenfoot.*;
/**
* Start game
* Class will be created when the user wants to start the game
*
* @author github.com/fiekzz
* @version 4 June 2022
*/
public class StartGame extends World
{
// game background
private GreenfootImage gameBg = new GreenfootImage("./assets/new_background.png");
// theme song
private GreenfootSound theme = new GreenfootSound("./assets/sounds/theme.mp3");
public StartGame()
{
// screen size
super(1200, 800, 1);
// scale the background image
gameBg.scale(getWidth(), getHeight());
setBackground(gameBg);
// spawn rocket
addObject(new Rocket(getHeight()), 200, 400);
// spawn location of planets
spawnEntity(600);
spawnEntity(1000);
// create entity (distractor) and speed counter
addObject(new CountEntity(),600,200);
addObject(new CountSpeed(), 600,200);
// score displayer and counter
addObject(new score(), -10, -10);
}
public void spawnEntity(int initialLocationX)
{
//theme.play();
int size = Greenfoot.getRandomNumber(200) + 100;
// spawn random planet
String planet = "./assets/Entity/e" + String.valueOf(Greenfoot.getRandomNumber(27) + 1) + ".png";
// create entity
entity distraction = new entity(planet, size);
addObject(distraction, initialLocationX, Greenfoot.getRandomNumber(700)+100);
}
}