Help with my "RPG"?

Blitz3D Forums/Blitz3D Beginners Area/Help with my "RPG"?

Hi well um im trying to make a online rpg (dont know what to call it cause there is going to be a 30 people server limit) and i need help with sounds. I have a 14 second loop song called song.wav
and i need it to play in my code while the people are doing stuff. Here is my unfinished code:
Graphics 800,600,32,2
AppTitle "RPG" 
AutoMidHandle True 
SeedRnd(MilliSecs()) 
startup()

;Constants 


Const UPKEY=200 
Const DOWNKEY=208 
Const LEFTKEY=203 
Const RIGHTKEY=205 

;Images 
Global background=LoadImage("background.bmp")
Global wizard=LoadImage("wizard.bmp")
Global wizblur=LoadImage("wizard blur.bmp")
Global invis=LoadImage("invisable.bmp")
Global rat=LoadImage("rat.bmp")
Global wich=LoadImage("wich.bmp")
Global wichblur=LoadImage("wich blur.bmp")
Global man=LoadImage("man.bmp")
Global women=LoadImage("women.bmp")
Global mf$,name$,password$
Global curser=LoadImage("curser.bmp")



;Types 
Type player 
Field x,y 
Field hitpoints%
Field name$
End Type 

Type monster
Field hitpoints%
End Type


;Type INI 

Global player.player=New player 

;Initalization 

typeini() 

;Main Loop 
x = 50
y = 50

While Not KeyDown(1) ;Esc
Cls 


leveldraw() 

playermovement() 

leveltrans() 


HidePointer
DrawImage curser, MouseX (), MouseY ()
 

Flip 
Wend 

;Functions 

Function leveldraw() 

TileImage background

HUD()
If mf$="male"
DrawImage man,player\x,player\y
Else
If mf$="female"
DrawImage women,player\x,player\y
EndIf
EndIf 

End Function 


Function typeini() 
player\x=500 
player\y=100 
player\hitpoints%=10 
End Function 

Function playermovement() 

If KeyDown(UPKEY) 
player\y=player\y-3 
ElseIf KeyDown(DOWNKEY) 
player\y=player\y+3 
ElseIf KeyDown(RIGHTKEY) 
player\x=player\x+3 
ElseIf KeyDown(LEFTKEY) 
player\x=player\x-3 
EndIf 

End Function 

Function leveltrans() 
If player\x=>1018 
player\x=player\x-1017 
ElseIf player\x=<6 
player\x=player\x+1018 
ElseIf player\y=>701 
player\y=player\y-700 
ElseIf player\y=<5 
player\y=player\y+695 

EndIf 
End Function 

Function HUD() 
Color 250,0,0
Text 1,1,"Health: " + player\hitpoints% + ""
End Function


Function Startup()
Print "Checking for info"
filein = ReadFile("userfile.txt")
If filein <> 0
	name$ = ReadLine$(filein)
	password$ = ReadLine$(filein)
	mf$ = ReadLine$(filein)
	Print "Name: "+ name$ + ""
	pass$=Input("Password: ")
	If pass$=password$
	Print "Welcome!"
	Delay 2000
	Else
	Print "Wrong password."
	Delay 2000
	End
	EndIf 
Else
	Print "You are a new user, please create an account:
	Print ""
	name$ = Input$("Enter a new name: ")
	password$ = Input$("Enter a new Password: ")
	mf$ = Input("male or female: ")
	fileout = WriteFile("userfile.txt")
	WriteLine(fileout,name$)
	WriteLine(fileout,password)
	WriteLine(fileout,mf)
	CloseFile fileout
	Print ""
	Print "Thank you, you will be automatically logged in"
	Delay 3000
End If
CloseFile filein
End Function 



Ok wow ive been working 3 stright hours and i need more help :(
1) I need help overwriting saved files...
2) How would i get my person to move screen to screen?
Like i have 6 screens and you need to be in one to get to another one. So i have arrows and if you hit the wasd keys (w is up,a is left ect.) how would i move? Its in level draw i think... heres new code...
Graphics 800,600,32,2
AppTitle "RPG"
AutoMidHandle True 
SeedRnd(MilliSecs()) 
login()

