Jump to content
IGNORED

Chase


Recommended Posts

On 11/23/2020 at 5:19 PM, Lillapojkenpåön said:

The original game was just a demo to demonstrate a NES library for the cc65 compiler I believe, but maybe we can add some fun stuff to it, I already have one idea.

I think this is the exciting part of this project, so I'm glad you're going this way. It's a super basic game, but good bones on which you can try out your own gameplay twists and ideas.

 

If things wind up interesting, you can even re-skin it and make it your own.

  • Like 6
Link to comment
Share on other sites

How do I plot a new level without the game freezing or crashing?

 

 

 clearscreen

 gosub loadLevel

 savescreen

I load the first level like that before the loop, 

but I haven't found any clearscreen/savescreen/restorescreen/drawscreen combo that works for loading a new level?

loadLevel

 level = level + 1



 on level goto _1 _1 _2 _3 _4



_1

 memcpy tilemap tiledMap8x8 540

 plotmapfile tiledMap8x8.tmx tilemap 0 1 20 27

 goto done



_2

 memcpy tilemap tiledMap8x8 540

 plotmapfile tiledMap8x8.tmx tilemap 0 1 20 27

 goto done



_3

 goto done



_4



done



 dotCounter = 0



 return thisbank

 

Link to comment
Share on other sites

On 11/27/2020 at 2:55 PM, RevEng said:

I'm not seeing anything there that should cause freezing or crashing. (assuming your "gosub loadlevel" is being called from the same bank containing loadlevel.

 

Feel free to shoot me some source in PM, so I can track down the source of the crash.

I don't know what I changed but it works now.

 

 

I started working on fade out and fade in routines, for fade out the color goes black after the darkest color, that happens to the darkest colors in the palette first, and they stay black while the other colors keep fading out until all are black, for fade in the brightest colors in the intended palette appears first while the darker ones remain black.. you get the idea.

It's alot of work to get right and I remembered that the NES C library I tried had functions for that

 

    pal_bright(4);    // can be a value 0 (all black) to 8 (all white), 4 = normal, the palette as it's defined

 

with that function it's extremely easy to fade in or out by just making your own little C function and using a variable instead of a number

 

 

I guess the palettes gets stored as tables, and then these tables are used to alter those values?

;void __fastcall__ pal_bright(unsigned char bright);

_pal_bright:

    tax
    lda palBrightTableL,x
    sta <PAL_PTR
    lda palBrightTableH,x    ;MSB is never zero
    sta <PAL_PTR+1
    sta <PAL_UPDATE
    rts



palBrightTableL:

    .byte <palBrightTable0,<palBrightTable1,<palBrightTable2
    .byte <palBrightTable3,<palBrightTable4,<palBrightTable5
    .byte <palBrightTable6,<palBrightTable7,<palBrightTable8

palBrightTableH:

    .byte >palBrightTable0,>palBrightTable1,>palBrightTable2
    .byte >palBrightTable3,>palBrightTable4,>palBrightTable5
    .byte >palBrightTable6,>palBrightTable7,>palBrightTable8

palBrightTable0:
    .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f    ;black
palBrightTable1:
    .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
palBrightTable2:
    .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
palBrightTable3:
    .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
palBrightTable4:
    .byte $00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0a,$0b,$0c,$0f,$0f,$0f    ;normal colors
palBrightTable5:
    .byte $10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$1a,$1b,$1c,$00,$00,$00
palBrightTable6:
    .byte $10,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2a,$2b,$2c,$10,$10,$10    ;$10 because $20 is the same as $30
palBrightTable7:
    .byte $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3a,$3b,$3c,$20,$20,$20
palBrightTable8:
    .byte $30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30    ;white
    .byte $30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30
    .byte $30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30
    .byte $30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30

If I wanted to do something similar in 7800basic I would start by putting the palettes in tables, but I don't know how to alter it with another brightness table?

If no one else knows then I would like to know how you fade in and out because my way feels wrong, to complicated.

 

 

 

Edited by Lillapojkenpåön
  • Like 1
Link to comment
Share on other sites

I've done a few fade-in / fade-outs and I use a different technique. Very helpfully with the way the 7800 palette is laid out the colour and brightness are each represented by half of the byte, so by doing a bitwise AND we can ignore the colour half, check the brightness half, and modify it as needed.

 

In this below bit of code I'm setting the starting colours I want, then checking to see if the brightness of each is greater than zero in which case I reduce the brightness but if it's already zero I set it to black.

As the palettes can only be written to and not read from I use temporary variables to keep track of what the values should be and then set the palettes after processing.

customTemp2 = $AB : customTemp3 = $5A : customTemp4 = $96 : customTemp5 = $0F 

