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

2018/11/29

Score counter broken on level two, works fine on level one

1
2
3
jonah420123 jonah420123

2018/11/29

#
Will do that other thing you said too.
jonah420123 jonah420123

2018/11/29

#
Do you mean remove the blueCounter and redCounter actors as in delete them? or
        redCounter = new Counter();    
        addObject(redCounter, 500, 25);
        blueCounter = new Counter();
        addObject(blueCounter, 400, 25);

        resetredbutton resetredButton = new resetredbutton();
        addObject(resetredButton, x, y);

    }
    public Counter getRedCounter()
    {
        return redCounter;
    }
 
    public Counter getBlueCounter()
   {
       return blueCounter;
   }
Remove part of this code?
danpost danpost

2018/11/29

#
jonah420123 wrote...
Will do that other thing you said too.
Please do. You have yet to change lines 8 and 9 as instructed above:
danpost wrote...
Like this:
private Counter redCounter;
private Counter blueCounter;
danpost danpost

2018/11/29

#
jonah420123 wrote...
Do you mean remove the blueCounter and redCounter actors as in delete them?
I mean right click on the class (in the class tree frame) and select 'Delete'; then confirm. Repeat for the other one and also for the Counter2 class.
jonah420123 jonah420123

2018/11/29

#
I have replaced
    private Counter getRedCounter;
    private Counter2 getBlueCounter;
with
    private Counter redCounter;
    private Counter blueCounter;
All the errors have gone however, whenever the red bike collects a coin, only the blue counter increases score. Additionally, on level two, both my counters have turned blue, the same problem with scoring occurs. When i asked "Remove part of this code?" i meant a which specific part? or did you mean delete all of it?
danpost danpost

2018/11/29

#
jonah420123 wrote...
When i asked "Remove part of this code?" i meant a which specific part? or did you mean delete all of it?
I am talking entire classes -- not parts of code.
danpost danpost

2018/11/29

#
jonah420123 wrote...
whenever the red bike collects a coin, only the blue counter increases score. Additionally, on level two, both my counters have turned blue, the same problem with scoring occurs.
The bike classes should be getting their respective counters from the worlds.
jonah420123 jonah420123

2018/11/29

#
Alright, i now have only one 'Counter' not 'redCounter' or whatever, and i have changed the information so there are no errors. I will test this now.
jonah420123 jonah420123

2018/11/29

#
After testing it, it works as a counter but isn't using the other counter. There are two counters each level, there are two levels and one counter for each bike per level. If you could show me how to make the other counter go up instead of one counter just increasing that would be appreciated.
danpost danpost

2018/11/29

#
jonah420123 wrote...
There are two counters each level, there are two levels and one counter for each bike per level.
I am well aware of this.
After testing it, it works as a counter but isn't using the other counter. If you could show me how to make the other counter go up instead of one counter just increasing that would be appreciated.
Please provide your bike class codes.
jonah420123 jonah420123

2018/11/29

