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

2013/8/5

Questions and other shinannigons

8bitcarrotjuice 8bitcarrotjuice

2013/8/5

#
Hello everyone, I have a few questions and some problems that I need clarifying.. Thanks for your help in advance! 1) How do you 'properly' clarify/declare an actor? At the moment I'm using something like this: ' Actor clss=getOneIntersectingObject(Clss.class); ' but I've seen a different method of doing this. I would use this for things like clss.getImage(), clss.getX/Y(), etc... 2) I am working on a game called cube cubed, and in the next update I want to be able to determine the platforms rotation inorder to set the rotation of the actor. The problems: the method 'move(...)' uses int's; I need to use doubles and I have another problem that I think I have solved, but the problem is that one actor would have different rotations(angles). The fix would look something like this: (not tested)
//World class:

Public World1() {
super(x,y,false/true);
addObject(new Platform(angle(e.g. 45),x,y);
}

//Platform class:

Public Platform(int angle) {
setRotation(angle); 
}
I know this is probably wrong, but correct me if it is! Thanks! Thanks for your time, and your help!
davmac davmac

2013/8/5

#
1) Can you be a bit more specific about what you want to do? 2) Again it would be good if you could be a bit clearer. There seem to be a few issues here that are all jumbled together. For instance you say:
... I want to be able to determine the platforms rotation inorder to set the rotation of the actor. The problems: the method 'move(...)' uses int's; I need to use doubles ...
but the move(...) method has nothing to do with rotation. For what it's worth I can't see anything specifically wrong with the code you have posted. If you need a move(...) method that is more precise, you can import the SmoothMover class.
8bitcarrotjuice 8bitcarrotjuice

2013/8/5

#
Sorry for being so vaig: In my game I need the cube to have the same angle as the platform, and setLocation(x,y) does not take in account the angle(or direction) of the object; that is my problem.
davmac davmac

2013/8/5

#
Ok, in that case you just need to use setRotation(...) together with setLocation(...).
8bitcarrotjuice 8bitcarrotjuice

2013/8/5

#
oh sorry, I need the whole jump method using move inorder to take the angle into account. This would be a rough sketch of the jump engine:
//Player class
int rot;
int gravity;
boolean fall;
boolean ready;
public void act(){
if(fall==true)
gravity--;
Actor plat=getOneIntersectingObject(Platform.class);
if(plat!=null) {
rot=plat.getRotation();
fall=false;
ready=true;
gravity=0;
setRotation(rot) }
if(ready==true&&Greenfoot.isKeyDown("w"){
gravity=8;
fall=true;
ready=true;
}
//rest of the code
}
8bitcarrotjuice 8bitcarrotjuice

2013/8/5

#
davmac wrote...
Ok, in that case you just need to use setRotation(...) together with setLocation(...).
How would I do that?
8bitcarrotjuice 8bitcarrotjuice

2013/8/5

#
Sorry Dav but I have to go, could you explain all that I have asked? Thanks in advance!
davmac davmac

2013/8/5

#
Please indent your code properly so that I can read it without getting a headache :\ Regarding using setRotation(...) together with setLocation(...), just call both methods, one after the other. actor.setLocation(..., ...); actor.setRotation(...);
8bitcarrotjuice 8bitcarrotjuice

2013/8/6

#
Ok, here is the code that I have for the jumping, but instead of using int's in the move() method, I need to use doubles. I don't know how 'actor.setLocation(..., ...); actor.setRotation(...);' will help with that, but if it would, please explain it to me. The current code I have is this, I will also note where I need it changed and into what:
public class Player extends Actor
public int rot;  
public int gravity;  
public boolean fall;  
public boolean ready;  
    public void act()  {  
        if(fall==true)  
        gravity-=0.2;//does not work, since move() does not accept doubles  
        Actor plat=getOneIntersectingObject(Platform.class);  
        if(plat!=null) {  
        rot=plat.getRotation();  
        fall=false;  
        ready=true;  
        gravity=0;  
        setRotation(rot) 
}  
        if(ready==true&&Greenfoot.isKeyDown("w")  {  
        gravity=8;  
        fall=true;  
        ready=true;  
    }  
//rest of the code  
}
and lastly, just to clarify, the game is a cube which changes gravity depending on the platform which it stood on lastly. Inorder to do this, I need to use the move method as it takes into account the angle of the player but does not accept double, whereas the setLocation method does not take into account the players angle but does accept doubles. That is my problem; I need to use doubles in the move method, or get a similar method that does the same thing with doubles. Thanks in advance!
danpost danpost

2013/8/6

#
If the rotation of all your actors are multiples of 90, then using doubles or ints is not an issue. The fact that move() does not except doubles is not the problem on line 8; it is that the 'gravity' field is an int. At any rate there is no movement code at all in the Player class as it is right now (no 'move' or 'setLocation' statement(s)).
8bitcarrotjuice 8bitcarrotjuice

2013/8/6

#
ah sorry, I'm making it so you can use any angle, not just multiples of 90. The code should look like this then:
    public class Player extends Actor  
    public int rot;    
    public double gravity;    
    public boolean fall;    
    public boolean ready;    
        public void act()  {   
            move(gravity);
            if(fall==true)    
            gravity-=0.2;//does not work, since move() does not accept doubles    
            Actor plat=getOneIntersectingObject(Platform.class);    
            if(plat!=null) {    
            rot=plat.getRotation();    
            fall=false;    
            ready=true;    
            gravity=0;    
            setRotation(rot)   
    }    
            if(ready==true&&Greenfoot.isKeyDown("w")  {    
            gravity=8;    
            fall=true;    
            ready=true;    
        }    
    //rest of the code    
    }  
and also I just recieved a error setting the angle of the platform, here it is:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;  
public class S1 extends Conector
{
    public Platform(int angle)
    {
        GreenfootImage image = new GreenfootImage(cubew, cubeh);  
        image.setColor(Color.gray);  
        image.fill();  
        setImage(image); 
        setRotation(angle);
    } 
    public void act() 
    {

    }  
}
the code I use to create a platform is this: addObject(new Platform(180),x,y); the error says: 'invalid method decleration; return type required'. Thanks for your help!
davmac davmac

2013/8/6

#
The move method accepts int, so you just need to cast the double to an int: move((int) gravity); Regarding your invalid method declaration, your constructor must match the name of the class (S1).
8bitcarrotjuice 8bitcarrotjuice

2013/8/8

#
Sorry, I'm still a newbie, and as for casting the double to a int, wouldn't that change the double(e.g.0.2) to a int(0)(rounding up?)? Otherwise, I think I have all the code I need inorder to launch the next update for my game! Thanks again, dav and dan!
You need to login to post a reply.