I decided during the summer holidays to try to make a small RPG Game to try and improve my programming skills as a little project. I have managed to code a very very basic a uncomplete battle system which is triggered by a timer (not random).
However the battle system lacks movement, animation and the camera needs work. I am a little unsure what to work on next and if someone would take a look a my code and suggest what to work on next and how it could be improved that would be appreciated.
BTW it is in the style of the FF series turn based battle system. And most of the media for the game can be found in the DB media files.
sync rate 60:sync on
`----------
`---Menu---
`----------
Menu:
set text size 24
load bitmap "Menu screen-RPG Game.bmp"
Blue=RGB(0,128,255)
White=RGB(255,255,255)
Set camera View 0,0,1,1
ink white,0
do
text 280, 180, "New Game"
text 280,200, "Load Game"
text 280,220, "Controls"
text 280,240, "Exit"
`print menu items
If mousex() > 280 and mousex() < 350 and mousey() > 180 and mousey() < 190
ink blue,0:text 280,180,"New Game"
if mouseclick()=1
goto main
Endif
else
ink white,0
endif
If mousex() > 280 and mousex() < 350 and mousey() > 200 and mousey() < 210
ink blue,0:text 280,200,"Load Game"
if mouseclick()=1
wait 1000
goto Load
Endif
else
ink white,0
endif
If mousex() > 280 and mousex() < 340 and mousey() > 220 and mousey() < 230
ink blue,0:text 280,220,"Controls"
if mouseclick()=1
goto Controls
endif
else
ink white,0
endif
If mousex() > 280 and mousex() < 330 and mousey() > 240 and mousey() < 250
ink blue,0:text 280,240,"Exit"
if mouseclick()=1
End
endif
else
ink white,0
endif
sync
loop
Load:
cls
load bitmap "menu screen-loadgame.bmp"
`LOADING THE SAVED GAME
ink white,0
Do
Dim Stats#(20,3)
load array "RPG_Save.dat",Stats#(0)
set cursor 50,100:print "Name: Jozers"
set cursor 240,100:print "Level: "; stats#(11,1)
set cursor 330,100:print "Race: "; racename$
set cursor 450,100:print "Class: ";Classname$
if mousex() > 0 and mousex() < 480 and mousey() > 75 and mousey() < 125
ink blue,0
set cursor 50,100:print "Name: Jozers"
set cursor 240,100:print "Level: "; stats#(11,1)
set cursor 330,100:print "Race: "; racename$
set cursor 450,100:print "Class: ";Classname$
if mouseclick()=1
goto loadloop
endif
else
ink white,0
endif
sync
Loop
Controls:
load bitmap "menu screen-Controls.bmp"
do
if keystate(14)=1 then goto menu
sync
loop
`----------
`---MAIN---
`----------
Main:
`-----------
`---STATS---
`-----------
Dim Stats#(20,3)
stats#(1,1)=100
stats#(2,1)=15
stats#(3,1)=10
stats#(4,1)=13
stats#(5,1)=12
stats#(6,1)=13
stats#(7,1)=12
stats#(8,1)=12
stats#(9,1)=14
stats#(10,1)=12
stats#(11,1)=1
stats#(12,1)=0
stats#(13,1)=0
stats#(14,1)=0
stats#(15,1)=0
stats#(16,1)=100
stats#(17,1)=0
stats#(18,1)=0
stats#(19,1)=0
stats#(20,1)=0
fog on
loadloop:
if object exist(15)=0
rem Make a floor and create texture for it
make object box 15,1000,10,1000 : position object 15,0,-5,0 : color object 15,rgb(0,255,0)
load bitmap "Grass15.bmp",1:get image 1,0,0,128,128 : delete bitmap 1 : texture object 15,1
scale object texture 15,200,200
endif
if object exist(11)=0
rem Make four walls
make object box 11,10,20,1000 : position object 11,-500,0,0 : color object 11,rgb(155,40,20)
make object box 12,10,20,1000 : position object 12, 500,0,0 : color object 12,rgb(155,40,20)
make object box 13,1000,20,10 : position object 13, 0,0,-500 : color object 13,rgb(155,40,20)
make object box 14,1000,20,10 : position object 14, 0,0, 500 : color object 14,rgb(155,40,20)
rem Make the wall and floor objects into static objects (for auto-camera collision)
for t=11 to 15
make static object t
objx#=object position x(t)
objy#=object position y(t)
objz#=object position z(t)
objsx#=object size x(t)/2.0
objsy#=object size y(t)/2.0
objsz#=object size z(t)/2.0
make static collision box objx#-objsx#,objy#-objsy#,objz#-objsz#,objx#+objsx#,objy#+objsy#,objz#+objsz#
delete object t
next t
endif
set camera view 0,0,640,480
`Scenery
`Fog
set ambient light 45
if object exist(1)=0
load object "idle.x",1:append object "attack.x",1,100:append object "walk.x",1,200
make object collision box 1,-5,-5,-5,5,5,5,0
yrotate object 1,180
fix object pivot 1
endif
scale object 1,20,20,20
`scenery
`Saving Game Variables
skychange=20
Darken=199
rem Start off player gravity
playergrav#=32.0
rem Main loop
do
`Arrays for Magic
Dim Magic$(6)
Magic$(1)="Fire"
Magic$(2)="Bolt"
Magic$(3)="Ice"
Magic$(4)="Cure"
Magic$(5)="-"
Magic$(6)="-"
`Arrays for Items
Dim Items$(6)
Items$(1)="Potion"
Items$(2)=""
Items$(3)=""
Items$(4)=""
Items$(5)=""
Items$(6)=""
Battle=Battle+1
if Battle>1000
Battle=0
wait 1000
goto Battle
endif
set cursor 100,100:print Battle
`DAY-NIGHT CYCLE
DayNight=DayNight+1
if DayNight=SkyChange
if Darken>199 then Add=0
if Darken<40 then Add=1
If Add=1 then Darken=Darken+1
If Add=0 then Darken=Darken-1
darken=10000
fog distance darken
endif
`SAVE GAME IF 'K' KEY IS PRESSED
if keystate(37)=1
save Array "RPG_Save.dat",Stats#(0)
text 10,460, "Game Saved"
endif
set cursor 10,10 : print stats#(1,1);"/";stats#(16,1)
rem Store old positions
oldposx#=object position x(1)
oldposy#=object position y(1)
oldposz#=object position z(1)
rem Control player object
if upkey()=1 then move object 1,1
if downkey()=1 then move object 1,-1
if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-3)
if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+3)
if spacekey()=1 and playergrav#=35.0 then playergrav#=37.0
rem Get current object position
posx#=object position x(1)
posy#=object position y(1)
posz#=object position z(1)
rem Handle a touch of gravity
playergrav#=playergrav#-0.1
posy#=posy#+playergrav#
rem Handle sliding collision for player object with other objects
position object 1,posx#,posy#-35,posz#
if object collision(1,0)>0
dec posx#,get object collision x()
dec posy#,get object collision y()
dec posz#,get object collision z()
playergrav#=35.0
endif
rem Set a size for the player object
s#=object size y(1)/2.0
rem Ensure camera stays out of static collision boxes
if get static collision hit(oldposx#-s#,oldposy#-s#,oldposz#-s#,oldposx#+s#,oldposy#+s#,oldposz#+s#,posx#-s#,posy#-s#,posz#-s#,posx#+s#,posy#+s#,posz#+s#)=1
dec posx#,get static collision x()
dec posy#,get static collision y()
dec posz#,get static collision z()
if get static collision y()<>0.0 then playergrav#=35.0
endif
rem Update with new object position
position object 1,posx#,posy#-35,posz#
rem Use camera tracker to follow player object
angle#=object angle y(1)
camdist#=50 : camhigh#=posy#+10.0 : camfade#=3.5
set camera to follow posx#,posy#,posz#,angle#,camdist#,camhigh#,camfade#,1
rem Tilt camera down a little
xrotate camera 15
sync
loop
rem Restore object if ever leave this loop
enable object zdepth 11
`----------
`--BATTLE--
`----------
Battle:
set text to normal
set text size 24
`Delete Current objects
`Make Matrix
`Load Character(s)
position object 1,-40,0,-7
point object 1,30,0,30
point object 1,-40,0,37
`Make plain for menu
make object plain 20,3.25,0.5
position object 20,0,-0.95,2
lock object on 20
load bitmap "Menu_bar copy.bmp",5
get image 5,0,0,325,50
texture object 20,5
delete bitmap 5
box BTimer#+500,405,600,412
load bitmap "time bar.bmp",2
set current bitmap 2
box 500,405,600,412
delete bitmap 2
make object plain 21,2,0.2
position object 21,0.05,1.1,2
lock object on 21
`Load Opposition
load object "gobidle.x",100:append object "punch.x",100,50
scale object 100,40,40,40
position object 100,-40,0,37
`Set Fog On
fog on
`Health
Gobhpmax=15
Gobhp=Gobhpmax
sec#=1
ink white,0
Etimer#=50
monnum=rnd(3)
set cursor 400,400:print monnum
Dim monstat(10)
load array "Monster Stats/Monster_stats_" + str$(monnum) + ".dat",monstat(10)
do
attack=0
set object speed 1,10
`---------------
`---Formulars---
`---------------
`Derived Stats
Att#=Stats#(2,1)+weapatkbonus
Defence#=stats#(8,1)+Armdefbonus
Magic#=Stats#(3,1)
`Physical Damage Attack Formula
PBaseDmg#=Att#+((att#+stats#(11,1))/32)*((att#*stats#(11,1))/32)
`Magical Damage Attack Formula
MBaseDmg#=6*(Magic#+stats#(11,1))
set cursor 75,85:print MBaseDmg#
set cursor 75,75:print PBaseDmg#
set cursor 30,30:print mousex()
set cursor 30,45:print mousey()
healthtemp#=stats#(1,1)
maxhealthtemp#=stats#(16,1)
hptest#=healthtemp#/maxhealthtemp#
hptest#=hptest#*100
set cursor 10,40:print screen fps()
text 40,405,"Jozers"
set cursor 10,10:print Monstat(1,1);"/";Monstat(5)
if menu =0
set cursor 205,410:print stats#(1,1);"/";stats#(16,1)
if hptest#<30 and hptest#>20
ink rgb(250,230,10),0:set cursor 205,410:print stats#(1,1);"/";stats#(16,1)
if hptest#<20
ink white,0:set cursor 205,410:print stats#(1,1);"/";stats#(16,1)
ink rgb(200,0,0),0:set cursor 205,410:print stats#(1,1);"/";stats#(16,1)
else
ink white,0:set cursor 205,410:print stats#(1,1);"/";stats#(16,1)
endif
endif
endif
ink white,0
`Battle Timer system
BTimer#=BTimer#+sec#
set cursor 100,100:print BTimer#
`----------
`---Menu---
`----------
if menu = 1
center text 200,356,"Attack"
center text 320,2,"Select!"
center text 200,380, "Defend"
center text 200,404,"Special"
center text 200,428,"Magic"
center text 200,452,"Item"
if mousex() > 190 and mousex() < 220 and mousey() > 356 and mousey() < 366
ink blue,0:center text 200,356,"Attack"
if mouseclick()=1
`Movement
set object speed 1,10
play object 1,100,130
monstat(1)=monstat(1)-PBaseDmg#
sec#=1
menu=0
BTimer#=0
endif
else
ink white,0
Endif
if mousex() > 190 and mousex() < 220 and mousey() > 380 and mousey() < 390
ink blue,0:center text 200,380, "Defend"
if mouseclick()=1
menu=0
BTimer#=0
sec#=1
endif
else
ink white,0
endif
if mousex() > 190 and mousex() < 220 and mousey() > 404 and mousey() < 414
ink blue,0:center text 200,404,"Special"
if mouseclick()=1
printitem=0
printmag=0
printspec=1
if object exist(23)=0
make object plain 23,0.3,0.4
position object 23,0,-0.4,1
lock object on 23
endif
menu = 0
endif
else
ink white,0
endif
if mousex() > 190 and mousex() < 220 and mousey() > 428 and mousey() < 438
Ink blue,0:center text 200,428,"Magic"
if mouseclick()=1
printitem=0
printmag=1
printspec=0
if object exist(23)=0
make object plain 23,0.3,0.4
position object 23,0,-0.4,1
lock object on 23
endif
menu = 0
printmag=0
endif
else
ink white,0
endif
if mousex() > 190 and mousex() < 220 and mousey() > 452 and mousey() < 462
ink blue,0:center text 200,452,"Item"
if mouseclick()=1
printitem=1
printmag=0
printspec=0
if object exist(23)=0
make object plain 23,0.3,0.4
position object 23,0,-0.4,1
lock object on 23
endif
menu = 0
endif
if mousex() > 281 and mousex() < 320 and mousey() > 353 and mousey() < 363
Ink blue,0:center text 300,350, items$(1)
if mouseclick()=1
endif
endif
else
ink white,0
endif
else
ink white,0
printitem=0
endif
if printitem=1
ink white,0
center text 300,350, items$(1)
center text 300,365, items$(2)
center text 300,380, items$(3)
center text 300,395, items$(4)
center text 300,410, items$(5)
center text 300,425, items$(6)
endif
if printmag=1
ink white,0
center text 300,350, magic$(1)
center text 300,365, magic$(2)
center text 300,380, magic$(3)
center text 300,395, magic$(4)
center text 300,410, magic$(5)
center text 300,425, magic$(6)
endif
`Battle menu end
`--------------------
`-In Battle Enemy AI-
`--------------------
if menu = 0
Etimer#=Etimer#+1
If Etimer# > 100
Damage = (Monstat(2)-Stats#(8,1))
if damage < 1 then damage = 1
stats#(1,1) = stats#(1,1) - Damage
set cursor 300,200:print Damage
play object 100,50,75
if object exist(100) then loop object 100,50,75
Etimer#=0
endif
endif
If BTimer#>100
sec#=0
menu=1
If object exist(22)=0
make object plain 22,0.3,0.4
position object 22,-0.3,-0.4,1
lock object on 22
endif
else
menu=0
center text 320,2,"Wait!"
if object exist(22)=1 then delete object 22
if object exist(23)=1 then delete object 23
endif
`-------------
`Calculate Exp
`-------------
`Calculation system will be do later for calculating groups of enemys
monstat(10)=Exp
if monstat(1) < 1
stats#(12,1)=stats#(12,1)+Exp
if object exist(100)=1 then delete object 100
if object exist(20)=1 then delete object 20
if object exist(21)=1 then delete object 21
chase_cam(1)
goto loadloop
endif
if object exist(100)
loop object 100,0,50:set object speed 100,20
endif
`update the camera
battle_Cam(1)
ink rgb(36,35,24),0
box BTimer#+500,405,600,412
ink white,0
sync
loop
`---------
`chase cam
`---------
function chase_cam(id)
`work out the angle of the object being chased
yAng#=wrapvalue(object angle y(id)+180)
`grab the objects current position
stats#(13,1)=object position x(id)
stats#(14,1)=object position y(id)
stats#(15,1)=object position z(id)
`other variables
camDist=50
camHeight=25
`work out new position
xCamPos#=newxvalue(stats#(13,1),yAng#,camDist)
zCamPos#=newzvalue(stats#(15,1),yAng#,camDist)
`work out camera height
if yCamPos# < stats#(14,1)+camHeight then yCamPos#=stats#(14,1)+camHeight
`update camera position
position camera xCamPos#,yCamPos#,zCampos#
point camera stats#(13,1),stats#(14,1)+camHeight,stats#(15,1)
endfunction
`------------
`-Battle Cam-
`------------
function battle_cam(id)
CamAng#=255
`rotate camera downwards
xrotate camera 340
`work out the angle of the object being chased
yAng#=wrapvalue(object angle y(id)+CamAng#)
`grab the objects current position
stats#(13,1)=object position x(id)
stats#(14,1)=object position y(id)
stats#(15,1)=object position z(id)
`other variables
camDist=150
camHeight=50
`work out new position
xCamPos#=newxvalue(stats#(13,1),yAng#,camDist)
zCamPos#=newzvalue(stats#(15,1),yAng#,camDist)
`work out camera height
if matrix exist(1) then yCamPos#=get ground height(1,xCamPos#,zCamPos#)+camHeight
if yCamPos# < stats#(14,1)+camHeight then yCamPos#=stats#(14,1)+camHeight
`update camera position
position camera xCamPos#,yCamPos#,zCampos#
point camera stats#(13,1),stats#(14,1)+camHeight,stats#(15,1)+10
endfunction
Cheers Jozers
Life is like a box of chocolates...