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

2016/4/26

Drift

Ragnar Ragnar

2016/4/26

#
I have a target circling around a stationary actor at the middle of the screen. If you press space he teleports to it. I am using the turnTowards method to make him move back to center, but I don't want him to turn (just drift). I needs to be facing the same way. Thanks
danpost danpost

2016/4/26

#
Ragnar wrote...
I have a target circling around a stationary actor at the middle of the screen. If you press space he teleports to it. I am using the turnTowards method to make him move back to center, but I don't want him to turn (just drift). I needs to be facing the same way.
Please be a bit more specific as to what is doing what. Also, you need to show the codes for the actions you indicated were taking place. Indicate which actor each bit of code is for. I think what you want would require two fields for the coordinates of the location you teleported to and one to track the distance returned. Then, you would have something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// instance fields
int teleX, teleY, retDist;
 
/**  in act or method called by it */
// migrate back toward center
if (getX() != getWorld().getWidth()/2 || getY() != getWorld().getHeight()/2)
{
    setLocation(teleX, teleY)
    int rotation = getRotation();
    turnTowards(getWorld().getWidth()/2, getWorld().getHeight()/2);
    retDist += 16; // adjust as needed
    move(retDist/10);
    if (retDist/10 > (? orbitalDistance ?))
    {
        setLocation(getWorld().getWidth()/2, getWorld().getHeight()/2);
    }
    setRotation(rotation);
}
// teleport to target
if (getX() == getWorld().getWidth()/2 && getY() == getWorld().getHeight()/2 && Greenfoot.isKeyDown("space"))
{
    Actor target = (Actor)getObjectsInRange(400, Target.class).get(0);
    teleX = target.getX();
    teleY = target.getY();
    setLocation(teleX, teleY);
    retDist = 0;
}
Ragnar Ragnar

2016/4/27

#
I have the teleport method and a 'go back to center' method. The actor returns to the center but not in the way that I like. He turns to the middle and moves forward. With the image I have, the actor can be upside down or skewed when it gets to the middle. I want him to face the same direction no matter what happens in the game. I can't figure out how to make the actor return to the middle while facing the same way when it teleported. Here is the main actor (one you control):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
public class Mark extends Actor
{
    public void act()
    {
        turnTowards(850, 450);
        move(3);
         
        World1 world1 = (World1) getWorld();
        Target target = world1.getTarget();
        if(Greenfoot.isKeyDown("space"))
        {
            setLocation(target.getX(), target.getY());
        }
        if(getOneObjectAtOffset(0, 0, Enemy.class) != null)
        {
            setImage("ded.jpg");
        }
    
}
Here is the target:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
public class Target extends Actor
{
    int moveCount = 0;
    int arcSwitch = 0;
    public void act()
    {
        moveCount++;
        move(6);
                 
        arcDown();
    }   
    public void arcDown()
    {
        setRotation(getRotation() + 1);
    }
    public void arcUp()
    {
        setRotation(getRotation() - 1);
    }
}
Here is a picture of the game (so you have a better idea): https://drive.google.com/open?id=0B9AtqZssYnhKNXctSWNRUThIQ1k
danpost danpost

2016/4/27

#
Line 7 of your Mark class seems to alter the rotation of the actor. Are you sure that it is not causing the issue? (no where else do I see any code that would change the rotation of the user controlled actor)
Ragnar Ragnar

2016/4/28

#
I know that it alters it. I don't want the actor to turn at all when he floats back to the center.
Ragnar Ragnar

2016/4/28

#
Nvm, my friend figured it out. Just added setRotation(0) after move(3);
You need to login to post a reply.