Jump to content
IGNORED

Demo: Flickering & animating four sprites


jrok

Recommended Posts

I thought I'd post an example of the way I am flickering and animating my four sprites in "Armageddon Complex." I suppose these strategies could have been broken into two separate demos, but I think that together they might be useful in visualizing Atari gameloops in general.

 

First we select some kernel options. In this example, sharp-looking sprites are more important than missiles.

 

 set kernel_options playercolors player1colors pfcolors
set smartbranching on

 

We define some coordinate variables for our four noble sprites, as well as two additional variables to measure the framerate and the currentframe.

 

 dim sprite1X = a
dim sprite1Y = b

dim sprite2X = d
dim sprite2Y = e

dim sprite3X = g
dim sprite3Y = h

dim sprite4X = j
dim sprite4Y = k

dim gameFrame = m
dim fspeed = n

 

Next, initialize the game and give our sprites some starting positions.

 

 playfield:
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
end

COLUBK = $E0

sprite1X=30
sprite1Y=48

sprite2X=60
sprite2Y=48

sprite3X=90
sprite3Y=48

sprite4X=120
sprite4Y=48

 

 

Our gameloop is responsible for doing three main things.

  • Count its own iteration (fspeed)
  • Keep track of which frame all the sprites are in (gameFrame)
  • Determine whether the current loop is an even or odd number

 

Inside the loop, fspeed tells the sprites to advance one frame every six gameloops. It also keeps track of which sprites player0 and player1 should draw. In this example, player0 draws sprites 1 & 4, and player1 draws sprites 2 & 3, and the subroutines that update them are balanced on either side of the drawscreen.

 

gameloop
fspeed = fspeed + 1
if fspeed=6 then gameFrame=gameFrame + 1 : fspeed=0
if gameFrame = 8 then gameFrame = 0

temp1 = fspeed & 1

if temp1 then updateSprite4

updateSprite2
temp1 = fspeed & 3
gosub Sprite2
goto DrawFrame

updateSprite4 
gosub Sprite4

DrawFrame
drawscreen

updateSprite3
gosub Sprite3

updateSprite1
gosub Sprite1

 goto gameloop

 

The subroutines themselves don't do much in this sample, except to repostion the player sprites to the appropriate xy value, and instuct it to go to its animation routine.

 

 
Sprite1
player0x=sprite1X : player0y=sprite1Y : goto Sprite1Frames
return

Sprite2
player1x=sprite2X : player1y=sprite2Y : goto Sprite2Frames
return

Sprite3
player1x=sprite3X : player1y=sprite3Y : goto Sprite3Frames
return

Sprite4
player0x=sprite4X : player0y=sprite4Y : goto Sprite4Frames
return

 

Finally, we animate the sprites by looking at the current value of gameFrame. Since gameFrame caps at 8, our sprites have a ceiling of 8 possible shapes in their animation. Of course, they don't have to have 8 different frames. And probably shouldn't, if you want to create the illusion that they are moving at different rates.

 

 
Sprite1Frames
on gameFrame goto Shape1_1 Shape1_2 Shape1_3 Shape1_4 Shape1_4 Shape1_4 Shape1_3 Shape1_2

Sprite2Frames 
on gameFrame goto Shape2_1 Shape2_2 Shape2_3 Shape2_4 Shape2_1 Shape2_4 Shape2_3 Shape2_2
  
Sprite3Frames 
on gameFrame goto Shape3_1 Shape3_2 Shape3_3 Shape3_1 Shape3_2 Shape3_3 Shape3_1 Shape3_1

Sprite4Frames
on gameFrame goto Shape4_1 Shape4_2 Shape4_3 Shape4_4 Shape4_5 Shape4_6 Shape4_7 Shape4_8

rem After this, you can draw all your purty graphics...

 

That's it! The attached source has some additional comments in it. I'm pretty new to batari programming, so I'm sure there are many other and better ways to do these sort of things. But I thought that maybe this general method might be useful for a few folks out there.

 

Cheers,

Jarod

4_multicolor_sprite_flicker.bas

4_multicolor_sprite_flicker.bas.bin

Edited by jrok
Link to comment
Share on other sites

Thanks for the demo. Now we can get more multicolored sprites up on the screen instead of being stuck with just one. The flickering seems to be even less noticeable with 3 sprites, and with 3, one of the sprites doesn't look like it flickers at all, which is amazing.

Link to comment
Share on other sites

Thanks for the demo. Now we can get more multicolored sprites up on the screen instead of being stuck with just one. The flickering seems to be even less noticeable with 3 sprites, and with 3, one of the sprites doesn't look like it flickers at all, which is amazing.

 

No problem. The cool thing is, with the phospor turned on full steam, there's no visible flicker at all. And even in the 70's range, the flicker is barely detectable. I'm already curious how this effect looks on an old-school TV tube... unfortunately I don't have an EPROM burner (or an old school TV).

 

The thing is, if you limit this loop to update only three sprites (like I'm doing in AC with a condition that tests whether or not all four sprites are present in a room) one of them actually won't be flickering at all. You just have to alter the loop to skip updating one of the sprites:

 

gameloop  
fspeed = fspeed + 1
if fspeed=6 then gameFrame=gameFrame + 1 : fspeed=0
if gameFrame = 8 then gameFrame = 0

temp1 = fspeed & 1

if temp1 && myVariable=someValue then updateSprite4
if temp1 && myVariable<someValue then DrawFrame

updateSprite2
temp1 = fspeed & 3
gosub Sprite2
goto DrawFrame

updateSprite4 
gosub Sprite4

DrawFrame
drawscreen

updateSprite3
gosub Sprite3

updateSprite1
gosub Sprite1

 goto gameloop

Edited by jrok
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...