Java game sokoban 128x160




















Pop - Dance. Rap - Hip Hop. Heavy Metal. TV Film. Country - Folk. Anthems Patriotic. Classical - Opera. Sports - Football. Name Tones. Celebrity Tones. Video Games. Wake Up Tones. Sound Effects. Like us on Facebook. Sheep Mania - Barnyard Dash x Burger Rush x Ki.

Sheep Mania - Puzzle Islands x N Sheep Mania - Puzzle Islands x Call Of Juarez x Contra 4 x K Enter your email:. This is the level of the game. Except for the space, there are five characters. The hash stands for a wall. The dot. The at character is the sokoban. The initWorld method initiates the game world. It goes through the level string and fills the above mentioned lists. In case of the dollar character, we create a Baggage object. The object is appended to the baggs list.

The x variable is increased accordingly. We iterate through the world container and draw the objects. The player and the baggage images are a bit smaller. We add 2px to their coordinates to center them. Inside the keyPressed method, we check what keys were pressed. We control the sokoban object with the cursor keys. If we press the left cursor key, we check if the sokoban collides with a wall or with a baggage.

If it does not, we move the sokoban to the left. The checkWallCollision method was created to ensure that the sokoban or a baggage do not pass the wall. The above lines check for the left collision. The checkBagCollision is a bit more involved. A baggage can collide with a wall, with a sokoban object or with another baggage. The baggage can be moved only if it collides with a sokoban and does not collide with another baggage or a wall.

When the baggage is moved, it is time to check if the level is completed by calling the isCompleted method. The isCompleted method checks if the level is completed. We get the number of bags. We compare the x and y coordinates of all the bags and the destination areas. The game is finished when the finishedBags variable equals the number of bags in the game.

If we do some bad move, we can restart the level. We delete all objects from the lists and initiate the world again. The isCompleted variable is set to false.



0コメント

  • 1000 / 1000