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

2011/12/21

Game trouble

2
3
4
5
6
jdemshki jdemshki

2011/12/24

#
nvm i fixed that, but he isn't moving vertically. the controls are just reversed. when i hit the key that should make him move forward it is backward
kiarocks kiarocks

2011/12/24

#
What's your entire lemur code?
jdemshki jdemshki

2011/12/24

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Lemur here. * * @author (your name) * @version (a version number or a date) */ public class Lemur extends Actor { /** * Act - do whatever the Lemur wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Lemur() { GreenfootImage img = getImage(); // ^gets the default image of the lemur img.mirrorVertically(); // ^inverts the image along one axis img.mirrorHorizontally(); // ^inverts the image along the other axis setRotation(180); // turns the actor on its side } public void act() { move(); } public void move() { move(0) ; {if ((Greenfoot.isKeyDown("w"))) { move(4) ; } if (Greenfoot.isKeyDown("a")) { setRotation(getRotation() - 3) ; } if (Greenfoot.isKeyDown("d")) { setRotation(getRotation() + 3) ; ; } {if ((Greenfoot.isKeyDown("s"))) { move(-4) ; } } if ("space".equals(Greenfoot.getKey())) { fire() ; } } } /** * Fire the lemur */ private void fire() { Bomb bomb = new Bomb() ; getWorld().addObject(bomb, getX(), getY()) ; bomb.setRotation(getRotation() - 180); bomb.move(30.0); } }
danpost danpost

2011/12/24

#
Play around with commenting out one or two of the commands in 'public Lemur()' . Try each one by itself, then combinations of two of them. (that would only be nine combinations) Actually, it would help us to know which where it is pointing to begin with (without any altering commands). Obviously, it would be facing right (or move that way, with rotation begin zero); but with that orientation, which way would you want the bomb to procede from it if it was oriented that way (up, down, left, or right.
jdemshki jdemshki

2011/12/24

#
i don't quite understand what to do. it begins facing to the right. i adjusted the rotation so that it is still to the right. however, the point of it was to get the lemur to move vertically.
danpost danpost

2011/12/24

#
I know that! But, when it is facing right, which direction would the bomb procede from the image?
jdemshki jdemshki

2011/12/24

#
to the right. thats not my problem though. i fixed that. i have the bomb firing to the right from the front of my lemur.
danpost danpost

2011/12/24

#
And, you want it to move vertically, and always fire to the left?
danpost danpost

2011/12/24

#
I came up with this ... Hold on.
danpost danpost

2011/12/24

#
Believe it or not, you will need a combination of actor setRotation(int) and image rotate(int):
        setRotation(90);
        getImage().rotate(90);
when you first construct it. Then you will need:
        setRotation(getRotation() + 180);
        GreenfootImage img = getImage();
        img.mirrorVertically();
        img.mirrorHorizontally();
    }
when you want it to change directions.
danpost danpost

2011/12/24

#
I think I know what is going on ... when we use setRotation to change the direction of the object, it changes to direction that the bombs go. When you set the rotation of the bomb, just use 180, nothing more.
danpost danpost

2011/12/24

#
NVM, im totally confused with the matter. Too much going on, and not enough input. Need to work on one thing at a time. Trying to work with multiple things gets confusing at heck!
jdemshki jdemshki

2011/12/24

#
The bomb is firing in the correct direction. That is fixed. The only problem is that the lemur won't move vertically
jdemshki jdemshki

2011/12/24

#
public Lemur() { GreenfootImage img = getImage(); setRotation(180); // turns the actor on its side // ^gets the default image of the lemur img.mirrorVertically(); // ^inverts the image along one axis img.mirrorHorizontally(); // ^inverts the image along the other axis } this is what i have right now. i changed the setRotation and now it looks correct. the bombs fire out correctly as well. the only problem is that it still moves horizontally
danpost danpost

2011/12/24

#
Try what I had said above. When creating the lemur, use both setRotation(90) on the actor AND rotate(90) on the image. UPDATE: i noticed you used setRotation(180) AND mirrored the image both ways. Use 90 for one and 270 fo the other.
There are more replies on the next page.
2
3
4
5
6