Code Snippets & Samples for bB Beginners
Started by Atarius Maximus, Jun 25 2007 1:43 PM
38 replies to this topic
#26
Posted Sat Jul 18, 2009 7:50 PM
These samples are fantastic! Thanks for making these available.
M.
M.
#29
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
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
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
Posted Wed Mar 10, 2010 8:22 AM
endrien, on Sat Oct 3, 2009 5:34 AM, said:
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
Posted Wed Mar 10, 2010 2:23 PM
Atarius Maximus, on Wed Mar 10, 2010 8:22 AM, said:
endrien, on Sat Oct 3, 2009 5:34 AM, said:
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
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
Steve
#34
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
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
Posted Thu Mar 18, 2010 4:52 PM
Cliff Friedel, on Wed Mar 17, 2010 10:43 PM, said:
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
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
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
Posted Thu Mar 18, 2010 10:34 PM
Random Terrain, on Thu Mar 18, 2010 4:52 PM, said:
Cliff Friedel, on Wed Mar 17, 2010 10:43 PM, said:
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
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
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
Posted Wed May 26, 2010 11:03 AM
Atarius Maximus, on Wed Mar 10, 2010 2:23 PM, said:
Atarius Maximus, on Wed Mar 10, 2010 8:22 AM, said:
endrien, on Sat Oct 3, 2009 5:34 AM, said:
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
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
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
Posted Tue Jul 26, 2011 9:43 AM
Thanks!!!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users














