Hi, I'm making a top down RPG and am wanting to place my enemies, characters, items, etc. via the map instead of programmatically. The issue I'm having is finding a way to then move/animate/update those sprites.
Currently my solution is: "scan" the map (iterate through each tile on the screen) and catalog the different types of sprites and their placement. Then I use mset to clear the tile and draw a new sprite of the same type in that same location and do the animations and movement from there.
It works ok but seems like there's no way that's the best solution. Also it doesn't make it easy to have each element act in a unique way (different enemy movement patterns, etc.)
Anyway, hope this makes sense. Let me know if you all have some tips and tricks to accomplishing something like this. Or if programmatically placing items is a better way to go.
Thanks!
Back on the Apple ][ computer, in Ultima II, lazerlex, when you opened a door it turned directly into the tile the player was standing on, which didn't always work out perfectly.
I suggest you could replace the unwanted sprite tile from your mapper with the tile directly BELOW it. That is, if your object in question is on the mapper at say 5,7. All you would need to do is copy tile 5,8 to 5,7.
That's what I did when I got around to making adventure games on that same computer and, like you, I wanted to use the raw map data for sprite definitions using a modulos position area of 4x4 to give them a further definition of script.
Thanks for the response dw817, though my issue isn't about replacing the tile it's more about animating/moving map sprites.
I wouldn't replace the sprites if i thought there was a way to use them as is but my "scan and swap" strategy is merely a way to utilize the map (not have to place all my game "actors" programmatically) but still have control over the logic and behavior of each actor sprite (different enemies with animation patterns specific to room, etc.).
Just trying to see if there's a good way to do that or if that's even a suggested way to use the map.
Errm ... You can't move map sprites except in 8x8 tight grid motions. If you're good with that, look at a cart I wrote recently to demonstrate how to do what you're wanting called, "Component Invaders."
https://www.lexaloffle.com/bbs/?pid=55875&tid=31766
Notice that they operate in an array and have no X or Y identity of their own, only a single number and color to represent who they are.
They "move" based upon the script I gave them and plot 0 (blank) behind them when they have moved.
To test the validity of this, you can "glitch" the cart while it runs by holding down the (X) key. Notice every new "sprite" added is just a single byte of information on a single array (mapper) and operates upon the rules given it.
This means its entirely possible to have invaders run into each other, have multiple firing spots, and multiple saucer launchers.
If you want to have smooth moving "sprites" solely with the mapper, it cannot be done.
Well, it's not absolutely impossible, but you would have to burn up at least 8 graphic sprites just to move vertically or horizontally by a single pixel, but not both.
If you wanted all of Up/Down/Left/Right, that would take a whopping 16-sprites for a single image for instance, and by default you only have a single layer so it could only move over one mapper tile type.
You would need 16-sprites for every tile type it tried to cross.
This would definitely not be worth it in the long run.
Instead, you will need to use the easier command, SPR() command in order to have smoothly moving individual sprites over a mapper field.
I have an example of that I wrote years ago HERE:
https://www.lexaloffle.com/bbs/?pid=28612&tid=27670
Bad coding though. It's just a simple example of moving a sprite over a field. Look to Tyroney's example beneath for the correct coding method of it.
Hope This Helps !
@lazerlex: You're pretty close to the most common technique I've seen in Pico-8 games. You scan the map for the initial placement of objects and enemies, store their locations in a Lua table, then erase them from the map with mset. For each frame, you draw the map, then iterate over the objects/enemies table and render them with spr() calls as appropriate. This can be as sophisticated as you need it to be, storing and updating objects that change animation frames, position, etc. The original map merely defines the initial positions, the subsequent map() calls merely draw the background without animated elements, and the spr() calls draw the objects on top of the map.
There are various ways to describe what's "under" the object, so you don't have to replace every object with an empty tile. An easy technique is to programmatically determine the replacement tile from an adjacent tile, e.g. the pig is near a grass tile, so you stash the pig's location then replace it with a grass tile. When you draw the map, then draw the pig on top, the pig is standing on grass, and the grass will still be there if the pig moves.
The included Jelpi demo game (a platformer) uses a simple version of this technique. (Type "install_demos" at the Pico-8 console prompt, then it's in the "demos/" subfolder). See also Curse of Greed for a more sophisticated example.
[Please log in to post a comment]