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

2014/1/10

String - crossing ?

Jabadu Jabadu

2014/1/10

#
Hello again, I have a game when snake leaves its trails behind. That trail is actually string "-" (string is written in my actor "Pika"), like this :
 public void risanjeSledi()
    {
        getWorld().getBackground().drawString("-", getX(), getY());
    }
Now I want to make that my game stop when actor ("Pika") hit his own trail (this string -> "-"), is it possible to do it ? PS: At first I didn't have string for trail, but I had another actor for trail. This thing was actually working, but there was a memory problem when I start game for few times, so beside this I want string for trails... And I don't know how to finish the code.. Any idea ?
danpost danpost

2014/1/10

#
Unless you make the string a color nowhere else found and search every pixel behind the tank for that color, you basically cannot detect the tracks in the background image. My suggestion, which I am somewhat reluctant to give, is to compromise and have every third or fourth track be an actor that can be detected.
Jabadu Jabadu

2014/1/11

#
Is there anything else beside string trails and actor trails ? I mean, is there any other way to make the trails without memory error in greenfoot ? Because your solution is not good enough for my game, I really need every peace of trail to be detected..
danpost danpost

2014/1/11

#
The only other thing I can think of right now, is to change the alpha value of the color of the pixels in the background image along the path of the tracks and then check for those pixels as the tank moves. This may end up to be a bit laggy, but you should not get any errors (if done right) -- no memory problems with excessive actor counts due to track actors. Just a note, all pixels of the background image start at a full opaque state (alpha value at '255'). Changing the alpha value of a pixel to '254', 253', or even '252' will not make any noticeable difference in the perception of that image.
Jabadu Jabadu

2014/1/11

#
I changed my mind.. I wanna make an actor trails, like I did the first time, but I want only some of them (I want to have a snakehead with 5 snakebodies), how should I write this ?
getWorld().addObject(new Pika1Telo(), getX(), getY());
This is my code for making trails (but it leaves it from start to end).. "Pika1" is my actor (otherwise head, which will player command) and "Pika1Telo" is body of this snake.
Jabadu Jabadu

2014/1/11

#
I would also like to know, how to write the code for crashing into own trail. I write it down like this:
if(canSee(Pika1Telo.class))
        {
            eat(Pika1Telo.class);
            Greenfoot.setWorld(new Zid());
            zacetekNoveRunde();
         }
If actor "Pika1" crash in his own trail "Pika1Telo", than the game needs to restart. The code doesn't give me any syntax error, but when I start the game, actor "Pika1" doesn't move.
You need to login to post a reply.