4bc13d6d57
# Conflicts: # SMIMS-Game/MyWorld.class
81 lines
2.5 KiB
Java
81 lines
2.5 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 = 200; //Zeit, bevor das erste Projektil auftaucht
|
|
//kann später noch beliebig angepasst werden
|
|
int targetTimer = 900;
|
|
/**
|
|
* 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, 50);
|
|
}
|
|
|
|
public void act()
|
|
{
|
|
if(PlattformCountdown==0) //Damit in regelmäßigen Abständen auf jeden Fall eine Plattform auftaucht
|
|
{
|
|
addObject(new Plattform(), Greenfoot.getRandomNumber(400), 5);
|
|
PlattformCountdown=100;
|
|
}
|
|
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(timer == 0){
|
|
Projectile projectile = new Projectile();
|
|
addObject(projectile,Greenfoot.getRandomNumber(300)+50,0);
|
|
timer = 200; //zeitlicher Abstand
|
|
}
|
|
else{
|
|
timer = timer - 1;
|
|
}
|
|
if(targetTimer == 0){
|
|
TargetingProjectile targetingProjectile = new TargetingProjectile();
|
|
addObject(targetingProjectile, Greenfoot.getRandomNumber(300)+50,0);
|
|
targetTimer = 900;
|
|
}
|
|
else{
|
|
targetTimer = targetTimer - 1;
|
|
}
|
|
}
|
|
|
|
}
|