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

2019/4/23

how to make a game end when an actor touches a color

Nico_ti Nico_ti

2019/4/23

#
I'm making a lightcycles game and i dont know how to make the game end if one of the Lightcycles touches the other ones' trail. Any ideas?
danpost danpost

2019/4/23

#
Nico_ti wrote...
I'm making a lightcycles game and i dont know how to make the game end if one of the Lightcycles touches the other ones' trail. Any ideas?
Info required: the making of the trails along with its codes.
Proprogrammer04 Proprogrammer04

2019/4/23

#
Nico_ti wrote...
I'm making a lightcycles game and i dont know how to make the game end if one of the Lightcycles touches the other ones' trail. Any ideas?
These aren‘t the best solutions, but I can‘t think of any other ideas… 1st You change the Lightcycles into an Object which changes his sizes or 2nd You create lists with the coordinates of the colored places and check if your objects is in range of these objects
Nico_ti Nico_ti

2019/4/24

#
danpost wrote...
Nico_ti wrote...
I'm making a lightcycles game and i dont know how to make the game end if one of the Lightcycles touches the other ones' trail. Any ideas?
Info required: the making of the trails along with its codes.
public void act() 
    {
        GreenfootImage img = getWorld().getBackground();
        
        if (img.getColorAt(getX(), getY()) == trailColor){
            Greenfoot.stop();
        }
        else{
      
            img.setColor(trailColor);
            img.fillRect(getX(), getY(), trailWidth, trailHeight);
            getWorld().setBackground(img);
            getWorld().repaint();
            move(3);
        }
danpost danpost

2019/4/24

#
You may have to use:
if (trailColor.equals(img.getColorAt(getX(), getY()))){
at line 5.
Nico_ti Nico_ti

2019/4/25

#
danpost wrote...
You may have to use:
if (trailColor.equals(img.getColorAt(getX(), getY()))){
at line 5.
It worked, but now the problem is that the game stops immediately when i run it. Is there a way to displace the color trail?
danpost danpost

2019/4/25

#
Nico_ti wrote...
It worked, but now the problem is that the game stops immediately when i run it. Is there a way to displace the color trail?
What is the trail width and height? I would not make it more than how far the actor moves. Also the trail should be centered at the location. Try subtracting one from both coordinates at which the trail is drawn.
Nico_ti Nico_ti

2019/4/25

#
danpost wrote...
Nico_ti wrote...
It worked, but now the problem is that the game stops immediately when i run it. Is there a way to displace the color trail?
What is the trail width and height? I would not make it more than how far the actor moves. Also the trail should be centered at the location. Try subtracting one from both coordinates at which the trail is drawn.
Thank you very much, just one more thing; now my actor dies when he touches his own color but i need the actors to die when they touch the enemies color as well
danpost danpost

2019/4/25

#
Nico_ti wrote...
my actor dies when he touches his own color but i need the actors to die when they touch the enemies color as well
If you have a flat (single-colored) background, you can just ask if it is not that color. Otherwise, you will need to check both trail colors individually.
Nico_ti Nico_ti

2019/4/26

#
danpost wrote...
Nico_ti wrote...
my actor dies when he touches his own color but i need the actors to die when they touch the enemies color as well
If you have a flat (single-colored) background, you can just ask if it is not that color. Otherwise, you will need to check both trail colors individually.
How would i do that? do i just write something like:
if (trailColor.equals(img.getColorAt(getX(), getY()) == color.RED)){
            Greenfoot.stop();
        }
danpost danpost

2019/4/26

#
Nico_ti wrote...
How would i do that? do i just write something like: << Code Omitted >>
You cannot compare a boolean to a color (see on either side of '==' comparison operator). What are you trying to compare here (you have 3 colors a trail color, a background color and a literal color, in your statement)?
Nico_ti Nico_ti

2019/4/26

#
danpost wrote...
Nico_ti wrote...
How would i do that? do i just write something like: << Code Omitted >>
You cannot compare a boolean to a color (see on either side of '==' comparison operator). What are you trying to compare here (you have 3 colors a trail color, a background color and a literal color, in your statement)?
I'm trying to have my actor die, when he touches the other actors trail color. My background is black with some white spots, while the trails of the lightcycles are blue and red respectively
danpost danpost

2019/4/26

#
You can use the line I gave above by replacing trailColor with Color.RED or Color.BLUE.
You need to login to post a reply.