#
Blue Bike:
 import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class bluebike extends character
{
public static boolean death = false;
public  boolean redbike = false;
    
    public void act() 
    {
        move(1);
        checkKeys();
        checkDeath();
     
        Actor disk;
        disk = getOneObjectAtOffset(0,0, disk.class);
    if (getWorld() instanceof Arena)
        {
        if(disk!=null)
    {
        Arena arena = (Arena)getWorld();
        arena.removeObject(disk);
        
        Counter bluecounter = arena.getCounter();
        bluecounter.bumpCount(1);   
    }
}
        if (getWorld() instanceof ArenaTwo)
        {
        if(disk!=null)
    {
        ArenaTwo arenatwo = (ArenaTwo)getWorld();
        arenatwo.removeObject(disk);
        
        Counter blueCounter = arenatwo.getBlueCounter();
        blueCounter.bumpCount(1);   
    }
}
    
        Actor resetredbutton;
        resetredbutton = getOneObjectAtOffset (0, 0, resetredbutton.class); 
        if (resetredbutton !=null)
        {
            World detect;
            detect = getWorld();
            detect.removeObject(resetredbutton);
        }
    }    

    public void checkKeys()
    {
        
        int rotation = getRotation();
        int xPos = getX();
        int yPos = getY();
        switch(rotation)
        {    
            case 0:
                xPos = getX();
                yPos = getY();
                xPos -= 1;
                getWorld().addObject(new trail(), xPos, yPos);
                break;
            case 90:
                xPos = getX();
                yPos = getY();
                yPos -= 1;
                getWorld().addObject(new trail(), xPos, yPos);
                break;
            case 180:
                xPos = getX();
                yPos = getY();
                xPos += 1;
                getWorld().addObject(new trail(), xPos, yPos);
                break;
            case 270:
                xPos = getX();
                yPos = getY();
                xPos += 1;
                getWorld().addObject(new trail(), xPos, yPos);
                break;
        }
        if (Greenfoot.isKeyDown("left"))
        {
       setRotation(180);
        }
        
        if (Greenfoot.isKeyDown("right"))
        {
       setRotation(0);
        }
        
        if (Greenfoot.isKeyDown("up"))
        {
        setRotation(270);
        }
        
        if (Greenfoot.isKeyDown("down"))
        {
        setRotation(90);  
        }
        
        
  }
  
  private void checkDeath()
    {
        int Rotation = getRotation();
        switch(Rotation)
        {
            case 0:
                Actor object = getOneObjectAtOffset(getImage().getWidth()/2, 0, trail2.class);
                if (object != null)
                {
                    death = true;
                    redbike = true;
                }
                break;    
                
            case 90:
                object = getOneObjectAtOffset(0, getImage().getWidth()/2, trail2.class);
                if (object != null)
                {
                    death = true;
                    redbike = true;
                }
                break;
                
            case 180:
                object = getOneObjectAtOffset(-getImage().getWidth()/2, 0, trail2.class);
                if (object != null)
                {
                    death = true;
                    redbike = true;
                }
                break;
                      
            case 270:
                object = getOneObjectAtOffset(0, -getImage().getHeight()/2, trail2.class);
                if (object != null)
                {
                    death = true;
                    redbike = true;
                }
                break;
                
        }
    
        if (getOneIntersectingObject(trail2.class) !=null)
        {
            death = true;
            redbike = true;
        }     
        
        if (getWorld() instanceof Arena)
        {
        if (death == true)
        {
        Greenfoot.setWorld(new ArenaTwo());
        }
      }
    }   
        
}
    
Red Bike:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class redbike extends character
{
public static boolean death = false;
public  boolean bluebike = false;
    
    public void act() 
    {
        move(1);
        checkKeys();
        checkDeath();

    Actor disk;
    disk = getOneObjectAtOffset(0,0, disk.class);   
    if (getWorld() instanceof Arena)
        {
        if(disk!=null)
    {
        Arena arena = (Arena)getWorld();
        arena.removeObject(disk);
        
        Counter counter = arena.getCounter();
        redcounter.bumpCount(1);   
    }
}
        if (getWorld() instanceof ArenaTwo)
        {
        if(disk!=null)
    {
        ArenaTwo arenatwo = (ArenaTwo)getWorld();
        arenatwo.removeObject(disk);
        
        Counter redcounter = arenatwo.getRedCounter();
        redcounter.bumpCount(1);   
    }
}
            
        Actor resetredbutton;
        resetredbutton = getOneObjectAtOffset (0, 0, resetredbutton.class);       
        if (resetredbutton !=null)
        {
            World detect;
            detect = getWorld();
            detect.removeObject(resetredbutton);
        }
}    


public void checkKeys()
{
        
        int rotation = getRotation();
        int xPos = getX();
        int yPos = getY();
        switch(rotation)
        {    
            case 0:
                xPos = getX();
                yPos = getY();
                xPos -= 1;
                getWorld().addObject(new trail2(), xPos, yPos);
                break;
            case 90:
                xPos = getX();
                yPos = getY();
                yPos -= 1;
                getWorld().addObject(new trail2(), xPos, yPos);
                break;
            case 180:
                xPos = getX();
                yPos = getY();
                xPos += 1;
                getWorld().addObject(new trail2(), xPos, yPos);
                break;
            case 270:
                xPos = getX();
                yPos = getY();
                xPos += 1;
                getWorld().addObject(new trail2(), xPos, yPos);
                break;
        }
        if (Greenfoot.isKeyDown("a"))
        {
       setRotation(180);
        }
        
        if (Greenfoot.isKeyDown("d"))
        {
       setRotation(0);
        }
        
        if (Greenfoot.isKeyDown("w"))
        {
        setRotation(270);
        }
        
        if (Greenfoot.isKeyDown("s"))
        {
        setRotation(90);  
        }
        
        
  }
  
  private void checkDeath()
    {
        int Rotation = getRotation();
        switch(Rotation)
        {
            case 0:
                Actor object = getOneObjectAtOffset(getImage().getWidth()/2, 0, trail.class);
                if (object != null)
                {
                    death = true;
                    bluebike = true;
                }
                break;    
                
            case 90:
                object = getOneObjectAtOffset(0, getImage().getWidth()/2, trail.class);
                if (object != null)
                {
                    death = true;
                    bluebike = true;
                }
                break;
                
            case 180:
                object = getOneObjectAtOffset(-getImage().getWidth()/2, 0, trail.class);
                if (object != null)
                {
                    death = true;
                    bluebike = true;
                }
                break;
                      
            case 270:
                object = getOneObjectAtOffset(0, -getImage().getHeight()/2, trail.class);
                if (object != null)
                {
                    death = true;
                    bluebike = true;
                }
                break;
                
        }
    
        if (getOneIntersectingObject(trail.class) !=null)
        {
            death = true;
            bluebike = true;
        }
        
        if (getWorld() instanceof Arena)
        {
        if (death == true)
        {
        Greenfoot.setWorld(new ArenaTwo());
        }
    }
    }
}
danpost danpost

