Jump to content

Photo

Code Snippets & Samples for bB Beginners


50 replies to this topic

#26 Mordekai OFFLINE  

Mordekai

    Combat Commando

  • 9 posts
  • Location:So. Cal

Posted Sat Jul 18, 2009 7:50 PM

These samples are fantastic! Thanks for making these available.

M.

#27 CurtisP OFFLINE  

CurtisP

    Chopper Commander

  • 211 posts

Posted Thu Jul 23, 2009 4:46 PM

Can anyone show me how to make a scrolling playfield?

Horizontal or Vertical Scroll?

#28 Animan OFFLINE  

Animan

    River Patroller

  • 2,391 posts
  • Just some guy who plays Atari and watches Anime.
  • Location:Texas

Posted Sat Jul 25, 2009 9:48 AM

Can anyone show me how to make a scrolling playfield?

Horizontal or Vertical Scroll?

Nevermind, i know how it's done.

#29 disjaukifa OFFLINE  

disjaukifa

    River Patroller

  • 2,125 posts
  • Berzerker In Training
  • Location:Research Triangle North Carolina

Posted Fri Sep 18, 2009 9:56 PM

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, Fri Sep 18, 2009 9:56 PM.


#30 endrien OFFLINE  

endrien

    Chopper Commander

  • 184 posts

Posted Sat Oct 3, 2009 5:34 AM

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

#31 Atarius Maximus OFFLINE  

Atarius Maximus

    Stargunner

  • Topic Starter
  • 1,794 posts
  • Load "Atari2600",8,1: SYS32777
  • Location:St. Louis, Missouri USA

Posted Wed Mar 10, 2010 8:22 AM

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

#32 Atarius Maximus OFFLINE  

Atarius Maximus

    Stargunner

  • Topic Starter
  • 1,794 posts
  • Load "Atari2600",8,1: SYS32777
  • Location:St. Louis, Missouri USA

Posted Wed Mar 10, 2010 2:23 PM

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

#33 Atarius Maximus OFFLINE  

Atarius Maximus

    Stargunner

  • Topic Starter
  • 1,794 posts
  • Load "Atari2600",8,1: SYS32777
  • Location:St. Louis, Missouri USA

Posted Fri Mar 12, 2010 6:01 PM

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

#34 Cliff Friedel OFFLINE  

Cliff Friedel

    Dragonstomper

  • 601 posts

Posted Wed Mar 17, 2010 10:43 PM

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

#35 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 27,801 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Thu Mar 18, 2010 4:52 PM

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


#36 Cliff Friedel OFFLINE  

Cliff Friedel

    Dragonstomper

  • 601 posts

Posted Thu Mar 18, 2010 10:34 PM

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

#37 rpgfaker OFFLINE  

rpgfaker

    Moonsweeper

  • 489 posts
  • Location:The Plague in Siena

Posted Wed May 26, 2010 11:03 AM

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


#38 esplonky OFFLINE  

esplonky

    Moonsweeper

  • 440 posts
  • Kinetic, Not synthetic.
  • Location:Canyon Lake, TX

Posted Mon Jun 13, 2011 11:31 AM

can someone show me Completely how to do sound with more than just a source code file? (like show me where to put things and how they work and stuff) i looked at the sound source code from RT but it was confusing.

#39 Jr. Pac OFFLINE  

Jr. Pac

    Dragonstomper

  • 775 posts
  • 1/4 of the fun with an Atari cart is cleaning it.
  • Location:In my room with my 2600.

Posted Tue Jul 26, 2011 9:43 AM

Thanks!!!

#40 esplonky OFFLINE  

esplonky

    Moonsweeper

  • 440 posts
  • Kinetic, Not synthetic.
  • Location:Canyon Lake, TX

Posted Mon Apr 30, 2012 11:11 AM

You should do a thread that has code snippets for intermediate programmers, like ones that use includes and Bit operations etc

#41 Rabbit 2600 OFFLINE  

Rabbit 2600

    Dragonstomper

  • 745 posts
  • Location:Sweden

Posted Sat Oct 13, 2012 11:37 AM

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

#42 Atarius Maximus OFFLINE  

Atarius Maximus

    Stargunner

  • Topic Starter
  • 1,794 posts
  • Load "Atari2600",8,1: SYS32777
  • Location:St. Louis, Missouri USA

Posted Mon Oct 29, 2012 10:01 PM

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

#43 Atarius Maximus OFFLINE  

Atarius Maximus

    Stargunner

  • Topic Starter
  • 1,794 posts
  • Load "Atari2600",8,1: SYS32777
  • Location:St. Louis, Missouri USA

Posted Wed Oct 31, 2012 7:48 AM

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


I posted a very simple example of how to make an enemy sprite follow a player sprite in the first post.

#44 Atarius Maximus OFFLINE  

Atarius Maximus

    Stargunner

  • Topic Starter
  • 1,794 posts
  • Load "Atari2600",8,1: SYS32777
  • Location:St. Louis, Missouri USA

Posted Wed Oct 31, 2012 7:49 AM

You should do a thread that has code snippets for intermediate programmers, like ones that use includes and Bit operations etc


That's a good idea, I may start doing something like that when I get some time.

#45 Udonge OFFLINE  

Udonge

    Space Invader

  • 31 posts
  • Moon Rabit of Insanity

Posted Sat Mar 30, 2013 9:15 PM

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

#46 Gemintronic OFFLINE  

Gemintronic

    Jason S. - Lead Developer & CEO

  • 8,768 posts

Posted Sat Mar 30, 2013 9:19 PM

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 :)

#47 Atarius Maximus OFFLINE  

Atarius Maximus

    Stargunner

  • Topic Starter
  • 1,794 posts
  • Load "Atari2600",8,1: SYS32777
  • Location:St. Louis, Missouri USA

Posted Sat Mar 30, 2013 9:31 PM

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

#48 DemonoidTentacle OFFLINE  

DemonoidTentacle

    Moonsweeper

  • 453 posts
  • Location:Melbourne, Australia

Posted Wed Sep 18, 2013 3:56 AM

I just had to let you know, you are amazing for sharing all those files with us. I'm working my way through them, and your structure of showing us beginners is excellent!



#49 Atarius Maximus OFFLINE  

Atarius Maximus

    Stargunner

  • Topic Starter
  • 1,794 posts
  • Load "Atari2600",8,1: SYS32777
  • Location:St. Louis, Missouri USA

Posted Sat Jun 14, 2014 8:26 AM

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



#50 freshbrood OFFLINE  

freshbrood

    Space Invader

  • 36 posts

Posted Wed Mar 8, 2017 1:41 AM

Would someone please offer me some .bas examples of playfield resolutions? I can't figure out how to change the size of the playfield blocks, and I know it should be quite simple. Also some DPC+ .bas examples/tutorials would be much appreciated. Thanks.






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users