Pushable Blocks Module

m8si

Active member
After I showed a video of my Lolo inspired engine a lot of NESmakers have asked for a tutorial. Well here it is.


In the attachments, there is a zip file containing a NESmaker module. Detailed install instructions can be found in the Youtube video below. You may need to press pause every now and then to follow along. =D There are also two very important steps in the tutorial video. Be sure to follow them both! ;)

Here are also some things you should know before using the module:
  • There is some room for optimisation when it comes to variables. The module uses three new object variables, but since there is always just one block moving at a time it could use normal variables instead.
  • Module is very strict about player's collider size. If you want to use other than 16x16 game object you most likely have to change some hardcoded values in boxTile.asm
  • Box is hardcoded as gameobject #8 if your game uses more game objects (enemies/pickaples etc.) the block logic will overwrite these and strange things can happen.
  • Floor and Block tiles must use the same palette. At least for now.
  • Works only on even screens. (00,02,04 etc...)
  • Please post a comment if you are making something cool out of this. I would love to see it!


Have fun making NES games!
 

Attachments

  • BlockPusher Mod.zip
    15.9 KB · Views: 15
Last edited:

baardbi

Well-known member
After I showed a video of my Lolo inspired engine a lot of NESmakers have asked for a tutorial. Well here it is.


In the attachments, there is a zip file containing a NESmaker module. Detailed install instructions can be found in the Youtube video below. You may need to press pause every now and then to follow along. =D There are also two very important steps in the tutorial video. Be sure to follow them both! ;)

Here are also some things you should know before using the module:
  • There is some room for optimisation when it comes to variables. The module uses three new object variables, but since there is always just one block moving at a time it could use normal variables instead.
  • Module is very strict about player's collider size. If you want to use other than 16x16 game object you most likely have to change some hardcoded values in boxTile.asm
  • Box is hardcoded as gameobject #8 if your game uses more game objects (enemies/pickaples etc.) the block logic will overwrite these and strange things can happen.
  • Floor and Block tiles must use the same palette. At least for now.
  • Please post a comment if you are making something cool out of this. I would love to see it!


Have fun making NES games!
I tried to follow this tutorial, but it looks like something is not working. Maybe I'm doing something wrong. I tried to remove the ; at line 419 in the boxTile.asm file, and that made it a little better but the new block didn't show up after the object was destroyed. Here is a video to show what I mean (this is before I tried to remove ; in the boxTile.asm file):

pushing.gif

This is after removing the ; at line 419 in the boxTile.asm file:

pushing2.gif
 

baardbi

Well-known member
I added this to doSpritePreDraw_AdventureBase.asm file (before DestroyObject) and now it works great.

Code:
LDA Object_x_hi,x
LSR
LSR
LSR
LSR
STA tempA

LDA Object_y_hi,x
LSR
LSR
LSR
LSR
STA tempB

ChangeTileAtPosition tempA,tempB,#$0E,#$03,camScreen
 

m8si

Active member
Looking Great! But when seeing that camScreen there. I realise I forgot to mention it only works on even screens. Sorry... Maybe you are using an odd screen? Other possible solution is that your player's or block's colliders aren't set exactly like they should. It is a bit picky system at it's current state.
 

m8si

Active member
Can you please tell me what specific asm. scripts are involved in this pushblock method?
It's all in the zip file. Collision check and calculations happen in boxTile.asm and doSpritePreDraw_AdventureBase.asm. (doDrawSprites is there only to fix the bug that misplaces objects by one pixel)
 
Looking Great! But when seeing that camScreen there. I realise I forgot to mention it only works on even screens. Sorry... Maybe you are using an odd screen? Other possible solution is that your player's or block's colliders aren't set exactly like they should. It is a bit picky system at it's current state.
I ran into the odd screens not working thing with a feature in my game awhile ago with the ChangeTileAtPosition...
Try replacing CamScreen with currentNametable
 

m8si

Active member
I ran into the odd screens not working thing with a feature in my game awhile ago with the ChangeTileAtPosition...
Try replacing CamScreen with currentNametable
It is due to a fact that I partly wrote tile change logic myself because I wanted to know how it works. And also did not mean to publicly share my code at first. :) So I didn't bother checking the nametable to make the code more complex while figuring things out. It is hard coded to use only the first nametable starting at $2000
 

baardbi

Well-known member
I ran into the odd screens not working thing with a feature in my game awhile ago with the ChangeTileAtPosition...
Try replacing CamScreen with currentNametable
This is probably the best way to handle it, because the ChangeTileAtPosition macro only wants a 0 or 1 as the last argument.

Code:
LDA currentNametable
AND #%00000001
STA temp

ChangeTileAtPosition #$03, #$0D, #$02, #$00, temp
 

baardbi

Well-known member
OK. I have played around a bit with this module now, and I have to say that I'm very impressed. You have even coded a lot of details that would be easy to miss when making something like this. Like for example pushing a box tile into another box tile stops both the tile and the player, and the same thing happens when pushing it against the solid wall. Very nice. Thank you again for sharing this. I have had so much fun playing around with this.
 

m8si

Active member
Thank you and awesome you had fun with it. That feels great! :) It is not perfect, but tried my best to make it usable.

It was fun to make too. Coding is always so satisfying. Having all those small things come together after smashing your head to the wall for a minute or two.. Lol! xD
 

m8si

Active member
I made a fun little test game today. It's a little too close to The Adventures of Lolo, so I'm not going to finish it. I made a short video about it on my YouTube channel.

View: https://youtu.be/QA0Jc9he5BY?si=DgHpAMyyDpZfKdEv

PS! Music by JollyShadow.
Whoa! That's really cool! And you made the boxes kill enemies too. Very nice! =D Haven't thought about that before but that would be fun logic for my game too.

But yea... It's hard to NOT make Lolo with this. My game looks a lot like Lolo too. Having the hud on the right and similar looking tiles around the level. But I'm trying to add some cool new mechanics to make it a different game. One idea is to let the water flood around the level if player breaks the dam with some stuff, opens a hatch etc. That will be also the next challenge... How to make the water flood fluently.
1711657068773.png
 
Top Bottom