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

2013/10/18

RPG Game for Beginners.

Tavi Tavi

2013/10/18

#
Hello everyone, First off, im really new here so i might need some not too technical answers :), I'm trying to create an RPG game where a character can throw stars at enemies, ( along the line i would love to have different stars for different character levels or via drop ) Now i have an integer direction ( 1 or 2 ) in my Character class, and i have a throw left and throw right method :
public void luckySeven(int richting)
    {
        if(richting == 1)
        {
            throwRight();
        }
        if(richting == 2)
        {
            throwLeft();
        }
    }
    
    public void throwRight()
    {
        ThrowingStar throwingstar = new ThrowingStar();
        getWorld().addObject(throwingstar, getX(), getY());
        throwingstar.move(40.0);
        throwingDirection = 10.0;
    }
    
    public void throwLeft()
    {
        ThrowingStar throwingstar = new ThrowingStar();
        getWorld().addObject(throwingstar, getX(), getY());
        throwingstar.move(-40.0);
        throwingDirection = -10.0;
    }
Now on to my ThrowingStar class, I Can't seem to get the direction from my char class to my ThrowingStar class.. I Also have multiple subclasses of the class Throwingstars, how can i activate these ? So far my Throwingstar class contains the following :
public class ThrowingStar extends Mover
{
    public double direction; 
    /**
     * Act - do whatever the ThrowingStar wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(10.0);
    }
However, this will throw the stars to the right wether i'm facing left or right.. :( Hope you can help me out !
davmac davmac

2013/10/18

#
You need to set the ThrowingStar rotation according to which way you want it to move. You should do this when you create it.
    public void throwLeft()  
    {  
        ThrowingStar throwingstar = new ThrowingStar();  
        getWorld().addObject(throwingstar, getX(), getY());  
        throwingstar.move(-40.0);
        throwingstar.setRotation(180);  // ADD THIS LINE
        throwingDirection = -10.0;  
    }  
Another possibility would be to store the movement amount in ThrowingStar, and have it move by that amount (either +10 or -10 according to the direction).
Tavi Tavi

2013/10/19

#
It's working now, thank you so much :) ..
You need to login to post a reply.