LWJGL 2.9.3 and Slick2D Hello, so Im making this game and its going quite well, but I cant figure this out: Ive got a 2d tile based map (wich is stored in a 2d array) and each tile has a coresponding class and an arrayList for it. Here is what I try to make: I want to be able to click on a stone tile (I have this part done), and then I want the stone tile to disapear after a set ammount of time (e.g. 10 seconds). The code:
last = (int) (Sys.getTime() / Sys.getTimerResolution());
globaltimed = last - (int) (Sys.getTime() / Sys.getTimerResolution());
last = (int) (Sys.getTime() / Sys.getTimerResolution());
globaltimes = last - (int) (Sys.getTime() / Sys.getTimerResolution());
lastn = (int) (System.nanoTime() / 100000000);
timesn = lastn - (int) (System.nanoTime() / 100000000);
^^ This is the part wich goes in the init method in my Play state class. ^^
timesn = (System.nanoTime() / 100000000);
// Global time w/ millisecond
globaltimed = (timesn - lastn) / 10;
// Global time in seconds
globaltimes = (timesn - lastn);
sec = (int) (globaltimed % 60);
min = (int) (Math.floor(globaltimed/60));
hour = (int) (Math.floor(min/60));
^^ This part goes in the update method of the Play state class. ^^ Thats all the time stuff.
if(Mouse.isButtonDown(1)){
for(Stone ss : blocks){
if(Collision.playerCBlock(new Point(mx, my), ss)){
if(ss.selected && ss.selectable){
//map[Collision.contxy(new Point(ss.x / 32, ss.y / 32), ss, 0)][Collision.contxy(new Point(ss.x / 32, ss.y / 32), ss, 1)] = 3;
//blocks.remove(ss);
//ss.setSolid(false);
//ss.setSelectable(false);
ss.addMine(globaltimed, gc);
//dirt.add(new Dirt(ss.x,ss.y,false));
}
}
}
}
^^ Ignore the comments, but here I go through the stone tiles, check if the mouse is on that tile, if that tile is selectable and selected (I select it when left clicking, same for loop pretty much). I want to be able to say ss.addMine(whatever) and then in the stone class to make it wait some time (while displaying that time on the tile) and after that time has passed I want to replace the stone tile with a dirt tile. ^^
if(!dead){
//timedl = timed;
minig = true;
if(timed + minetime >= Play.getTimed()){
//gc.sleep(minetime * 1000);
setSolid(false);
setSelectable(false);
Play.dirt.add(new Dirt(x,y,false));
dead = true;
}
}
^^ This is the addMine method in the stone class. I played with this for about an hour but I dont really have any time left now. setSolid and setSelectable baisicly remove its collision and make it unselectable. play.dirt.add(...) adds a dirt tile ontop of the stone tile (Replaces it; not efficiently, but it works for now). ^^ Thats all the important code, now, does anyone have a concept to delay the replacement of the tile(setSolid(false)...dead=true that part) for some time in seconds w/ or w/o milliseconds (globaltimed is w/ millis, and globaltimes is in seconds only(and int)). Thank you