FadeOutLoop
	if customTemp2&#$0F > 0 then customTemp2=customTemp2-1 else customTemp2 = 0
	if customTemp3&#$0F > 0 then customTemp3=customTemp3-1 else customTemp3 = 0
	if customTemp4&#$0F > 0 then customTemp4=customTemp4-1 else customTemp4 = 0
	if customTemp5&#$0F > 0 then customTemp5=customTemp5-1 else customTemp5 = 0
	
	P7C2 = customTemp2
	P6C2 = customTemp3
	P0C2 = customTemp4
	P1C2 = customTemp5
	

do other things, draw the screen, loop

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

 

I was wondering if you could read half the byte for the brightness, that's very nice!

How do you fade in? That's the trickiest part, I guess there's no easy way, I set the.. registers? to black and variables to the darkest brightness of the color, then use the loop counter to determine when it's time to increase the brightness, and when to update the register from black to the variable.

 _P0C1 = $80 : _P0C2 = $80 : _P0C3 = $80 

 _P1C1 = $a0 : _P1C2 = $a0 : _P1C3 = $a0



 P0C1 = $00 

 P0C2 = $00

 P0C3 = $00 



 P1C1 = $00

 P1C2 = $00

 P1C3 = $00
fadeIn

 for temp6 = 0 to 13 



  if temp6 >= (13 - 6) then P0C1 = _P0C1

  if temp6 >= (13 - 9) then P0C2 = _P0C2

  if temp6 >= (13 - 13) then P0C3 = _P0C3



  if temp6 >= (13 - 6) then P1C1 = _P1C1

  if temp6 >= (13 - 9) then P1C2 = _P1C2

  if temp6 >= (13 - 13) then P1C3 = _P1C3





 ;delay

 for temp5 = 0 to 1 

 restorescreen

 drawscreen

 next



 if temp6 > (13 - 6) then _P0C1 = _P0C1 + 1  

 if temp6 > (13 - 9) then _P0C2 = _P0C2 + 1

 if temp6 > (13 - 13) then _P0C3 = _P0C3 + 1



 if temp6 > (13 - 6) then _P1C1 = _P1C1 + 1  

 if temp6 > (13 - 9) then _P1C2 = _P1C2 + 1

 if temp6 > (13 - 13) then _P1C3 = _P1C3 + 1

 next





 return thisbank

The brightness is suppose to end on 6, 9 and d, I think it's right?

 

Edited by Lillapojkenpåön
  • Like 1
Link to comment
Share on other sites

For fade-ins I do pretty much the same as the fade-outs.

To set it up I'll set the actual palettes to black for as long as I need, but then I'll set the temp copies to be #$x0 where x is the colour I want then increment my counters.

Rather than checking if the brightness is greater than 0 I check if it's less that my target brightness for that colour.

      customTemp1=$50 : customTemp2 = $A0 : customTemp3 = $90 : customTemp4 = $00
FadeInLoop	
      if customTemp1&#$0F < #$0A then customTemp1=customTemp1+1
      if customTemp2&#$0F < #$0B then customTemp2=customTemp2+1
      if customTemp3&#$0F < #$06 then customTemp3=customTemp3+1
      if customTemp4&#$0F < #$0F then customTemp4=customTemp4+1

      P6C2 = customTemp1
      P7C2 = customTemp2
      P0C2 = customTemp3
      P1C2 = customTemp4

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

5 minutes ago, SmittyB said:

For fade-ins I do pretty much the same as the fade-outs.

To set it up I'll set the actual palettes to black for as long as I need, but then I'll set the temp copies to be #$x0 where x is the colour I want then increment my counters.

Rather than checking if the brightness is greater than 0 I check if it's less that my target brightness for that colour.


      customTemp1=$50 : customTemp2 = $A0 : customTemp3 = $90 : customTemp4 = $00
FadeInLoop	
      if customTemp1&#$0F < #$0A then customTemp1=customTemp1+1
      if customTemp2&#$0F < #$0B then customTemp2=customTemp2+1
      if customTemp3&#$0F < #$06 then customTemp3=customTemp3+1
      if customTemp4&#$0F < #$0F then customTemp4=customTemp4+1

      P6C2 = customTemp1
      P7C2 = customTemp2
      P0C2 = customTemp3
      P1C2 = customTemp4

 

 

I think that would increase the brightness for all colors every frame until they reach the target? I need to fade in a different way, imagine the fade out in reverse.

  • Like 1
Link to comment
Share on other sites

6 minutes ago, SmittyB said:

I suppose in that case I'd do it by decrementing a set of delay counters and in those if statements have '&& delayCounter1=0'.

 

Might not be the most efficient but it would easy to set up and change if needed.

I think I will try that, atleast I can look at it and know what's going on, THANKS!

Link to comment
Share on other sites

If you have too many objects being plotted into a zone, then it can overrun the memory for that zone and corrupt the next one. It sounds to me like that's what you're describing.

 

