Platformer Demo

This is very impressive. I wonder how far fill can be pushed to create off grid movement.

After chatting with people on discord, we were wondering if you could use fill to fake an alpha channel on a non 8x8 sprite.
alp

Would this be possible @Yousurname ?

By using fill, you can definitely choose certain pixels of the 8x8 (or bigger) sprite to be fully transparent instead of opaque white or black. However, semi-transparency is not possible unless you fake it with some sort of flickering (also possible with the fill bug where it uses anti-aliasing).

Oh sorry, I can see how my example is confusing now.

I certainly wasn't looking to hack some semi-transparency, that was just to show the layers.

Would you be willing to do a write up on your fill code?

All the code is inside the JSON file attached, but here is the code to draw the player at (px, py) in the player's draw event:

	// draw player
	fill "black" at px,py,8,8
	x = px
	x++
	y = py
	y++
	fill "white" at x,y,6,6
	x++
	y++
	fill "black" at x,y,4,4
	y++
	fill "white" at x,y,4,1
	x++
	y--
	fill "white" at x,y,2,3

The four parameters after at represent the X position, Y position, width, and height, respectively, each one in terms of pixels instead of tiles.

That I'm following but what I'm not following is drawing tiles behind the "player"
And how pulp works out what it's targeting when you are off grid.

You don't have to do anything special with the tiles behind the player; they're already drawn on their own. fill just draws over everything else in the game.

fill also doesn't really target anything—it really just draws a rectangle where you tell it to. It doesn't know or care what you're trying to draw. You could use it to draw a progress bar, or a box, or the player (as in this case).

It looks like redrawing the background tiles behind the player addresses a bug where the dirty rects behind the fill rect are not updated properly. This is what it looks like if you comment out those calls:

Yea, that's what I thought might happen.

So on every frame, you would need to tell pulp to read and redraw a tile, then fill over top of it right?

You shouldn’t need to, those artifacts left over from the previous frame are definitely a runtime bug (which I’m looking into right now :playdate:).

Oh I see. Does that bug show up on the hardware also?

So to be clear, on draw, the code is using fill to make the player character. And on the next frame, it basically clears the screen and fills again?

BTW, Thanks for talking to me about this stuff.

1 Like

Yup, that will appear on the hardware as well since it’s a runtime bug. When you use fill to draw a rectangle, it (is supposed to anyway :sweat_smile:) mark all the cells that you are drawing on top of as dirty so on the next frame they can be redrawn (this way we’re not redrawing the entire screen every frame). Because it’s not working as intended Yousurname is redrawing the dirtied tiles manually.

1 Like

You can see the problem clearly here (the red overlays are tiles that were identified as dirtied on the previous frame):
dirty-rects

And this is what it should look like:
dirty-fix

I made the mistake of assuming that the width of the rect divided by the tileWidth was the number of dirty tiles but that can’t be assumed to be true when they are the same width.

Except even this is wrong, it’s too greedy. :playdate_crying: Even when perfectly aligned to a tile it still dirties the next column and row.

Here we go:

dirty-really-fixed

When the player is perfectly aligned with the tile grid (like when they’re against the left side of the screen) they only dirty a single tile as expected. We got there! :playdate_cry_laugh:

4 Likes

And that fix is now live. If you add n = name tx,ty to the collect_coin handler you can delete the calls to draw_tiles. (Note that you’ll need to download a new pdx in order to pick up the runtime fix for this.)

5 Likes

Thanks for your work @shaun!

Incredible. Thanks for sharing the source code!

this is realy cool!
im gonna use it as a base for my puzzle platformer called: ghostshift

hi im also doing that but when im trying to connect different rooms together, it doesnt work. have you got it to work?

If people want an easier way to make platformers, maybe take a look at Cotton.

1 Like

This looks promising. I need to check this out. Thank you! :playdate_happy:

awesome i downloaded and played with it, can you used exit to go into other rooms? i tried to do it with pulp it didn't work