1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class MyWorld extends World { int pipeCounter = 0 ; int flappyCounter = 0 ; int SPACE_BETWEEN_PIPES = 0 ; int score = 0 ; int FIRST_PIPE = 240 ; int randomLoc; // int addVal=230; int counter = 0 ; //int scoreV= 0; Score scoreObj = null ; /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 600 , 400 , 1 , false ); setPaintOrder(GameOver. class , Score. class , FlappyBird. class , TopPipe. class ); FlappyBird flappy = new FlappyBird(); addObject(flappy, 100 , 200 ); scoreObj = new Score(); scoreObj.setScore( 0 ); addObject(scoreObj, 70 , 355 ); } public void act() { pipeCounter++; if (pipeCounter % 100 == 0 ) { createPipes(); } if (pipeCounter >= FIRST_PIPE) { if (flappyCounter % 100 == 0 ) { score++; scoreObj.setScore(score); } flappyCounter++; } } //public int addVal =230; private void createPipes() { if (pipeCounter== 100 ) { BottomPipe bottompipe = new BottomPipe(); randomLoc = Greenfoot.getRandomNumber( 200 )- 100 ; addObject(bottompipe, getWidth(), getHeight() + SPACE_BETWEEN_PIPES / 2 + randomLoc); TopPipe toppipe = new TopPipe(); addObject(toppipe, getWidth(), 0 - SPACE_BETWEEN_PIPES / 2 + randomLoc); pipeCounter = 0 ; } } } ___________________________________________ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) //import java.awt.Color; import greenfoot.Color; //import java.awt.Font; import greenfoot.Font; /** * Write a description of class Score here. * * @author (your name) * @version (a version number or a date) */ public class Score extends Actor { public Score() { GreenfootImage newImage = new GreenfootImage( 100 , 50 ); setImage(newImage); } public void setScore( int score) { GreenfootImage newImage =getImage(); newImage.clear(); Font f = new Font( "Comic sans MS" , 32 ); newImage.setFont(f); Color c = new Color( 127 , 127 , 127 , 127 ); newImage.setColor(c); newImage.fill(); newImage.setColor(Color.BLACK); newImage.drawString( "" + score, 30 , 30 ); setImage(newImage); } } |