You can see how many display objects you have per zone in the 7800basic compile messages. It will look something like "$1880 to $1fff used as zone memory, allowing 13 display objects per zone."

 

As to whether double-buffer will help or not. If you're getting flickering of some sprites, due to them not being plotted within a single frame, then yes. If the cause of your issue is running out of zone memory, then no. For the latter you'll need to look at giving more memory to the display, with either "set extradlmemory on" or "set dlmemory [start] [end]".

  • Thanks 1
Link to comment
Share on other sites

I get a little flickering of some sprites

$7000 to $7fff used as zone memory, allowing 28 display objects per zone.

 

with doublebuffer on and

$5000 to $7fff used as zone memory, allowing 43 display objects per zone.

I get allmost, if not exactly the same flickering

 

Also, when I replaced all drawscreens, like the one in my fade in loop with doublebuffer flip, the colors after my fade in wasn't right, do I need to do something to compensate, like twice as many loops? Or maybe doublebuffer just uses one of the temp variables I'm using

 

 

Link to comment
Share on other sites

Yeah, you can't rely on the temp# variables being unused by the routines. Certain double buffer operations do indeed use the temp variables. The 7800 has enough memory that it's really not worth playing the bB game of trying to anticipate when temp variables are used or not by certain commands, and later discovering that you've unknowingly shot yourself in the foot. Just dim a few of your own temps, and run with those.

 

It would be easier if you were able to post a specific example, because your program really shouldn't be flickering if you have doublebuffering on and have enough zone memory. I can imagine a bunch of things you might do wrong that could corrupt the display and/or flicker sprites (using temps in an interrupt, using plotchar beyond the buffer memory, ...) but it will be quicker to just look at what's going on rather than guessing.

Link to comment
Share on other sites

I changed the temp variables, that wasn't it, only one color is wrong and it's only after the first fade in, it just stops turning brighter, but for the next levels it works as it should, but nevermind that, It will probably solve itself when the bigger problems gets solved.

 

Here it is

I would also appreciate any tips for improvements or optimization of the code

 

 

 

Edited by Lillapojkenpåön
Link to comment
Share on other sites

The issue of the sprites disappearing for a frame is related to your frame index, which alternates between 0 and 2, and you have 2 enemy (tallsprite) frames. With the changes in the last version of 7800basic, you should access these 2 frames with a frame parameter of 0 and 1.

 

I switched back to the old behavior with the setting "set deprecated frameheight" at the top of the source, and the blinking is gone.

  • Like 1
Link to comment
Share on other sites

7 hours ago, RevEng said:

The issue of the sprites disappearing for a frame is related to your frame index, which alternates between 0 and 2, and you have 2 enemy (tallsprite) frames. With the changes in the last version of 7800basic, you should access these 2 frames with a frame parameter of 0 and 1.

 

I switched back to the old behavior with the setting "set deprecated frameheight" at the top of the source, and the blinking is gone.

I downloaded latest ADS and changed the frame index, it didnt't affect the level three flickering at all for me?

Link to comment
Share on other sites

9 hours ago, Lillapojkenpåön said:

I downloaded latest ADS and changed the frame index, it didnt't affect the level three flickering at all for me?

Oh, I thought you were talking about the flickering due to indexes hitting empty sprites.

 

I see what you mean now. Basically Maria is running out of DMA time to render all of your objects. Here's your third level...

 

0000.png.45032b6effa09c4165c64edcd55ca043.png

 

In any given zone here, the palette requirement is changing every couple of graphics bytes. This means in that middle row you have 14 character objects. (a new palette means a new character object)

 

You can do one of two things about this. You can redesign the levels to not alternate palettes, which I think would be a shame for this game. Or you can write a level loading routine to draw those 14 objects as sprites instead of characters, since sprites use less DMA compared to similarly wide character objects. This is the approach @mksmith took for Arkanoid and Millie&Molly.

 

To keep the bouncing dots, you'd either need to take a hybrid approach - i.e. still use characters for the background with a single palette, and draw walls with sprites (which could lead to dma problems when you turn up the number of enemies, or make levels even more complex) - or you'd need to bounce the dot sprites using under the hood functionality.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

So the best would be if everything was sprites? Mhm.. here I thought I was being smart avoiding using sprites as much as possible.

 

I wonder if instead of this..

 

 

   y = (playerY - screenYoffset) / tileHeight

   x = playerX / tileWidth

   charValue = peekchar( tilemap, x, y, 20, 27 ) ; top left

   if charValue > bgTile then...

 

..this would work for collisions with the maze?

 

   y = (playerY - screenYoffset) & 240

   x = playerX / tileWidth

   temp5 = x + y

   if collisionMap[temp5] then...

  

 

 ;paint maze with ones here

 data collisionMap
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

end

 

I will have to make my screenheight and playfield a little smaller so it's just 20x12 metatiles if this works

Edited by Lillapojkenpåön
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...