PLEX Update

Leave a comment Standard

Time Spent – 6 hours

Despite the torture of being made to program over spring break I managed to get block selection working. Every time you click on the game screen it calls a click routine.

This routine checks several things:

1) are you clicking on blocks

2) are you clicking on a character on the board

3) are you clicking on the store

4) are you clicking on save game

Once it determines where you’re clicking it goes into a function to handle the particular action. Right now only the click block function works.

In the click block:

1) It calculates which block you’ve clicked on

2) It checks to see if this is the first block you’ve clicked on. If it is then this is the block you’re going to move. It sets selected block x and y variables. It doesn’t worry about the depth of the block you’re trying to select.

3) If you click on a block and the selected block x and y variables are already set then it assumes you’re trying to move the selected block to a new position. It calculates the x and y of the destination block and then passes this information into the game logic class.

The game logic class takes care of the actual manipulation of everything in the game, whereas the gameengine class has to deal with the graphics, music, and passing off keyboard/mouse usage to the right classes as the right time.

The game logic placeBlock function:

1) it checks to make sure you’re not trying to move the selected block to the same position (as it wouldn’t really move at all)

2) it checks to make sure you are not on the selected block (or any other character or item)

3) it checks if you are trying to move the selected block to a place on the board where the level below it has a tall block. If the level below has a tall block there then it extends up to the level above it.

4) it checks to make sure you aren’t trying to move the block more then x+1 or x-1 or y+1 or y+1 from the block’s x and y. This way you can only move the block one space from its original destination in all direction (forwards, backwards, and on diagonals).

4) it checks to make sure you aren’t trying to move the block to a section on the board that is completely full on all levels. Basically you can’t move a block past the height of the tallest spot on the array. You can’t select blocks below the topmost block, so it will always return the topmost block from any position you’ve selected a block to move.

5) if all of those conditions are met then it determines the depth of the block you selected. To do this it goes through all levels of the array until it finds the topmost block.

Once it finds the block it moves it to the destination position. The block’s old position is set to NOBLOCK, or being empty.

6) Finally the block is moved! The placeBlock function returns true or false for the successful block move. If the block is placed successfully it plays a falling sound, otherwise it plays an error sound.

Another thing I had to tackle in order to get block selection working seamlessly was my blockOver function. This function takes care of blitting blocks over top of the character so it looks like its BEHIND taller blocks on the board.

I added another check to see if the character is behind blocks from levels above it. One of the problems I ran into had to do with tall blocks. When you’re standing on a block on say the second level, and there’s a block on the level above you, I redraw the block on the level above after the character has moved to that position. This makes it look like the character is behind the block because it cuts off part of its body. However, what I had been doing was then drawing the top part of the block BELOW the block I just covered the character up with on the bottom of it. This makes it seemlessly blend back into the scenery.

The problem I ran into was if there was a tall block behind a block from a different depth level. To overcome this I had to make several if statements. If there is a tall block behind the block from another level, blit that. Otherwise blit the block from the same level.

Phew! That was a lot to write. In a nutshell, I now have block movement working. The only other issue I have is with the game freezing a lot. I’m not sure if this is my computer or the sounds I added, however I had the freezing problem every once in a while before I incorporated the sounds into the game.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s