map editor help.

BlitzMax Forums/BlitzMax Beginners Area/map editor help.

Amon_old(Posted 2005) [#1]
heres my current code. Please look at the createtile function and tell me what I'm doing wrong.

Ill post the first code which doesnt work because of an index out of bounds in an array and the other code which works but wothout the createtile function.

CODE 1:
Strict

Rem 
MapEditor Version 0.1
Author   : Amon
Compiler : BlitzMax
EndRem

Incbin "backblock.png"
Incbin "icon.png"

Graphics 800,600,16,0

SetMaskColor 0,0,0

Global tiles:TImage = LoadAnimImage("incbin::backblock.png",50,50,0,9,MASKEDIMAGE)
Global icon:TImage = LoadImage("incbin::icon.png",MASKEDIMAGE)

Global tileframe:Int = 0

Global mapx:Int = 16
Global mapy:Int = 12
Global x:Int
Global y:Int
Global image:String

Global map:Int[mapx,mapy]

Type tile

	Field x:Int, y:Int
	Field image
	
End Type

Repeat 

	Cls
	
		drawtile()
		drawcurser()
		
		changetile()
		
		If MouseDown(KEY_MOUSELEFT) Then createtile()
	Flip
	
Until KeyHit(KEY_ESCAPE)

Function drawtile()

	Local xpos:Int = 0
	Local ypos:Int = 550
	Local frame:Int = 0
	
	For Local i:Int = 0 To 8
	
		DrawImage tiles,xpos,ypos,frame
		
		xpos:+50
		
		frame:+1
		
		If frame > 8 Then frame = 0
		
	Next
	
End Function

Function drawcurser()
	
	Local x:Int = MouseX()/50
	Local y:Int = MouseY()/50
	
	DrawImage icon,x*50,y*50,0

	
End Function

Function createtile()

	Local t:tile = New tile
	t.x = MouseX()
	t.y = MouseY()
	t.image = tiles
	
	map[mapx,mapy] = tileframe
	
End Function
		
Function changetile()

	If MouseHit(KEY_MOUSERIGHT) 
	
		tileframe:+1
		
		If tileframe > 8 Then tileframe = 0
		
	End If
	
End Function


CODE 2 works :

Global tiles:TImage = LoadAnimImage("incbin::backblock.png",50,50,0,9,MASKEDIMAGE)
Global icon:TImage = LoadImage("incbin::icon.png",MASKEDIMAGE)

Global tileframe:Int = 0

Global mapx:Int = 16
Global mapy:Int = 12
Global x:Int
Global y:Int
Global image:String

Global map:Int[mapx,mapy]

Type tile

	Field x:Int, y:Int
	Field image
	
End Type

Repeat 

	Cls
	
		drawtile()
		drawcurser()
		changetile()
		
	Flip
	
Until KeyHit(KEY_ESCAPE)

Function drawtile()

	Local xpos:Int = 0
	Local ypos:Int = 550
	Local frame:Int = 0
	
	For Local i:Int = 0 To 8
	
		DrawImage tiles,xpos,ypos,frame
		
		xpos:+50
		
		frame:+1
		
		If frame > 8 Then frame = 0
		
	Next
	
End Function

Function drawcurser()
	
	Local x:Int = MouseX()/50
	Local y:Int = MouseY()/50
	
	DrawImage icon,x*50,y*50,0

	
End Function
		
Function changetile()

	If MouseHit(KEY_MOUSERIGHT) 
	
		tileframe:+1
		
		If tileframe > 8 Then tileframe = 0
		
	End If
	
End Function



here are the images






altitudems(Posted 2005) [#2]
Amon,

It's pretty simple.
'*This is where you are defining the size of the map array

Global mapx:Int = 16
Global mapy:Int = 12

'*Now the array is create with the size of 16x12 tiles.
'*REMEMBER: This starts from ZERO NOT ONE

Global map:Int[mapx,mapy]
'* Later you try and change the value inside the map array.
'* What your not understanding is that you are trying to change tile (16,12)
'* If you count from 0 it would actualy be (15,11)

map[mapx,mapy] = tileframe

'So in that case, the following would work

map[mapx-1,mapy-1] = tileframe