Hello,
I am developing a piano tiles game, and have successfully managed to code a basic piano tiles simulator. However, I have a few issues that currently require help:
1) Currently my score counter does not work. The code for the Score counter is posted below:
The Score class is executed in my Greenfoot scenario, however, the score does now increment every time I successfully press a key, when it should have. My take on this is that the Score class is working perfectly, the exception is that the world class Piano() has some limitations. Below is the code for the aforementioned world class which includes the Score class:
And below is my code for if the correct key is pressed, along with the execution if the correct key is not pressed and if the piano tile reaches the bottom edge of the world:
I am not sure why this is happening, but help would be greatly appreciated. If I missed anything just ask me to add in more information.
2) It would also be a great help if I could implement continuous piano tiles into my game, where the player has to hold the key down for an extended period of time for the continuous bar to disappear from the world, instead of simply pressing the key.
public class Score extends Actor { /** * Act - do whatever the Score wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public int points = 0; public Score(){ GreenfootImage scr = new GreenfootImage("Score: "+points,40,Color.BLACK,new Color(0,0,0,0)); setImage(scr); } public void addScore(int newPoints){ points += newPoints; GreenfootImage scr = new GreenfootImage("Score: "+points,40,Color.BLACK,new Color(0,0,0,0)); setImage(scr); } public void setScore(int zero){ points = 0; GreenfootImage nil = new GreenfootImage("Score: "+points,40,Color.BLACK,new Color(0,0,0,0)); setImage(nil); } }
public Piano() //declares a public method Piano { super(900, 600, 1, false); //sets the dimensions for the world setPaintOrder(Score.class); Score score = new Score(); addObject(score, 787, 52); makeKeys(); //calls the makeKeys method act(); //calls the makeBars method prepare(); }
public void scoreboard(){ score.addScore(1); }
public void act() { // Add your action code here. atWorldEdge(); fall(4); if (getWorld() != null && isDown == false && Greenfoot.isKeyDown(bar)){ Piano piano = (Piano)getWorld(); GreenfootImage downImage = new GreenfootImage("images/bars-down.PNG"); piano.scoreboard(); piano.removeObject(this); } else if (isDown == true && !Greenfoot.isKeyDown(bar)){ GreenfootImage upImage = new GreenfootImage("images/bars.PNG"); setImage(upImage); isDown = false; } else{ GreenfootImage upImage = new GreenfootImage("images/bars.PNG"); setImage(upImage); isDown = false; } }