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

2021/6/24

Dance game notes not being removed

1
2
Beaver Beaver

2021/6/24

#
Okay, so I am trying to make a " Friday Night Funkin' " type of game. In it, I have different arrows that come down and when you press the key they represent they would disappear and give you a point. I tried adding a double "if"
, but it simply doesn't see the second if. I also tried using "&&" and only 1 "if" but that just removes the arrows without the keypress.
public void Catch()
    {
        if(Greenfoot.isKeyDown("right"))
        {
            if(isTouching(RightArrow.class))
                removeTouching(RightArrow.class);
        } 
        if(Greenfoot.isKeyDown("left"))
        {
            if(isTouching(LeftArrow.class))
                removeTouching(LeftArrow.class);
        } 
        if(Greenfoot.isKeyDown("up"))
        {
            if(isTouching(UpArrow.class))
                removeTouching(UpArrow.class);
        } 
        if(Greenfoot.isKeyDown("down"))
        {
            if(isTouching(DownArrow.class))
                removeTouching(DownArrow.class);
        } 
    }
Beaver Beaver

2021/6/24

#
This was my second attempt, still not working.
if(Greenfoot.isKeyDown("right") && isTouching(Dreapta.class))
        {
                removeTouching(Dreapta.class);
        } 
        if(Greenfoot.isKeyDown("left") && isTouching(Stanga.class))
        {
                removeTouching(Stanga.class);
        } 
        if(Greenfoot.isKeyDown("up") && isTouching(Sus.class))
        {
                removeTouching(Sus.class);
        } 
        if(Greenfoot.isKeyDown("down") && isTouching(Jos.class))
        {
                removeTouching(Jos.class);
        } 
danpost danpost

2021/6/24

#
Does it even see the first "if"? Where is the Catch method being called from?
Beaver Beaver

2021/6/24

#
This is the full code if that helps. The code is for a line in the game that indicates where and when you should press the keys. I didn't really understand why it would not see the first "if".
import greenfoot.*;
public class Line extends Actor
{
    public void act()
    {
        Catch();
    }
    public void Catch()
    {
        if(Greenfoot.isKeyDown("right") && isTouching(RightArrow.class))
        {
                removeTouching(RightArrow.class);
        } 
        if(Greenfoot.isKeyDown("left") && isTouching(LeftArrow.class))
        {
                removeTouching(LeftArrow.class);
        } 
        if(Greenfoot.isKeyDown("up") && isTouching(UpArrow.class))
        {
                removeTouchingUpArrow.class);
        } 
        if(Greenfoot.isKeyDown("down") && isTouching(DownArrow.class))
        {
                removeTouching(DownArrow.class);
        } 
    }
}
danpost danpost

2021/6/24

#
Provide code for one of the arrows, please. Also, what are the dimensions of the Line class default image?
Beaver Beaver

2021/6/24

#
This is the code, and the size is 280, 40 p
import greenfoot.*;
public class DownArrow extends Actor
{
    int speed = Greenfoot.getRandomNumber(4);
    public DownArrow()
    {
        if (speed == 0)
           speed = 1;
    }
    public void act()
    {
        ifAtWorldEdge();
        move();
        move(speed);
        if (speed == 0)
        speed = 1;
    }
    public void move()
    {
       setRotation(+90);
        
    }
     public void ifAtWorldEdge()
    {
        if (isAtEdge())
        {
             getWorld().removeObject(this);
        }
    }
}
danpost danpost

2021/6/24

#
Okay, what is size of world and where is Line instance placed? Also, what are the dimensions of default images of arrows?
danpost danpost

2021/6/24

#
Beaver wrote...
This is the code, and the (Line instance default image) size is 280, 40 p << Code Omitted >>
Cleaning up:
import greenfoot.*;

public class DownArrow extends Actor
{
    int speed = 1+Greenfoot.getRandomNumber(3);

    public DownArrow()
    {
        setRotation(90);
    }

    public void act()
    {
        move(speed);
        if (isAtEdge()) getWorld().removeObject(this);
    }
}
Beaver Beaver

2021/6/24

#
That's a lot cleaner. The Line is placed at 130, 260, the arrows are all 140 by 140 p and the world is 800 by 300
danpost danpost

2021/6/24

#
Beaver wrote...
That's a lot cleaner. The Line is placed at 130, 260, the arrows are all 140 by 140 p and the world is 800 by 300
So, the line only extends horizontally across 35 percent of the width of the world (???).
Beaver Beaver

2021/6/24

#
Yes, the line does cover around 35% of the world, and that is because it doesn't sit exactly at the start of it.
danpost danpost

2021/6/24

#
Beaver wrote...
Yes, the line does cover around 35% of the world, and that is because it doesn't sit exactly at the start of it.
What about the other (65+ percent) right side of the world? The arrows will miss the line altogether.
Beaver Beaver

2021/6/24

#
Well, the other 65% of the world is planned for something else. The arrows are spawning between x(0) and x(280), which is 65% of the world.
danpost danpost

2021/6/24

#
Beaver wrote...
Well, the other 65% of the world is planned for something else. The arrows are spawning between x(0) and x(280), which is 35% of the world.
Try changing the method name from "Catch" to "catchArrow". Maybe problem arises from "catch" being a java keyword.
Beaver Beaver

2021/6/24

#
It still doesn't seem to work. The hitbox of the line is ok since this worked;
import greenfoot.*;
public class Line extends Actor
{
    public void act()
    {
        catchArrow();
    }
    public void catchArrow()
    {
        if(isTouching(RightArrow.class))
        {
                removeTouching(RightArrow.class);
        } 
        if(isTouching(LeftArrow.class))
        {
                removeTouching(LeftArrow.class);
        } 
        if(isTouching(UpArrow.class))
        {
                removeTouching(UpArrow.class);
        } 
        if(isTouching(DownArrow.class))
        {
                removeTouching(DownArrow.class);
        } 
    }
}
But, adding the "Greenfoot.isKeyDown("")" still doesn't work. I thought of adding a boolean, that is true whenever the key is pressed, but it is still wrong. (It removes the arrow without the key actually being pressed.)
There are more replies on the next page.
1
2