Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.tu_darmstadt.fop.geometrywars.model.events;
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.state.StateBasedGame;
- import eea.engine.event.Event;
- import java.util.Random;
- public class OpponentSpawnEvent extends Event {
- private float frequency;
- public static int count = 0;
- public static long time = System.currentTimeMillis();
- public static long updates = 0;
- private static Random r = new Random();
- /**
- * Constructor
- * @param id id of the event
- * @param frequency frequency should be between 0.01f and 0.99f
- */
- public OpponentSpawnEvent(String id, float frequency) {
- super(id);
- this.frequency = frequency / 100.0f;
- }
- @Override
- protected boolean performAction(GameContainer gc, StateBasedGame sb, int delta) {
- updates++;
- boolean b = Math.random() < frequency;
- if (b) {
- count++;
- 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");
- }
- return b;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement