| 
/*****Legend of Legaia*****
 
 RPG Game by Drew Martell
 
 This program will create a Role playing
 game in which you encounter random
 battles and have a unique battle system
 ***************************************/
 
 
 %IMPORTING
 import Characters in "DATA/SPRITES/CHARACTERS/Characters.tu", %imports character models
 Monsters in "DATA/SPRITES/MONSTERS/Monsters.tu", %imports monster models
 Status in "DATA/STATUS/Status.tu", %imports character status
 Files in "DATA/STATUS/Files.tu", %imports save and load procedures
 Maps in "DATA/MAPS/Maps.tu", %imports land maps
 Fonts in "DATA/FONTS/Fonts.tu", %imports fonts/text
 Playing in "DATA/MUSIC/Playing.tu", %imports music
 Refresh in "DATA/OTHER/Refreshes.tu", %imports refreshing state procedures
 Other in "DATA/OTHER/Other.tu" %imports various data
 
 %VARIABLES
 var damage : int %junk variable to maintain damage counter
 var lastYTop, lastYBottom : int %battle choice highlighter
 var menuLastTop, menuLastBottom : int %menu highlighter
 var chance := 300 %encounter rate
 var key : array char of boolean %menu key
 var outerKey : array char of boolean %control key
 var safe : boolean %determines fight free areas
 var escape := false %when true, leaves battle
 
 %PAUSE FOR KEY
 proc Pause
 Input.Flush %empty's keyboard buffer
 Input.Pause %pauses for keystroke
 end Pause
 
 
 %VICTORY MENU
 procedure Victory
 var speed : int %experience increasing/decreasing speed
 var junkVar := Status.vahnEXP %vahn's exp duplicated
 var junkVar2 := Monsters.monsterMaxHP (Monsters.M) %monster's exp value
 delay (25)
 Music.PlayFileReturn ("DATA/MUSIC/FF7_VICTORY.mid")
 delay (5500)
 drawfillbox (0, 0, maxx, maxy, blue)
 drawbox (20, 20, maxx - 20, maxy - 20, white)
 %determines speed delay of exp increasing/decreasing
 if (Monsters.monsterMaxHP (Monsters.M) < 100) then
 speed := 35
 elsif (Monsters.monsterMaxHP (Monsters.M) >= 100) and (Monsters.monsterMaxHP (Monsters.M) <= 300) then
 speed := 10
 elsif (Monsters.monsterMaxHP (Monsters.M) > 300) and (Monsters.monsterMaxHP (Monsters.M) < 1000) then
 speed := 5
 else
 speed := 0
 end if
 colourback (blue)
 color (white)
 locate (3, 5)
 put "Vahn's Total EXP: ", Status.vahnEXP %displays your exp
 locate (4, 5)
 put "EXP Gained: ", Monsters.monsterMaxHP (Monsters.M) %displays exp earned
 View.Update
 Pause
 for decreasing i : Monsters.monsterMaxHP (Monsters.M) .. 0
 locate (4, 5)
 put "EXP Gained: ", i %displays exp transfering to you in increments
 fork Playing.Sound (20 * i, 100)
 View.Update
 delay (speed)
 end for
 for i : 0 .. Monsters.monsterMaxHP (Monsters.M)
 locate (3, 23)
 put junkVar %displays exp gained in increments
 junkVar += 1
 fork Playing.Sound (20 * i, 100)
 View.Update
 delay (speed)
 end for
 Status.vahnEXP += Monsters.monsterMaxHP (Monsters.M) %increases Vahn's overall exp
 Files.LevelChart %determines level up or not
 locate (5, 5)
 put "Press any key to continue. . ."
 Pause
 Music.PlayFileStop
 Music.PlayFileReturn ("DATA/MUSIC/WORLD_MAP.mid")
 Monsters.MonsterSet %resets monsters and their initial status
 end Victory
 
 %ALLOWS YOU TO ATTACK
 procedure Attack
 Refresh.RefreshBattle %buffers
 Refresh.RefreshHP %buffers
 colourback (11)
 damage := Rand.Int (0, Status.maxDamage) %determines your damage inflicted
 Monsters.monsterDamage (1) := Rand.Int (0, 9) %monster's attack power
 Monsters.monsterHP (Monsters.M) -= damage %monster's health depletion
 %locates text appropriately in regards to the ammount of damage
 if (damage < 100) then
 locate (9, 22)
 elsif (damage >= 100) then
 locate (9, 21)
 elsif (damage >= 1000) then
 locate (9, 20)
 end if
 
 %extra graphical battle effects
 colour (black)
 colourback (11)
 put damage
 fork Playing.Sound (30, 5)
 drawstar (140, 230, 210, 300, yellow)
 View.Update
 delay (500)
 Refresh.RefreshHP
 drawfillstar (140, 230, 210, 300, 11)
 Refresh.RefreshHP
 
 if (Monsters.monsterHP (Monsters.M) <= 0) then
 %if (monsterHP (M) = monsterHP (M)) then
 Victory
 escape := true %leaves the battle
 return
 end if
 
 Status.vahnHP -= Monsters.monsterDamage (1) %monster inflicted damage against you
 
 %graphical enhancments
 locate (9, 40)
 colourback (11)
 put Monsters.monsterDamage (1)
 fork Playing.Sound (30, 10)
 drawstar (280, 230, 350, 300, brightred)
 delay (500)
 Refresh.RefreshHP
 drawfillstar (280, 230, 350, 300, 11)
 delay (500)
 Refresh.RefreshHP
 end Attack
 
 %MAGIC SPELLS
 procedure Magic
 Refresh.RefreshBattle
 end Magic
 
 %ITEM USAGE
 procedure Item
 Refresh.RefreshBattle
 drawfillbox (0, 0, maxx, 110, white)
 drawbox (10, 5, maxx - 10, 100, black)
 if ~ (Status.vahnHP >= Status.vahnMaxHP) then
 put "HP + 20!"
 Status.vahnHP += 20
 Refresh.RefreshHP
 else
 locate (1, 1)
 put "HP Is Full!"
 delay (500)
 Refresh.RefreshBattle
 end if
 View.Update
 Refresh.RefreshHP
 end Item
 
 %THIS BEGINS THE BATTLE MENU
 proc Battle
 Music.PlayFileStop
 var battleKey : array char of boolean %battle keys
 %random battle effects
 for i : 1 .. 100
 var x := Rand.Int (0, 1000)
 fork Playing.Sound (x, i)
 drawfillbox (0, 0, maxx, maxy, Rand.Int (16, 31))
 View.Update
 end for
 delay (50)
 Music.PlayFileReturn ("DATA/MUSIC/FF7_FIGHT.mid")
 %prepares monster status
 Monsters.MonsterSet
 Monsters.MonsterHPSet
 Refresh.RefreshHP
 Refresh.RefreshBattle
 View.Set ("nocursor")
 
 loop
 Input.KeyDown (battleKey) %waits for input
 if (escape = true) then %determines if battle is over
 cls
 Refresh.RefreshBackground
 escape := false
 exit
 end if
 
 %effects of battle menu
 if battleKey (KEY_DOWN_ARROW) then
 fork Playing.Sound (345, 10)
 drawfillbox (15, Refresh.yTop, 100, Refresh.yBottom, white)
 Refresh.yTop -= 20
 Refresh.yBottom -= 20
 lastYTop := Refresh.yTop
 lastYBottom := Refresh.yBottom
 drawfillbox (15, lastYTop, 100, lastYBottom, brightblue)
 delay (100)
 Refresh.RefreshBattle
 end if
 if battleKey (KEY_UP_ARROW) then
 fork Playing.Sound (345, 10)
 drawfillbox (15, Refresh.yTop, 100, Refresh.yBottom, white)
 Refresh.yTop += 20
 Refresh.yBottom += 20
 lastYTop := Refresh.yTop
 lastYBottom := Refresh.yBottom
 drawfillbox (15, lastYTop, 100, lastYBottom, brightblue)
 delay (100)
 Refresh.RefreshBattle
 end if
 
 %determines which action is being called
 if battleKey (KEY_ENTER) and (Refresh.yTop = 95) then
 delay (200)
 Attack
 elsif battleKey (KEY_ENTER) and (Refresh.yTop = 75) then
 delay (200)
 Magic
 elsif battleKey (KEY_ENTER) and (Refresh.yTop = 55) then
 delay (200)
 Item
 elsif battleKey (KEY_ENTER) and (Refresh.yTop = 30) or battleKey (KEY_ENTER) and (Refresh.yTop = 35)
 or battleKey (KEY_ESC) then
 Music.PlayFileStop
 for i : 1 .. Monsters.MAX_MONSTER
 Monsters.monsterHP (i) := Monsters.monsterMaxHP (i) %resets the monsters hp to full
 end for
 for i : 0 .. 100
 fork Playing.Sound (20 * i, i * 2)
 end for
 delay (100)
 Music.PlayFileReturn ("DATA/MUSIC/WORLD_MAP.mid")
 cls
 Refresh.RefreshBackground
 exit
 end if
 
 if battleKey ('h') then
 %free healing feature (for me only =p)
 Status.vahnHP := 100
 Refresh.RefreshHP
 end if
 
 %buffers screen
 if (Refresh.yTop > 95) then
 Refresh.yTop := 95
 Refresh.yBottom := 70
 Refresh.RefreshBattle
 elsif (Refresh.yTop < 30) then
 Refresh.yTop := 30
 Refresh.yBottom := 10
 Refresh.RefreshBattle
 elsif (Refresh.yTop < 35) then
 Refresh.yTop := 35
 Refresh.yBottom := 15
 end if
 end loop
 end Battle
 
 %DETERMINES ENCOUNTER RATE
 procedure Encounter (rate : int)
 var encounter := Rand.Int (0, rate) %determines when next battle takes place
 if (encounter = Rand.Int (0, rate)) and (safe = false) then %engages in battle accordingly
 Battle
 end if
 end Encounter
 
 %WHEN A KEY IS PRESSED IT DOES THIS
 procedure Step
 Refresh.RefreshBackground
 Encounter (chance) %encounter rate
 end Step
 
 %VIEWS STATUS
 procedure ViewStatus
 %the status feature, which displays all of Vahn's current status
 drawfillbox (0, 0, maxx, maxy, blue)
 locate (3, 5)
 colourback (blue)
 colour (white)
 put "Vahn\tHP: ", Status.vahnHP, " / ", Status.vahnMaxHP
 Pic.Draw (Characters.VAHN_PICTURE, 40, 170, picCopy)
 locate (16, 5)
 put "LEVEL ", Status.vahnLV, "\tEXP: ", Status.vahnEXP, " / ", Files.nextLevel
 locate (17, 5)
 put (Files.nextLevel - Status.vahnEXP), " EXP to the next level!"
 locate (19, 8)
 put "Max Damage :", Status.maxDamage
 locate (22, 5)
 put "(Press any key to return)"
 drawbox (20, 20, maxx - 20, maxy - 20, white)
 end ViewStatus
 
 %CALLS THE MAIN MENU
 proc MainMenu
 var menuKey : array char of boolean
 Refresh.RefreshMainMenu
 
 loop
 Input.KeyDown (menuKey)
 View.Update
 colourback (white)
 locate (1, 1)
 %put Refresh.menuTop, ' ', Refresh.menuBottom
 
 %sets up graphical highlight for the main menu
 if menuKey (KEY_DOWN_ARROW) then
 fork Playing.Sound (345, 10)
 drawfillbox (55, Refresh.menuTop, 200, Refresh.menuBottom, blue)
 Refresh.menuTop -= 40
 Refresh.menuBottom -= 40
 menuLastTop := Refresh.menuTop
 menuLastBottom := Refresh.menuBottom
 drawfillbox (55, menuLastTop, 200, menuLastBottom, brightblue)
 delay (100)
 Refresh.RefreshMainMenu
 end if
 if menuKey (KEY_UP_ARROW) then
 fork Playing.Sound (345, 10)
 drawfillbox (55, Refresh.menuTop, 200, Refresh.menuBottom, brightblue)
 Refresh.menuTop += 40
 Refresh.menuBottom += 40
 menuLastTop := Refresh.menuTop
 menuLastBottom := Refresh.menuBottom
 drawfillbox (55, menuLastTop, 200, menuLastTop, brightblue)
 delay (100)
 Refresh.RefreshMainMenu
 end if
 
 if (Refresh.menuTop > 349) then
 Refresh.menuTop := 349
 Refresh.menuBottom := 319
 Refresh.RefreshMainMenu
 elsif (Refresh.menuTop < 109) then
 Refresh.menuTop := 109
 Refresh.menuBottom := 79
 Refresh.RefreshMainMenu
 end if
 
 %determines which item has been selected
 colourback (blue)
 colour (white)
 if menuKey (KEY_ENTER) and (Refresh.menuTop >= 349) and (Refresh.menuBottom <= 319) then
 put "Function not implemented yet"
 elsif menuKey (KEY_ENTER) and (Refresh.menuTop >= 309) and (Refresh.menuBottom <= 279) then
 put "Function not implemented yet"
 elsif menuKey (KEY_ENTER) and (Refresh.menuTop >= 269) and (Refresh.menuBottom <= 239) then
 put "Function not implemented yet"
 elsif menuKey (KEY_ENTER) and (Refresh.menuTop >= 229) and (Refresh.menuBottom <= 199) then
 ViewStatus
 elsif menuKey (KEY_ENTER) and (Refresh.menuTop >= 189) and (Refresh.menuBottom <= 159) then
 Files.Save %saves all of your status into a file
 elsif menuKey (KEY_ENTER) and (Refresh.menuTop >= 149) and (Refresh.menuBottom <= 119) then
 Files.Load %loads all of your status from a file
 end if
 
 if menuKey (KEY_BACKSPACE) or menuKey (KEY_ENTER) and (Refresh.menuTop >= 109) and (Refresh.menuBottom <= 79) then
 %returns to gameplay
 Refresh.RefreshBackground
 return
 end if
 end loop
 cls
 end MainMenu
 
 forward proc OutsideWorld %allows procedure to be called from early on in the program
 var speed := 2 %default speed
 var x := 330 %starting x-position
 var y := 285 %starting y-position
 
 proc RimElm
 safe := true %no battles in town
 Music.PlayFileStop
 Music.PlayFileReturn ("DATA/MUSIC/RIM_ELM.mid")
 Maps.CURRENT := Maps.RIM_ELM %changes towns
 Refresh.RefreshBackground
 if (whatdotcolour (x, y) = 114) then %allows you to leave town
 OutsideWorld
 end if
 end RimElm
 
 %OUTSIDE WORLD
 body proc OutsideWorld %main procedure, will be called often
 safe := false %allows you to engage in battles
 Music.PlayFileStop
 Music.PlayFileReturn ("DATA/MUSIC/WORLD_MAP.mid")
 Maps.CURRENT := Maps.OUTSIDE %outside map is default
 Refresh.RefreshBackground
 loop
 locate (1, 1)
 colour (black)
 colourback (brightgreen)
 %put "x:", x, "   y:", y, "   COLOUR:", whatdotcolour (x, y)
 Pic.Draw (Characters.VAHN_DIR, x, y, picMerge) %draws main character =)
 View.Update
 Input.KeyDown (outerKey)
 delay (speed)
 
 %calls corrisponding functions and returns true if followed through
 if outerKey (KEY_UP_ARROW) then
 Characters.VAHN_DIR := Characters.VAHN_DIR_BACKWARD_1
 y += 1
 Step
 elsif outerKey (KEY_RIGHT_ARROW) then
 Characters.VAHN_DIR := Characters.VAHN_DIR_RIGHT_1
 x += 1
 Step
 elsif outerKey (KEY_DOWN_ARROW) then
 Characters.VAHN_DIR := Characters.VAHN_DIR_FORWARD_1
 y -= 1
 Step
 elsif outerKey (KEY_LEFT_ARROW) then
 Characters.VAHN_DIR := Characters.VAHN_DIR_LEFT_1
 x -= 1
 Step
 end if
 if outerKey (KEY_SHIFT) then
 speed := 0
 else
 speed := 2
 end if
 if outerKey (KEY_ESC) then
 MainMenu
 end if
 
 %player boundaries
 if (x >= maxx - 35) then
 x := maxx - 35
 elsif (y >= maxy - 35) then
 y := maxy - 35
 elsif (x < 0) then
 x := 0
 elsif (y < 0) then
 y := 0
 end if
 
 if (whatdotcolour (x, y) = grey) then
 x += 1
 end if
 if (whatdotcolour (x + 25, y) = grey) then
 x -= 1
 end if
 if (whatdotcolour (x, y + 25) = grey) then
 y -= 1
 end if
 if (whatdotcolour (x, y - 3) = grey) then
 y += 1
 end if
 if (whatdotcolour (x, y - 5) = brightblue) then
 y += 1
 end if
 if (whatdotcolour (x, y) = 114) then %checks if player meets gate to town
 RimElm
 end if
 end loop
 end OutsideWorld
 
 %BEGINNING INTRO
 procedure Intro
 %main introduction with an explination of game at excecution
 Music.PlayFileReturn ("DATA/MUSIC/FF_PRELUDE.mid")
 drawfillbox (0, 0, maxx, maxy, blue)
 Pic.Draw (Other.LOGO, 67, 260, picCopy)
 View.Set ("nocursor")
 colourback (blue)
 colour (brightgreen)
 locate (12, 1)
 put "\t\t\t/*****Legend of Legaia*****\\"
 put "\t\t\t  RPG Game by Drew Martell"
 put "\t\tThis program will create a Role playing"
 put "\t\tgame in which you encounter random"
 put "\t\tbattles and have a unique battle system."
 put "\t\t\\***************************************/"
 colour (brightred)
 put ""
 put "\t\t\tLast edited on May 25, 2006"
 colour (white)
 put "\t\t\tPress any key to continue. . ."
 drawbox (110, 70, 500, 240, white)
 Pause
 Music.PlayFileStop
 cls
 end Intro
 
 %SEQUENCE OF EVENTS IN WHICH THE GAME STARTS
 View.Set ("nocursor")
 colour(white)
 put "Press any key to boot game..."
 Input.Pause
 View.Set ("nobuttonbar")
 View.Set ("title:Legend Of Legaia RPG;position:250,200")
 Intro
 View.Set ("offscreenonly") %allows double buffering for smooth graphical effect
 Refresh.RefreshBackground
 OutsideWorld
 
 
 
 
 
 |