I'm a pretty noob on Greenfoot, but I wanted to programm a game. My following Code doesn't work propably. I tried to make a method for a better move so I can slowly move in any direction. Could you give me some tips, how I can solve the problem?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Stab here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Stab extends Player
{
int CooldownCounter;
boolean ShootBall = false;
int ProjektileX;
int ProjektileY;
int ProjektileSpeed = 1;
int ProjektileDamage = 10;
int ProjektileEffekt;
int ScaleWidth;
int ScaleHeight;
int ProjektileRotation;
LightningBall lightningball;
/**
* Act - do whatever the Stab wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
StaffMath();
StaffDisplay();
}
/**
@Override
protected void addedToWorld(World Sandworld)
{
}
*/*
public void StaffMath()
{
StaffCooldown();
StaffSettings();
}
public void StaffSettings()
{
ScaleWidth = this.getY()/9;
ScaleHeight = this.getY()/6;
ProjektileX = this.getX();
ProjektileY = this.getY() - ScaleHeight/4;
MouseInfo mouseInfo = Greenfoot.getMouseInfo();
turnTowards(mouseInfo.getX(), mouseInfo.getY());
ProjektileRotation = getRotation();
setRotation(0);
}
public void StaffCooldown()
{
if (Greenfoot.isKeyDown("space")){
if (CooldownCounter == 0){
CooldownCounter = 1000;
ShootBall = true;
}
}
if (CooldownCounter > 0){
CooldownCounter = CooldownCounter - 1;
}
}
public void StaffDisplay()
{
DisplaySettings();
Shoot();
}
public void DisplaySettings()
{
this.getImage().scale(ScaleWidth, ScaleHeight);
}
public void Shoot()
{
if (ShootBall == true){
ShootBall = false;
lightningball = new LightningBall();
getWorld().addObject(lightningball, ProjektileX, ProjektileY);
lightningball.setRotation(ProjektileRotation);
lightningball.speed = ProjektileSpeed;
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class LightningBall here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class LightningBall extends Projektile
{
int speed;
double ExactXCord;
double ExactYCord;
int ThisRotation = getRotation();
int RoundXCord;
int RoundYCord;
/**
* Act - do whatever the LightningBall wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
MoveFunction();
MoveDisplay();
}
@Override
protected void addedToWorld(World Sandworld)
{
ExactXCord = (double)this.getX();
ExactYCord = (double)this.getY();
}
public void MoveFunction()
{
ExactXCord = MovingXCord(speed,ThisRotation,ExactXCord);
ExactYCord = MovingYCord(speed,ThisRotation,ExactYCord);
RoundXCord = (int)Math.round(ExactXCord);
RoundYCord = (int)Math.round(ExactYCord);
}
public void MoveDisplay()
{
setLocation(RoundXCord,RoundYCord);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Standardfunktionen here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Standardfunktionen extends Actor
{
/**
* Act - do whatever the Standardfunktionen 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.
}
public double MovingXCord(int objSpeed, int objRotation, double objXCord){
return Math.cos(objRotation)*objSpeed + objXCord;
}
public double MovingYCord(int objSpeed, int objRotation, double objYCord){
return Math.sin(objRotation)*objSpeed + objYCord;
}
}

