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

2013/5/27

Why does this not work

Game/maniac Game/maniac

2013/5/27

#
I am trying to work out the rotation of my plane, but every time I inspect the planes rotation array I only get 0 for both rotations, and when I work it out on a calculator the rotations I should be getting is 144 and 0. Heres the code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Player here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Player extends SpriteSheet
{
    public int[] rotation = {0, 0};
    public Player() {
        setImage(getSprite(new GreenfootImage("Plane.png"), 400, 0, 600, 200, 200, 200));
    }
    
    public void act() {
        Worldy world = (Worldy)getWorld();
        rotation[0] = (int)((double)(world.view[0]/3000)*360);
        rotation[1] = (int)((double)(world.view[1]/3000)*360);
        if(Greenfoot.isKeyDown("a")) {
            world.lookLeft(10);
            setImage(getSprite(new GreenfootImage("Plane.png"), 200, 0, 400, 200, 200, 200));
        } else if(Greenfoot.isKeyDown("d")) {
            world.lookRight(10);
            setImage(getSprite(new GreenfootImage("Plane.png"), 600, 0, 800, 200, 200, 200));
        } else {
            setImage(getSprite(new GreenfootImage("Plane.png"), 400, 0, 600, 200, 200, 200));
        }
        if(Greenfoot.isKeyDown("w")) {
            world.lookUp(10);
        } else if(Greenfoot.isKeyDown("s")) {
            world.lookDown(10);
        }
    }
}
Kartoffelbrot Kartoffelbrot

2013/5/27

#
Maybe there is a problem with your methods of the world.
Game/maniac Game/maniac

2013/5/27

#
Don't think that is the problem
Game/maniac Game/maniac

2013/5/27

#
The problem is that the rotation variable doesn't seem to be changing no matter what I do
Gevater_Tod4711 Gevater_Tod4711

2013/5/27

#
I think the problem might be in line 18. The array world.view is probably an int array. You devide the value by 3000 and if the value of world.view is less than 3000 the result is 0 (because of the int). Then you cast the result of this to double but after deviding it. If you change the code in line 18 to
rotation[1] = (int)(((double) world.view[1])/3000*360);
it should work.
Game/maniac Game/maniac

2013/5/27

#
thank you it works now
You need to login to post a reply.