This site requires JavaScript, please enable it in your browser!
Greenfoot back
AdventureGameDE
AdventureGameDE wrote ...

2015/5/13

Gameproblem

AdventureGameDE AdventureGameDE

2015/5/13

#
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; } }
lordhershey lordhershey

2015/5/13

#
I do not see anything immediately jumping out - can we see your world class prepare() method? Unless you are not setting the speed variable - are the object just standing in place in the world? I am assuming this since movement was mentioned.
danpost danpost

2015/5/13

#
I seriously doubt that a staff is a more specific type of player and therefore the Staff class should not extend the Player class. The same situation applies with Standardfunktionen and Actor. A standardfunktionen object is not an actor. In fact, it is a bit abstract in that is has no inherent or residual information (no data is contained within the class for any amount of time). The 'sin' and 'cos' methods of the Math class need angle values in 'double radian' measure, not 'int degrees' measure. This alone will cause your actors to behave improperly.
AdventureGameDE AdventureGameDE

2015/5/16

#
Sry my english isn't good. It's not a Staff it's a wand and one error was, that he couldn't get the mouse coordinats, if the mouse isn't on the display, but I fixed it. It still doesn't work, but I'll try to use the double radian and how can I use my Standardfunktionen if my actor doesn't extend them?
AdventureGameDE AdventureGameDE

2015/5/16

#
No it works fine ty.
AdventureGameDE AdventureGameDE

2015/5/16

#
@lordhershey the speed is given from the wand: lightningball.speed = ProjektileSpeed
AdventureGameDE AdventureGameDE

2015/5/16

#
Now*
danpost danpost

2015/5/16

#
AdventureGameDE wrote...
how can I use my Standardfunktionen if my actor doesn't extend them?
Since all information needed is supplied through the parameters of the methods and no data needs to be retained within the class, we can make the class a 'static' class that extends Object (by default):
public abstract class Standardfunktionen
{
    public static double MovingXCord(int speed, int angle, double initX){
        return Math.cos(angle)*speed+ initX;
    }
    public static double MovingYCord(int speed, int angle, double initY){
        return Math.sin(angle)*speed+ initY;
    }
}
The methods of this class can be called from anywhere within your project by calling the method on the name of the class. For example, your first line in the 'MoveFunction' method would be written as follows:
ExactXCord = Standardfunktionen.MovingXCord(speed,ThisRotation,ExactXCord);
AdventureGameDE AdventureGameDE

2015/5/17

#
ok thx
You need to login to post a reply.