Hello, I would like to put up my first decent DBP code. It is a battle system for text-based adventure games. Feel free to use it, I don't want any credit, just PM me how you used it/ changed it. Here it is:
Battlesystem:
Enemyword$="Your enemy's health is "
Health#=100
Healthword$="Your health is "
Gosub Weaponchooser rem probably not used in game
Gosub Enemychooser rem probably not used in game
Do
iblock=0
cls
print "Your enemy is a "+foe$
Print "Your weapon is a "+Weapon$
Print Healthword$+str$(Health#)
Print Enemyword$+str$(Enemy#)
print Attackword$
print Eattack$
print "Press A to use your main weapon, B for a dagger attack and D to defend."
wait key
do
If keystate(30)=1
gosub attack
Exit
Endif
If keystate(48)=1
gosub dagattack
Exit
Endif
If keystate(32)=1
gosub defend
exit
endif
loop
ED=0
gosub enemymove
Loop
Weaponchooser:
rem This picks a random weapons. Should be removed if in an adventure
iweapon=rnd(4)
Dim Weapon#(4)
if iweapon=0
Weapon$="Spear"
Endif
if iweapon=1
Weapon$="Bow"
endif
if iweapon=2
Weapon$="Axe"
endif
if iweapon=3
Weapon$="Sword"
endif
if iweapon=4
Weapon$="Club"
endif
Print "Your weapon is a "+Weapon$
Return
Enemychooser: rem also probably removed
ifoe=rnd(4)
if ifoe=0
Enemy#=50
Foe$="Bear"
endif
if ifoe=1
Enemy#=75
foe$="Enemy Soilder"
endif
if ifoe=2
Enemy#=100
foe$="Orc"
endif
if ifoe=3
Enemy#=30
foe$="Wolf"
endif
if ifoe=4
Enemy#=200
foe$="Dragon"
endif
return
Attack: Rem Basic attack, may miss
If iweapon=0 rem spear
ihit=rnd(3)
if ihit = 0
Attackword$="You stab with the spear and miss"
else
Damage#=rnd(25)+1
if ED=1 then Damage#=Damage#/2
Attackword$="You stab with the spear and deal "+str$(Damage#)+" damage"
Enemy#=Enemy#-Damage#
Endif
Endif
If iweapon=1 rem bow
ihit=rnd(2)
if ihit = 0
Attackword$="You shoot the bow and miss"
else
Damage#=rnd(40)+1
if ED=1 then Damage#=Damage#/2
Attackword$="You stick your enemy with an arrow for "+str$(Damage#)+" damage"
Enemy#=Enemy#-Damage#
Endif
Endif
If iweapon=2 rem axe
ihit=rnd(5)
if ihit = 0
Attackword$="You swing the axe but miss"
else
Damage#=rnd(20)+1
if ED=1 then Damage#=Damage#/2
Attackword$="You slice with the axe and deal "+str$(Damage#)+" damage"
Enemy#=Enemy#-Damage#
Endif
Endif
If iweapon=3 rem sword
ihit=rnd(7)
if ihit = 0
Attackword$="You swing the sword and miss"
else
Damage#=rnd(40)+1
if ED=1 then Damage#=Damage#/2
Attackword$="You hack at your enemy with a sword and deal "+str$(Damage#)+" damage"
Enemy#=Enemy#-Damage#
Endif
Endif
If iweapon=4 rem club
ihit=rnd(7)
if ihit = 0
Attackword$="You swing the club and miss"
else
Damage#=rnd(20)+1
if ED=1 then Damage#=Damage#/2
Attackword$="You wack your enemy with the club and deal "+str$(Damage#)+" damage"
Enemy#=Enemy#-Damage#
Endif
Endif
If Enemy#<1 rem end battle
cls
Print "You have won the battle. Play again? (Y/N)"
do
If keystate(21)=1
goto Battlesystem
Endif
If keystate(49)=1
End
Endif
loop
Endif
return
dagattack: rem definate attack, less strength
Damage#=rnd(15)+1
if ED=1 then Damage#=Damage#/2
Attackword$="You stab your enemy with your dagger and deal "+str$(Damage#)+" damage"
Enemy#=Enemy#-Damage#
If Enemy#<1 rem end battle
cls
Print "You have won the battle. Play again? (Y/N)"
do
If keystate(21)=1
goto Battlesystem
Endif
If keystate(49)=1
End
Endif
loop
Endif
return
defend: rem 1/2 chance to block the enemy attack. Else devides it in 1/3.
iblock=rnd(1)+1
if iblock=1
D=1
Else
B=1
endif
return
Enemymove:
idowhat=rnd(2)
if idowhat=0
ED=1
Eattack$="The enemy is getting ready to block your attack"
endif
if idowhat=1
if ifoe=0 rem bear
Edamage#=rnd(15)+1
if D=1 then Edamage#=0
if B=1 then Edamage#=Edamage#/2
if Edamage#>0
Eattack$="The bear bit you for "+STR$(Edamage#)+" damage"
Health#=Health#-Edamage#
Else
Eattack$="You have blocked the bear's attack"
Endif
endif
if ifoe=1 rem soilder
Edamage#=rnd(20)+1
if D=1 then Edamage#=0
if B=1 then Edamage#=Edamage#/2
if Edamage#>0
Eattack$="The soilder hit you for "+STR$(Edamage#)+" damage"
Health#=Health#-Edamage#
Else
Eattack$="You have blocked the soilder's attack"
Endif
Endif
if ifoe=2 rem orc
Edamage#=rnd(20)+1
if D=1 then Edamage#=0
if B=1 then Edamage#=Edamage#/2
if Edamage#>0
Eattack$="The Orc hit you for "+STR$(Edamage#)+" damage"
Health#=Health#-Edamage#
Else
Eattack$="You have blocked the orc's attack"
Endif
Endif
if ifoe=3 rem Wolf
Edamage#=rnd(10)+1
if D=1 then Edamage#=0
if B=1 then Edamage#=Edamage#/2
if Edamage#>0
Eattack$="The wolf bit you for "+STR$(Edamage#)+" damage"
Health#=Health#-Edamage#
Else
Eattack$="You have blocked the wolf's attack"
Endif
Endif
if ifoe=4 rem Dragon
Edamage#=rnd(50)+1
if D=1 then Edamage#=0
if B=1 then Edamage#=Edamage#/2
if Edamage#>0
Eattack$="The dragon shot fire at you for "+STR$(Edamage#)+" damage"
Health#=Health#-Edamage#
Else
Eattack$="You have blocked the dragon's attack"
Endif
Endif
If Health#<1 rem end battle
cls
Print "You have lost the battle. Play again? (Y/N)"
do
If keystate(21)=1
goto Battlesystem:
Endif
If keystate(49)=1
End
Endif
loop
Endif
Endif
If idowhat=2 then Eattack$= "The enemy attacked, but missed."
return
Any comments/suggestions are welcome...
Don't follow in my footsteps... I often walk into walls