2018/11/29

#
Please check line 22 in both classes. If you remove the getCounter method from your world classes, you would catch this.
jonah420123 jonah420123

2018/11/29

#
Ok, so I've compromised by swapping the coordinates of the counters for both levels because it works but they were the wrong side of each other. Appreciate the help thanks. Now i just have to fix the fact that they dont die after colliding with each other... if you have the chance to help me fix this i would appreciate this.
jonah420123 jonah420123

2018/11/29

#
 private void checkDeath()
    {
        int Rotation = getRotation();
        switch(Rotation)
        {
            case 0:
                Actor object = getOneObjectAtOffset(getImage().getWidth()/2, 0, trail2.class);
                if (object != null)
                {
                    death = true;
                    redbike = true;
                }
                break;    
                
            case 90:
                object = getOneObjectAtOffset(0, getImage().getWidth()/2, trail2.class);
                if (object != null)
                {
                    death = true;
                    redbike = true;
                }
                break;
                
            case 180:
                object = getOneObjectAtOffset(-getImage().getWidth()/2, 0, trail2.class);
                if (object != null)
                {
                    death = true;
                    redbike = true;
                }
                break;
                      
            case 270:
                object = getOneObjectAtOffset(0, -getImage().getHeight()/2, trail2.class);
                if (object != null)
                {
                    death = true;
                    redbike = true;
                }
                break;
                
        }
    
        if (getOneIntersectingObject(trail2.class) !=null)
        {
            death = true;
            redbike = true;
        }     
        
        if (getWorld() instanceof Arena)
        {
        if (death == true)
        {
        Greenfoot.setWorld(new ArenaTwo());
        }
      }
    }   
Blue bike above^ This is the code i use for detecting collisions. My game is basically TRON, if you have ever seen that. Below is the Red bike version;
  private void checkDeath()
    {
        int Rotation = getRotation();
        switch(Rotation)
        {
            case 0:
                Actor object = getOneObjectAtOffset(getImage().getWidth()/2, 0, trail.class);
                if (object != null)
                {
                    death = true;
                    bluebike = true;
                }
                break;    
                
            case 90:
                object = getOneObjectAtOffset(0, getImage().getWidth()/2, trail.class);
                if (object != null)
                {
                    death = true;
                    bluebike = true;
                }
                break;
                
            case 180:
                object = getOneObjectAtOffset(-getImage().getWidth()/2, 0, trail.class);
                if (object != null)
                {
                    death = true;
                    bluebike = true;
                }
                break;
                      
            case 270:
                object = getOneObjectAtOffset(0, -getImage().getHeight()/2, trail.class);
                if (object != null)
                {
                    death = true;
                    bluebike = true;
                }
                break;
                
        }
    
        if (getOneIntersectingObject(trail.class) !=null)
        {
            death = true;
            bluebike = true;
        }
        
        if (getWorld() instanceof Arena)
        {
        if (death == true)
        {
        Greenfoot.setWorld(new ArenaTwo());
        }
    }
    }
danpost danpost

2018/11/29

#
jonah420123 wrote...
Now i just have to fix the fact that they dont die after colliding with each other... if you have the chance to help me fix this i would appreciate this.
Is this like a Tron light cycle match type game? If so, then I do not believe a bike can run into its own trail as well. If I were to code this, I would have just one Bike class and one Trail class where color was just a state (a field value in the Bike class). The trails would get their color from the bikes.
There are more replies on the next page.
1
2
3