Skip to content
Snippets Groups Projects
Select Git revision
  • 4a157bf1285018299c287fdda085fef3c562e044
  • master default protected
2 results

openvmtools.sls

Blame
  • Welt.java 1.56 KiB
    import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
    import java.util.List;
    /**
     * Write a description of class Welt here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class Welt extends World
    {
        public static final int WIDTH = 1400;
        public static final int HEIGHT = 630;
        public static final int CELL = 1;
    
        private Scroller scroller = null;
        /**
         * Constructor for objects of class Welt.
         * 
         */
        public Welt()
        {    
            // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
            super(WIDTH, HEIGHT, CELL, true); 
            scroller = new Scroller(this, new GreenfootImage("World.png"));
            prepare();
        }
    
        public void act() {
            scroll();
            spawnCoronaVirus();
        }
        
        public void spawnCoronaVirus(){
            if(Greenfoot.getRandomNumber(1000)<10)
            {
                List<CoronaVirus> allVirus = getObjects(CoronaVirus.class);
                if(allVirus.size() < 10){
                    int width = WIDTH-10;
                    int height = Greenfoot.getRandomNumber(HEIGHT-10);
                    this.addObject(new CoronaVirus(),width, height);  
                }
            }
        }
        
        
        
        
        
        
        
        int speed = 1;
        private void scroll() {
            scroller.scroll(speed,0);
        }
    
        /**
         * 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,137,398);
        }
    }