;Constants 


Const UPKEY=200 
Const DOWNKEY=208 
Const LEFTKEY=203 
Const RIGHTKEY=205 




;Images 
Global mf$,name$,password$,ww$,l$,I$,m$,image$
Global castle=LoadImage("castle.bmp")
Global house=LoadImage("house.bmp")
Global background1=LoadImage("background.bmp")
Global background2=LoadImage("background.bmp")
Global background3=LoadImage("background.bmp")
Global background4=LoadImage("background.bmp")
Global background5=LoadImage("background.bmp")
Global background6=LoadImage("background.bmp")
Global wizard=LoadImage("wizard.bmp")
Global wizblur=LoadImage("wizard blur.bmp")
Global invis=LoadImage("invisable.bmp")
Global rat=LoadImage("rat.bmp")
Global wich=LoadImage("wich.bmp")
Global wichblur=LoadImage("wich blur.bmp")
Global man=LoadImage("man.bmp")
Global women=LoadImage("women.bmp")
Global curser=LoadImage("curser.bmp")
Global arrowu=LoadImage("arrow up.bmp")
Global arrowd=LoadImage("arrow down.bmp")
Global arrowr=LoadImage("arrow right.bmp")
Global arrowl=LoadImage("arrow left.bmp")
Global map=LoadImage("map.bmp")
Global inventory=LoadImage("backpack.bmp")
Global money=LoadImage("coin.bmp")
Global sword=LoadImage("sword.bmp")
Global bone=LoadImage("bone.bmp")


;Types 
Type player 
Field x,y 
Field hitpoints%
Field name$
Field items$
End Type 

Type monster
Field hitpoints%
End Type


;Type INI 

Global player.player=New player 

;Initalization 

typeini() 

;Main Loop 
x = 50
y = 50

While Not KeyDown(1) ;Esc
Cls 

If KeyDown(19)
rules()
EndIf 

If KeyDown(35)
help
EndIf 

If KeyDown(50)
Cls
DrawImage map,400,300
WaitMouse()
EndIf 




leveldraw() 

playermovement() 

leveltrans() 


HidePointer
DrawImage curser, MouseX (), MouseY ()


Flip 
Wend 

;Functions 

Function leveldraw() 
image$=background1

If image$=background1
If KeyHit(17) ;w
image$=background3
EndIf
EndIf 

If image$=background3
If KeyHit(17) ;w
image$=background5
If KeyHit(30) ;a
image$=background4
If KeyHit(31)
image$=background1
EndIf
EndIf
EndIf
EndIf 

If image$=background2
If KeyHit(17) ;w
image$=background4
EndIf
EndIf 

If image$=background4
If KeyHit(32) ;d
image$=background3
If KeyHit(31) ;s
image$=background2
EndIf
EndIf 
EndIf

If image$=background5
If KeyHit(31) ;s
image$=background3
If KeyHit(30) ;a
image$=background6
EndIf
EndIf  
EndIf 

If image$=background1
If KeyHit(32) ;d
image$=background5
EndIf
EndIf 

TileImage image$

If image$=background1
DrawImage arrowu,400,40
EndIf 
If image$=background2
DrawImage arrowu,400,40
EndIf 
If image$=background3
DrawImage arrowu,400,40
DrawImage arrowl,40,300
DrawImage arrowd,400,560
EndIf 
If image$=background4
DrawImage arrowr,760,300
DrawImage arrowd,400,560
EndIf 
If image$=background5
DrawImage arrowl,40,300
DrawImage arrowd,400,560
EndIf
If image$=background6
DrawImage arrowr,760,300
EndIf 


HUD()

If ww$="wich"
DrawImage wich,player\x,player\y
Else
If mf$="female"
DrawImage women,player\x,player\y
EndIf
EndIf
If ww$="wizard"
DrawImage wizard,player\x,player\y
Else
If mf$="male"
DrawImage man,player\x,player\y
EndIf
EndIf


End Function 


Function typeini() 
player\x=500 
player\y=100 
player\hitpoints%=10 
End Function 

Function playermovement() 

