Making a Game with MooClick - Part 2
Making a Game with MooClick - Part 2
by Flava

Custom movement
If your making a game, it's VERY likely you will need movement. But, different movements can affect your game and cause lag if not coded efficiently. Here I'm going to tell you how to make a normal movement engine which has virtually no lag (every now and again players may jump depending on pings in server - that's normal).

In part one, you made some funky detectors for your player. Well Done! Firstly, we need to set the positions of the detectors to your player. I assume you know how to do this..

+ Always - Set position of Up Detector to (0,-9) of Your Player
- Set position of Down detector...
- Set position of left detector...
- Set position of right detector...
- Make detectors invisible

Obviously the positions will vary to mind if you have different sized players .etc.

+ Repeat while left arrow is pressed
+ Left detector ISNT overlapping backdrop
- Set value A of Your Player to -1

+ Repeat while right arrow is pressed
+ Right detector ISNT overlapping backdrop
- Set value A of Your Player to 1

This will be more explainable later - but notice that Value A of your player covers the X directions. Therefore we'll use value B to cover our Y directions.

+ Repeat while up arrow is pressed
+ Up detector ISNT overlapping backdrop
- Set value B of Your Player to -1

+ Repeat while down arrow is pressed
+ Down detector ISNT overlapping backdrop
- Set value B of Your Player to 1

Now things may get a little confusing here on, I'll try to explain best I can though.

+ Your Player: Value A different to Value C
- Your Player: Set value C to Value A
- MooClick: Channel - Str$( X( "Your Player" ) ) + , + Str$( Y( "Your Player" ) ) + "," + Str$( Alterable Value A( "Your Player" ) ) + , + Str$( Alterable Value B( "Your Player" ) ) on subchannel 0

Basically if Value A is different to Value C, then we send our positions. By default, Value C is 0 - therefore if we move left and right, Value A gets set to 1 or -1 - making it different to value C. If the values are different, then we send our positions and set value C to value A (so they are the same again). This is virtually a lag free system, as it only sends our positions when needed too. We also send alterable values A and B which show the players direction and position gap - if you remember, we set these to -1, 1 when pressing keys. If you read part 1, you will know that these are the 3rd and 4th elements - and when retrieved, they are set to values B and C of the other player (remember - value A is already being used for the other player's MOO ID).

+ Your Player: Value B different to Value D
- Your Player: Set value D to Value B
- MooClick: Channel - Send Str$( X( "Your Player" ) ) + , + Str$( Y( "Your Player" ) ) + "," + Str$( Alterable Value A( "Your Player" ) ) + , + Str$( Alterable Value B( "Your Player" ) ) on subchannel 0

Exactly the same as above - but this time we use value B for Y positions, and compare it to value D. Hope I haven't confused you here.

+ Your Player: Value A different to 0
- Set x position to (X position) + Value A

+ Your Player: Value B different to 0
- Set Y position to (Y position) + Value B

If you press an arrow key, then values A and B set to 1 or -1, making them different to 0. If the values are 0, that means your not moving. This basically says that if values A or B are different to 0, then set X pos to A and Y Pos to B. Or, if your pressing a key, making your player move.

+ Other Player: Value B different to 0
- Set x position to (X position) + Value B

+ Other Player: Value C different to 0
- Set Y position to (Y position) + Value C

This basically makes the player move with almost no lag. If you remember, when a key is pressed - value A and B are set to either 1 or -1. We then send these via string parser (elements 3 and 4) and they a retrieved to another player and set to value B and C. Hope that makes sense!

+ (NEGATE) Repeat while Left key is pressed
- Your Player: Set value A to 0

+ (NEGATE) Repeat while Right key is pressed
- Your Player: Set value A to 0

+ (NEGATE) Repeat while Up key is pressed
- Your Player: Set value B to 0

+ (NEGATE) Repeat while Down key is pressed
- Your Player: Set value B to 0

Basically, if the player is pressing no keys - don't make the player's object move. Remember, setting to 0 means the player doesn't move.

Name tags
This is actually very simple - and considering you understood everything above, I have no doubt that you will know/understand how to do this. Basically, we're going to use text blitter to display players name tags. We need to retrieve player's names when they join the game, or if they are already apart of the game.

+ Start of level
- Text Blitter: Destroy

+ Mooclick: User - On user joined
+ Value A of Other Player = PCU_GetID( "MooClick" )
- Create text blitter object
- Text blitter: Change text to PCU_GetName$( "MooClick" )

+ Mooclick: User - On user is here
+ Value A of Other Player = PCU_GetID( "MooClick" )
- Create text blitter object
- Text blitter: Change text to PCU_GetName$( "MooClick" )

Firstly we destroy all text blitter objects at start of level so they do not get in the way. Then, if a user joins, we compared value A to a player ID and then change the text blitter text to the name of the player with that ID. We then do exactly the same if a player is already here.

+ Text$( "Text Blitter" ) = PCU_GetName$( "MooClick" )
- Text blitter: Set position at (-24,-20) from Other Player

Basically, we compared the name of a player to the text of the text blitter object. If they are the same, then we position the text blitter to that player. You can use events to align the text blitter in order to align it in the correct position each time - but that does not involve MooClick, therefore I will not go over it.

+ MooClick: User - On user left
+ Value A of Other Player = PCU_GetID( "MooClick" )
+ Text$( "Text Blitter" ) = PCU_GetName$( "MooClick" )
- Text Blitter: Destroy

When a user leaves, we compare the player IDs and text blitter names and then destroy the text blitter object that is needed to be destroyed. (In other words, we destroy the text blitter object of the player which has left).

Making a Game with MooClick - Part 3 >>