Bruce

Oct 17, 20213 min

Let's create an MPAGD game - Part 18: DIG these FODDERBLOCKs

Updated: Oct 30, 2021

Let's go back to the BLOCK EDITOR and take a look at one of the other BLOCKTYPES we can use in our MPAGD games. So far we've looked at:

WALLBLOCKS - solid blocks that the player can't pass through but can walk on

PLATFORMBLOCKS - that the player can pass through and walk on

LADDERBLOCKS - that the player can climb up and down and pass across

EMPTYBLOCKS - that the player can pass through

The next one we'll take a look at are FODDERBLOCKS. Open up your BLOCK EDITOR and hit X to create a new block, then change its BLOCK TYPE to FODDER

I'm going to create some Blue Soil...

Next open up your SCREEN EDITOR and add an area of FODDERBLOCKS

Now let's test the game

As you can see, FODDERBLOCKS by default behave like WALLBLOCKS , Stinky Dog can not pass through them but can walk on top of them. So how is he going to get that buried bone?

So what's the point of FODDERBLOCKS?, well the big difference between FODDER & WALL blocks is that FODDERBLOCKS can be removed by the use of the DIG command.

Let's give Stinky Dog the ability to dig through fodderblocks, to do this, we just need to add a few lines of code to the PLAYER EVENT

We need to find the two statements that control moving Stinky Dog to the Left and to the right and add the code I've highlighted below:

IF KEY LEFT ; Is the left key pressed?
 
LET DIRECTION = LEFT ; if so, remember I am going LEFT
 
LET IMAGE = 1 ; display the left facing image
 
IF X <= LEFTEDGE ; are we at the left edge of the screen?
 
SCREENLEFT ; if so, go to the screen to left on the map
 
LET X = RIGHTEDGE ; and put me at the right edge of that screen
 
EXIT ; and stop processing this event
 
ELSE ; if I'm not at the left edge
 
IF CANGOLEFT ; is there space to the left of me?
 
SPRITELEFT ; if so move me left
 
ANIMATE ; and animate me
 
ELSE ; if I cant go left
 
DIG LEFT ; remove any FODDER to my left
 
ENDIF
 
ENDIF
 
ENDIF
 

 
IF KEY RIGHT ; Is the right key pressed?
 
LET DIRECTION = RIGHT ; if so, remember I am going RIGHT
 
LET IMAGE = 0 ; display the right facing image
 
IF X >= RIGHTEDGE ; Am I at the right edge of the screen?
 
SCREENRIGHT ; if so go to the screen to right on the map
 
LET X = LEFTEDGE ; and put me at the left edge
 
EXIT ; and stop processing this event
 
ELSE ; if I'm not at the right edge
 
IF CANGORIGHT ; is there space to the right of me?
 
SPRITERIGHT ; if so, move me right
 
ANIMATE ; and animate me?
 
ELSE ; if I can't go right
 
DIG RIGHT ; move any fodder to my right
 
ENDIF
 
ENDIF
 
ENDIF

The CANGOLEFT and CANGORIGHT functions check to see if we can move in those directions, in other words, are there WALLBLOCKS or other blocks that do not allow the player to pass through, which as standard, is the case for FODDERBLOCKS.

Our new code will now automatically remove (DIG) any fodderblocks that are in our way (without this, FODDERBLOCKS will just work like WALLBLOCKS.

Let's give it a test...

Now Stinky Dog can remove the dirt to get to the buried bone.

DIG always requires a direction - we've use LEFT and RIGHT here but you can also use UP and DOWN if your game requires it.

Note that FODDERBLOCKS that have been dug will be redrawn after any command that forces a redraw such as MENU or REDRAW or if the player re-enters a screen, or is respawned after a death. There is a way to permanently remove dug fodder, but it requires a small change to the MPAGD engine and for your game to run in Adventure Mode...but that's a bit more advanced and a topic I will tackle another day!

NEXT: PART 19: DEADLY, CUSTOM AND WATER BLOCKS

    3950
    5