Hello,
I'm trying to make a "kick-ups" game, where the player tries to keep a ball in the air without letting it fall on ground, by clicking on it, but I'm having trouble making the ball turn by some amount every kick, which I want to accomplish. Can someone please help? Thank you.
Here's code for Ball class:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ball extends Actor
{
private final int GRAV = 1;
private int velocity;
public Ball(){
velocity = 0;
getImage().scale(50, 50);
}
/**
* Act - do whatever the Ball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
if (Greenfoot.mouseClicked(this)){
int amo = -30 + Greenfoot.getRandomNumber(70);
turn(amo);
jump();
}
fall();
}
public void fall(){
setLocation(getX(), getY() + velocity);
if (getY() > getWorld().getHeight() - getImage().getHeight()/2){
velocity = 0;
} else {
velocity += GRAV;
}
}
public void jump(){
velocity = -20;
}
}
