dabyx
Processing Plant
Posts: 27
|
Post by dabyx on Jul 26, 2023 11:32:53 GMT
Hi guys,
Using MPAGD (amazing software btw, thanks)
and trying to replace a collectable with either an empty or custom block when collected.
Having a bit of trouble as all I can seem to do is get PUTBLOCK to place a block what seems like a random place when using LINE,COLUMN as the players X and Y (and tried dividing by 8 like the manual)
I must be missing something super obvious but just can't seem to wrap my hear around why I can't.
Any help or explanation on PUTBLOCK appreciated thanks 🙂
|
|
|
Post by ramon on Jul 27, 2023 15:17:35 GMT
COLLECT BLOCKS
MPAGD easily solves this typical mechanism of arcade games.
1- Simply Create a collectible block in your Screen editor.
2- Activate the mechanism by adding GETBLOCKS inside the event of your PLAYER.
3- That's it.
The game engine will place an empty block for you when the PLAYER collides with the block you've created, it also triggers the EVENT COLLECTBLOCK, giving you a separate programming space to organize your code.
PRINT A BLOCK
MPAGD uses the PUTBLOCK command as follows:
AT Y X PUTBLOCK 0 ; prints an empty block (type 0) in row Y, column X
NOTE: You must take the offset of the game grid into account when locating where you should place that block.
DETECT BLOCK TYPE
MPAGD uses the GETBLOCK (GetBlockType) command as follows:
GETBLOCK X Y ; Activates the mechanism to DETECT type of block that inhabits the horizontal X and vertical Y coordinates expressed in pixels. You will get the type of the BLOCK variable.
NOTE: The BLOCK variable cannot be saved to another variable, nor can it be printed or displayed. It can only be read. Example IF BLOCK = EMPTYBLOCK ... ENDIF
NOTE: Again take the game grid offset into account to calculate your coordinates.
Notice the naming convention:
If we express in pixels, the coordinates are X,Y.
If we express it in cells on the screen: the coordinates are Y,X.
Fix grid offset:
8 pixels for each cell, or a corresponding column or row.
I hope I have been helpful. luck!
|
|
dabyx
Processing Plant
Posts: 27
|
Post by dabyx on Jul 27, 2023 20:03:55 GMT
I see, Thanks Ramon 🙂
I may have been confusing the x, y coords and line,column.
Am I right that I could put the PUTBLOCK code in the COLLECTBLOCK Event?
Or would it be best in the Player script along with GETBLOCK?
Thanks 😁
|
|
|
Post by ramon on Jul 27, 2023 20:52:13 GMT
The answer is the following:
If you want to use the PLAYER's position coordinates privately to place your block, you must include PUTBLOCK in your SCRIPT. That is, if you want to replace the collectible block with another one other than the EMPTYBLOCK.
Note that EMPTYBLOCK is set automatically if you have GETBLOCKS enabled within the PLAYER SCRIPT.
If you don't want to replace the collectible block with any block other than EMPTYBLOCK, in the PLAYER's coordinates. You don't need to do anything, just write GETBLOCKS in the PLAYER event.
The player's coordinates are only accessible when their script is running. A very common strategy is to post them in two variables V, W so that enemies can see where you are and chase you in their Scrips.
Something to put in the EVENT COLLECTBLOCK would be this:
EVENT COLLECT BLOCK
; At first you can't simply access the coordinates of the PLAYER...
SCORE 5
AT 0 15
SHOWSCORE
AT 0 0 putblock 1 ; An ornament, an icon, a door, a hole...
DIVIDE w by 8
DIVIDE v by 8 AT W V PUTBLOCK 1 ; ... But if you have previously saved X Y of the PLAYER in the public variables V W. FIX OFFSET
|
|
dabyx
Processing Plant
Posts: 27
|
Post by dabyx on Jul 28, 2023 10:51:18 GMT
Brilliant, thanks a lot Ramon 🙂
I have the player's X,Y in variables already so this helps.
All the best 😁
|
|