Help wit my game please!

Blitz3D Forums/Blitz3D Beginners Area/Help wit my game please!

ok well im making a basic rpg with pictures (Or atleast trying) and i need to get the person's name under the picture of him. Im not sure what code you need but here is a little bit of it.


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 

Text ,,"" + name$ + ""

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 


How big are the players' pictures??

If you want to center the text then add half the width of the image to its x coordinate and subtract half the pixel width of the text to get the appropriate x value; The y value for the text will be the ycoord of the image plus the image's height plus however much padding you want.

EDIT:
Here's a rough example. Notice that the text is treated as if it were a bitmap font, which is what you'll inevitably end up using.
Graphics 640,480,0,2
SetBuffer BackBuffer()

Const AVATAR_WIDTH% = 64
Const AVATAR_HEIGHT% = 128
Const FONT_WIDTH% = 12
Const FONT_HEIGHT% = 12

MakeAvatar("Sarah")
MakeAvatar("John")
MakeAvatar("Zed")
MakeAvatar("JJ")
MakeAvatar("X")

Color 100,255,100

While Not KeyHit(1)
	DrawAllAvatars()
	Text 10,10,"Left Mouse Button To Delete Avatars..."

	Flip True
	Cls
	
	If MouseHit(1) DeleteAvatar()
Wend
End




Global Avatar_Count% = 0

Type TAvatar
	Field piccy%
	Field name$
End Type


Function MakeAvatar(name_arg$)
	Color 100+Rand(155),100+Rand(155),100+Rand(155)
	Rect 0,0,AVATAR_WIDTH,AVATAR_HEIGHT
	
	newAvatar.TAvatar = New TAvatar
	newAvatar\name = name_arg
	newAvatar\piccy = CreateImage(AVATAR_WIDTH,AVATAR_HEIGHT)
	GrabImage newAvatar\piccy,0,0
	Cls
	
	Avatar_Count = Avatar_Count+1
End Function

Function DeleteAvatar()
       	If Avatar_Count = 0 Return

	Local avatarToDelete.TAvatar = First TAvatar
	FreeImage avatarToDelete\piccy
	Delete avatarToDelete 
	Avatar_Count=Avatar_Count-1
End Function

Function DrawAllAvatars()
	If Avatar_Count = 0 Return
	
	Local xSpace% = GraphicsWidth()/(Avatar_Count+1)
	Local currentAvatarIndex% = 1

	For currentAvatar.TAvatar = Each TAvatar
		DrawBlock currentAvatar\piccy,(currentAvatarIndex*xSpace)-(AVATAR_WIDTH*.5),GraphicsHeight()-AVATAR_HEIGHT-10-FONT_HEIGHT
		DrawName(currentAvatar\name,(currentAvatarIndex*xSpace)-(AVATAR_WIDTH*.5),GraphicsHeight()-10-FONT_HEIGHT)

		currentAvatarIndex = currentAvatarIndex+1
	Next
End Function

Function DrawName(string_arg$, xPos_arg%, yPos_arg%)
	Local pixelWidth% = Len(string_arg)*FONT_WIDTH
	Local centeredX% = (xPos_arg+(AVATAR_WIDTH*.5)) - (pixelWidth*.5)
	
	For currentCharIndex = 0 To Len(string_arg)
		Text centeredX+(currentCharIndex*FONT_WIDTH),yPos_arg,Mid(string_arg,currentCharIndex+1,1)
	Next
End Function


i tried your code and i cant figure it out still. :( the people's pictures are 50 by 50 pixels

Location of text =

NOTE: START X and START Y are the top corner your using to draw the image.

x = (the START X + (HALF OF THE WIDTH of the image)) - (HALF the width of the text)

y = the START Y + HEIGHT of the image + SPACING between the text and the picture

Note, the above is if you wish to centre some text. Practical example:


message$ = "John"

image = createimage(50,50)

startX = 50
startY = 50

spacing = 10 ; 10 pixels spacing.

DrawImage image,startX,startY

Text (startX + (imagewidth(image)/2)) - (stringwidth(message)/2) , startY + imageheight(image) + spacing, message



ok but my people move and i would like to make the text under and folow them. That way people know which person is which

And that will happen. startX and startY are simply variables. Just adjust them as needed, like when the player moves. Simple variable stuff ;o)

Ok well, im really bad at this stuff. i cant really program and the biggest program i made is a 2D rpg. I found some code with pictures and moveing people and im trying to make an rpg with all the code i got. here is what i have so far. Help please!!!

Graphics 800,600,32,2
AutoMidHandle True 


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


Type player 
Field x,y,startX,startY 
Field name$
End Type 


name$ = "nick"
Global image=LoadImage("statusbar.png")
Global background2=LoadImage("mapp 2.bmp")

Global player.player=New player 

startX = 50
startY = 50

spacing = 10 ; 10 pixels spacing.

DrawImage image,startX,startY

Text (startX + (ImageWidth(image)/2)) - (StringWidth(name)/2) , startY + ImageHeight(image) + spacing, name

typeini()

While Not KeyDown(1) ;Esc
Cls 



leveldraw() 

playermovement() 

leveltrans() 
 
Flip 
Wend 


Function typeini() 
player\x=500 
player\y=100 
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 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 leveldraw() 

TileImage background2
;DrawImage tree,

;DrawImage statusbarimage,400,580 

DrawImage image,player\x,player\y

End Function 


Text x,y,message,1,0;

the two optional parameters centre the string.

You need to put the text command and the image drawing stuff in the main loop, or else it will be drawn once and deleted.

you're going to want to use the entity parent command to set the picture (name) as a child element to the (normal) picture.

He is using 2d graphics, so you can't use entityparent in this instance.