|
Post by Enzo on Jul 14, 2020 19:30:29 GMT
ms = 100 time1 = time$("ms")
timer 60, [ms] wait
[ms] timer 0 time2 = time$("ms")
timerstatement = limiter(time2,time1,ms,buffer,timestatement)
print time2 - time1 print ms - (time2 - time1) print timerstatement
wait
Function limiter(time2,time1,ms,buffer,timestatement) if time2-time1 < ms then timestatement = ms-(time2-time1)+int(luck*3) else time2=time$("ms") if time2 - time1 > ms+buffer then timestatement = 17 end if limiter = timestatement end if End Function
Work prefectly, lol
|
|
|
Post by Enzo on Jul 14, 2020 19:34:19 GMT
Funny thing was it was working then I didnt change anything then it stopped working
|
|
|
Post by cundo on Jul 14, 2020 19:40:04 GMT
I use the timer as a pause, at the end of loops, like: [reDo] timer 0 code more code timer 56,[reDo] wait
|
|
|
Post by Enzo on Jul 14, 2020 19:44:28 GMT
Seemed to be a variable name mismatch even though I thought it was updating?
|
|
|
Post by Enzo on Jul 14, 2020 19:45:40 GMT
Working, updated; code
'credit to cundo for the framework, JustBASIC.proforums.com/ -2020 July 6th 'r]pg game base by Enzo
dim npc.x(100) dim npc.y(100) dim old.npc.x(100) dim old.npc.y(100) dim map$(100,100)
dim playerfiles$(100)
global playerfile$, downloadfile$, pid, PID, myPID, x, y, player.x, player.y, yes, debug, startup, frames, PIDid, command$, commandtype$, inputcommand$, playercount,_ playerpos$, ms, luck, buffer, null, map.x, map.y, screen.x, screen.y, TILESIZE, OFFSET, loopx, time, fps, base10, debugnull,_ set, playeraccuracy, skill, luck, health, currentplayercount, frames, timerstatement, timestatement, time1, time2,_ loopcount, id
base10=10
playeraccuracy = 10' 1 - 10 low-high skill = .9 ' .5 - .9 high level, .10 - .40 low level luck = .9 '.01-.99
seconds = 3 'desired debug run amount in seconds of 10 frames a second
health = 100 player(2,2) = health'input from file on server-client 'function for loading health from playerfiles
null = 0 id = 2 'set max hit calculated by point system divided 'set = skill * 7 'unsed
buffer = 10 'ms buffer to bad loop yes = 1 '1 operator for debug startup = 1
ms = 100 'for timerloop (1000/ms)
frames = 10 'desired fps; actual fps may very use 'display() = fps()' function to find fps
playerfile$="player" downloadfile$=playerfile$ 'attribute to files, will add "offline" to name if player is not online 'offline$="OFFLINE" not used currently
'NOMAINWIN
'basic gui data below, using on screen sprites for icons for menus TILESIZE = 64 : SCREENWIDTH = 11 : SCREENHEIGHT = 8 : OFFSET = TILESIZE GAMEWIDTH = SCREENWIDTH*TILESIZE-TILESIZE*2+64 GAMEHEIGHT = SCREENHEIGHT*TILESIZE-TILESIZE*2 WindowWidth = GAMEWIDTH : WindowHeight = GAMEHEIGHT+100 : BackgroundColor$ = "BLACK" UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2) button #main.bmpbutton, "bmp", [bmp], UL, 10, 10 'load bmp file to game import as new sprite uploadsprite() graphicbox #main.gbx, 64, 0,GAMEWIDTH , GAMEHEIGHT textbox #main.textbox, 14, 400, 352, 25 'not sure where text will be displayed currently saving for last open "r]pg - client" for window_nf as #main #main.gbx "down; fill BLACK; flush" #main "trapclose [quit.main]" #main.gbx "Getbmp empty.bmp 1 1 ";TILESIZE;" ";TILESIZE*2
[splashscreen] confirm "debug = 1 (yes)?";answer$ if answer$ = "yes" then debugnull = 1 end if
'splashscreen()
'loadbmp display loading bar_ '1%
'5% [0] 'import screen objects sprites for menus
[1a]'tile import -10%'loading bar noftication for start splash screen tile.list$ = "dirt water grass rock sand" For i = 1 To 5 loadbmp left$(word$(tile.list$,i),1);".bmp",word$(tile.list$,i);".bmp" #main.gbx "drawbmp ";left$(word$(tile.list$,i),1);".bmp 1 ";TILESIZE+1;" ; ";_ "Getbmp ";left$(word$(tile.list$,i),1);".bmp 1 1 ";TILESIZE;" ";TILESIZE*2 Next [2b]'user/player files -20%'loading bar noftication for start splash screen player.list$ = "1.bmp 2.bmp 3.bmp 4.bmp ";_ "5.bmp 6.bmp 7.bmp 8.bmp" For i = 1 To 8 loadbmp "player";i;".bmp", Word$(player.list$,i) Next [3c]'start int -30%'loading bar noftication for start splash screen #main.gbx "setfocus;" ;_ "When characterInput [keys]; ";_ "Getbmp back.bmp 1 1 10 10;" ;_ "Background back.bmp;" ;_ "DRAWSPRITES" [4d] '40%'loading bar noftication for start splash screen OPEN "map.txt" For input AS #mapfile
While not(eof(#mapfile)) line input #mapfile, itemdata$ id$=trim$(itemdata$) if left$(id$,1)<>"'" and id$<>"" Then Select case case instr(id$,"width") map.width = val( trim$(word$(id$,2,"="))) case instr(id$,"height") map.height = val( trim$(word$(id$,2,"="))) case instr(id$,"playerX") player.x = val( trim$(word$(id$,2,"="))) case instr(id$,"playerY") player.y = val( trim$(word$(id$,2,"="))) case instr(id$,"others") npc.n = val( trim$(word$(id$,2,"="))) IF npc.n>0 Then DIM npc.x(npc.n),npc.y(npc.n) DIM old.npc.x(npc.n),old.npc.y(npc.n) For L = 1 To npc.n line input #mapfile, id$ npc.sprite.name$(L) = WORD$(id$,1,";") npc.bmp.name$(L) = WORD$(id$,2,";") npc.x(L) = val(TRIM$(WORD$(id$,3,";"))) npc.y(L) = val(TRIM$(WORD$(id$,4,";"))) old.npc.x(L) = npc.x(L): old.npc.y(L) = npc.y(L) 'PRINT npc.bmp.name$ Next L End if case else DIM map$(map.width,map.height)
For y = 1 To map.height
For x = 1 To map.width
map$(x,y) = TRIM$(word$(id$,x,",")) 'PRINT map$(x,y) Next line input #mapfile, id$ if instr(id$,"END") Then exit FOR Next
end select End if Wend Close #mapfile
[5e] '60%'loading bar noftication for start splash screen ' 10 * 7 DIM tile(SCREENWIDTH*SCREENHEIGHT,2) for h = 1 To SCREENHEIGHT for w = 1 To SCREENWIDTH obj=obj+1 #main.gbx "addsprite obj";obj;" empty.bmp d.bmp w.bmp g.bmp r.bmp s.bmp" tile(obj,1)=w tile(obj,2)=h next:next [6f] #main.gbx "addsprite player player1.bmp player2.bmp player3.bmp";_ " player4.bmp player5.bmp player6.bmp player7.bmp player8.bmp ;";_ "spritexy player ";player.x*TILESIZE-TILESIZE-OFFSET;" ";player.y*TILESIZE-TILESIZE-OFFSET [7g] '70%'loading bar noftication for start splash screen if npc.n Then For L = 1 To npc.n loadbmp npc.bmp.name$(L),npc.bmp.name$(L) #main.gbx "addsprite ";npc.sprite.name$(L);" ";npc.bmp.name$(L) #main.gbx "spritexy ";npc.sprite.name$(L);" ";npc.x(L)*TILESIZE-TILESIZE-OFFSET;_ " ";npc.y(L)*TILESIZE-TILESIZE-OFFSET
Next End if [8h] '80% currentplayercount = playercount(startup)'move to below : [m] timer 0 : for cycling in new players [9i] '100% 'loading bar noftication for start splash screen '100% loading bar 'keeping 0-5 and 95-100 by line input gives a giveaway to where error if any 'close splashscreen()
timer 21, [reDo] 'pause for timer 0
wait
[timer] null = null [reDo] Timer 0 [branch] loopx = loopx + 1 clientloop = clientloop + 1 if clientloop = frames*seconds then 'frames = 10 FPS, refer fps() for actual fps clientloop = 0
debug = 2:null = debug(debug)
timer 1000*seconds, [timer] wait
' text=loadtext() 'load text once per second end if
time1 = time$("ms")
printf = fps(fps,time1,loopx)
currentplayercount = playercount(null)'
debug = 3:null = debug(debug)
for PID = 1 to currentplayercount 'download every users file of "XX YY" 'add more data here cache$ = downloadplayerfile$(PID) 'function downloads pid file and updates npc.x(pid) npc.y(pid) playerfiles$(PID) = cache$ next PID 'next playercount loop
now = uploadtolan()
gosub [moveMap] player.y = player.y + INT(screen.y) map.y = map.y + INT(screen.y) player.x = player.x + INT(screen.x) map.x = map.x + INT(screen.x)
updateXY$ = playerpos$(player.x,player.y)
if abs(screen.y)>=1 Then screen.y = 0 if abs(screen.x)>=1 Then screen.x = 0 #main.gbx "DRAWSPRITES"
time2 = time$("ms")
timestatement = limiter(time2,time1,ms,buffer,timestatement)
debug = 5:null = debug(debug) debug = 4:null = debug(debug) TIMER timestatement,[reDo] ' 1 game tic = ms WAIT
[moveMap] for i =1 To obj SCAN'this might allow for extra input, not desired on metered game w = tile(i,1) h = tile(i,2)
if walk.val<1 Then
#main.gbx "Spritexy obj";i;" ";_ w*TILESIZE-TILESIZE - (screen.x*TILESIZE) - OFFSET; " ";_ h*TILESIZE-TILESIZE - (screen.y*TILESIZE) - OFFSET
End if
If map.x+w< map.width AND map.x+w>0 AND _ map.y+h < map.height AND map.y+h>0 Then
#main.gbx "SpriteImage obj";i;" "; map$(w+map.x,h+map.y);".bmp"
For L=1 to pid
#main.gbx "spritexy ";npc.sprite.name$(L);" ";_ (npc.x(L)-map.x-screen.x)*TILESIZE-TILESIZE - OFFSET ;" ";_ (npc.y(L)-map.y-screen.y)*TILESIZE-TILESIZE - OFFSET
NEXT L Else ' set the tiles to an empty image
#main.gbx "SpriteImage obj";i;" empty.bmp"
End if Next RETURN [attack] Timer 0 #main.gbx "When characterInput"
probabilityvariable = rnd(10)*10 + playeraccuracy + luck * base10 'rnd with positive additive of player trained skill variable = probabilityvariable if variable > base10 then 'adds bonus if exptionale accurate, directly from the RND for realisitic play hitbonus = 10 - variable '10 point buffer for allowing not to powerful end if if variable < 5 then 'see if 50/50 with accuracy added(max up to 1 to 13-29 "i think") gives hit or not print "miss" goto [branch] end if
hit = int(rnd(10)*10)*10+ int(rnd(10)*10)*base10 + hitbonus 'basically grabs postive handi capped "55+" RND adds bonus if accuracy is expectionale accurate over 100, to the handicap with a max of unknown, this gives base 55+/45- type RND sets, allowing for a positive gameplay without "sluggish" hits then times this number by your decimcal (skill level * 7) and divides by 3, this part is hard to explain how it linearized RND to be RND still, it just is because the seed is RND, now out of 100 this is not random, there is a positive value frequency to this code as stated before hit = hit*skill hit = hit / 3 + (luck + skill)
'add a little 'luck' here players will gain small amount of luck thru out game and its added to a hidden hit value that could "stack" or add up after every hit if hit < 1 then hit = 5*luck*luck end if debug = 8:null=debug(debug)
#main.gbx "When characterInput [keys]" goto [branch]
[keys] Timer 0 #main.gbx "When characterInput"
k$ = Inkey$ keyValue = asc(right$(k$, 1)) walk.val = .5'adds stepped input
select case keyValue
case _VK_DOWN
if player.y + 1 < map.height Then new.pos$ = map$(player.x,player.y+1) If new.pos$<>"r" and new.pos$ <>"w" Then screen.y = screen.y + walk.val Else screen.y=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";1+spi;".bmp" 'pidid End if
case _VK_UP
if player.y - 1 >0 Then new.pos$=map$(player.x,player.y-1) If new.pos$<>"r" and new.pos$ <>"w" Then screen.y = screen.y - walk.val Else screen.y=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";3+spi;".bmp" 'pidid End if case _VK_LEFT if player.x - 1 > 0 Then new.pos$ = map$(player.x-1,player.y) If new.pos$<>"r" and new.pos$ <>"w" Then screen.x = screen.x - walk.val Else screen.x = 0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";5+spi;".bmp" 'pidid End if case _VK_RIGHT if player.x +1 < map.width Then new.pos$ = map$(player.x+1,player.y) If new.pos$<>"r" and new.pos$ <>"w" Then screen.x = screen.x + walk.val Else screen.x=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";7+spi;".bmp" 'PIDid End if
case _VK_ESCAPE '[escape] to quit or [trapclose] goto [quit.main]
case _VK_INSERT 'attack goto [attack]
case _VK_CONTROL 'chat input CTRL instead of ENTER"
print #main.textbox, "!contents? textchat$"; print #main.textbox, "!disable" outputchat$ = textchat$ PRINT #Main.textbox, "sending...." send = loadtext(outputchat$) print #main.textbox, "" if debug = 1 then 'debug for adding tiles print #main.textbox, "~" check$ = commands$(outputchat$) else check$ = commands$(outputchat$) end if print #main.textbox, "!enable" 'admin commands restyled into funtionableility
end select #main.gbx "When characterInput [keys]" GOTO [reDo]
WAIT
'------------------------------------------------------------------------ '------------------------------------------------------------------------
[bmp] WindowWidth = 168 WindowHeight = 140 graphicbox #bmp.sixfour, 6, 6, 64, 64 statictext #bmp.credit1, "Credit to cundo", 6, 76, 144, 20 statictext #bmp.credit2, "JB forums", 6, 91, 144, 20 statictext #bmp.credit3, "JustBASIC 2.0", 70, 91, 144, 20 open "Add .bmp file to game" for dialog_nf_modal as #bmp print #bmp.sixfour,"down; fill white; flush" print #bmp, "trapclose [quit.bmp]" print #bmp, "font ms_sans_serif 10" [startbmpdialog] FILEDIALOG "Open & add new .bmp to game!", "*.bmp", bmpfile$ 'display bmp if bmpfile$="" then confirm "Close bmp upload?";yesno$ if yesno$ = "yes" then goto [quit.bmp] else goto [startbmpdialog] end if end if
yesno$=""'reset
confirm "Keep .BMP?"; yesno$ if yesno$ = "no" then goto [quit.bmp] else 'turn into sprite 'add to new tile data array 'wait for admin command to change value '~map XXYY aVar$ = command$ end if
debug = 6:null = debug(debug)
[quit.bmp] Close #bmp goto [reDo]
[quit.main] unloadbmp "back.bmp" unloadbmp "empty.bmp" for i = 1 To 5 unloadbmp left$(word$(tile.list$,i),1);".bmp" Next for i = 1 TO 8 unloadbmp "player";i;".bmp" next
'if npc.n Then FOr L = 1 To npc.n unloadbmp npc.bmp.name$(L) NExt 'End if
Close #main END
'------------------------------------------------------------------------ '------------------------------------------------------------------------ ' ' Functions '------------------------------------------------------------------------ Function limiter(time2,time1,ms,buffer,timestatement) if time2-time1 < ms then timestatement = ms-(time2-time1)+int(luck*3) limiter = timestatement end if End Function
Function playercount(startup) 'gets current player count and updates if startup = yes then open playerfile$+".txt" for input as #1 'open playercount file needs to have starting data of a single "0" zero count$ = input$(#1,lof(#1)) playercount = val(count$) playercount = playercount + 1 close #1
'add satefy for adding new file filecheck() to not allow new user until files been appeneded
PID = playercount 'keep track of position in file or clients PID myPID = PID 'duplicate variable for <> loops of PID
open playerfile$+".txt" for append as #playercount print #playercount, myPID close #playercount else open playerfile$+".txt" for input as #2 'open playercount file count$ = input$(#2,lof(#2)) playercount = val(count$) close #2 end if
npc.n = playercount
End Function
Function uploadtolan() open playerfile$+str$(PID);".txt" for output as #outputupload print #outputupload, playerpos$ close #outputupload uploadtolan = 1 End Function
Function downloadplayerfile$(pid) if pid <> myPID then string$ = downloadfile$+str$(pid);"A.txt" open string$ for input as #download 'open file by player log in order ID or PID playerpagefile$ = input$(#download,lof(#download)) downloadplayerfile$=playerpagefile$ 'read line close #download npcx=val(left$(downloadplayerfile$,1)) npcy=val(right$(downloadplayerfile$,1)) npc.x(pid) =npcx npc.y(pid) =npcy end if End Function
Function loadanimations() 'search playerfiles$() for animation tag character 'display x y starts and stops 'step program thru loop 8 frames; (4) animation frames twice per theoretical slowed down second 1000ms / 8 'count 'aninum = count ' readnow= loadanimations() 'for ani = 0 to readnow ' print #w.g, "addsprite ";animation$;" "animation1$;" ";animation2$;" "animation3$ ' print #w.g, "cyclesprite ";animation$;" 1" ' print #w.g, "spritemovexy ";animation$;" 4 0" ' loadnanimations = aninum End Function
function playerpos$(player.x,player.y) 'updates player position into string$ for output to be downloaded by pid playerpos$=str$(player.x);" ";str$(player.y)
debug = 7:null = debug(debug)
end function
Function loadtext(textchat$) if textchat$ <> "" then open "text.txt" for output as #uploads print #uploads, time$("ms");" ";textchat$ close #uploads end if End Function
'commands Function commands$(inputcommand$) 'EXAMPLE: ~map/npc/oject 0X 0Y refID$ ctrl$ = "~" 'COMMAND KEY INT. -> "~" if left$(outputchat$, 1) = ctrl$ then commands = commands + 1 'keep track of commands commandsarray$(commands) = word$(outputchat$,2) commandtype$ = commandsarray$(commands) xmap= val(left$(inputmap$, 2)) ymap= val(right$(inputmap$, 2)) mapcommandtile$ = word$(outputchat$, 3) print ":COMMANDISSUED:SET>";left$(outputchat$, 4);" ";val(left$(inputmap$, 2));" ";val(right$(inputmap$, 2));"<"; word$(outputchat$,3) ;">tileRefID$: "
select case commandtype$ case "map" map$(xmap,ymap)=mapcommandtile$ 'actual input line command here case "npc", "object" 'npc object commands end select
commands$=commandtype$ 'for ref end if End Function
Function fps(fps,time,loopx) 'print #main.gbx, "/text fps(";int(actualfps) End Function
Function debug(debug) if debugnull = 1 then select case debug
case 2 notice frames;" x ";seconds;" seconds / frames (Double Click) [ENTER]" notice "Continue [enter]" 'pause break case 3 print currentplayercount;" current player count" case 4 print (time2-time1);" ms game compiled frame in, ";timestatement;" lag/wait until next frame" timerstatement = timerstatement' - buffer case 5 timerstatement = timerstatement + 1000 * seconds ' wait for debug next frame case 6 print "closing for now 0% upload not featured in code yet" case 7 print playerpos$ 'debug case 8 print hit case 9 notice "null not used case 9"
end select end if End Function
|
|
|
Post by Enzo on Jul 14, 2020 20:38:43 GMT
Did some more updating, it seems I do have a file error on multiple opens, my fix is to add more files for each PID and shell like commands to update instead of a transfer file, does anyone think this isn't the right way to go?
as in it was like open/run "libertyapp.tkn var1 var2 var3"
|
|
|
Post by cundo on Jul 14, 2020 20:54:21 GMT
What kind of error? a JB error? a workaround would be to catch the Error: "on error goto"
|
|
|
Post by Enzo on Jul 14, 2020 20:57:02 GMT
What kind of error? a JB error? a workaround would be to catch the Error: "on error goto" Gave a #handle error, I could slow everything down to a 200ms-400ms loop I bet it would still work Is it not possible to excute more then one command onto a .tkn
|
|
|
Post by cundo on Jul 17, 2020 1:47:53 GMT
Which one is the latest version? I was playing with the 2.1 zip file contents. I added a timerstatement default value because it was crashing due to a "#word expected error".
|
|
|
Post by Enzo on Jul 17, 2020 23:06:39 GMT
Sorry for the bad code upload, again, but here's; a fresh update off the compile button, guaranteed to work Check debug list at bottom of code first for quicker understanding Attachments:2.2.bas (19.85 KB)
|
|
|
Post by Enzo on Oct 27, 2020 21:15:10 GMT
ibb.co/G2Cs41P ibb.co/DDyF0qh
Graphical mockup update
|
|
|
Post by Enzo on Oct 30, 2020 2:59:33 GMT
Updated alpha code, ready to finalizations
Note currently some strings are variables vise versa, i.e itemselected or selected$
'credit to cundo for the framework, JustBASIC.proforums.com/ -2020 October 29th 9PM 'r]pg game base by Enzo
global MAPX, MAPY, totalitems, objcount, div, clientcount clientcount = 10 'number of max clients MAPX=100:MAPY=100:totalitems=10:objcount=10:div=2 '5 sprites of 10 images each
dim npc.x(100) dim npc.y(100) dim old.npc.x(100) dim old.npc.y(100) dim map$(MAPX,MAPY)
dim room(3) room(1) = 1 room(2) = 2 room(3) = 3
'dim mapitems(MAPX,MAPY) dim item(totalitems,3) '1 =unsed 2=type 3=unsed dim itemdisplay(totalitems, 2)
dim objdisplay(objcount, 2) dim objdisplay2(objectcount, 2)
dim inventory(8) dim bank(10)
dim specialattack(4)
dim playerfiles$(clientcount, 2)
global playerfile$, downloadfile$, pid, PID, myPID, x, y, player.x, player.y, yes, debug, startup, frames, PIDid, command$, commandtype$, inputcommand$, playercount,_ playerpos$, ms, luck, buffer, null, map.x, map.y, screen.x, screen.y, TILESIZE, OFFSET, loopx, time, fps, base10, debugnull,_ set, playeraccuracy, skill, luck, health, currentplayercount, frames, timerstatement, timestatement, time1, time2,_ loopcount, id, clickms, npc.n global MouseX, MouseY, TileX, TileY,_ Bankspace, currentbankcount, inventory, selected,_ mana, magicklevel, specialbar, specialtimer, attacktimer, defendtimer,_ lastselected$,selecteditem$, selected$, action$,_ attack, defend, attacktimer, defendtimer, defend1, defend2, attacktime1, attacktime2,_ combines, combinations
base10=10
combinations = 10
npcname$ = "player.bmp"' add to keys after
playeraccuracy = 10' 1 - 10 low-high skill = .9 ' .5 - .9 high level, .10 - .40 low level luck = .9 '.01-.99
seconds = 3 'desired debug run amount in seconds of 10 frames a second
health = 100 player(1,2) = health player(2,2) = health'input from file on server-client 'function for loading health from playerfiles
null = 0 id = 2 'set max hit calculated by point system divided 'set = skill * 7 'unsed
buffer = 10 'ms buffer to bad loop yes = 1 '1 operator for debug startup = 1
ms = 950 'for timerloop (1000/ms)
frames = 10 'desired fps; actual fps may very use 'display() = fps()' function to find fps
playerfile$="player" downloadfile$=playerfile$+"A" 'attribute to files, will add "offline" to name if player is not online 'offline$="OFFLINE" not used currently
'NOMAINWIN
'basic gui data below, using on screen sprites for icons for menus TILESIZE = 64 : SCREENWIDTH = 11 : SCREENHEIGHT = 8 : OFFSET = TILESIZE GAMEWIDTH = SCREENWIDTH*TILESIZE-TILESIZE*2+64 GAMEHEIGHT = SCREENHEIGHT*TILESIZE-TILESIZE*2 WindowWidth = GAMEWIDTH : WindowHeight = GAMEHEIGHT+100 : BackgroundColor$ = "BLACK" UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2) button #main.bmpbutton, "bmp", [bmp], UL, 10, 10 'load bmp file to game import as new sprite uploadsprite() graphicbox #main.gbx, 64, 0,GAMEWIDTH , GAMEHEIGHT textbox #main.textbox, 14, 400, 352, 25 'not sure where text will be displayed currently saving for last open "r]pg - client" for window_nf as #main #main.gbx "down; fill BLACK; flush" #main "trapclose [quit.main]" #main.gbx "Getbmp empty.bmp 1 1 ";TILESIZE;" ";TILESIZE*2
[splashscreen] confirm "debug = 1 (yes)?";answer$ if answer$ = "yes" then debugnull = 1 end if
'splashscreen()
'loadbmp display loading bar_ '1%
'5% [0] 'import screen objects sprites for menus
[1a]'tile import -10%'loading bar noftication for start splash screen tile.list$ = "dirt water grass rock sand" For i = 1 To 5 loadbmp left$(word$(tile.list$,i),1);".bmp",word$(tile.list$,i);".bmp" #main.gbx "drawbmp ";left$(word$(tile.list$,i),1);".bmp 1 ";TILESIZE+1;" ; ";_ "Getbmp ";left$(word$(tile.list$,i),1);".bmp 1 1 ";TILESIZE;" ";TILESIZE*2 Next [2b]'user/player files -20%'loading bar noftication for start splash screen player.list$ = "1.bmp 2.bmp 3.bmp 4.bmp ";_ "5.bmp 6.bmp 7.bmp 8.bmp" For i = 1 To 8 loadbmp "player";i;".bmp", Word$(player.list$,i) Next [3c]'start int -30%'loading bar noftication for start splash screen #main.gbx "setfocus;" ;_ "When characterInput [keys]; ";_ "Getbmp back.bmp 1 1 10 10;" ;_ "Background back.bmp;" ;_ "DRAWSPRITES" [4d] '40%'loading bar noftication for start splash screen OPEN "map.txt" For input AS #mapfile
While not(eof(#mapfile)) line input #mapfile, itemdata$ id$=trim$(itemdata$) if left$(id$,1)<>"'" and id$<>"" Then Select case case instr(id$,"width") map.width = val( trim$(word$(id$,2,"="))) case instr(id$,"height") map.height = val( trim$(word$(id$,2,"="))) case instr(id$,"playerX") player.x = val( trim$(word$(id$,2,"="))) case instr(id$,"playerY") player.y = val( trim$(word$(id$,2,"="))) case instr(id$,"others") npc.n = val( trim$(word$(id$,2,"="))) IF npc.n>0 Then DIM npc.x(npc.n),npc.y(npc.n) DIM old.npc.x(npc.n),old.npc.y(npc.n) For L = 1 To npc.n line input #mapfile, id$ npc.sprite.name$(L) = WORD$(id$,1,";") npc.bmp.name$(L) = WORD$(id$,2,";") npc.x(L) = val(TRIM$(WORD$(id$,3,";"))) npc.y(L) = val(TRIM$(WORD$(id$,4,";"))) old.npc.x(L) = npc.x(L): old.npc.y(L) = npc.y(L) 'PRINT npc.bmp.name$ Next L End if case else DIM map$(map.width,map.height)
For y = 1 To map.height
For x = 1 To map.width
map$(x,y) = TRIM$(word$(id$,x,",")) 'PRINT map$(x,y) Next line input #mapfile, id$ if instr(id$,"END") Then exit FOR Next
end select End if Wend Close #mapfile
[5e] '60%'loading bar noftication for start splash screen ' 10 * 7 DIM tile(SCREENWIDTH*SCREENHEIGHT,2) for h = 1 To SCREENHEIGHT for w = 1 To SCREENWIDTH obj=obj+1 #main.gbx "addsprite obj";obj;" empty.bmp d.bmp w.bmp g.bmp r.bmp s.bmp" tile(obj,1)=w tile(obj,2)=h next:next [6f] #main.gbx "addsprite player player1.bmp player2.bmp player3.bmp";_ " player4.bmp player5.bmp player6.bmp player7.bmp player8.bmp ;";_ "spritexy player ";player.x*TILESIZE-TILESIZE-OFFSET;" ";player.y*TILESIZE-TILESIZE-OFFSET [7g] '70%'loading bar noftication for start splash screen if npc.n Then For L = 1 To npc.n loadbmp npc.bmp.name$(L),npc.bmp.name$(L) #main.gbx "addsprite ";npc.sprite.name$(L);" ";npc.bmp.name$(L) #main.gbx "spritexy ";npc.sprite.name$(L);" ";npc.x(L)*TILESIZE-TILESIZE-OFFSET;_ " ";npc.y(L)*TILESIZE-TILESIZE-OFFSET
Next End if [8h] '80% currentplayercount = playercount(startup)'move to below : [m] timer 0 : for cycling in new players [9i] '100% 'loading bar noftication for start splash screen '100% loading bar 'keeping 0-5 and 95-100 by line input gives a giveaway to where error if any 'close splashscreen()
timer 50, [reDo] 'pause only for timer 0 at top of client branch function
wait
[timer] null = null
[reDo]
Timer 0 [branch] loopx = loopx + 1 clientloop = clientloop + 1
if clientloop = frames*seconds then 'frames = 10 FPS, refer fps() for actual fps clientloop = 0
debug = 2:null = debug(debug)
timer 1000*seconds, [timer] wait
' text=loadtext() 'load text once per second end if
time1 = time$("ms")
printf = fps(fps,time1,loopx)
currentplayercount = playercount(null)'
debug = 3:null = debug(debug)
for PID = 1 to currentplayercount 'download every users file of "XX YY" 'add more data here cache$ = downloadplayerfile$(PID) 'function downloads pid file and updates npc.x(pid) npc.y(pid) playerfiles$(PID) = cache$ next PID 'next playercount loop
gosub [moveMap] player.y = player.y + INT(screen.y) map.y = map.y + INT(screen.y) player.x = player.x + INT(screen.x) map.x = map.x + INT(screen.x)
updateXY$ = playerpos$(player.x,player.y) now$ = uploadtolan$(updateXY$,healthnull)
if abs(screen.y)>=1 Then screen.y = 0 if abs(screen.x)>=1 Then screen.x = 0 #main.gbx "DRAWSPRITES"
time2 = time$("ms")
timestatement = limiter(time2,time1,ms,buffer,timestatement)
debug = 5:null = debug(debug) debug = 4:null = debug(debug) TIMER timestatement, [reDo] ' 1 game tic = ms WAIT
[moveMap] for i =1 To obj SCAN'this might allow for extra input, not desired on metered game w = tile(i,1) h = tile(i,2)
if walk.val<1 Then
#main.gbx "Spritexy obj";i;" ";_ w*TILESIZE-TILESIZE - (screen.x*TILESIZE) - OFFSET; " ";_ h*TILESIZE-TILESIZE - (screen.y*TILESIZE) - OFFSET
End if
If map.x+w< map.width AND map.x+w>0 AND _ map.y+h < map.height AND map.y+h>0 Then
#main.gbx "SpriteImage obj";i;" "; map$(w+map.x,h+map.y);".bmp"
For L=1 to pid
#main.gbx "spritexy ";npc.sprite.name$(L);" ";_ (npc.x(L)-map.x-screen.x)*TILESIZE-TILESIZE - OFFSET ;" ";_ (npc.y(L)-map.y-screen.y)*TILESIZE-TILESIZE - OFFSET
NEXT L Else ' set the tiles to an empty image
#main.gbx "SpriteImage obj";i;" empty.bmp"
End if Next RETURN [attack] Timer 0 #main.gbx "When characterInput"
probabilityvariable = rnd(10)*10 + playeraccuracy + luck * base10 'rnd with positive additive of player trained skill variable = probabilityvariable if variable > base10 then 'adds bonus if exptionale accurate, directly from the RND for realisitic play hitbonus = 10 - variable '10 point buffer for allowing not to powerful end if if variable < 5 then 'see if 50/50 with accuracy added(max up to 1 to 13-29 "i think") gives hit or not print "miss" goto [branch] end if debug=101:null=debug(debug) hit = int(rnd(10)*10)*10+ int(rnd(10)*10)*base10 + hitbonus 'basically grabs postive handi capped "55+" RND adds bonus if accuracy is expectionale accurate over 100, to the handicap with a max of unknown, this gives base 55+/45- type RND sets, allowing for a positive gameplay without "sluggish" hits then times this number by your decimcal (skill level * 7) and divides by 3, this part is hard to explain how it linearized RND to be RND still, it just is because the seed is RND, now out of 100 this is not random, there is a positive value frequency to this code as stated before hit = hit*skill hit = hit / 3 + (luck + skill)
'add a little 'luck' here players will gain small amount of luck thru out game and its added to a hidden hit value that could "stack" or add up after every hit if hit < 1 then hit = 5*luck*luck end if debug = 8:null=debug(debug)
#main.gbx "When characterInput [keys]" goto [branch]
[keys] Timer 0 #main.gbx "When characterInput"
k$ = Inkey$ keyValue = asc(right$(k$, 1)) walk.val = .5'adds stepped input
select case keyValue
case _VK_DOWN
if player.y + 1 < map.height Then new.pos$ = map$(player.x,player.y+1) If new.pos$<>"r" and new.pos$ <>"w" Then screen.y = screen.y + walk.val Else screen.y=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";1+spi;".bmp" 'pidid End if
case _VK_UP
if player.y - 1 >0 Then new.pos$=map$(player.x,player.y-1) If new.pos$<>"r" and new.pos$ <>"w" Then screen.y = screen.y - walk.val Else screen.y=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";3+spi;".bmp" 'pidid End if case _VK_LEFT if player.x - 1 > 0 Then new.pos$ = map$(player.x-1,player.y) If new.pos$<>"r" and new.pos$ <>"w" Then screen.x = screen.x - walk.val Else screen.x = 0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";5+spi;".bmp" 'pidid End if case _VK_RIGHT if player.x +1 < map.width Then new.pos$ = map$(player.x+1,player.y) If new.pos$<>"r" and new.pos$ <>"w" Then screen.x = screen.x + walk.val Else screen.x=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";7+spi;".bmp" 'PIDid End if
case _VK_ESCAPE '[escape] to quit or [trapclose] goto [quit.main]
case _VK_INSERT 'attack goto [attack]
case _VK_CONTROL 'chat input CTRL instead of ENTER"
print #main.textbox, "!contents? textchat$"; print #main.textbox, "!disable" outputchat$ = textchat$ print #main.textbox, "PRINT #M lol nato sending...." send = loadtext(outputchat$) print #main.textbox, "" if debug = 1 then 'debug for adding tiles print #main.textbox, "~" check$ = commands$(outputchat$) else check$ = commands$(outputchat$) end if print #main.textbox, "!enable" 'admin commands restyled into funtionableility
end select #main.gbx "When characterInput [keys]" GOTO [reDo]
WAIT
'------------------------------------------------------------------------ '------------------------------------------------------------------------
[quit.bmp] Close #bmp goto [reDo]
[quit.main] unloadbmp "back.bmp" unloadbmp "empty.bmp" for i = 1 To 5 unloadbmp left$(word$(tile.list$,i),1);".bmp" Next for i = 1 TO 8 unloadbmp "player";i;".bmp" next
'if npc.n Then FOr L = 1 To npc.n unloadbmp npc.bmp.name$(L) NExt 'End if
Close #main END
'------------------------------------------------------------------------ '------------------------------------------------------------------------ ' ' Functions '------------------------------------------------------------------------
Function mousehandler(MouseX, MouseY) TileXY$ = MouseXY.Tilefinder$(MouseX, MouseY)
clickarea$ = left$(TileXY$,1)
selected$=right$(TileXY$,2)
pos$ = right$(TileXY$,1);" ";right$(TileXY$,2) pos = val(pos$)
select case clickarea$
case "inventory" return$ = inventory.handler$(selected$, pos)
case "special" reset$ = click$(lastselected$, selected$) 'spec=special()
case "four tiles"
'check rotation, 'pickup(selected,pos) 'activate(lastselected$) 'goto [attack] case else reset$ = click$(lastselected$, selected$) end select
End Function
function click$(lastselected$,selected$) lastselected$="" selected$="" 'stopcombat() end function
Function activate(pos) obj = room(pos) End Function
Function pickup(selected$, pos) func = deleteitem(selected$, pos)
null = null 'prevent from double pickup null = null
func = newitem(selected) End function
Function deleteitem(selected$, pos) ' TileX = val(left$(pos,1) ' TileY = val(right$(pos,2)) mapitems(TileX,TileY)=null End Function
Function newitem(selected) for inventoryslot = 1 to 10 if inventory(inventoryslot) <> null then null = null else inventory(inventoryslot) = selected end if 'make sure draw sprites command renews graphics next inventoryslot End Function
Function attack(attacktimer, attacktime1, attacktime2)'via button
End Function
Function defend(defendtimer, defend1, defend2)'via space bar or key
End Function
Function special(specialbar) 'mouse click
End Function
Function inventory.handler$(selected$, pos) selecteditem = inventory(pos) 'retur = item.handler(selecteditem) End Function
Function bank()
End Function
Function item.handler(selecteditem) parser = parse(selecteditem)' find item type id if parser = 2 then 'DELETE ITEM, ADD HEALTH end if if lastselected$ = "" then lastselectede$ = selecteditem$ selecteditem$ = "" else if item(selecteditem,2) = item(lastselected,2) then 'deleteitem(1) 'deleteitem(2)
new = val(selecteddone$) retur = newitem(new) end if end if End Function
Function parse(selecteditem) parse = item(selecteditem,2) End Function
Function MouseXY.Tilefinder$(MouseX, MouseY) 'get mouse sx mouse y input prase through the 8 inventory post four tiles around player, special bar 'select case <> for each area 'return as three part string item position area string$ End Function
Function limiter(time2,time1,ms,buffer,timestatement) if time2-time1 < ms then timestatement = ms-(time2-time1)+int(luck*3) limiter = timestatement end if End Function
Function playercount(startup) 'gets current player count and updates if startup = yes then open playerfile$+".txt" for input as #1 'open playercount file needs to have starting data of a single "0" zero count$ = input$(#1,lof(#1)) playercount = val(count$) playercount = playercount + 1 close #1
'add satefy for adding new file filecheck() to not allow new user until files been appeneded
PID = playercount 'keep track of position in file or clients PID myPID = PID 'duplicate variable for <> loops of PID
open playerfile$+".txt" for append as #playercount print #playercount, myPID close #playercount
else 'regular loop
open playerfile$+".txt" for input as #2 'open playercount file count$ = input$(#2,lof(#2)) playercount = val(count$) close #2 end if
npc.n = playercount
End Function
Function uploadtolan$(playerpos$,healthnull) open playerfile$+str$(PID);".txt" for output as #outputupload print #outputupload, playerpos$;" ";npcname$ close #outputupload uploadtolan = 1 End Function
Function downloadplayerfile$(pid) if pid <> myPID then string$ = downloadfile$+str$(pid);".txt" open string$ for input as #download 'open file by player log in order ID or PID playerpagefile$ = input$(#download,lof(#download)) downloadplayerfile$=playerpagefile$ 'read line close #download npcx=val(left$(downloadplayerfile$,1)) npcy=val(right$(downloadplayerfile$,3)) ' npcname$ = right$(downloadplayerfile$,2) ' heathnull = val(right$(downloadplayerfile$,1)) 'hit npc.x(pid) =npcx 'update game data here npc.y(pid) =npcy 'npc.name$(npcx,npcy) = npcname$ 'health 'hit
end if End Function
Function loadanimations() 'search playerfiles$() for animation tag character 'display x y starts and stops 'step program thru loop 8 frames; (4) animation frames twice per theoretical slowed down second 1000ms / 8 'count 'aninum = count ' readnow= loadanimations() 'for ani = 0 to readnow ' print #w.g, "addsprite ";animation$;" "animation1$;" ";animation2$;" "animation3$ ' print #w.g, "cyclesprite ";animation$;" 1" ' print #w.g, "spritemovexy ";animation$;" 4 0" ' loadnanimations = aninum End Function
function playerpos$(player.x,player.y) 'updates player position into string$ for output to be downloaded by pid playerpos$=str$(player.x);" ";str$(player.y)';" ";npcname$;" ";player(myPID,healthnull)
debug = 7:null = debug(debug)
end function
Function loadtext(textchat$) if textchat$ <> "" then open "text.txt" for output as #uploads print #uploads, time$("ms");" ";textchat$ close #uploads end if End Function
'commands Function commands$(inputcommand$) 'EXAMPLE: ctrl+map/npc/oject 0X 0Y refID$ ctrl$ = "1" 'COMMAND KEY INT. -> "1" if left$(outputchat$, 1) = ctrl$ then commands = commands + 1 'keep track of commands commandsarray$(commands) = word$(outputchat$,1) commandtype$ = commandsarray$(commands) xmap= val(word$(inputmap$, 2)) ymap= val(word$(inputmap$, 3)) mapcommandtile$ = word$(outputchat$, 4)
print ":COMMANDISSUED:SET>";left$(outputchat$, 4);" ";str$(xmap);" ";str$(ymap);"<"; word$(outputchat$,4) ;">tileRefID$: "
select case commandtype$ case "1map" map$(xmap,ymap)=mapcommandtile$ 'actual input line command here case "1npc" pid = val(mapcommandtile$) npc.x(pid) =xmap 'update game data here npc.y(pid) =ymap 'npc object commands case "1object"
end select
commands$=commandtype$ 'for ref end if End Function
Function fps(fps,time,loopx) 'print #main.gbx, "/text fps(";int(actualfps) End Function
Function debug(debug) if debugnull = 1 then select case debug
case 2 notice frames;" x ";seconds;" seconds / frames (Double Click) [ENTER]" notice "Continue [enter]" 'pause break case 3 print currentplayercount;" current player count" case 4 print (time2-time1);" ms game compiled frame in, ";timestatement;" lag/wait until next frame" timerstatement = timerstatement' - buffer case 5 timerstatement = timerstatement + 1000 * seconds ' wait for debug next frame case 6 print "closing for now 0% upload not featured in code yet" case 7 print playerpos$ 'debug case 8 print hit case 9 notice "null not used case 9" case 101 print time$("ms") - clickms end select end if End Function
|
|
|
Post by Enzo on Oct 30, 2020 22:41:27 GMT
Update:
'credit to cundo for the framework, JustBASIC.proforums.com/ -2020 October 29th 9PM 'r]pg game base by Enzo
global MAPX, MAPY, totalitems, objcount, div, clientcount clientcount = 10 'number of max clients MAPX=100:MAPY=100:totalitems=10:objcount=10:div=2:lag=100 '5 sprites of 10 images each
dim npc.x(100) dim npc.y(100) dim old.npc.x(100) dim old.npc.y(100) dim map$(MAPX,MAPY)
dim room(3) room(1) = 1 room(2) = 2 room(3) = 3
'dim mapitems(MAPX,MAPY) dim item(totalitems,3) '1 =unsed 2=type 3=unsed dim itemdisplay(totalitems, 2)
dim objdisplay(objcount, 2) dim objdisplay2(objectcount, 2)
dim inventory(8) dim bank(10)
dim specialattack(4)
dim playerfiles$(clientcount, 2)
global playerfile$, downloadfile$, pid, PID, myPID, x, y, player.x, player.y, yes, debug, startup, frames, PIDid, command$, commandtype$, inputcommand$, playercount,_ playerpos$, ms, luck, buffer, null, map.x, map.y, screen.x, screen.y, TILESIZE, OFFSET, loopx, time, fps, base10, debugnull,_ set, playeraccuracy, skill, luck, health, currentplayercount, frames, timerstatement, timestatement, time1, time2,_ loopcount, id, clickms, npc.n global MouseX, MouseY, TileX, TileY,_ Bankspace, currentbankcount, inventory, selected,_ mana, magicklevel, specialbar, specialtimer, attacktimer, defendtimer,_ lastselected$,selecteditem$, selected$, action$,_ attack, defend, attacktimer, defendtimer, defend1, defend2, attacktime1, attacktime2,_ combines, combinations
base10=10
combinations = 10
npcname$ = "player.bmp"' add to keys after
playeraccuracy = 10' 1 - 10 low-high skill = .9 ' .5 - .9 high level, .10 - .40 low level luck = .9 '.01-.99
seconds = 3 'desired debug run amount in seconds of 10 frames a second
health = 100 player(1,2) = health player(2,2) = health'input from file on server-client 'function for loading health from playerfiles
null = 0 id = 2 'set max hit calculated by point system divided 'set = skill * 7 'unsed
buffer = 10 'ms buffer to bad loop yes = 1 '1 operator for debug startup = 1
ms = 950 'for timerloop (1000/ms)
frames = 10 'desired fps; actual fps may very use 'display() = fps()' function to find fps
playerfile$="player" downloadfile$=playerfile$+"A" 'attribute to files, will add "offline" to name if player is not online 'offline$="OFFLINE" not used currently
'NOMAINWIN
'basic gui data below, using on screen sprites for icons for menus TILESIZE = 64 : SCREENWIDTH = 11 : SCREENHEIGHT = 8 : OFFSET = TILESIZE GAMEWIDTH = SCREENWIDTH*TILESIZE-TILESIZE*2+64 GAMEHEIGHT = SCREENHEIGHT*TILESIZE-TILESIZE*2 WindowWidth = GAMEWIDTH : WindowHeight = GAMEHEIGHT+100 : BackgroundColor$ = "BLACK" UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2) button #main.bmpbutton, "bmp", [bmp], UL, 10, 10 'load bmp file to game import as new sprite uploadsprite() graphicbox #main.gbx, 64, 0,GAMEWIDTH , GAMEHEIGHT textbox #main.textbox, 14, 400, 352, 25 'not sure where text will be displayed currently saving for last open "r]pg - client" for window_nf as #main #main.gbx "down; fill BLACK; flush" #main "trapclose [quit.main]" #main.gbx "Getbmp empty.bmp 1 1 ";TILESIZE;" ";TILESIZE*2
[splashscreen] confirm "debug = 1 (yes)?";answer$ if answer$ = "yes" then debugnull = 1 end if
'splashscreen()
'loadbmp display loading bar_ '1%
'5% [0] 'import screen objects sprites for menus
[1a]'tile import -10%'loading bar noftication for start splash screen tile.list$ = "dirt water grass rock sand" For i = 1 To 5 loadbmp left$(word$(tile.list$,i),1);".bmp",word$(tile.list$,i);".bmp" #main.gbx "drawbmp ";left$(word$(tile.list$,i),1);".bmp 1 ";TILESIZE+1;" ; ";_ "Getbmp ";left$(word$(tile.list$,i),1);".bmp 1 1 ";TILESIZE;" ";TILESIZE*2 Next [2b]'user/player files -20%'loading bar noftication for start splash screen player.list$ = "1.bmp 2.bmp 3.bmp 4.bmp ";_ "5.bmp 6.bmp 7.bmp 8.bmp" For i = 1 To 8 loadbmp "player";i;".bmp", Word$(player.list$,i) Next [3c]'start int -30%'loading bar noftication for start splash screen #main.gbx "setfocus;" ;_ "When characterInput [keys]; ";_ "Getbmp back.bmp 1 1 10 10;" ;_ "Background back.bmp;" ;_ "DRAWSPRITES" [4d] '40%'loading bar noftication for start splash screen OPEN "map.txt" For input AS #mapfile
While not(eof(#mapfile)) line input #mapfile, itemdata$ id$=trim$(itemdata$) if left$(id$,1)<>"'" and id$<>"" Then Select case case instr(id$,"width") map.width = val( trim$(word$(id$,2,"="))) case instr(id$,"height") map.height = val( trim$(word$(id$,2,"="))) case instr(id$,"playerX") player.x = val( trim$(word$(id$,2,"="))) case instr(id$,"playerY") player.y = val( trim$(word$(id$,2,"="))) case instr(id$,"others") npc.n = val( trim$(word$(id$,2,"="))) IF npc.n>0 Then DIM npc.x(npc.n),npc.y(npc.n) DIM old.npc.x(npc.n),old.npc.y(npc.n) For L = 1 To npc.n line input #mapfile, id$ npc.sprite.name$(L) = WORD$(id$,1,";") npc.bmp.name$(L) = WORD$(id$,2,";") npc.x(L) = val(TRIM$(WORD$(id$,3,";"))) npc.y(L) = val(TRIM$(WORD$(id$,4,";"))) old.npc.x(L) = npc.x(L): old.npc.y(L) = npc.y(L) 'PRINT npc.bmp.name$ Next L End if case else DIM map$(map.width,map.height)
For y = 1 To map.height
For x = 1 To map.width
map$(x,y) = TRIM$(word$(id$,x,",")) 'PRINT map$(x,y) Next line input #mapfile, id$ if instr(id$,"END") Then exit FOR Next
end select End if Wend Close #mapfile
[5e] '60%'loading bar noftication for start splash screen ' 10 * 7 DIM tile(SCREENWIDTH*SCREENHEIGHT,2) for h = 1 To SCREENHEIGHT for w = 1 To SCREENWIDTH obj=obj+1 #main.gbx "addsprite obj";obj;" empty.bmp d.bmp w.bmp g.bmp r.bmp s.bmp" tile(obj,1)=w tile(obj,2)=h next:next [6f] #main.gbx "addsprite player player1.bmp player2.bmp player3.bmp";_ " player4.bmp player5.bmp player6.bmp player7.bmp player8.bmp ;";_ "spritexy player ";player.x*TILESIZE-TILESIZE-OFFSET;" ";player.y*TILESIZE-TILESIZE-OFFSET [7g] '70%'loading bar noftication for start splash screen if npc.n Then For L = 1 To npc.n loadbmp npc.bmp.name$(L),npc.bmp.name$(L) #main.gbx "addsprite ";npc.sprite.name$(L);" ";npc.bmp.name$(L) #main.gbx "spritexy ";npc.sprite.name$(L);" ";npc.x(L)*TILESIZE-TILESIZE-OFFSET;_ " ";npc.y(L)*TILESIZE-TILESIZE-OFFSET
Next End if [8h] '80% currentplayercount = playercount(startup)'move to below : [m] timer 0 : for cycling in new players [9i] '100% 'loading bar noftication for start splash screen '100% loading bar 'keeping 0-5 and 95-100 by line input gives a giveaway to where error if any 'close splashscreen()
timer 50, [reDo] 'pause only for timer 0 at top of client branch function
wait
[timer] null = null
[reDo]
Timer 0 [branch] loopx = loopx + 1 clientloop = clientloop + 1
if clientloop = frames*seconds then 'frames = 10 FPS, refer fps() for actual fps clientloop = 0
debug = 2:null = debug(debug)
timer 1000*seconds, [timer] wait
' text=loadtext() 'load text once per second end if
time1 = time$("ms")
printf = fps(fps,time1,loopx)
currentplayercount = playercount(null)'
debug = 3:null = debug(debug)
for PID = 1 to currentplayercount 'download every users file of "XX YY" 'add more data here cache$ = downloadplayerfile$(PID) 'function downloads pid file and updates npc.x(pid) npc.y(pid) playerfiles$(PID) = cache$ next PID 'next playercount loop
gosub [moveMap] player.y = player.y + INT(screen.y) map.y = map.y + INT(screen.y) player.x = player.x + INT(screen.x) map.x = map.x + INT(screen.x)
updateXY$ = playerpos$(player.x,player.y) now$ = uploadtolan$(updateXY$,healthnull)
if abs(screen.y)>=1 Then screen.y = 0 if abs(screen.x)>=1 Then screen.x = 0 #main.gbx "DRAWSPRITES"
time2 = time$("ms")
timestatement = limiter(time2,time1,ms,buffer,timestatement)
debug = 5:null = debug(debug) debug = 4:null = debug(debug) TIMER timestatement, [reDo] ' 1 game tic = ms WAIT
[moveMap] for i =1 To obj SCAN'this might allow for extra input, not desired on metered game w = tile(i,1) h = tile(i,2)
if walk.val=.5 Then
#main.gbx "Spritexy obj";i;" ";_ w*TILESIZE-TILESIZE - (screen.x*TILESIZE) - OFFSET; " ";_ h*TILESIZE-TILESIZE - (screen.y*TILESIZE) - OFFSET
End if
If map.x+w< map.width AND map.x+w>0 AND _ map.y+h < map.height AND map.y+h>0 Then
#main.gbx "SpriteImage obj";i;" "; map$(w+map.x,h+map.y);".bmp"
'[debugA] need help here for items, objects, npcs for items = 1 to itemcount ' #main.gbx "SpriteImage item";i;" "; itemmap$(w+map.x,h+map.y);".bmp"
#main.gbx "spritexy ";npc.sprite.name$(items);" ";_ (item.x(items)-map.x-screen.x)*TILESIZE-TILESIZE - OFFSET ;" ";_ (item.y(items)-map.y-screen.y)*TILESIZE-TILESIZE - OFFSET next items Else ' set the tiles to an empty image
#main.gbx "SpriteImage obj";i;" empty.bmp"
End if
Next
RETURN [attack] Timer 0 #main.gbx "When characterInput"
probabilityvariable = rnd(10)*10 + playeraccuracy + luck * base10 'rnd with positive additive of player trained skill variable = probabilityvariable if variable > base10 then 'adds bonus if exptionale accurate, directly from the RND for realisitic play hitbonus = 10 - variable '10 point buffer for allowing not to powerful end if if variable < 5 then 'see if 50/50 with accuracy added(max up to 1 to 13-29 "i think") gives hit or not print "miss" goto [branch] end if debug=101:null=debug(debug) hit = int(rnd(10)*10)*10+ int(rnd(10)*10)*base10 + hitbonus 'basically grabs postive handi capped "55+" RND adds bonus if accuracy is expectionale accurate over 100, to the handicap with a max of unknown, this gives base 55+/45- type RND sets, allowing for a positive gameplay without "sluggish" hits then times this number by your decimcal (skill level * 7) and divides by 3, this part is hard to explain how it linearized RND to be RND still, it just is because the seed is RND, now out of 100 this is not random, there is a positive value frequency to this code as stated before hit = hit*skill hit = hit / 3 + (luck + skill)
'add a little 'luck' here players will gain small amount of luck thru out game and its added to a hidden hit value that could "stack" or add up after every hit if hit < 1 then hit = 5*luck*luck end if debug = 8:null=debug(debug)
#main.gbx "When characterInput [keys]" goto [branch]
[keys] Timer 0 #main.gbx "When characterInput"
k$ = Inkey$ keyValue = asc(right$(k$, 1)) walk.val = .5'adds stepped input
select case keyValue
case _VK_DOWN
if player.y + 1 < map.height Then new.pos$ = map$(player.x,player.y+1) If new.pos$<>"r" and new.pos$ <>"w" Then screen.y = screen.y + walk.val Else screen.y=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";1+spi;".bmp" 'pidid End if
case _VK_UP
if player.y - 1 >0 Then new.pos$ = map$(player.x,player.y-1) If new.pos$<>"r" and new.pos$ <>"w" Then screen.y = screen.y - walk.val Else screen.y=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";3+spi;".bmp" 'pidid End if case _VK_LEFT if player.x - 1 > 0 Then new.pos$ = map$(player.x-1,player.y) If new.pos$<>"r" and new.pos$ <>"w" Then screen.x = screen.x - walk.val Else screen.x = 0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";5+spi;".bmp" 'pidid End if case _VK_RIGHT if player.x +1 < map.width Then new.pos$ = map$(player.x+1,player.y) If new.pos$<>"r" and new.pos$ <>"w" Then screen.x = screen.x + walk.val Else screen.x=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";7+spi;".bmp" 'PIDid End if
case _VK_ESCAPE '[escape] to quit or [trapclose] goto [quit.main]
case _VK_INSERT 'attack goto [attack]
case _VK_CONTROL 'chat input CTRL instead of ENTER"
print #main.textbox, "!contents? textchat$"; print #main.textbox, "!disable" outputchat$ = textchat$ print #main.textbox, "PRINT #M lol nato sending...." send = loadtext(outputchat$) print #main.textbox, "" if debug = 1 then 'debug for adding tiles print #main.textbox, "~" check$ = commands$(outputchat$) else check$ = commands$(outputchat$) end if print #main.textbox, "!enable" 'admin commands restyled into funtionableility
end select #main.gbx "When characterInput [keys]" GOTO [reDo]
WAIT
'------------------------------------------------------------------------ '------------------------------------------------------------------------
[quit.bmp] Close #bmp goto [reDo]
[quit.main] unloadbmp "back.bmp" unloadbmp "empty.bmp" for i = 1 To 5 unloadbmp left$(word$(tile.list$,i),1);".bmp" Next for i = 1 TO 8 unloadbmp "player";i;".bmp" next
'if npc.n Then FOr L = 1 To npc.n unloadbmp npc.bmp.name$(L) NExt 'End if
Close #main END
'------------------------------------------------------------------------ '------------------------------------------------------------------------ ' ' Functions '------------------------------------------------------------------------
Function mousehandler(MouseX, MouseY) TileXY$ = MouseXY.Tilefinder$(MouseX, MouseY)
clickarea$ = left$(TileXY$,1)
selected = val(right$(TileXY$,2))
pos$ = right$(TileXY$,1);" ";right$(TileXY$,2) pos = val(pos$)
select case clickarea$
case "inventory" retur = inventory.handler(selected, pos)
case "special" reset = click(lastselected, selected) prime=specialbar()
case "four tiles"
'check rotation,
if lastselected = 3 then '3 = quest item
end if 'pickup(selected,pos)
'goto [attack] case else reset = click(lastselected, selected) end select
End Function
function click(lastselected,selected) 'resets selected when click on non clickable area of game/map if lastselected <> 0 then lastselected=0 selected=0 end if
if incombat = 1 then incombat = stopcombat() end if
delay = pause(lag) debug = 9:debug(debug)
end function
function pause(lag) startpausetime = time$("ms") for lagg = 1 to lag/2 null = null 'add a bit of lag here next lagg pause = time$("ms")-startpausetime end function
Function activate(pos) incombat = stopcombat() 'or after obj either; or obj = room(pos) End Function
Function pickup(selected, pos) func = deleteitem(selected, pos)
null = null 'prevent from double pickup null = null
func = newitem(selected) End function
Function deleteitem(selected, pos) ' TileX = val(left$(pos,1) ' TileY = val(right$(pos,2)) mapitems(TileX,TileY)=null End Function
Function newitem(selected) for inventoryslot = 1 to 10 if inventory(inventoryslot) > null then 'check if slot is free if not null = null else it is a free slot null = null else inventory(inventoryslot) = selected 'inputs selected data here for new item on next draw inventoryslot = 10 end if 'make sure draw sprites command renews graphics next inventoryslot End Function
Function item.handler(selecteditem) parser = parse(selecteditem)' find item type id if parser = 2 then '2 = food 'DELETE ITEM, ADD HEALTH delete = deleteitem(selecteditem) end if if lastselected = 0 then lastselected = selecteditem selecteditem = 0 else if item(selecteditem,2) = item(lastselected,2) then 'deleteitem(1) 'deleteitem(2)
new = selectedone retur = newitem(new) end if end if End Function
Function parse(selecteditem) parse = item(selecteditem,2) End Function
Function MouseXY.Tilefinder$(MouseX, MouseY) 'get mouse sx mouse y input prase through the 8 inventory post four tiles around player, special bar 'select case <> for each area 'return as three part string item position area string$ End Function
Function inventory.handler$(selected, pos) selecteditem = inventory(pos) 'retur = item.handler(selecteditem) End Function
Function bank()
End Function
Function stopcombat() stopcombat = 0 End Function
Function attack(attacktimer, attacktime1, attacktime2)'via button
End Function
Function defend(defendtimer, defend1, defend2)'via space bar or key
End Function
Function specialbar(specialbar) 'mouse click if special > weaponspecial then 'see if there's enough special left special = special - weaponspecial 'subtract special end if incombat = stopcombat() ' require reclick? specialbar = special End Function
Function limiter(time2,time1,ms,buffer,timestatement) if time2-time1 < ms then timestatement = ms-(time2-time1)+int(luck*3) limiter = timestatement end if End Function
Function playercount(startup) 'gets current player count and updates if startup = yes then open playerfile$+".txt" for input as #1 'open playercount file needs to have starting data of a single "0" zero count$ = input$(#1,lof(#1)) playercount = val(count$) playercount = playercount + 1 close #1
'add satefy for adding new file filecheck() to not allow new user until files been appeneded
PID = playercount 'keep track of position in file or clients PID myPID = PID 'duplicate variable for <> loops of PID
open playerfile$+".txt" for append as #playercount print #playercount, myPID close #playercount
else 'regular loop
open playerfile$+".txt" for input as #2 'open playercount file count$ = input$(#2,lof(#2)) playercount = val(count$) close #2 end if
npc.n = playercount
End Function
Function uploadtolan$(playerpos$,healthnull) open playerfile$+str$(PID);".txt" for output as #outputupload print #outputupload, playerpos$;" ";npcname$ close #outputupload uploadtolan = 1 End Function
Function downloadplayerfile$(pid) if pid <> myPID then string$ = downloadfile$+str$(pid);".txt" open string$ for input as #download 'open file by player log in order ID or PID playerpagefile$ = input$(#download,lof(#download)) downloadplayerfile$=playerpagefile$ 'read line close #download npcx=val(left$(downloadplayerfile$,1)) npcy=val(right$(downloadplayerfile$,3)) ' npcname$ = right$(downloadplayerfile$,2) ' heathnull = val(right$(downloadplayerfile$,1)) 'hit npc.x(pid) =npcx 'update game data here npc.y(pid) =npcy 'npc.name$(npcx,npcy) = npcname$ 'health 'hit
end if End Function
Function loadanimations() 'search playerfiles$() for animation tag character 'display x y starts and stops 'step program thru loop 8 frames; (4) animation frames twice per theoretical slowed down second 1000ms / 8 'count 'aninum = count ' readnow= loadanimations() 'for ani = 0 to readnow ' print #w.g, "addsprite ";animation$;" "animation1$;" ";animation2$;" "animation3$ ' print #w.g, "cyclesprite ";animation$;" 1" ' print #w.g, "spritemovexy ";animation$;" 4 0" ' loadnanimations = aninum End Function
function playerpos$(player.x,player.y) 'updates player position into string$ for output to be downloaded by pid playerpos$=str$(player.x);" ";str$(player.y)';" ";npcname$;" ";player(myPID,healthnull)
debug = 7:null = debug(debug)
end function
Function loadtext(textchat$) if textchat$ <> "" then open "text.txt" for output as #uploads print #uploads, time$("ms");" ";textchat$ close #uploads end if End Function
'commands Function commands$(inputcommand$) 'EXAMPLE: ctrl+map/npc/oject 0X 0Y refID$ ctrl$ = "1" 'COMMAND KEY INT. -> "1" if left$(outputchat$, 1) = ctrl$ then commands = commands + 1 'keep track of commands commandsarray$(commands) = word$(outputchat$,1) commandtype$ = commandsarray$(commands) xmap= val(word$(inputmap$, 2)) ymap= val(word$(inputmap$, 3)) mapcommandtile$ = word$(outputchat$, 4)
print ":COMMANDISSUED:SET>";left$(outputchat$, 4);" ";str$(xmap);" ";str$(ymap);"<"; word$(outputchat$,4) ;">tileRefID$: "
select case commandtype$ case "1map" map$(xmap,ymap)=mapcommandtile$ 'actual input line command here case "1npc" pid = val(mapcommandtile$) npc.x(pid) =xmap 'update game data here npc.y(pid) =ymap 'npc object commands case "1object"
end select
commands$=commandtype$ 'for ref end if End Function
Function fps(fps,time,loopx) 'print #main.gbx, "/text fps(";int(actualfps) End Function
Function debug(debug) if debugnull = 1 then select case debug
case 2 notice frames;" x ";seconds;" seconds / frames (Double Click) [ENTER]" notice "Continue [enter]" 'pause break case 3 print currentplayercount;" current player count" case 4 print (time2-time1);" ms game compiled frame in, ";timestatement;" lag/wait until next frame" timerstatement = timerstatement' - buffer case 5 timerstatement = timerstatement + 1000 * seconds ' wait for debug next frame case 6 print "closing for now 0% upload not featured in code yet" case 7 print playerpos$ 'debug case 8 print hit case 9 print delay delay = 0 case 101 print time$("ms") - clickms end select debug = 0 'reset debug end if End Function
|
|
|
Post by Rod on Nov 2, 2020 14:25:16 GMT
I think I have said this before. If you want folks to look at something like this you need to zip it all and offer a link to the .zip. No one is going to go looking for all the resource files. Bundle it and you will get more folks trying it out.
|
|
|
Post by Enzo on Nov 3, 2020 2:45:54 GMT
Sadly the code does not run currently, hasn't for a few releases, getting closer to debug time and posting a working (or semi-working) release with all attached files, including some bmp's of items, objects, characters and server and map file, here's yet another release as i'm getting closer
'credit to cundo for the framework, JustBASIC.proforums.com/ -2020 October 29th 9PM 'r]pg game base by Enzo
'study the code to learn how to play
global MAPX, MAPY, totalitems, objcount, div, clientcount clientcount = 10 'number of max clients MAPX=100:MAPY=100:totalitems=10:objcount=10:div=2:lag=100 '5 sprites of 10 images each
dim npc.x(100) dim npc.y(100) dim old.npc.x(100) dim old.npc.y(100) dim map$(MAPX,MAPY)
dim room(3) room(1) = 1 room(2) = 2 room(3) = 3
dim attacktime(5) 'attack rythm medium, short, long, mid, very short, medium, short, long, mid, ect. attacktime(1)=15 attacktime(2)=-10 attacktime(3)=20 attacktime(4)=10 attacktime(5)=-20
'dim mapitems(MAPX,MAPY) dim item(totalitems,3) '1 =unsed 2=type 3=unsed dim itemdisplay(totalitems, 2)
dim objdisplay(objcount, 2) dim objdisplay2(objectcount, 2)
dim inventory(8) dim bank(10)
dim specialattack(4)
dim playerfiles$(clientcount, 4) '1=health, 3=hit, 2=npc graphic
global playerfile$, downloadfile$, pid, PID, myPID, x, y, player.x, player.y, yes, debug, startup, frames, PIDid, command$, commandtype$, inputcommand$, playercount,_ playerpos$, ms, luck, buffer, null, map.x, map.y, screen.x, screen.y, TILESIZE, OFFSET, loopx, time, fps, base10, debugnull,_ set, playeraccuracy, skill, luck, health, currentplayercount, frames, timerstatement, timestatement, time1, time2,_ loopcount, id, clickms, npc.n global MouseX, MouseY, TileX, TileY,_ Bankspace, currentbankcount, inventory, selected,_ mana, magicklevel, specialbar, specialtimer, attacktime, defendtimer,_ lastselected$,selecteditem$, selected$, action$,_ attack, defend, attacktimer, defendtimer, defend1, defend2, attacktime1, attacktime2,_ combines, combinations
ms = 950 'for timerloop (1000/ms frames = 10 'desired fps; actual fps may very use 'display() = fps()' function to find fps base10=10
'\\ basic debug/building data combinations = 10 'item combines, to new itemid here=item(itemid,2) npcname$ = "player.bmp"' add to keys after playeraccuracy = 10' 1 - 10 low-high skill = .9 ' .5 - .9 high level, .10 - .40 low level luck = .9 '.01-.99 seconds = 3 'desired debug run amount in seconds of 10 frames a second
health = 100
player(1,2) = health player(2,2) = health'input from file on server-client 'function for loading health from playerfiles
null = 0 null = null
id = 2 'set max hit calculated by point system divided '\\
'set = skill * 7 'unsed
buffer = 10 'ms buffer to bad loop yes = 1 '1 operator for debug startup = 1
[debugdata] ' debug(debug$) at bottom of code, select case debug$ confirm "debug = 1 (yes)?";answer$ if answer$ = "yes" then debugnull = 1 end if
if debugnull > null then NOMAINWIN end if
[splashscreen] start=splashscreen(1)'basic gui data below, using on screen sprites for icons for menus timer 350, [minus1] wait [minus1] timer 0 startserverdata = globalint(playerfile$,downloadfile$,offline$) [0] update=splashscreen(5) 'import screen objects sprites for menus [1a]'tile import -10%'loading bar noftication for start splash screen update=splashscreen(10) callfunction = loadmaptiles(tile.list$, i, TILESIZE) [2b]'user/player files -20%'loading bar noftication for start splash screen update=splashscreen(20) callfunction=playerbmpload(player.list$,i) [3c]'start int -30%'loading bar noftication for start splash screen update=splashscreen(30) loadsettings=setup() [4d] '40%'loading bar noftication for start splash screen update=splashscreen(40) callfunction=loadmap(itemdata,id,map.width,map.height, player.x, player.y, npc.n, L) [5e] '60%'loading bar noftication for start splash screen update=splashscreen(60) callfuntion=loadscreenobj(SCREENWIDTH,SCREENHEIGHT,h,w,obj) [6f] update=splashscreen(65) callfunction=loadplayersprite(player.x,player.y,TILESIZE,OFFSET) [7g] update=splashscreen(67) callfunction=npcload(npc.n,L,TILESIZE,OFFSET) [8h] '70% update=splashscreen(70) currentplayercount = playercount(startup)'move to below : [m] timer 0 : for cycling in new players timer 50, [reDo] 'pause only for timer 0 at top of client branch function wait
[timer] null = null [reDo] Timer 0 [branch] debug=1000: debug=debug(debug) time1 = time$("ms") printf = fps(fps,time1,loopx)
'too fast of loop limiter here, trap input by user for next command, keep looping while; currentplayercount = playercount(null)' debug = 3:debug = debug(debug) for PID = 1 to currentplayercount 'download every users file of "XX YY" 'add more data here cache$ = downloadplayerfile$(PID) 'function downloads pid file and updates npc.x(pid) npc.y(pid) playerfiles$(PID) = cache$ next PID 'next playercount loop gosub [moveMap] updateXY$ = playerpos$(player.x,player.y, screen.y, screen.x, map.x, map.y) now$ = uploadtolan$(updateXY$,healthnull) #main.gbx "DRAWSPRITES" time2 = time$("ms") timestatement = limiter(time2,time1,ms,buffer,timestatement)
debug = 5:debug = debug(debug) debug = 4:debug = debug(debug) TIMER timestatement, [reDo] ' 1 game tic = ms WAIT [moveMap] 'credit to cundo for i =1 To obj SCAN'this might allow for extra input, not desired on metered game w = tile(i,1) h = tile(i,2)
if walk.val=.5 Then #main.gbx "Spritexy obj";i;" ";_ w*TILESIZE-TILESIZE - (screen.x*TILESIZE) - OFFSET; " ";h*TILESIZE-TILESIZE - (screen.y*TILESIZE) - OFFSET End if If map.x+w< map.width AND map.x+w>0 AND _ map.y+h < map.height AND map.y+h>0 Then #main.gbx "SpriteImage obj";i;" "; map$(w+map.x,h+map.y);".bmp"
'[debugA] need help here for items, objects, npcs for items = 1 to itemcount ' #main.gbx "SpriteImage item";i;" "; itemmap$(w+map.x,h+map.y);".bmp"
#main.gbx "spritexy ";npc.sprite.name$(items);" ";_ (item.x(items)-map.x-screen.x)*TILESIZE-TILESIZE - OFFSET ;" ";(item.y(items)-map.y-screen.y)*TILESIZE-TILESIZE - OFFSET next items Else ' set the tiles to an empty image #main.gbx "SpriteImage obj";i;" empty.bmp" End if Next RETURN [attackloop] attacktime1 = time$("ms") attacktimer = attackime1 attacktime2 = time$("ms")
callfunction = attack(attacktime, attacktimer, attacktime1, attacktime2, luck) if gotoattack = 1 then gotoattack = 0 goto [attack] end if
goto [branch]
[attack] Timer 0 #main.gbx "When characterInput"
probabilityvariable = rnd(10)*10 + playeraccuracy + luck * base10 'rnd with positive additive of player trained skill variable = probabilityvariable if variable > base10 then 'adds bonus if exptionale accurate, directly from the RND for realisitic play hitbonus = 10 - variable '10 point buffer for allowing not to powerful end if if variable < 5 then 'see if 50/50 with accuracy added(max up to 1 to 13-29 "i think") gives hit or not print "miss" goto [branch] end if debug=101:debug=debug(debug) hit = int(rnd(10)*10)*10+ int(rnd(10)*10)*base10 + hitbonus 'basically grabs postive handi capped "55+" RND adds bonus if accuracy is expectionale accurate over 100, to the handicap with a max of unknown, this gives base 55+/45- type RND sets, allowing for a positive gameplay without "sluggish" hits then times this number by your decimcal (skill level * 7) and divides by 3, this part is hard to explain how it linearized RND to be RND still, it just is because the seed is RND, now out of 100 this is not random, there is a positive value frequency to this code as stated before hit = hit*skill hit = hit / 3 + (luck + skill)
'add a little 'luck' here players will gain small amount of luck thru out game and its added to a hidden hit value that could "stack" or add up after every hit if hit < 1 then hit = 5*luck*luck end if debug = 8:debug=debug(debug)
#main.gbx "When characterInput [keys]" goto [branch]
[defend] 'space bar defendtime = time$("ms") defendvar = defend(defendtimer, defendtime1, defendtime2, luck) if defendtime < defendvar and defendtime > defendvar then blocknexthit = 1 defendvar = 0 defendtime = 0 end if goto [branch] [keys] 'credit to cundo Timer 0 #main.gbx "When characterInput"
k$ = Inkey$ keyValue = asc(right$(k$, 1)) walk.val = .5'adds stepped input
select case keyValue
case _VK_DOWN
if player.y + 1 < map.height Then new.pos$ = map$(player.x,player.y+1) If new.pos$<>"r" and new.pos$ <>"w" Then screen.y = screen.y + walk.val Else screen.y=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";1+spi;".bmp" 'pidid End if
case _VK_UP
if player.y - 1 >0 Then new.pos$ = map$(player.x,player.y-1) If new.pos$<>"r" and new.pos$ <>"w" Then screen.y = screen.y - walk.val Else screen.y=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";3+spi;".bmp" 'pidid End if case _VK_LEFT if player.x - 1 > 0 Then new.pos$ = map$(player.x-1,player.y) If new.pos$<>"r" and new.pos$ <>"w" Then screen.x = screen.x - walk.val Else screen.x = 0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";5+spi;".bmp" 'pidid End if case _VK_RIGHT if player.x +1 < map.width Then new.pos$ = map$(player.x+1,player.y) If new.pos$<>"r" and new.pos$ <>"w" Then screen.x = screen.x + walk.val Else screen.x=0 End if spi = abs(not(spi)) #main.gbx "spriteImage player player";7+spi;".bmp" 'PIDid End if
case _VK_ESCAPE '[escape] to quit or [trapclose] goto [quit.main]
case _VK_INSERT 'attack [f] [g] keys and space bar goto [attackloop]
case _VK_CONTROL 'chat input CTRL instead of ENTER"
print #main.textbox, "!contents? textchat$"; print #main.textbox, "!disable" outputchat$ = textchat$ print #main.textbox, "PRINT #M lol nato sending...." send = loadtext(outputchat$) print #main.textbox, "" if debug = 1 then 'debug for adding tiles print #main.textbox, "~" check$ = commands$(outputchat$) else check$ = commands$(outputchat$) end if print #main.textbox, "!enable" 'admin commands restyled into funtionableility end select #main.gbx "When characterInput [keys]" GOTO [reDo]
WAIT
'------------------------------------------------------------------------ '------------------------------------------------------------------------
[quit.bmp]'credit: cundo Close #bmp goto [reDo]
[quit.main] unloadbmp "back.bmp" unloadbmp "empty.bmp" for i = 1 To 5 unloadbmp left$(word$(tile.list$,i),1);".bmp" Next for i = 1 TO 8 unloadbmp "player";i;".bmp" next
'if npc.n Then FOr L = 1 To npc.n unloadbmp npc.bmp.name$(L) NExt 'End if
Close #main notice "Framework credit, justBasic proforums . com / Member: cundo" END
'------------------------------------------------------------------------ '------------------------------------------------------------------------ ' ' Functions '------------------------------------------------------------------------
Function mousehandler(MouseX, MouseY) TileXY$ = MouseXY.Tilefinder$(MouseX, MouseY)
clickarea$ = left$(TileXY$,1)
selected = val(right$(TileXY$,2))
pos$ = right$(TileXY$,1);" ";right$(TileXY$,2) pos = val(pos$)
select case clickarea$
case "inventory" retur = inventory.handler(selected, pos)
case "special" reset = click(lastselected, selected) prime = specialbar()
case "four tiles" if pos > 0 and pos < 4 then 'check rotation, if selected = 2 then [attackloop]
'if selected = 3 then '3 = quest item ' 'end if
if selected = 1 then '1 = item newitem = pickup(selected,pos) end if end if
case "other" reset = click(lastselected, selected) end select
End Function
function click(lastselected,selected) 'resets selected when click on non clickable area of game/map if lastselected <> 0 then lastselected=0 selected=0 end if
if incombat = 1 then incombat = stopcombat() end if
delay = pause(lag) debug = 9:debug=debug(debug)
end function
function pause(lag) startpausetime = time$("ms") for lagg = 1 to lag/div null = null 'add a bit of lag here next lagg pause = time$("ms")-startpausetime end function
Function activate(pos) incombat = stopcombat() 'or after obj either; or obj = room(pos) End Function
Function pickup(selected, pos) func = deleteitem(selected, pos) 'delete item
null = null 'prevent from double pickup null = null
func = newitem(selected) 'create new item in inventory End function
Function deleteitem(selected, pos) ' TileX = val(left$(pos,1) ' TileY = val(right$(pos,2)) mapitems(TileX,TileY)=null End Function
Function newitem(selected) for inventoryslot = 1 to 10 if inventory(inventoryslot) > null then 'check if slot is free if not null = null else it is a free slot null = null else inventory(inventoryslot) = selected 'inputs selected data here for new item on next draw inventoryslot = 10 end if 'make sure draw sprites command renews graphics next inventoryslot End Function
Function item.handler(selecteditem) parser = parse(selecteditem)' find item type id if parser = 2 then '2 = food 'DELETE ITEM, ADD HEALTH delete = deleteitem(selecteditem) end if if lastselected = 0 then lastselected = selecteditem selecteditem = 0 else if item(selecteditem,2) = item(lastselected,2) then 'deleteitem(selecteditem) 'deleteitem(lstselected)
new = item(selecteditem, 2) retur = newitem(new) end if end if End Function
Function parse(selecteditem) parse = item(selecteditem,2) 'find itemtypeid 1= item 2=food 3= End Function
Function MouseXY.Tilefinder$(MouseX, MouseY) 'get mouse sx mouse y input prase through the 8 inventory post four tiles around player, special bar 'select case <> for each area 'return as three part string item position area string$
MouseX = MX : MouseY = MY
'right hand side if MX > 400 and MX < 500 then if MY >100 and MY < 200 then pos = 5 end if end if
if MX > 400 and MX < 500 then if MY >300 and MY < 400 then pos = 6 end if end if
if MX > 400 and MX < 500 then if MY >400 and MY < 500 then pos = 7 end if end if
if MX > 400 and MX < 500 then if MY >500 and MY < 600 then pos = 8 end if end if 'right handside/ 'bottom of screen
if MY > 500 and MY < 600 then if MX > 100 and MX < 200 then pos = 9 end if end if
if MX > 400 and MX < 500 then if MY > 200 and MY < 300 then pos = 10 end if end if
if MX > 400 and MX < 500 then if MY > 300 and MY < 400 then pos = 11 end if end if
if MX > 400 and MX < 500 then if MY >400 and MY < 500 then pos = 12 end if end if
'end bottom/
'four tiles
'special
if pos = 0 then pos = -1 end if
if pos > 0 and pos < 4 then clickarea$ = "four tiles" end if
if pos > 4 and pos < 13 clickarea$ "inventory" end if
if pos = 14 then clickarea$ = "special" end if
if pos = 15 then clickarea$ = "" end if
if pos = -1 then clickarea$ = "other" end if MouseXY.Tilefinder$ = clickarea$'+string$(pos) End Function
Function inventory.handler$(selected, pos) selecteditem = inventory(pos) if selecteditem = 0 then null=null else retur = item.handler(selecteditem) end if End Function
Function bank()
End Function
'combat
Function stopcombat() stopcombat = null 'return 0 as if then not allowing combat next loop End Function
Function attack(attacktime, attacktimer, attacktime1, attacktime2, luck)'via button if attacktime1 > 0 then if a = 5 then a = 0 end if a = a + 1 attacktime = attacktime(a) - luck*luck '16-18 15-19 if attacktime+attacktimer<attacktime2-luck then gotoattack = 1 attacktime = 0 : attacktimer = 0 : attacktime2 = 0 : attacktime1 = 0 end if End Function
Function defend(defendtimer, defendtime1, defendtime2, luck)'via space bar or key
if defendtime1 > 0 then if b = 5 then b = 0 end if b = b + 1
defendtime = attacktime(b) - luck*luck '16-18 15-19 using array for both if defendtime+defendtimer<defendtime2-luck then defend = (defendtime2-defendtime1)/2+luck defendtime = 0 : defendtimer = 0 : defendtime2 = 0 : defendtime1 = 0 end if End Function
Function specialbar(specialbar) 'mouse click if special > weaponspecial then 'see if there's enough special left special = special - weaponspecial 'subtract special end if incombat = stopcombat() ' require reclick? specialbar = special End Function
'luck
Function limiter(time2,time1,ms,buffer,timestatement) if time2-time1 < ms then timestatement = ms-(time2-time1)+int(luck*3) limiter = timestatement end if End Function
'filesystem
Function playercount(startup) 'gets current player count and updates if startup = yes then open playerfile$+".txt" for input as #1 'open playercount file needs to have starting data of a single "0" zero count$ = input$(#1,lof(#1)) playercount = val(count$) playercount = playercount + 1 close #1
'add satefy for adding new file filecheck() to not allow new user until files been appeneded A B swap for infomation and x2 time ms
PID = playercount 'keep track of position in file or clients PID myPID = PID 'duplicate variable for <> loops of PID
open playerfile$+".txt" for append as #playercount print #playercount, myPID close #playercount
else 'regular loop
open playerfile$+".txt" for input as #2 'open playercount file count$ = input$(#2,lof(#2)) playercount = val(count$) close #2 end if
npc.n = playercount
End Function
Function uploadtolan$(playerpos$,healthnull) open playerfile$+str$(PID);".txt" for output as #outputupload print #outputupload, playerpos$;" ";npcname$ close #outputupload uploadtolan = 1 End Function
Function downloadplayerfile$(pid) if pid <> myPID then string$ = downloadfile$+str$(pid);".txt" open string$ for input as #download 'open file by player log in order ID or PID playerpagefile$ = input$(#download,lof(#download)) downloadplayerfile$=playerpagefile$ 'read line close #download npcx=val(left$(downloadplayerfile$,1)) npcy=val(right$(downloadplayerfile$,3)) ' npcname$ = right$(downloadplayerfile$,2) ' heathnull = val(right$(downloadplayerfile$,1)) 'hit npc.x(pid) =npcx 'update game data here npc.y(pid) =npcy 'npc.name$(npcx,npcy) = npcname$ 'health 'hit
end if End Function
function playerpos$(player.x,player.y, screen.y, screen.x, map.x, map.y) 'updates player position into string$ for output to be downloaded by pid npcgraphics and health incombatpid = otherplayer pid and hit player.y = player.y + INT(screen.y) map.y = map.y + INT(screen.y) player.x = player.x + INT(screen.x) map.x = map.x + INT(screen.x)
if abs(screen.y)>=1 Then screen.y = 0 if abs(screen.x)>=1 Then screen.x = 0
playerpos$=str$(player.x);" ";str$(player.y)';" ";npcname$;" ";player(myPID,healthnull)
debug = 7:debug = debug(debug)
end function
Function loadtext(textchat$) if textchat$ <> "" then open "text.txt" for output as #uploads print #uploads, time$("ms");" ";textchat$ close #uploads end if End Function
'extras
Function fps(fps,time,loopx) 'print #main.gbx, "/text fps(";int(actualfps) End Function
'commands Function commands$(inputcommand$) 'EXAMPLE: ctrl+map/npc/oject 0X 0Y refID$ ctrl$ = "1" 'COMMAND KEY INT. -> "1" if left$(outputchat$, 1) = ctrl$ then commands = commands + 1 'keep track of commands commandsarray$(commands) = word$(outputchat$,1) commandtype$ = commandsarray$(commands) xmap= val(word$(inputmap$, 2)) ymap= val(word$(inputmap$, 3)) mapcommandtile$ = word$(outputchat$, 4)
print ":COMMANDISSUED:SET>";left$(outputchat$, 4);" ";str$(xmap);" ";str$(ymap);"<"; word$(outputchat$,4) ;">tileRefID$: "
select case commandtype$ case "1map" map$(xmap,ymap)=mapcommandtile$ 'actual input line command here case "1npc" pid = val(mapcommandtile$) npc.x(pid) =xmap 'update game data here npc.y(pid) =ymap 'npc object commands case "1object"
end select
commands$=commandtype$ 'for ref end if End Function
'int function npcload(npc.n,L,TILESIZE,OFFSET) if npc.n Then For L = 1 To npc.n loadbmp npc.bmp.name$(L),npc.bmp.name$(L) #main.gbx "addsprite ";npc.sprite.name$(L);" ";npc.bmp.name$(L) #main.gbx "spritexy ";npc.sprite.name$(L);" ";npc.x(L)*TILESIZE-TILESIZE-OFFSET;_ " ";npc.y(L)*TILESIZE-TILESIZE-OFFSET
Next End if End Function
function loadplayersprite(player.x,player.y,TILESIZE,OFFSET) 'credit to cundo #main.gbx "addsprite player player1.bmp player2.bmp player3.bmp";_ " player4.bmp player5.bmp player6.bmp player7.bmp player8.bmp ;";_ "spritexy player ";player.x*TILESIZE-TILESIZE-OFFSET;" ";player.y*TILESIZE-TILESIZE-OFFSET end function
function setup() 'credit to cundo #main.gbx "setfocus;" ;_ "When characterInput [keys]; ";_ "Getbmp back.bmp 1 1 10 10;" ;_ "Background back.bmp;" ;_ "DRAWSPRITES" end function
function playerbmpload(player.list$,i) 'credit to cundo player.list$ = "1.bmp 2.bmp 3.bmp 4.bmp ";_ "5.bmp 6.bmp 7.bmp 8.bmp" For i = 1 To 8 loadbmp "player";i;".bmp", Word$(player.list$,i) Next end function
function loadscreenobj(SCREENWIDTH,SCREENHEIGHT,h,w,obj) 'credit to cundo ' 10 * 7 DIM tile(SCREENWIDTH*SCREENHEIGHT,2) for h = 1 To SCREENHEIGHT for w = 1 To SCREENWIDTH obj=obj+1 #main.gbx "addsprite obj";obj;" empty.bmp d.bmp w.bmp g.bmp r.bmp s.bmp" tile(obj,1)=w tile(obj,2)=h next:next end function
function loadmaptiles(tile.list$, i, TILESIZE) 'credit to cundo for this function tile.list$ = "dirt water grass rock sand" For i = 1 To 5 loadbmp left$(word$(tile.list$,i),1);".bmp",word$(tile.list$,i);".bmp" #main.gbx "drawbmp ";left$(word$(tile.list$,i),1);".bmp 1 ";TILESIZE+1;" ; ";_ "Getbmp ";left$(word$(tile.list$,i),1);".bmp 1 1 ";TILESIZE;" ";TILESIZE*2 Next end function
function loadmap(itemdata,id,map.width,map.height, player.x, player.y, npc.n, L) 'credit to cundo for map file type; system function OPEN "map.txt" For input AS #mapfile
While not(eof(#mapfile)) line input #mapfile, itemdata$ id$=trim$(itemdata$) if left$(id$,1)<>"'" and id$<>"" Then Select case case instr(id$,"width") map.width = val( trim$(word$(id$,2,"="))) case instr(id$,"height") map.height = val( trim$(word$(id$,2,"="))) case instr(id$,"playerX") player.x = val( trim$(word$(id$,2,"="))) case instr(id$,"playerY") player.y = val( trim$(word$(id$,2,"="))) case instr(id$,"others") npc.n = val( trim$(word$(id$,2,"="))) IF npc.n>0 Then DIM npc.x(npc.n),npc.y(npc.n) DIM old.npc.x(npc.n),old.npc.y(npc.n) For L = 1 To npc.n line input #mapfile, id$ npc.sprite.name$(L) = WORD$(id$,1,";") npc.bmp.name$(L) = WORD$(id$,2,";") npc.x(L) = val(TRIM$(WORD$(id$,3,";"))) npc.y(L) = val(TRIM$(WORD$(id$,4,";"))) old.npc.x(L) = npc.x(L): old.npc.y(L) = npc.y(L) 'PRINT npc.bmp.name$ Next L End if case else DIM map$(map.width,map.height)
For y = 1 To map.height
For x = 1 To map.width
map$(x,y) = TRIM$(word$(id$,x,",")) 'PRINT map$(x,y) Next line input #mapfile, id$ if instr(id$,"END") Then exit FOR Next
end select End if Wend Close #mapfile
end function
function globalint(playerfile$,downloadfile$,offline$) playerfile$="player" downloadfile$=playerfile$+"A" 'attribute to files, will add "offline" to name if player is not online offline$="OFFLINE"' not used currently end function
'debug Function debug(debug) if debugnull = 1 then select case debug
case 2 notice frames;" x ";seconds;" seconds / frames (Double Click) [ENTER]" notice "Continue [enter]" 'pause break case 3 print currentplayercount;" current player count" case 4 print (time2-time1);" ms game compiled frame in, ";timestatement;" lag/wait until next frame" timerstatement = timerstatement' - buffer case 5 timerstatement = timerstatement + 1000 * seconds ' wait for debug next frame case 6 print "closing for now 0% upload not featured in code yet" case 7 print playerpos$ 'debug case 8 print hit case 9 print delay delay = 0 case 101 print time$("ms") - clickms case 1000 loopx = loopx + 1 clientloop = clientloop + 1
if clientloop = frames*seconds then 'frames = 10 FPS, refer fps() for actual fps clientloop = 0
debug = 2:debug = debug(debug)
timer 1000*seconds, [timer] wait
' text=loadtext() 'load text once per second end if end select debug = 0 'reset debug end if End Function
'animations
Function loadanimations() 'search playerfiles$() for animation tag character 'display x y starts and stops 'step program thru loop 8 frames; (4) animation frames twice per theoretical slowed down second 1000ms / 8 'count 'aninum = count ' readnow= loadanimations() 'for ani = 0 to readnow ' print #w.g, "addsprite ";animation$;" "animation1$;" ";animation2$;" "animation3$ ' print #w.g, "cyclesprite ";animation$;" 1" ' print #w.g, "spritemovexy ";animation$;" 4 0" ' loadnanimations = aninum End Function
'splashscreen loading menu
function splashscreen(percentage,TILESIZE, SCREENWIDTH, SCREENHEIGHT, OFFSET, GAMEWIDTH, GAMEHEIGHT,BackgroundColor$,UpperLeftY, UpperLeftX) select case percentage case 1 '11 bmps. 10 with percentages TILESIZE = 64 : SCREENWIDTH = 11 : SCREENHEIGHT = 8 : OFFSET = TILESIZE GAMEWIDTH = SCREENWIDTH*TILESIZE-TILESIZE*2+64 GAMEHEIGHT = SCREENHEIGHT*TILESIZE-TILESIZE*2 WindowWidth = GAMEWIDTH : WindowHeight = GAMEHEIGHT+100 : BackgroundColor$ = "BLACK" UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2) button #main.bmpbutton, "bmp", [bmp], UL, 10, 10 'load bmp file to game import as new sprite uploadsprite() graphicbox #main.gbx, 64, 0,GAMEWIDTH , GAMEHEIGHT textbox #main.textbox, 14, 400, 352, 25 'not sure where text will be displayed currently saving for last open "r]pg - client" for window_nf as #main #main.gbx "down; fill BLACK; flush" #main "trapclose [quit.main]" #main.gbx "Getbmp empty.bmp 1 1 ";TILESIZE;" ";TILESIZE*2 'start first screen case 5 '5, ect. case 10
case 20
case 30
case 40
case 60
case 67
case 70
case 95
case 98
delay=pause(lag) 'a bit of epic pause here, hopefully be used later in-game delay=pause(lag) case 100
case else errornumber = 1 null = noticeerror(errornumber,percentage) end end function
'pause function null function pause(leg) for paus = 1 to 4 'ready game window delay=pause(lag) next paus end function
'fail to load error notice function noticeerror(errornumber,percentage,) select case errornumber case 1 notice "ERROR ";errornumber;" ";percentage;" loaded." case 2 notice "ERROR ";errornumber;" ";;" loaded." case 3 notice "ERROR ";errornumber;" ";;" loaded." end function
|
|