yeah its neat..... so right now im trying to minimize one of my classes Entity and it has kind of a bunch of crap that doesnt always get used. entity is basically my equivalent of a game maker object. position, speed, image related stuff, alarms, theres also a hash set of tags for things like collision. but nine times out of ten at least some aspect of this goes unused, and when i feel like i will be wasting resources, i climb the ladder and extend EntityBase (the parent for oddwarg and i's own entity classes) but ultimately this means i have to fill out a bunch of methods. so im making MinEntity which has position, collision support, and alarms. i dropped the image shit because it's way too game maker and for a lot of these objects im not just drawing one sprite, but many, so its ultimately not very helpful. when i do end up using EntityBase, i always end up needing alarms. the implementation for alarms in Entity is reaaaaally naive and bad. its an int array with a size determined in the constructor. each entry in the array is decreased by 1 every step and when one of the entries in the array reaches 0 it invokes a method alarmEvent(int alarmId)..... the alarmEvent functions usually look really cluttered and bad for cutscenes and shit. so instead of all this crap i have a queue of instances of a simple class Alarm that takes an int initialTime and a lambda function event. the time is decreased and the lamba function is called at 0.
the only bummer is that it's not really possible for the lambda function to setup an alarm with the same function.. so in some of these games there might be a timer that ticks every 30 frames, its alarmEvent(int i) would have looked like this
public void alarmEvent(int i){
if (i == 0){
crap();
alarm[0] = 30;
}
}
this isnt really possible to do with lambda expressions in java, so my solution is the following
repeatAlarm(() -> 30, () -> {
double newTime = Math.max(World.JAIL.stats.get("sentence") - 1, 0);
World.JAIL.stats.set("sentence", newTime);
if (newTime <= 0){
}
else{
}
});
the first argument to repeatAlarm is a lambda function that generates the amount of time each iteration should take. in some of my other classes that do things like Vibrate Wildly, i use a bunch of dumb alarms with random times to take care of Jittering. the second argument is the event. what this is saying is to perform this event every 30 frames. the only problem is there is no way to kill the alarm. my alarm() method could return a reference to the Alarm object would could be appended with a destroy() method or something