Hey! I need your help! I have 2 Codes:
and
the first code is for jumping and the second is that you can move.
But how can i get these both codes into 1?
So that in the end i have one figure that can move and jump.
Thanks a lot and best greetings
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Jumper here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Jumper1 extends Actor
{
private final int GRAVITY = 1;
private int velocity;
public Jumper1() {
velocity = 5;
}
public void act()
{
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;
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Mann here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Mann extends Actor
{
/**
* Act - do whatever the Mann wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add yo public void act()
{
int speed = 1;
if (Greenfoot.isKeyDown("a"))
setLocation(getX() - speed, getY());
if (Greenfoot.isKeyDown("d"))
setLocation(getX() + speed, getY());
}
}
}
