Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
- /**
- * Write a description of class Example here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Example extends World
- {
- // add (if you do not already have) these instance fields
- private Clock clock; // sub 'Player' with name of player-controlled actor class
- private int gameTime; // number of game-time units elapsed
- private int gameTimer; // frame counter
- /**
- * Constructor for objects of class Example.
- *
- */
- public Example()
- {
- // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
- super(600, 400, 1);
- }
- public void act ()
- {
- // in the world constructor
- clock = new Clock();
- addObject(new Clock(), 89, 99);
- // in world act method or method it calls
- if (clock.getWorld() != null)
- {
- gameTimer = (gameTimer + 1) % 60; // adjust 6 to suit
- if (gameTimer == 0) gameTime++;
- }
- else
- {
- // if game is over
- addObject(new Clock(), 60, 60); // now add it to the world
- Greenfoot.stop();
- // show value of 'gameTime'; in normal speed scenario, this will be approximate seconds
- // code to end game, reset level or start another life
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement