Jump to content
IGNORED

Code Snippets & Samples for bB Beginners


Atarius Maximus

Recommended Posts

  • 1 month later...

I know this is probably going to be complicated, but I am making a Galxian/Space Invaders game called Earth Invaders, and I have my ship, I have the play field, I have the missile . . . well I don't have the missile working yet but hope to soon.

 

Here is what I have yet to figure out, how exactly do I make the enemys??? Also if someone could send me a link that explains frames that would be helpful!!!!

 

Thanks

Disjaukifa

Edited by disjaukifa
Link to comment
Share on other sites

  • 2 weeks later...
  • 5 months later...

This might sound a fair bit "Noobish" but how can you combine these codes? Any time I try add missiles to movement it doesn't work..

 

I know your post was 5 months ago, but I can work on combining a few of the samples, yes. I just posted another sample that demonstrates how to use bankswitching.

 

Steve

Link to comment
Share on other sites

This might sound a fair bit "Noobish" but how can you combine these codes? Any time I try add missiles to movement it doesn't work..

 

I know your post was 5 months ago, but I can work on combining a few of the samples, yes. I just posted another sample that demonstrates how to use bankswitching.

 

Steve

 

 

As requested, I added another demo file (#14 in the first post) that shows how to combine a moving animated player sprite with the ability to fire in any direction, including diagonally.

 

Steve

Link to comment
Share on other sites

I added another sample to the first post (#15). This one demostrates collision detection for a player sprite inside of a room from all directions. It's really simple and efficient. The code was actually pulled from the old "move around rooms" demo from SeaGtGruff - it's great code and I've used it in several of my games.

 

Steve

Link to comment
Share on other sites

Anyone happen to have an example of a sound system subroutine that can be called from a main loop? The only way I can think of doing this would be to have the sound registers, a duration, the voice it belongs to (0 or 1)and then having it do something like

 

subroutine

if a = 1 then read data : load sound registers for voice

if a=duration variable then turn off audv0 or audv1 : a = 0 : return

a = a + 1

return

 

This seems like it would work, but I figured I would ask before trying it and wasting time (and bytes). Any other ideas?

 

Cliff

Link to comment
Share on other sites

Anyone happen to have an example of a sound system subroutine that can be called from a main loop? The only way I can think of doing this would be to have the sound registers, a duration, the voice it belongs to (0 or 1)and then having it do something like

 

subroutine

if a = 1 then read data : load sound registers for voice

if a=duration variable then turn off audv0 or audv1 : a = 0 : return

a = a + 1

return

 

This seems like it would work, but I figured I would ask before trying it and wasting time (and bytes). Any other ideas?

 

Cliff

You mean like the kind of thing that the Music and Sound Editor can create? Right now it creates code using sdata, based on the Music Starter using sdata, but after the next update it will also create code that uses regular data if you want that will look like this:

 

   rem  *****************************************************
  rem  *
  rem  *  Music Starter using data
  rem  *
  rem  *  Based on code posted in the Ballblazer thread at AtariAge:
  rem  *  http://www.atariage.com/forums/index.php?s=&showtopic=130990&view=findpost&p=1615280
  rem  *
  rem  *  Code adapted by Duane Alan Hahn (Random Terrain)
  rem  *
  rem  *  Explanation:
  rem  *  This has a 256-byte limitation.
  rem  *
  rem  *****************************************************


  set smartbranching on


  rem  *****************************************************
  rem  *  Create aliases for variables
  rem  *****************************************************
  dim duration=a
  dim rand16=z


  rem  *****************************************************
  rem  *  Variable descriptions
  rem  *****************************************************
  rem  *  duration - how long each note plays
  rem  *  x - data counter
  rem  *  rand16 - makes better random numbers


  rem  *  Volume off
  AUDV0=0
  AUDV1=0


  rem  *  Initialize duration and data counter
  duration = 1 : x = 0




  rem  *****************************************************
  rem  *
  rem  *  Main game loop starts here.
  rem  *
  rem  *****************************************************
MainLoop

  goto GetMusic
GotMusic

  drawscreen

  goto MainLoop




  rem  *****************************************************
  rem  *  Music
  rem  *****************************************************
GetMusic

  rem  *  Check for end of current note
  duration = duration - 1
  if duration>0 then GotMusic


  rem  *  Retrieve channel 0 data
  temp4 = musicData[x] : x = x + 1
  temp5 = musicData[x] : x = x + 1
  temp6 = musicData[x] : x = x + 1


  rem  *  Check for end of data
  if temp4=255 then duration = 1 : x = 0 : goto GotMusic


  rem  *  Play channel 0
  AUDV0 = temp4
  AUDC0 = temp5
  AUDF0 = temp6


  rem  *  Retrieve channel 1 data
  temp4 = musicData[x] : x = x + 1
  temp5 = musicData[x] : x = x + 1
  temp6 = musicData[x] : x = x + 1


  rem  *  Play channel 1
  AUDV1 = temp4
  AUDC1 = temp5
  AUDF1 = temp6


  rem  *  Set duration
  duration = musicData[x] : x = x + 1
  goto GotMusic




  rem  *****************************************************
  rem  *  Music Data Block
  rem  *****************************************************
  rem  *  Format:
  rem  *  v,c,f (channel 0)
  rem  *  v,c,f (channel 1) 
  rem  *  d
  rem  *
  rem  *  Explanation:
  rem  *  v - volume (0 to 15)
  rem  *  c - control [a.k.a. tone, voice, and distortion] (0 to 15)
  rem  *  f - frequency (0 to 31)
  rem  *  d - duration


  data musicData
  8,12,29
  0,0,0
  15
  2,12,29
  0,0,0
  8
  8,12,19
  0,0,0
  15
  2,12,19
  0,0,0
  8
  8,12,17
  0,0,0
  15
  2,12,17
  0,0,0
  8

  255
end
  goto GotMusic

Link to comment
Share on other sites

Anyone happen to have an example of a sound system subroutine that can be called from a main loop? The only way I can think of doing this would be to have the sound registers, a duration, the voice it belongs to (0 or 1)and then having it do something like

 

subroutine

if a = 1 then read data : load sound registers for voice

if a=duration variable then turn off audv0 or audv1 : a = 0 : return

a = a + 1

return

 

This seems like it would work, but I figured I would ask before trying it and wasting time (and bytes). Any other ideas?

 

Cliff

You mean like the kind of thing that the Music and Sound Editor can create? Right now it creates code using sdata, based on the Music Starter using sdata, but after the next update it will also create code that uses regular data if you want that will look like this:

 

   rem  *****************************************************
  rem  *
  rem  *  Music Starter using data
  rem  *
  rem  *  Based on code posted in the Ballblazer thread at AtariAge:
  rem  *  http://www.atariage.com/forums/index.php?s=&showtopic=130990&view=findpost&p=1615280
  rem  *
  rem  *  Code adapted by Duane Alan Hahn (Random Terrain)
  rem  *
  rem  *  Explanation:
  rem  *  This has a 256-byte limitation.
  rem  *
  rem  *****************************************************


  set smartbranching on


  rem  *****************************************************
  rem  *  Create aliases for variables
  rem  *****************************************************
  dim duration=a
  dim rand16=z


  rem  *****************************************************
  rem  *  Variable descriptions
  rem  *****************************************************
  rem  *  duration - how long each note plays
  rem  *  x - data counter
  rem  *  rand16 - makes better random numbers


  rem  *  Volume off
  AUDV0=0
  AUDV1=0


  rem  *  Initialize duration and data counter
  duration = 1 : x = 0




  rem  *****************************************************
  rem  *
  rem  *  Main game loop starts here.
  rem  *
  rem  *****************************************************
MainLoop

  goto GetMusic
GotMusic

  drawscreen

  goto MainLoop




  rem  *****************************************************
  rem  *  Music
  rem  *****************************************************
GetMusic

  rem  *  Check for end of current note
  duration = duration - 1
  if duration>0 then GotMusic


  rem  *  Retrieve channel 0 data
  temp4 = musicData[x] : x = x + 1
  temp5 = musicData[x] : x = x + 1
  temp6 = musicData[x] : x = x + 1


  rem  *  Check for end of data
  if temp4=255 then duration = 1 : x = 0 : goto GotMusic


  rem  *  Play channel 0
  AUDV0 = temp4
  AUDC0 = temp5
  AUDF0 = temp6


  rem  *  Retrieve channel 1 data
  temp4 = musicData[x] : x = x + 1
  temp5 = musicData[x] : x = x + 1
  temp6 = musicData[x] : x = x + 1


  rem  *  Play channel 1
  AUDV1 = temp4
  AUDC1 = temp5
  AUDF1 = temp6


  rem  *  Set duration
  duration = musicData[x] : x = x + 1
  goto GotMusic




  rem  *****************************************************
  rem  *  Music Data Block
  rem  *****************************************************
  rem  *  Format:
  rem  *  v,c,f (channel 0)
  rem  *  v,c,f (channel 1) 
  rem  *  d
  rem  *
  rem  *  Explanation:
  rem  *  v - volume (0 to 15)
  rem  *  c - control [a.k.a. tone, voice, and distortion] (0 to 15)
  rem  *  f - frequency (0 to 31)
  rem  *  d - duration


  data musicData
  8,12,29
  0,0,0
  15
  2,12,29
  0,0,0
  8
  8,12,19
  0,0,0
  15
  2,12,19
  0,0,0
  8
  8,12,17
  0,0,0
  15
  2,12,17
  0,0,0
  8

  255
end
  goto GotMusic

 

Thanks. This will definitely do what I want. I was hoping to maybe reduce the data size per note to 5 being v,c,f,voice,d, but I can see potential issues with syncing the voices if I do that. Better to do it the way you have.

 

Have you thought about posting this to the front of the thread? This is definitely something people could use. Thanks again.

 

Cliff

Link to comment
Share on other sites

  • 2 months later...

This might sound a fair bit "Noobish" but how can you combine these codes? Any time I try add missiles to movement it doesn't work..

 

I know your post was 5 months ago, but I can work on combining a few of the samples, yes. I just posted another sample that demonstrates how to use bankswitching.

 

Steve

 

 

As requested, I added another demo file (#14 in the first post) that shows how to combine a moving animated player sprite with the ability to fire in any direction, including diagonally.

 

Steve

Hi Steve I was playing around with this code and made an alternate version

 

 rem *******alternative move and fire in 8 directions + animation, variable cost = 7
 rem modification saves 18 bytes adds 1 variable & fixes player reflection
 rem ------------------------------------------------------------------------------------
  rem Demo for moving an animated sprite that can fire a missile in any direction
  rem   
  rem   You can move around your sprite and fire in any direction.
  rem
  rem  In trying to keep this code as short as possible, I left out the following:
  rem   There is no collision detection
  rem   There are no enemies to shoot at
  rem   player movement is not restricted, you can move off of the screen
  rem   There is no defined playfield
  rem ----------------------------------------------------------------------------
  rem ----------------------------------------------------------------------------
  rem  Variables
  rem
  rem     I set the inital direction of the joystick to RIGHT, so when you start
  rem     the game for the first time you're able to fire the gun before you move
  rem
  rem ----------------------------------------------------------------------------

  a=76   : rem player1x location
  b=50   : rem player1y location
  c{1}=0 : rem Turned on if the last location of the joystick was UP
  c{2}=0 : rem Turned on if the last location of the joystick was DOWN
  c{3}=0 : rem Turned on if the last location of the joystick was LEFT
  c{4}=1 : rem Turned on if the last location of the joystick was RIGHT
  c{5}=0 :rem Turned on if the last location of the joystick was UP+LEFT
  c{6}=0 :rem Turned on if the last location of the joystick was UP+RIGHT
  c{7}=0 :rem Turned on if the last location of the joystick was DOWN+LEFT
  c{0}=0 :rem Turned on if the last location of the joystick was DOWN+RIGHT
  e=20   : rem Counter for limiting travel of fired missile
  w=1    : rem Used to determine player reflection (REFP1)
  rem y is the animation counter
  rem t replaces the still function from original code
  rem  ---------------------------------------------------------------------------------
start
rem reset animation control flag
t = 0
rem if reflection is switched 'on' by the w variable this keeps it in place
if w=0 then REFP1 = 8
if w=1 then REFP1 = 0


  rem ---------------------------------------------------------------------------------
  rem This section sets a value for the last direction the joystick was pushed
  rem
  rem  This determines the direction the bullet will be fired later, and also
  rem  allows you to keep firing the bullet in the same direction after you
  rem  have stopped moving.
  rem
  rem  Each time you move, each of the eight possible directions of the joystick is
  rem  marked as on or off with a bit variable.
  rem ---------------------------------------------------------------------------------
  drawscreen
  if joy0up then                c{1}=1:c{2}=0:c{3}=0:c{4}=0:c{5}=0:c{6}=0:c{7}=0:c{0}=0
  if joy0down then              c{1}=0:c{2}=1:c{3}=0:c{4}=0:c{5}=0:c{6}=0:c{7}=0:c{0}=0
  if joy0left then              c{1}=0:c{2}=0:c{3}=1:c{4}=0:c{5}=0:c{6}=0:c{7}=0:c{0}=0
  if joy0right then             c{1}=0:c{2}=0:c{3}=0:c{4}=1:c{5}=0:c{6}=0:c{7}=0:c{0}=0
  if joy0up && joy0left then    c{1}=0:c{2}=0:c{3}=0:c{4}=0:c{5}=1:c{6}=0:c{7}=0:c{0}=0
  if joy0up && joy0right then   c{1}=0:c{2}=0:c{3}=0:c{4}=0:c{5}=0:c{6}=1:c{7}=0:c{0}=0
  if joy0down && joy0left then  c{1}=0:c{2}=0:c{3}=0:c{4}=0:c{5}=0:c{6}=0:c{7}=1:c{0}=0
  if joy0down && joy0right then c{1}=0:c{2}=0:c{3}=0:c{4}=0:c{5}=0:c{6}=0:c{7}=0:c{0}=1
  rem ------------------------------------------------------------------
  rem  Set color of player sprites and missiles
  rem ------------------------------------------------------------------
  COLUP1=28
  COLUP0=28
  rem ------------------------------------------------------------------
  rem  Set initial location of player sprite
  rem ------------------------------------------------------------------
  player1x=a:player1y=b
  rem ------------------------------------------------------------------
  rem  Increase 20 to a larger number to make the bullets travel farther
  rem ------------------------------------------------------------------
  e=e+1
  if e>20 then e=0
  rem ------------------------------------------------------------------
  rem  Player Movement
  rem ------------------------------------------------------------------
  rem t control variable added to advance animation counter, w ties to reflection
  if joy0up then b=b-1 : t = 1
  if joy0down then b=b+1 : t = 1
  if joy0left then a=a-1 : t = 1 : w = 0
  if joy0right then a=a+1 : t = 1 : w = 1
  if !joy0fire then missile0x=0:missile0y=0:e=0

  rem diagonal shots
  if joy0fire && c{0} then missile0x=player1x+7+e:missile0y=player1y-3+e
  if joy0fire && c{5} then missile0x=player1x-e:missile0y=player1y-7-e
  if joy0fire && c{7} then missile0x=player1x-e:missile0y=player1y+1+e
  if joy0fire && c{6} then missile0x=player1x+7+e:missile0y=player1y-7-e

  rem left and right shots
  if joy0fire && c{3} then missile0x=player1x-e:missile0y=player1y-5
  if joy0fire && c{4} then missile0x=player1x+8+e:missile0y=player1y-5

  rem up and down shots
  if joy0fire && c{1} then missile0x=player1x+5:missile0y=player1y-10-e
  if joy0fire && c{2} then missile0x=player1x+5:missile0y=player1y+3+e

  rem if not moving go to player1 standing position
  if !joy0up && !joy0down && !joy0left && !joy0right then y=10
  rem t is the keytrap tied to joy0 directional movement if active advances animation
  if t = 1 then y=y+1
  rem ------------------------------------------------------------------
  rem Player Animation
  rem   Y is the counter for the player animation.  You can change the
  rem   animation rate by changing the 30,20,10 to a different 
  rem   sequence of numbers.
  rem ------------------------------------------------------------------
  if y=30 then player1:
       000110
       100100
       110100
       011000
       000000
       %10011110
       %01100100
       010000
       011000
       111100
       011000
end
 if y=20 then player1:
       %01000000
       %01100011
       110110
       011100
       101000
       111100
       100100
       010000
       011000
       111100
       011000
end
 if y=10 then player1:
       011100
       011000
       011000
       100000
       %01011010
       %01111100
       100100
       010000
       011000
       111100
       011000
end
rem if animation counter reaches 30 reset it
  if y>30 then y=0
rem repeat loop
goto start

Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...
  • 9 months later...
  • 5 months later...
  • 3 weeks later...

Could you do a snippet about making enemies following the player in a well documented way?

 

Yes, I could make a sample program that demonstrates that, it's pretty easy to do, but it may be a little while before I could put it together and post a well documented example. I never seem to have time for Atari related projects any more. :( I did post a sample of an enemy following a player with a very rudimentary AI here: http://www.atariage.com/forums/topic/178934-enemy-ai/ , although the source isn't as well documented as the other examples in this thread. I'll keep it in mind and try to do a more basic, well documented example soon.

 

Steve

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

I'd like a sample that demonstrates the use of the Game Select switch for game variations. Seems there's everything here but that.

 

My last game M.M.S.B.C. II has a difficulty select feature:

http://atariage.com/...6-mmsbc-2-done/

 

You can see the relevent code starting in the select_level label

 

This isn't an example. Should at least give you in idea of what working code looks like :)

Link to comment
Share on other sites

My last game M.M.S.B.C. II has a difficulty select feature:

http://atariage.com/...6-mmsbc-2-done/

 

You can see the relevent code starting in the select_level label

 

This isn't an example. Should at least give you in idea of what working code looks like :)

Thanks for pointing out your MMSBC code, loon, that is a very good example. I'll work on a simple standalone example for this thread as soon as time allows.

 

Steve

  • Like 1
Link to comment
Share on other sites

  • 5 months later...
  • 8 months later...

I should have added these links to this thread a long time ago and I put them in the first post too (along with a few others). Here's some excellent tutorials from other AA Members.

 

From CurtisP: Programming Tutorial

From SeaGtGruff: Tutorial Session 1 | Tutorial Session 2 | Tutorial Session 3

Link to comment
Share on other sites

  • 2 years later...

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...