If KeyDown(UPKEY) 
player\y=player\y-3 
ElseIf KeyDown(DOWNKEY) 
player\y=player\y+3 
ElseIf KeyDown(RIGHTKEY) 
player\x=player\x+3 
ElseIf KeyDown(LEFTKEY) 
player\x=player\x-3 
EndIf 

End Function 

Function leveltrans() 
If player\x=>1018 
player\x=player\x-1017 
ElseIf player\x=<6 
player\x=player\x+1018 
ElseIf player\y=>701 
player\y=player\y-700 
ElseIf player\y=<5 
player\y=player\y+695 

EndIf 
End Function 

Function HUD() 
Color 250,0,0
Text 1,1,"Health: " + player\hitpoints% + ""
End Function


Function login()
Print "Checking for info"
filein = ReadFile("userinfo.txt")
If filein <> 0
	name = ReadLine$(filein)
	password = ReadLine$(filein)
	mf$ = ReadLine$(filein)
	Print "Name: " + name + ""
	pass$=Input("Password: ")
	If pass$=password$
	Print "Welcome " + name + "!"
	Delay 2000
	Else
	Print "Wrong!"
	Delay 3000
	End
	EndIf 
Else
	Print "You are a new user, please create an account:"
	Print ""
	name = Input$("Enter a new name: ")
	password$ = Input$("Enter a new password: ")
	mf$ = Input$("male or female: ")
	fileout = WriteFile("userinfo.txt")
	WriteLine(fileout,name)
	WriteLine(fileout,password$)
	WriteLine(fileout,mf$)
	CloseFile fileout
	Print ""
	Print "Thank you, you are automatically logged in"
	Delay 3000
End If
End Function 


Function help()
Cls 
Print "If you see a red arrow, use the WASD keys like arrow keys"
Print "to move to a new page. The M key is your map. Red blocks"
Print "on the map mean you can go that way. Arrows on your screen"
Print "tell you the same. Pressing the ENTER key brings you to chat."
Print "Pressing it again sends your message. The R key shows you the"
Print "rules. I is inventory and to talk to a npc, click on them."
Print "Thats it for now :). Click To continue..."
WaitKey()
End Function 

Function rules()
Cls 
Print "1) No bad lanuage."
Print "2) No useing 3rd party softwear.(ex. auto talker,skiller...)"
Print "3) No hacking or cheating."
Print "4) No creating private servers."
Print "5) Try not to be rude."
Print "Click to continue..."
WaitMouse()
End Function 

Function inventory()
End Function



For the sound thing, Load the sound to memory and set it to loop with:

	MySound=LoadSound(Sound_Filename$)
	LoopSound MySound

Just before the game-loop where it should play:
	MySoundChannel=PlaySound(MySound) 


When it's time to stop the music playing (FOr example, all players are established)
	StopChannel MySoundChannel


I'm not sure what the meaning is of a lot of the code, it seems pretty messy to me:

Function leveldraw() 
image$=background1

If image$=background1
If KeyHit(17) ;w
image$=background3
EndIf
EndIf 

If image$=background3
If KeyHit(17) ;w
image$=background5
If KeyHit(30) ;a
image$=background4
If KeyHit(31)
image$=background1
EndIf
EndIf
EndIf
EndIf 



Background1 Background2 etc. ARE ALL THE SAME Image ("background.bmp")
And in the snippet above, you are seeing if "image$" (A string) is equivalent to the Image handle?

Also the entrie funciton begins with:
image$=background1

If image$=background1
If KeyHit(17) ;w
image$=background3
EndIf
EndIf 


So Image$ WILL ONLY BE = background1, meaning the only possible outcome is that w must be pressed in order to change the value of Image$ to further affect the following If's... Very unlikely anyone has reflexes quick enough to press the 'correct' keys in the 'correct' order to achieve much.

Thanks for the help but for the background thing, well i am going to make this multiplayer and load more images. For each background there is going to be something differnt on there that i use the drawimage command for. Here is a pic of the map of the game...

how would you move the person screen to screen if it has an arrow on it (Red block)? For the music i need it to play the whole game. Loop after loop after loop.