Post by Enzo on Jun 26, 2020 0:25:45 GMT
Current verison
Trying to convert commands into a simple universal function right now, lost my NPC's though, maybe because its apart of the same array for cheating to see if it worked. cundo what do you means X Y player movement boundries which [branch] is that located?
'
' The Background seems to move, but I'm just changing the Images with the SpriteImage Command.
' It's faster and you don't need a large amount of sprites, allowing the creation of a
' big map.
' There are only 10*7 sprites composed by tiles (sprites).
dim npc.x(100)
dim npc.y(100)
dim old.npc.x(100)
dim old.npc.y(100)
dim map$(100,100)
'NOMAINWIN
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
graphicbox #main.gbx, 64, 0,GAMEWIDTH , GAMEHEIGHT
textbox #main.textbox, 14, 400, 352, 25
open "JB-RPG" 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
[a]
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
[b]
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
[c]
#main.gbx "setfocus;" ;_
"When characterInput [keys]; ";_
"Getbmp back.bmp 1 1 10 10;" ;_
"Background back.bmp;" ;_
"DRAWSPRITES"
[d]
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
[e]
' 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
[f]
#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
[g]
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
[reDo]
'text=loadtext()
Timer 0
GOSUB [main.Branch]
m=not(m)
If m=-1 Then Gosub [npc.movement]
TIMER 17,[reDo]
WAIT
[main.Branch]
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)
if abs(screen.y)>=1 Then screen.y = 0
if abs(screen.x)>=1 Then screen.x = 0
#main.gbx "DRAWSPRITES"
RETURN
[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"
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"
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"
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"
End if
case _VK_ESCAPE
goto [quit.main]
case _VK_CONTROL 'chat input CTRL instead of ENTER"
print #main.textbox, "!contents? textchat$";
outputchat$ = textchat$
print #main.textbox, "!disable"
o = outputchat(outputchat$)
print #main.textbox, ""
print #main.textbox, "!enable"
'admin commands need to be restyled into funtionableility
if left$(outputchat$, 4) = "@map" then
n = n + 1
inputmap$(n) = word$(outputchat$,2)
inputmap$ = inputmap$(n)
xmap= val(left$(inputmap$, 2))
ymap= val(right$(inputmap$, 2))
mapcommandtile$ = word$(outputchat$, 3)
'boolean to debug
command$ = str$(xmap);" ";str$(ymap);" ";mapcommandtile$
print ":COMMANDISSUED:SET>MAP X Y tileRefID$: ";command$
'update data
map$(xmap,ymap)=mapcommandtile$
end if
textchat$=""
end select
' if npc.x(1) = player.x AND npc.y(1)=player.y Then
' PRINT "collision"
'End if
'For L = 1 To npc.n
'npc.x(L) = npc.x(L) - INT(screen.x)
'npc.y(L) = npc.y(L) - INT(screen.y)
'Next
GOSUB [main.Branch]
#main.gbx "When characterInput [keys]"
GOTO [reDo]
WAIT
[moveMap]
For i =1 To obj
SCAN
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 npc.n
#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
[npc.movement]
'npc random movement:
For L = 1 to npc.n
random.move.x= INT(rnd(0)*3)-1
random.move.y= INT(rnd(0)*3)-1
if random.move.x+npc.x(L)<map.width AND random.move.y+npc.y(L)<map.height AND _
random.move.x+npc.x(L)>0 AND random.move.y+npc.y(L)>0 Then
if INT(rnd(0)*2) =0 Then
npc.x(L)=npc.x(L) + random.move.x
Else
npc.y(L)=npc.y(L) + random.move.y
End if
select case map$(npc.x(L),npc.y(L))
case "w","r"
npc.x(L)=old.npc.x(L)
npc.y(L)=old.npc.y(L)
case else
old.npc.x(L)=npc.x(L)
old.npc.y(L) =npc.y(L)
end select
End if
NEXT
RETURN
[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
confirm "Keep .BMP?"; yesno$
if yesno$ = "no" then
goto [quit.bmp]
else
keep$=yesno$
end if
'turn into sprite
'add to new tile data array
'wait for admin command to change value
'@map XXYY aVar$ = command$
[quit.bmp]
Close #bmp
goto [reDo]
[quit.main]
unloadbmp "back.bmp"
unloadbmp "empty.bmp"
for i = 1 To 4
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 outputchat(textchat$)
if textchat$ <> "" then
open "text.txt" for output as #uploads
print #uploads, time$("ms");" ";textchat$
close #uploads
end if
End Function
Trying to convert commands into a simple universal function right now, lost my NPC's though, maybe because its apart of the same array for cheating to see if it worked. cundo what do you means X Y player movement boundries which [branch] is that located?