Timer  | Newbie | | Join Date: May 2007
Posts: 11
| | |
Hello,
I have a program - it is accually a game, BoulderDash. A man runs an collets some crystals and when he has already collected the needed amount of crystals, he goes to the given destination and goes to another level. In the game besides the crystals there are also stones. When a stone or a crystal falls on the man's head, the game is over. The stone or crystal cannot fall from the grass or wall, but from another stone or crystal it can fall to the right or to the left.
Now I have made the program, I have the man moving across the game field, he collets the crystals, the stones are falling too. But there is a problem, when the man goes under the stone, this stone moves only when the man is moving, to steps with the man (I don't know if this is correct english, I hope you'll understand). So it is impossible to kill the man, because the man MUST go a step somewhere else, so that the stone can move a tile further.
I would like to make such thing, when the man goes under the stone, the stone falls abstractedly from the man. I want to use Timer, but I think, there's a little more needed, because the current operation, which is actually executing, must be suspended in a moment, when the player pushes some arrow. And I think, that javax.swing.Timer takes all the events and enqueques them into the queue of events, so they all will be accomplished. I need only the current event to be accomplished, and if there is some executing, it must be suspended.
I don't know how to do it, can somebody help me? Please..
| | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: Timer Quote:
Originally Posted by mishela Hello,
I have a program - it is accually a game, BoulderDash. A man runs an collets some crystals and when he has already collected the needed amount of crystals, he goes to the given destination and goes to another level. In the game besides the crystals there are also stones. When a stone or a crystal falls on the man's head, the game is over. The stone or crystal cannot fall from the grass or wall, but from another stone or crystal it can fall to the right or to the left.
Now I have made the program, I have the man moving across the game field, he collets the crystals, the stones are falling too. But there is a problem, when the man goes under the stone, this stone moves only when the man is moving, to steps with the man (I don't know if this is correct english, I hope you'll understand). So it is impossible to kill the man, because the man MUST go a step somewhere else, so that the stone can move a tile further.
I would like to make such thing, when the man goes under the stone, the stone falls abstractedly from the man. I want to use Timer, but I think, there's a little more needed, because the current operation, which is actually executing, must be suspended in a moment, when the player pushes some arrow. And I think, that javax.swing.Timer takes all the events and enqueques them into the queue of events, so they all will be accomplished. I need only the current event to be accomplished, and if there is some executing, it must be suspended.
I don't know how to do it, can somebody help me? Please.. I'm sorry I didn't fully get your explanation. I don't want you to have to post all your code (I don't think it's necessary a.t.m) but why not freeze everything when you want to drop the stone on the man's head (everything except the stone of course).
| | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: Timer Correct me if I'm wrong.
Assumption 1.) The stone moves independantly of the man.
Assumption 2.) The man is considered hit if the stone comes into contact with any part of him.
Now according to your ealier description, it seems that assumption 1 is not being satisfied.
|  | Newbie | | Join Date: May 2007
Posts: 11
| | | re: Timer Quote:
Originally Posted by r035198x Correct me if I'm wrong.
Assumption 1.) The stone moves independantly of the man.
Assumption 2.) The man is considered hit if the stone comes into contact with any part of him.
Now according to your ealier description, it seems that assumption 1 is not being satisfied. 1.)correct
2.)The stone falls from up to down, so if it falls to the head of the man it will kill him. Exactly like in that original game.
Yes, the assumption 1 is not being satisfied.
| | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: Timer Quote:
Originally Posted by mishela 1.)correct
2.)The stone falls from up to down, so if it falls to the head of the man it will kill him. Exactly like in that original game.
Yes, the assumption 1 is not being satisfied. Well I'm not a fan of having large amounts of code posted. So could you explain how you are moving the stone and how you are moving the man so that we can see why these two movements are not happening independant of each other.
|  | Newbie | | Join Date: May 2007
Posts: 11
| | | re: Timer
the whole code is based on this logic:
while(some stone is falling in the field) {
for(every row in the field) {
for(every column in the field) {
if(tile[row][column] is not a stone or crystal - something that cannot fall) {
//do nothing
}
else if(tile[row][column] is a stone or crystal - something that can fall) {
if(the tile under the tile[row][column], that means tile[row-1][column] is a blank tile) {
//the stone falls one tile down and if there is a man two tiles down, the stone will then kill him
}
else if(the tile under the tile[row][column], that means tile[row-1][column] is something from the stone or crystal can fall, that means, it is a stone, a crystal, a man, or a wall) {
//the stone falls only if there is a blank area left or right
}
}
}
}
printField();
}
in a simple version..
And a move is simple: if the man has where to move - that means, if in the direction is a tile that is blank, or there is a grass, he is moving one tile in that direction, and the field is tested for falling stones (that algorithm up).
If the man goes left or right, and in the direction there is a stone and a blank tile after, the man pushes the stone to that blank tile, and again the field is tested for falling stones.
If there is something else in the direction, do nothing.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|