Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
  2.  
  3. /**
  4. * Write a description of class Example here.
  5. *
  6. * @author (your name)
  7. * @version (a version number or a date)
  8. */
  9. public class Example extends World
  10. {
  11. // add (if you do not already have) these instance fields
  12. private Clock clock; // sub 'Player' with name of player-controlled actor class
  13. private int gameTime; // number of game-time units elapsed
  14. private int gameTimer; // frame counter
  15.  
  16. /**
  17. * Constructor for objects of class Example.
  18. *
  19. */
  20. public Example()
  21. {
  22. // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
  23. super(600, 400, 1);
  24.  
  25. }
  26. public void act ()
  27. {
  28. // in the world constructor
  29. clock = new Clock();
  30. addObject(new Clock(), 89, 99);
  31. // in world act method or method it calls
  32. if (clock.getWorld() != null)
  33. {
  34. gameTimer = (gameTimer + 1) % 60; // adjust 6 to suit
  35. if (gameTimer == 0) gameTime++;
  36. }
  37. else
  38. {
  39. // if game is over
  40. addObject(new Clock(), 60, 60); // now add it to the world
  41. Greenfoot.stop();
  42. // show value of 'gameTime'; in normal speed scenario, this will be approximate seconds
  43. // code to end game, reset level or start another life
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement