TGC Codebase Backup



Text based RPG battle by Anti Human

23rd Jul 2008 5:21
Summary

Incomplete battle sequence for RPG. all text-based. real shabby but i'm still learning



Description

7/21/08 Something I'v been working on the past 2 nights. might be cleaner if I can get arrays to work. Planning on adding: weapons, armor, enemies, and player actions.

Been using this as a test bed to teach myself DBP. Will update once in awhile.

7/23/08 Had sound added to new code, made second save and removed all sound (i think!). couldn't get all sounds in 500kb zip. changed enemies, and some more stuff is random now.
cut health and potions.
added stuff to things i'm planning: player xp and lvl, enemy lvl based on players, loot (mostly more health potions). and making it so you don't have to start fresh each fight.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    RemStart Couple of Notes. This is just the sequence of battle. I'm
hoping to actually get it some what finished so I can work on the
rest of the RPG.

There probably better ways of coding any piece of this, I don't
know what they are or I would have used them. hoh_antihuman@hotmail.com
let me know please. Just pointing me in the direction would work.

Want to add: More Enemies, Weapon, and Armor. Magic, XP, and Loot.
Enemy Lvl & Equipment generation based on player lvl.
need to learn arrays.

any feed back at all is welcome, even negative.
RemEnd


`Setting up the screen. This really helps when using the Text command.
set display mode 800,600,32
hide mouse

Restart:

`Random numbers for Luck stat and creating the Enemy.
Randomize Timer()

`Variblies I couldn't invent a name for.
Global E_Time=100
Global P_Time=100
Global Damage=0

`All the Player (P_) variblies.
Global Player$="Player" : Global P_Health=P_THP : Global P_THP=50
Global P_Str=0 : Global P_Dex=0 : Global P_Luck=0 : Global P_Con=0
Global P_Weapon$="Fork" : Global P_WD=0 : Global P_WW=0
Global P_Armor$="Spoon" : Global P_Arm=0 : Global P_AW=0
Global P_Att=0 : Global P_Def=0 : Global P_Spd=0 : Global P_Wght=2
Global P_Potion=3

`All the Enemy (E_) variblies.
Global Enemy$="Enemy" : Global E_Health=0 : Global E_THP=0
Global E_Str=0 : Global E_Dex=0 : Global E_Luck=0 : Global E_Con=0
Global E_Weapon$="Plate" : Global E_WD=0 : Global E_WW=0
Global E_Armor$="Bowl" : Global E_Arm=0 : Global E_AW=0
Global E_Att=0 : Global E_Def=0 : Global E_Spd=0 : Global E_Wght=2

Gosub Main_Menu

Gosub Enemy

Round:

CLS : Gosub Stats

`Main Do/Loop.
Do

`Checking Health for Winner
If E_Health <1
  Winner$=Player$
  Gosub EndGame
 Endif

If P_Health <1
  Winner$=Enemy$
  Gosub EndGame
 Endif

`Turn Timers based on Speed and Luck.
E_Time=E_Time-(E_Spd+Rnd(E_Luck))
P_Time=P_Time-(P_Spd+Rnd(E_Luck))

`Activating the turns.
If E_Time <1
  Gosub EnemyMove
 Endif

If P_Time <1
  Gosub PlayerMove
Endif

Loop
End

`E_ Timer reached 0.
EnemyMove:
CLS : Gosub Stats

`Keeping real E_Stat, Resetting P_Combo.
E_Def2=E_Def : E_Luck2=E_Luck : P_Combo=0

`Hoping this will make the Enemy defend once in awhile.
If E_Health+P_Time<50 And E_Time>P_Time/2
  E_Def=E_Def2
  E_Def2=E_Def2+E_Str+Rnd(E_Luck2)
  Text 5,500, Enemy$+" is defending."
  Wait key
  CLS : Gosub Stats
  Wait 500
 Else
  Gosub E_Attack
 Endif

E_Time=100

Gosub Stats
Gosub Round
Return

`Enemy attacks.
E_Attack:
CLS : Gosub Stats

E_Combo=E_Combo+1 : E_Luck2=E_Luck : E_Luck2=E_Luck2*E_Combo

Text 5,500, Enemy$+" "+E_WepAtt$+" at "+Player$+"."

`Figures hit and damage done in attack.
If E_Spd*2+Rnd(E_Luck2)<P_Spd+Rnd(P_Luck2)
  Text 5,520, Player$+" Dodges."
  Wait key
  CLS : Gosub Stats
  Wait 500
  E_Time=120
  CLS
  Gosub Round
 Endif

Damage=(E_Att+Rnd(E_Luck2))-((P_Def2+Rnd(P_Luck2))/2)
If Damage<0
  Damage=0
 Endif
P_Health=P_Health-Damage

Text 5,520, Enemy$+" Hits! "+Str$(Damage)+" damage done."
Wait key
CLS : Gosub Stats
Wait 500

`Resets Enemies Turn Timer.
E_Time=100

CLS : Gosub Stats
Gosub Round
Return

`Players Timer reached 0.
PlayerMove:
CLS : Gosub Stats

`Keeping real stats. reset E_ combo count.
PM$="0" : P_Def2=P_Def : P_Luck2=P_Luck : E_Combo=0

`Player selecting action. [2] raises Def stat until next player turn.
Text 5,500, "Please select an action. "
Text 5,520, "[1]Attack [2]Defend [3]Potion("+Str$(P_Potion)+")"

Repeat
  PM$=Upper$(Inkey$())
 Until PM$="1" or PM$="2" or PM$="3"

If PM$="1"
  Gosub P_Attack
 Endif

If PM$="2"
  P_Def=P_Def2
  P_Def2=P_Def2+P_Str+Rnd(P_Luck2)
  CLS : Gosub Stats
  Text 5,500, Player$+" is defending."
  Wait key
  CLS : Gosub Stats
  Wait 500
 Endif

If PM$="3"
  If P_Potion=0
    CLS : Gosub Stats
    Text 5,500, "You do not have any potions."
    Wait key
    Wait 500
   Else
    P_Health=P_Health+20
    P_Potion=P_Potion-1
    Text 5,500, Player$+" uses potion."
    Wait keys
    CLS : Gosub Stats
    Wait 500
   Endif
 Endif

P_Time=100

CLS : Gosub Stats
Gosub Round
Return

`Player attacks.
P_Attack:
CLS : Gosub Stats

P_Combo=P_Combo+1 : P_Luck2=P_Luck : P_Luck2=P_Luck2*P_Combo

Text 5,500, Player$+" "+P_WepAtt$+" at "+Enemy$+"."

`Figures hit and damage done. Increases Time if dodged.
If P_Spd*2+Rnd(P_Luck2)<E_Spd+Rnd(E_Luck2)
  Text 5,520, Enemy$+" Dodges."
  Wait key
  Wait 500
  P_Time=120
  CLS : Gosub Stats
  Gosub Round
 Endif

Damage=(P_Att+Rnd(P_Luck2))-((E_Def+Rnd(P_Luck2))/2)
If Damage<0
  Damage=0
 Endif
E_Health=E_Health-Damage

Text 5,520, "Hits! "+Str$(Damage)+" damage done."
Wait key
Wait 500

`Resets Players Turn Timer
P_Time=100

CLS : Gosub Stats
Gosub Round
Return

`And the Winner is?
EndGame:
CLS

  Text 10,10, Winner$+" wins."
  Text 10,30, "Would you like to play again? Y/N "

Repeat
  L$=Upper$(Inkey$())
 Until L$="Y" or L$="N"

If L$="Y"
  CLS
  Gosub Restart
 Endif

If L$="N"
  CLS
  End
 Endif

Return

`The Main Menu. Hoping to add Load when I learn array command.
Main_Menu:
CLS

Set Text Font "roman",1
Set Text Size 50
Center Text 400,200, "Sword Play"
sleep 3000
CLS

Center Text 400,100, "Sword Play"
Set Text Size 20
Center Text 400,200, "[1]New Game"
Center Text 400,300, "[2]Exit"

Repeat
  M$=Inkey$()
 Until M$="1" or M$="2"

If M$="1"
  Gosub New_Game
 Endif

If M$="2"
  End
 Endif

Return

`Creating Players Charactor.
New_Game:
CLS

Input "Please enter your charactors name. ", Player$

`Selecting Players Stats.
Stat_Reset:
SkPt=15
CLS

Text 10,10, "You have 15 points to spend on 4 stats. Str, Dex, Con, and Luck."

Set Cursor 10,30, : Input "Enter Strength ", P_Str

If P_Str>SkPt
  Text 10,50, "Sorry, you don't have that many points."
  Wait key
  Goto Stat_Reset
 Else
  SkPt=SkPt-P_Str
 Endif

Set Cursor 10,50, : Input "Enter Dex ", P_Dex

If P_Dex>SkPt
  Text 10,50, "Sorry, you don't have that many points."
  Wait key
  Goto Stat_Reset
 Else
  SkPt=SkPt-P_Dex
 Endif

Set Cursor 10,70, : Input "Enter Con ", P_Con

If P_Con>SkPt
  Text 10,50, "Sorry, you don't have that many points."
  Wait key
  Goto Stat_Reset
 Else
  SkPt=SkPt-P_Con
 Endif
P_Luck=SkPt

Text 10,90, "That leaves "+Str$(SkPt)+" for Luck."
Wait key
Wait 500
CLS

SkPt=SkPt-P_Luck
If SkPt <>0
  Goto Stat_Reset
 Endif

`Selecting Players Weapon.
Text 10,10, "Please select your weapon. "
Text 10,30, "[1]Spear D:2 W:3"
Text 10,50, "[2]Sword D:5 W:6"
Text 10,70, "[3]Mace  D:8 W:9"

Repeat
  W$=Inkey$()
 Until W$="1" or W$="2" or W$="3"

`WD=Weapon Damage, WW=Weapon Weight
If W$="1"
  P_Weapon$="Spear" : P_WD=2 : P_WW=3 : P_WepAtt$="Stabs"
 Endif

If W$="2"
  P_Weapon$="Sword" : P_WD=5 : P_WW=6 : P_WepAtt$="Slashes"
 Endif

If W$="3"
  P_Weapon$="Mace" : P_WD=8 : P_WW=9 : P_WepAtt$="Bashes"
 Endif

Wait 500

CLS

`Selecting Players Armor.
Text 10,10, "Please select your armor. "
Text 10,30, "[1]Leather A:2 W:3"
Text 10,50, "[2]Mail    A:5 W:6"
Text 10,70, "[3]Plate   A:8 W:9"

Repeat
  A$=Inkey$()
 Until A$="1" or A$="2" or A$="3"

`Arm=Armor Value, AW=Armor Weight
If A$="1"
  P_Armor$="Leather" : P_Arm=2 : P_AW=3
 Endif

If A$="2"
  P_Armor$="Mail" : P_Arm=5 : P_AW=6
 Endif

If A$="3"
  P_Armor$="Plate" : P_Arm=8 : P_AW=9
 Endif

Wait 500

`Using Players Weapon and Armor to assign Players Stats.
P_Att=P_WD+P_Str : P_Def=P_Arm+P_Con
P_THP=P_THP+(P_Con*2) : P_Health=P_THP
P_Wght=P_WW+P_AW+2 : P_Spd=P_Dex*3-P_Wght/2
CLS

Text 10,10, Player$+", armed with a "+P_Weapon$+" and "+P_Armor$+"."
Text 10,30, "Base Stats: Str "+Str$(P_Str)+" Dex "+Str$(P_Dex)+" Luck "+Str$(P_Luck)
Text 10,50, "Attack: "+Str$(P_Att)+" Defense: "+Str$(P_Def)+" Speed: "+Str$(P_Spd)
Text 10,70, "Weight "+Str$(P_Wght)+"."

Text 10,90, "Is this okay? Y/N "

Repeat
  L$=Upper$(Inkey$())
 Until L$="Y" or L$="N"

If L$="Y"
  CLS
  Gosub Enemy
 Endif

If L$="N"
  CLS
  Gosub Stat_Reset
 Endif

Return

`Use to Create almost random Enemy.
Enemy:

RN=Rnd(2)+1

`Random Creature.
If RN=1
  Enemy$="Rat" : E_Health=25 : E_THP=25
  E_Str=4 : E_Dex=3 : E_Luck=2 : E_Con=2
  E_Weapon$="Bites" : E_WD=1 : E_WW=0 : E_WepAtt$="Bites"
  E_Armor$="Fur" : E_Arm=1 : E_AW=0
  E_Att=0 : E_Def=0 : E_Spd=0 : E_Wght=2
  E_SkPt=5
 Endif

If RN=2
  Enemy$="Slime" : E_Health=10 : E_THP=10
  E_Str=2 : E_Dex=5 : E_Luck=4 : E_Con=0
  E_Weapon$="Punch" : E_WD=2 : E_WW=0 : E_WepAtt$="Punches"
  E_Armor$="None" : E_Arm=0 : E_AW=0
  E_Att=0 : E_Def=0 : E_Spd=0 : E_Wght=1
  E_SkPt=5
 Endif

If RN=3
  Enemy$="Bat" : E_Health=20 : E_THP=20
  E_Str=3 : E_Dex=4 : E_Luck=3 : E_Con=1
  E_Weapon$="Teeth" : E_WD=1 : E_WW=0 : E_WepAtt$="Bites"
  E_Armor$="Fur" : E_Arm=1 : E_AW=0
  E_Att=0 : E_Def=0 : E_Spd=0 : E_Wght=1
  E_SkPt=5
 Endif

`Random Stats.
RES=Rnd(E_SkPt)
 E_Str=E_Str+RES
 E_SkPt=E_SkPt-RES

RED=Rnd(E_SkPt)
 E_Dex=E_Dex+RED
 E_SkPt=E_SkPt-RED

REC=Rnd(E_SkPt)
 E_Con=E_Con+REC
 E_SkPt=E_SkPt-REC

 E_Luck=E_Luck+E_SkPt

`Random Weapon.
REMSTART Remed this off until I get XP and lvl system, then use it for
lvl 2 creatures (Gnolls, Orcs, Trolls) and maybe lvl 3 (Ogres, Giants)
RW=Rnd(2)+1

If RW=1
  E_Weapon$="Spear"
  E_WD=2
  E_WW=1
 Endif

If RW=2
  E_Weapon$="Sword"
  E_WD=5
  E_WW=5
 Endif

If RW=3
  E_Weapon$="Mace"
  E_WD=8
  E_WW=9
 Endif

`Random Armor.
RA=RND(2)+1

If RA=1
  E_Armor$="Leather"
  E_Arm=2
  E_AW=2
 Endif

If RA=2
  E_Armor$="Mail"
  E_Arm=5
  E_AW=5
 Endif

If RA=3
  E_Armor$="Plate"
  E_Arm=8
  E_AW=8
 Endif

REMEND

`Using E_ Weapon and Armor to assign Enemies Stats.
E_Att=E_WD+E_Str : E_Def=E_Arm+E_Dex
E_Wght=E_WW+E_AW+2 : E_Spd=E_Dex*3-E_Wght/2

Return

`Displays P_ and E_ Stats.
Stats:

Text 5,5, Player$
Text 5,25, "HP: "+Str$(P_Health)
Text 5,45, "Turn Time: "+Str$(P_Time)

Text 500,5, Enemy$
Text 500,25, "HP: "+Str$(E_Health)
Text 500,45, "Turn Time: "+Str$(E_Time)

Return