ddba231979
# Conflicts: # SMIMS-Game/Groundflower.class # SMIMS-Game/Groundflower.java # SMIMS-Game/MyWorld.class # SMIMS-Game/Player.class # SMIMS-Game/Player.java # SMIMS-Game/project.greenfoot
158 lines
5.1 KiB
Java
158 lines
5.1 KiB
Java
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 MyWorld extends World
|
|
{
|
|
int PlattformCountdown;
|
|
int timer = 300; //Zeit, bevor das erste Projektil auftaucht
|
|
//kann später noch beliebig angepasst werden
|
|
int targetTimer = 1000;
|
|
int time = 0;
|
|
int enemyTimer;
|
|
int score = 0;
|
|
/**
|
|
* Constructor for objects of class MyWorld.
|
|
*
|
|
*/
|
|
public MyWorld()
|
|
{
|
|
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
|
|
super(400, 600, 1);
|
|
prepare();
|
|
}
|
|
|
|
/**
|
|
* Prepare the world for the start of the program.
|
|
* That is: create the initial objects and add them to the world.
|
|
*/
|
|
private void prepare()
|
|
{
|
|
Player player = new Player();
|
|
addObject(player,302,320);
|
|
Score score = new Score();
|
|
addObject(score, 200, 30);
|
|
score.setImage("Score1.png");
|
|
Score score1 = new Score();
|
|
addObject(score1, 200, 60);
|
|
score1.setImage("Score2.png");
|
|
Plattform plattform = new Plattform();
|
|
addObject(plattform,285,577);
|
|
plattform.setLocation(286,492);
|
|
plattform.setLocation(293,379);
|
|
removeObject(plattform);
|
|
Plattform plattform2 = new Plattform();
|
|
addObject(plattform2,291,373);
|
|
Plattform plattform3 = new Plattform();
|
|
addObject(plattform3,123,268);
|
|
plattform3.setLocation(136,306);
|
|
Plattform plattform4 = new Plattform();
|
|
addObject(plattform4,294,204);
|
|
Plattform plattform5 = new Plattform();
|
|
addObject(plattform5,105,112);
|
|
plattform2.setLocation(320,367);
|
|
plattform2.setLocation(312,371);
|
|
plattform2.setLocation(308,382);
|
|
Healthbar healthbar = new Healthbar();
|
|
addObject(healthbar,50,50);
|
|
Heart heart = new Heart();
|
|
addObject(heart,371,27);
|
|
Heart heart2 = new Heart();
|
|
addObject(heart2,343,27);
|
|
Heart heart3 = new Heart();
|
|
addObject(heart3,314,27);
|
|
|
|
addObject(new TemporaryGround(60*50), 200, 575);
|
|
}
|
|
|
|
public void act()
|
|
{
|
|
if (getObjects(Score.class).size() > 0){
|
|
removeObjects(getObjects(Score.class));
|
|
}
|
|
Score score = new Score();
|
|
addObject(score, 200, 30);
|
|
score.setImage("Score1.png");
|
|
Score score1 = new Score();
|
|
addObject(score1, 200, 60);
|
|
score1.setImage("Score2.png");
|
|
showScore();
|
|
projectile();
|
|
spawnEnemies();
|
|
targetingProjectile();
|
|
if(PlattformCountdown==0) //Damit in regelmäßigen Abständen auf jeden Fall eine Plattform auftaucht
|
|
{
|
|
addObject(new Plattform(), Greenfoot.getRandomNumber(400), 5);
|
|
PlattformCountdown=50;
|
|
}
|
|
PlattformCountdown--;
|
|
if(Greenfoot.getRandomNumber(100000)>=99800)
|
|
{
|
|
addObject(new Plattform(), Greenfoot.getRandomNumber(400), 5);
|
|
}
|
|
if(Greenfoot.getRandomNumber(100000)>=99900)
|
|
{
|
|
addObject(new MovingPlattform(2), Greenfoot.getRandomNumber(400), 6); //Nach Rechts bewegende Plattform
|
|
}
|
|
if(Greenfoot.getRandomNumber(100000)>=99900)
|
|
{
|
|
addObject(new MovingPlattform(-2), Greenfoot.getRandomNumber(400), 6); //Nach Links bewegende Plattform
|
|
}
|
|
if(Greenfoot.getRandomNumber(100000)>=99750)
|
|
{
|
|
addObject(new BreakingPlattform(50), Greenfoot.getRandomNumber(400), 6); //Nach Links bewegende Plattform
|
|
}
|
|
if(Greenfoot.getRandomNumber(100000)>=99750)
|
|
{
|
|
addObject(new SpikedPlattform(100), Greenfoot.getRandomNumber(400), 6); //Nach Links bewegende Plattform
|
|
}
|
|
|
|
if(Greenfoot.getRandomNumber(100000)>=99750)
|
|
{
|
|
addObject(new Groundflower(), Greenfoot.getRandomNumber(400), 6); //Nach Links bewegende Plattform
|
|
}
|
|
}
|
|
|
|
|
|
public void spawnEnemies(){
|
|
enemyTimer++;
|
|
if (enemyTimer == 420){
|
|
Enemy enemy = new Enemy(Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()/2));
|
|
addObject(enemy, Greenfoot.getRandomNumber(300)+50,0);
|
|
enemyTimer = 0;
|
|
}
|
|
|
|
}
|
|
public void projectile(){
|
|
if(timer == 0){
|
|
Projectile projectile = new Projectile();
|
|
addObject(projectile,Greenfoot.getRandomNumber(300)+50,0);
|
|
timer = 300; //zeitlicher Abstand
|
|
}
|
|
else{
|
|
timer = timer - 1;
|
|
}
|
|
}
|
|
|
|
public void targetingProjectile(){
|
|
if(targetTimer == 0){
|
|
TargetingProjectile targetingProjectile = new TargetingProjectile();
|
|
addObject(targetingProjectile, Greenfoot.getRandomNumber(300)+50,0);
|
|
targetTimer = 1000;
|
|
}
|
|
else{
|
|
targetTimer = targetTimer - 1;
|
|
}
|
|
}
|
|
|
|
public void showScore(){
|
|
time++;
|
|
score = time/60;
|
|
showText("" + score, 200, 60);
|
|
}
|
|
}
|