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!!!
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 | 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()); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 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(); } } |