Page 1 of 2

Advice needed

Posted: Tue Apr 18, 2023 10:27 am
by productiondave
Calling for developer advice...

I am looking at the next game. An invaders clone.

I am sort of stuck on something at the moment and it's a bit tricky to explain.

So what I want to know is, how does one generate a smooth pixel level animation by updating patterns and tiles?

Here is an ascii art demonstration of the problem: In the beginning I have a tile in position 1 and I update its pattern 8 times to move pixels within the tile over from the left of the tile towards the right of the tile. When I get to the last frame in Tile 1 (Frame 7), I need to clear tile1 and set up tile2 but with the pattern such that the pixels are on the left of the tile again. It's all simple enough to understand, except that updating the patterns is instant. you get a glitch where the pattern updates but the new tile isn't drawn yet, or the new tile is drawn but with the old pattern. I don't seem to be able to figure out how to synchronize these two different ways of putting pixels on the screen.

I bet I am missing some very obvious thing here.

Code: Select all

          tile1    | tile 2
Frame 0 | X....... | ........
Frame 1 | .X...... | ........
Frame 2 | ..X..... | ........
Frame 3 | ...X.... | ........
Frame 4 | ....X... | ........
Frame 5 | .....X.. | ........
Frame 6 | ......X. | ........
Frame 7 | .......X | ........
          tile1    | tile 2
Frame 8 | ........ | X.......
Frame 9 | ........ | .X......
Frame A | ........ | ..X.....
Frame B | ........ | ...X....
Frame C | ........ | ....X...
Frame D | ........ | .....X..
Frame E | ........ | ......X.
Frame F | ........ | .......X

Re: Advice needed

Posted: Tue Apr 18, 2023 11:01 pm
by DJ Sures
I have an idea. Can whip something up later this week. Have a few non nabu stuff taking priority :)

Re: Advice needed

Posted: Wed Apr 19, 2023 3:25 am
by productiondave
Thanks DJ - no rush.

Just a bit of extra context...

I am using two tiles to draw an alien. I have 4 patterns for the left half and 4 patterns for the right half.

Each pattern animates the alien within the same tile position by moving it over by 2 pixels and changing other features for the animation effect. Thanks to Troy from the excellent hbc-56 GitHub repo where he has done all this in 6502 assembly.
Although his liberal use of acme macros makes the code really hard to follow. That's why I'm doing it in C.

Https://GitHub.com/visrealm/hbc-56.git

Re: Advice needed

Posted: Wed Apr 19, 2023 3:37 am
by DJ Sures
I haven't looked at your code yet - it'll be a few days but I can say that you'll need 3 tiles per invader (the invader only ever crosses two tiles at max). That gives you 1 tile between invaders at all times. That way, you only need 5 frames of the invader moving across the tile

Re: Advice needed

Posted: Wed Apr 19, 2023 3:44 am
by DJ Sures
Oh i should add that i started on a tile editor. It's somewhat functional - but I'll release it soon as i finish a few more things. I'm making it to do what the existing tile editors don't do. You'll see :)

It'll do any tile, including fonts. And you can load existing fonts into it. It has import option
Capture.PNG

Re: Advice needed

Posted: Wed Apr 19, 2023 7:53 am
by productiondave
DJ Sures wrote: Wed Apr 19, 2023 3:37 am I haven't looked at your code yet - it'll be a few days but I can say that you'll need 3 tiles per invader (the invader only ever crosses two tiles at max). That gives you 1 tile between invaders at all times. That way, you only need 5 frames of the invader moving across the tile
I've not shared any of my code. :D

I'm intrigued by your 3 tiles comment. I'm not sure I understand exactly what you mean. Why can't the invader move within the two tiles with 4 frames?

Re: Advice needed

Posted: Wed Apr 19, 2023 8:08 am
by DJ Sures
productiondave wrote: Wed Apr 19, 2023 7:53 am
DJ Sures wrote: Wed Apr 19, 2023 3:37 am I haven't looked at your code yet - it'll be a few days but I can say that you'll need 3 tiles per invader (the invader only ever crosses two tiles at max). That gives you 1 tile between invaders at all times. That way, you only need 5 frames of the invader moving across the tile
I've not shared any of my code. :D

I'm intrigued by your 3 tiles comment. I'm not sure I understand exactly what you mean. Why can't the invader move within the two tiles with 4 frames?
maybe it can? My thoughts are you'd need overlap for the invaders on each side of using only 2 tiles, no? So if they got shot, you'd need another set of tiles that contains the invader without another invader next to it.

Re: Advice needed

Posted: Wed Apr 19, 2023 11:11 am
by productiondave
The way I have it in mind is that an invader pattern takes up about 10 pixels. Leaving a 6 pixel gap before the next one.
The invader can move 3 times inside the tiles it's occupying before we need to move it over by one tile and put him back to the other edge of the tile.

Each animation moves the invader by 2 pixels.

I have the tile patterns for this already from the hbc-56 repository. I also have them for when the invaders move down.

Re: Advice needed

Posted: Wed Apr 19, 2023 9:46 pm
by DJ Sures
productiondave wrote: Wed Apr 19, 2023 11:11 am The way I have it in mind is that an invader pattern takes up about 10 pixels. Leaving a 6 pixel gap before the next one.
The invader can move 3 times inside the tiles it's occupying before we need to move it over by one tile and put him back to the other edge of the tile.

Each animation moves the invader by 2 pixels.

I have the tile patterns for this already from the hbc-56 repository. I also have them for when the invaders move down.
Will have a tile with 2 invaders?

Re: Advice needed

Posted: Sat Apr 29, 2023 3:04 pm
by productiondave
I've managed to solve it.

The way to do it is to load all the patterns for all states the invader can be in. 8 per invader type.

Then keep track of the x pixel location.

Tile location is floor(x / 8). Pattern name is x % 8 + offset to first of 8 consecutive patterns for the invader type.

As my patterns shift over by 2 pixels between them, and my invaders span 2 tiles, my math is a bit different, but same principal applies.

All I need to do with this approach is fill up a ram buffer with the correct tile names and then flush it to the vdp on vsync.

I have an MP4 video of it but can not attach it.

Thanks to John Winans from John's basement for pointing me in the right direction.