Hello!
I have these Code:
this is my world, i dont know if you need this information:
do you know any kinds of improvements?
thx a lot!!!
import greenfoot.*; public class Jumper2 extends Actor { private final int GRAVITY = 1; private int velocity; int speed = 1; public Jumper2() { velocity = 5; } public void act() { mover(); fall(); if (Greenfoot.isKeyDown("space") && getY() > getWorld().getHeight() -50) jump(); } public void fall() { setLocation(getX(), getY() + velocity); if (getY() > getWorld().getHeight() -50) velocity = 5; else velocity += GRAVITY; } public void jump() { velocity = -20; } public void mover() { if (Greenfoot.isKeyDown("a")) setLocation(getX() - speed, getY()); if (Greenfoot.isKeyDown("d")) setLocation(getX() + speed, getY()); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Die einzigen aktiven Akteure in der Roboterwelt sind die Roboter. * Die Welt besteht aus 14 * 10 Feldern. */ public class SpielWelt extends World { private static int zellenGroesse = 30; GreenfootSound backgroundMusic = new GreenfootSound("BoxCat Games - Mt Fox Shop.mp3"); /** * Erschaffe eine Welt mit 14 * 10 Zellen. */ public SpielWelt() { super(24, 12, zellenGroesse); setBackground("images/spielhintergrund.jpg"); backgroundMusic.playLoop(); } }