Event Mechanic

I was thinking about a way to use an event driven mechanic where you move over a map with your player and dependant on the location of the map there is a certain chance that an event will come up. For example I am driving a car on a drawn map of a city and if the player is in a certain location a dialog pops up and the player can choose from different options which will affect further events in the future.

What would be the best method to get this working?

I have already a way to determine the location, is it a good idea to make different array lists for each location which contain an “event” object that refers to a particular event and then randomly choose one of these events? I am a bit confused if it is a bit unwieldy to create a class for each event.

Unless you are going to introduce scripting, then tough lol. You could easily give your game an EventHandler that keeps track of your current Area at all times, have each area hold an Array of possible Events that could happen there, the EventHandler can pick from this Array if an Event is to happen.

Hmmm, you might want to consider making an array that handles all the events and sorts them based on locations on the map. If the character moves over that location, then you can trigger that the event fires off. To make it random, you can either determine it randomly before they hit the array, or you can have a random variable inside the event that fires each time the player goes in the even zone. My example skeleton covers the latter…


import java.util.Random;

public class Event{

//x-axis location of the event field
int posx;
//y-axis location of the event field
int posy;
//The width of the event field
int sizex;
//The height of the event field
int sizey;
// A basic random object
Random rand;

public void init(){
     //Initialize all values...
}
public void event(int rand){
       //Insert event here if within the right random number...
       //Ignore the event if not
}

Put these events into an array and then check them. You can use a hash to keep checks low, but this is one way that you can accomplish it without the need of scripting.

@Gibbo3771
I don’t think I am ready yet for scripting but I believe scripts aren’t really used in java compared to c++ right?

But I am quite interested how scripts are implemented into java.

@ctomni231
thanks for the answer, I will try to use classes for now and see how it goes.
:slight_smile:

I don’t think it is really language specific, can you imaging having to code in missions/quest with a ton of dialogue?

Same with events, you can code the bass of the event but things such as dialogue and maybe predefined paths and what not would be done by external script in order to keep the code tidy and untangled.