Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package de.tu_darmstadt.fop.geometrywars.model.events;
  2.  
  3. import org.newdawn.slick.GameContainer;
  4. import org.newdawn.slick.state.StateBasedGame;
  5.  
  6. import eea.engine.event.Event;
  7.  
  8. import java.util.Random;
  9.  
  10. public class OpponentSpawnEvent extends Event {
  11.  
  12. private float frequency;
  13. public static int count = 0;
  14. public static long time = System.currentTimeMillis();
  15. public static long updates = 0;
  16. private static Random r = new Random();
  17. /**
  18. * Constructor
  19. * @param id id of the event
  20. * @param frequency frequency should be between 0.01f and 0.99f
  21. */
  22. public OpponentSpawnEvent(String id, float frequency) {
  23. super(id);
  24. this.frequency = frequency / 100.0f;
  25. }
  26.  
  27. @Override
  28. protected boolean performAction(GameContainer gc, StateBasedGame sb, int delta) {
  29. updates++;
  30. boolean b = Math.random() < frequency;
  31. if (b) {
  32. count++;
  33. System.out.println(count + ". enemy in " + (int)(System.currentTimeMillis()-time)/1000f + ". second. | " + count/((System.currentTimeMillis()-time)/1000f) + " enemies per second | " + 1f*count/updates + " enemies per update");
  34. }
  35. return b;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement