Controls: Move with directional keys, NPC chat with right CTRL, exit with Esc
Note: Upon startup, press enter to view it normally (will automatically choose best graphics mode). If you get error "unable to create graphics" then open again and type "y" for 1024x768 windowed.
Note 2: You can edit in your own NPCs! Just open "npc.txt" and directions are inside.
Source code at bottom of page, compile with Blitz3D v198
Global char = LoadImage("char2.png")
Global map = LoadImage("map1.png")
Global map2 = LoadImage("map2.png")
Global map3 = LoadImage("map3.png")
Global map4 = LoadImage("map4.png")
Global map5 = LoadImage("map5.png")
Global map6 = LoadImage("map6.png")
Global map7 = LoadImage("map7.png")
Global map8 = LoadImage("map8.png")
Global map9 = LoadImage("map9.png")
If Not char
RuntimeError "Could not load char2.png. Please check if it exists, or make sure you extracted first."
End
EndIf
If Not map
RuntimeError "Could not load map1.png. Please check if it exists, or make sure you extracted first."
End
EndIf
MaskImage char, 94, 141, 41
Global playerx, playerxspeed = 12 ;player position and speed variables
Global playery, playeryspeed = 12
Global npcid, currentnpcID ;Most recently issued NPC ID
font1 = LoadFont("Comic Sans MS",28)
SetFont font1
;main NPC type
Type npc
Field x, y, npcid, text1$, text2$, text3$, text4$, name$
End Type
;Set up game
npcf = ReadFile("npc.txt")
While Not Eof(npcf)
xs$=Left(ReadLine(npcf),1)
If xs = ";"
While xs=";"
xs=Left(ReadLine(npcf),1)
Wend
EndIf
x=Int(xs)
Local y=Int(ReadLine(npcf)),name$=ReadLine(npcf),t1$=ReadLine(npcf),t2$=ReadLine(npcf),t3$=ReadLine(npcf),t4$=ReadLine(npcf)
CreateNPC(x,y,name$,t1$,t2$,t3$,t4$)
blank$=ReadLine(npcf)
If blank$ = ""
DebugLog "np"
Else
DebugLog blank$
RuntimeError("NPC.txt corrupted, please follow the proper format.")
EndIf
Wend
CloseFile(npcf)
Global milliseconds = MilliSecs()
Global millisecs1 = milliseconds
Global gtime=0
;MAIN LOOP
While Not KeyHit(1)
DetectKeys()
DrawScreen()
FPSLimit()
Wend
End
Function CreateNPC(npcx, npcy, name$, itext1$, itext2$, itext3$, itext4$)
ccnpc.npc = New npc ;Create a new NPC at the given coordinates
ccnpc\x = npcx
ccnpc\y = npcy
ccnpc\npcid = npcID + 1001
ccnpc\text1$ = itext1$
ccnpc\text2$ = itext2$
ccnpc\text3$ = itext3$
ccnpc\text4$ = itext4$
ccnpc\name$ = name$
npcID = npcID + 1
End Function
Function DetectKeys() ;Detect which keys were pressed and act accordingly
If KeyDown(UP_KEY)
playery = playery - playeryspeed
EndIf
If KeyDown(DOWN_KEY)
playery = playery + playeryspeed
EndIf
If KeyDown(LEFT_KEY)
playerx = playerx - playerxspeed
EndIf
If KeyDown(RIGHT_KEY)
playerx = playerx + playerxspeed
EndIf
If KeyHit(RIGHT_CTRL) ;Detect if player is talking to an NPC
If drawnpctext = True
For cnpc.npc = Each NPC
If cnpc\npcID = currentnpcID
Select npctext$
Case cnpc\text1$
npctext$ = cnpc\text2$
Case cnpc\text2$
npctext$ = cnpc\text3$
Case cnpc\text3$
npctext$ = cnpc\text4$
Case cnpc\text4$
npctext$ = ""
npcname$ = ""
drawnpctext = False
Default
npctext$ = cnpc\text1$
End Select
If npctext$ = ""
drawnpctext = False
Return
EndIf
Exit
EndIf
Next
EndIf
For cnpc.npc = Each npc ;Detect if player is near NPC
If (Sqr(((playerx - (cnpc\x + (ImageWidth(char)/2)))^2) + ((playery - (cnpc\y + (ImageHeight(char)/2))) ^ 2))) < 190
drawnpctext = True
currentnpcID = cnpc\npcID
If npctext$ = ""
npctext$ = cnpc\text1$
npcname$ = cnpc\name$
EndIf
EndIf
;draw text
Color(250,250,250)
Text(((GraphicsWidth()/2) - (StringWidth(npctext$)/2)) + 15, (GraphicsHeight() - (GraphicsHeight()/3)) + 10, npcname$)
Text(((GraphicsWidth()/2) - (StringWidth(npctext$)/2)) + 30, (GraphicsHeight() - (GraphicsHeight()/3)) + 50, npctext$)
End Function
Function FPSLimit()
time = 0
Repeat
milliseconds = ((MilliSecs()-millisecs1))
Delay(1)
If time = 0
time = milliseconds
EndIf
Until milliseconds > 16
If milliseconds > 16
millisecs1 = MilliSecs()
EndIf
gtime = time
End Function
Function DrawScreen() ;Render all objects to be displayed
Cls()
Local mapx = (-(playerx) + (GraphicsWidth()/2)), mapy = (-(playery) + (GraphicsHeight()/2)) ;calculate map coordinates
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum