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

2011/12/21

Game trouble

1
2
3
4
5
6
jdemshki jdemshki

2011/12/23

#
public Lemur() {//image setRotation(90); } public void mirrorVertically() //image {mirrorVertically();} public void mirrorHorizontally() //image {mirrorHorizontally();} i put all of this in and it didn't work. it lets me move vertically but my image is facing the wrong way still.
jdemshki jdemshki

2011/12/23

#
im also trying to get the blocker to fire back at the lemur. I've done that but i can't figure out how to make it fire so its not a constant stream. i tried using the delay method but i don't think I'm using it correctly. public void act() { move(10); if (this.atWorldEdge()) {setRotation(getRotation() - 180); } fire(); } public void delay() {} public void fire() { delay(); Bomb bomb = new Bomb() ; getWorld().addObject(bomb, getX(), getY()) ; bomb.setRotation(180); bomb.move(30.0); }
danpost danpost

2011/12/23

#
This is what you say you have
public Lemur()
    {//image 
        setRotation(90);
    }
    public void mirrorVertically()
    //image
    {mirrorVertically();}
    public void mirrorHorizontally()
    //image
    {mirrorHorizontally();}
This is what you should have
public Lemur()
{
    GreenfootImage img = getImage(); 
    // ^gets the default image of the lemur
    img = img.mirrorVertically();  
    // ^inverts the image along one axis
    img = img.mirrorHorizonally(); 
    // ^inverts the image along the other axis
    setRotation(90); // turns the actor on its side
}
This is what you should not have
    public void mirrorVertically()
    //image
    {mirrorVertically();}
    public void mirrorHorizontally()
    //image
    {mirrorHorizontally();}
danpost danpost

2011/12/23

#
To fire randomly you need your lemur class to look something like this:
import Greenfoot.*; // ....

public class Lemur extends Actor
{
    private int actCounter = 50;

    public Lemur()
    {
        setRotation(270);
        changeDirection();
    }

    public void act() 
    {
        move(10);
        if (this.atWorldEdge())
        { 
            changeDirection(); 
        }  
        fire();
    }

    public void fire()
    {
        actCounter--;
        if (actCounter == 0)
        {
            Bomb bomb = new Bomb() ; 
            getWorld().addObject(bomb, getX(), getY()) ;
            bomb.setRotation(180);
            bomb.move(30.0);
            actCounter = Greenfoot.getRandomNumber(50) + 50;
        }
    }

    private void changeDirection()
    {
        GreenfootImage img = getImage();
        img = img.mirrorVertically();
        // ^ if vertical does not work, try horizontal
        setRotation(getRotation() + 180);
    }
}
You can play around with the numbers for the actCounter, whatever suits your needs. The number inside the parenthesis of Greenfoot.getRandomNumber is one more than the high integer limit (a 50 would result in a return in the range of zero to forty-nine (0 <= n < 50)). The number added to that returned value would be the minimum number of acts before the next Bomb.
danpost danpost

2011/12/23

#
If your image is still facing the wrong way, describe exactly how it is while going up, and then how it is while going down.
jdemshki jdemshki

2011/12/23

#
for the image of the lemur, it says incompatible types - found void but expected greenfoot.GreenfootImage
danpost danpost

2011/12/23

#
That means you have nothing set as the default image for the lemur. Is there a file that holds the image of your lemur?
jdemshki jdemshki

2011/12/23

#
and i'm trying to fire randomly form my blocker class. the lemur is what the player is controlling
jdemshki jdemshki

2011/12/23

#
its just one of the images that green foot supplies but i scaled it in the code to make it look different
jdemshki jdemshki

2011/12/23

#
crap sorry i confused myself. the image just comes from green foot
jdemshki jdemshki

2011/12/23

#
all of the randomly fire stuff is for the blocker but I'm hitting the same error as the lemur thing
danpost danpost

2011/12/24

#
OK, sorry, just move the relavent actCounter statements to the blocker class. Is the lemur firing when the player hits a key on the keyboard? And what error are you getting?
jdemshki jdemshki

2011/12/24

#
i did that and I'm still getting incompatible types - found void but expected greenfoot.GreenfootImage. the lemur fires when the player hits the space bar
danpost danpost

2011/12/24

#
What line of code is being highlighted and what is the code around it, what class and method is it in?
jdemshki jdemshki

2011/12/24

#
Blocker class: private void changeDirection() { GreenfootImage img = getImage(); img = img.mirrorVertically(); (THIS line is being highlighted) setRotation(getRotation() + 180); } Lemur Class: { GreenfootImage img = getImage(); // ^gets the default image of the lemur img = img.mirrorVertically(); (THIS line is being highlighted) // ^inverts the image along one axis img = img.mirrorHorizonally(); // ^inverts the image along the other axis setRotation(90); // turns the actor on its side }
There are more replies on the next page.
1
2
3
4
5
6