• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Iso Mouse Mapping

This topic is 5329 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay I read Steven Harrison''s Mouse mapping artical, but I have a question... Im using BlitzBasic and I was wondering if anyone would know how this could be done thru Basic code..?

##### Share on other sites
Hi again,
It''s been a while since I used Blitz (I''m going back to the Amiga version here) but I belive that the same holds true for the version on the PC.

All you need to do is create your mouse map tiles and load them into an array, then use the array as your lookup.

If you give me a couple of hours I''ll convert the c++ code in my article to basic, it might not be blitz but it will be basic.

You should be able to convert the code directly to basic from C as I''m not using anything in C that Basic can not do...

When I find my code in tons of trouble,
Friends and colleages come to me,
Speaking words of wisdom:
"Write in C."

##### Share on other sites
cool.. im trying to make a game like Transport Tycoon and i need the Heightmapping thanks

##### Share on other sites
OK this is the quick and dirty conversion of my code that was posted in the article to Blitz Basic.

I appologise ahead of time as the code posted here is not tested and could be full of syntax errors, mainly because I have just downloaded and installed the Blitz Plus Demo on my laptop. As far as I can tell from looking at the examples it is syntactically correct I may have a few things wrong, as the demo does not come with any help files (a programming language with no command list is a bit silly IMHO!!!)

; Ok this is a quick and not tested conversion of my code to Blitz Plus V1.11 (Demo version); One thing I''m doing in this conversion is removing the ability to change the tile sizes while your; running the code, as I do not know Blitz Basic that well to include the more advanced features that ; C allows.; I will not convert the LoadMouseMaps() code as it is basically a file reading and storing function; Original C code first then the blitz conversion;Int MM_LookUp( Int x, Int y, Int t );{;  Int v;;;  x %= ( m_Size == 1 ? 32 : 64 );;  y %= ( m_Size == 1 ? 32 : 64 );;;  v = g_MouseMap[m_Size][t][y][x >> 1];;;  If( ( x & 1 ) == 0 );    v = v & 0x0F;;  Else;    v = ( v >> 4 ) & 0x0F;;;  Return v;;}Function MM_Lookup( x, y, t )	v = 0;		x = x Mod 64 ; I''ll assume your tiles are 64x32, if not change the 64 to your width	y = y Mod 64 ; As above, and because the tile maps are square this is the width of your tile		; This is a multi-dimention array that you have loaded in the mouse map tiles earlier	v = g_MouseMap( t, y, x / 2 )		; Because I stored the data into nibbles (4 bits) instead of bytes (8 bits) I''m only going 	; to return the correct nibble / offset number.		If ( ( x And 1 ) == 1 ) Then		v = v And 15	Else		v = (v / 16) And 15	End IfEnd Function; No c souce this time as it''s a bit large...; mx and my will contain the map x and y positions when the function finishes, since I do; not know how this is done in Blitz (I just downloaded it now...) I will leave this to you to work; out; m_OffX and m_OffY are the world offsetsFunction MouseMap( xp, yp, mx, my )	m = 0	cx = 0	cy = 0	fx = 0	fy = 0	md = 0	mc = 0		; Adjustment for the lower left corner offset	yp = yp + 64		; Step 1 : Screen -> World Co-ords	xp = xp + m_OffX	yp = yp + m_OffY		; Step 2 : Offset world co-ords of tile (0,0) i.e. your very first tile	xp = xp - ( ( 0 - 0 ) * 64 )	yp = yp - ( ( 0 + 0 ) * 32 )	; Ok I know it looks silly, but it''s TANSTAAFL does in his code...		; Step 3 : Determine MouseMap Co-ords		; Course co-ords	cx = xp / 64 ; Assuming tiles are 64 x 32	cy = yp / 32		; Fine co-ords	fx = xp Mod 64	fy = yp Mod 32		; Adjustment for the square mouse maps and not the tile size mouse maps	fy = fy + 16 ; 1/4 of a tile width / height		; Adjustment for the negative co-ords	If ( fx < 0 ) Then		fx = fx + 64;		cx = cx - 1;	End If		If ( fy < 0 ) Then		fy = fy + 64;		cy = cy - 1;	End If		; Step 4 Perform course tile walk	mx = 0	my = 0		While( cy < 0 )		TileWalk ( mx, my, ISO_NORTH );		cy = cy + 1;	Wend		While( cy > 0 )		TileWalk ( mx, my, ISO_SOUTH );		cy = cy - 1;	Wend		While( cx < 0 )		TileWalk ( mx, my, ISO_WEST );		cx = cx + 1;	Wend		While( cx > 0 )		TileWalk ( mx, my, ISO_EAST );		cx = cx - 1;	Wend		; Step 5 : Use the lookup table for the final tile walk...	m = -1 	mc = 4 ; Used to track the number of moves we have done in oposit directions.		While( ( m != MM_NONE ) && ( mc > 0 ) )		; With out the inline if statement in C ( the (my >= 0 ) ? my : 0 ) part ) then the		; following may cause errors...		m = MM_Lookup( fx, fy + ( Map( my, mx )\height * 8 ), Map( my, mx )\Floor )				; With out the inline if statement in C ( the (my >= 0 ) ? my : 0 ) part ) then the		; following may cause errors...		tfy = ( fy + Map( my, mx )\height * 8 )				If( ( fx >= 0 ) And ( tfy >= 0 ) And ( fx < 64 ) And ( tfy < 64 ) ) Then			Select m				Case MM_NORTHWEST:					If( md = MM_SOUTHEAST )						mc = mc - 1;					Else						mc = 4;					TileWalk( mx, my, ISO_NORTHWEST );					fx = fx + 32 ; Half tile x height (assuming tiles are 64 x 23 )					fy = fy + 16 ; Half tile y height (assuming tiles are 64 x 23 )				End Case				Case MM_NORTH:					If( md = MM_SOUTH )						mc = mc - 1;					Else						mc = 4;					TileWalk( mx, my, ISO_NORTH );					fy = fy + 16 ; Half tile y height (assuming tiles are 64 x 23 )				End Case				Case MM_NORTHEAST:					If( md = MM_SOUTHWEST )						mc = mc - 1;					Else						mc = 4;					TileWalk( mx, my, ISO_NORTHEAST );					fx = fx - 32 ; Half tile x height (assuming tiles are 64 x 23 )					fy = fy + 16 ; Half tile y height (assuming tiles are 64 x 23 )				End Case				Case MM_SOUTHWEST:					If( md = MM_NORTHEAST )						mc = mc - 1;					Else						mc = 4;					TileWalk( mx, my, ISO_SOUTHWEST );					fx = fx + 32 ; Half tile x height (assuming tiles are 64 x 23 )					fy = fy - 16 ; Half tile y height (assuming tiles are 64 x 23 )				End Case				Case MM_SOUTH:					If( md = MM_NORTH )						mc = mc - 1;					Else						mc = 4;					TileWalk( mx, my, ISO_SOUTH );					fy = fy - 16 ; Half tile y height (assuming tiles are 64 x 23 )				End Case				Case MM_SOUTHEAST:					If( md = MM_NORTHWEST )						mc = mc - 1;					Else						mc = 4;					TileWalk( mx, my, ISO_SOUTHEAST );					fx = fx - 32 ; Half tile x height (assuming tiles are 64 x 23 )					fy = fy - 16 ; Half tile y height (assuming tiles are 64 x 23 )				End Case			End Select		Else			If( tfy >= 64 ) ) Then				m = MM_SOUTH;				TileWalk( mx, mym ISO_SOUTH );				fy = fy - 32;			End If		End If		md = m	WendEnd Function; OK that''s the main mouse map functions converted, as I said previously the mx, and my variables; are changed inside other functions and since I do not know how to do this in blitz I have just done; a straight convesrion from C to Basic and also added a few errors which I have pointed out already...

When I find my code in tons of trouble,
Friends and colleages come to me,
Speaking words of wisdom:
"Write in C."

##### Share on other sites
I''ve just noticed that the code for the tile walk function is not there, this is a simple function that moves the mx and my variables according to the direction passed into it from the calling code, infact this is probably one of the only bits of TANSTAAFL''s code I changed...

##### Share on other sites
Thanks,

From what I see its a good conversion there are a few errors, which I may need you to look at for insance

; Step 5 : Use the lookup table for the final tile walk...
m = -1
mc = 4 ; Used to track the number of moves we have done in oposit directions.

While( ( m <> MM_NONE ) And ( mc > 0 ) )
; With out the inline if statement in C ( the (my >= 0 ) ? my : 0 ) part ) then the
; following may cause errors...
m = MM_Lookup( fx, fy + ( Map( my, mx )\height * 8 ), Map( my, mx )\Floor )

; With out the inline if statement in C ( the (my >= 0 ) ? my : 0 ) part ) then the
; following may cause errors...
tfy = ( fy + Map( my, mx )\height * 8 )

the Map(my,mx) is this a function that I might not have?? it gives me a expecting ) like you said before there might be chance of error.. so I know don't know if the coversion is correct..

other than thats looks good

[EDIT]

From what I see thru the code there is a few arrays not defined.. this can cause alot of problems and i don't know which arrays need to be defined and how much also the lines

While( cy < 0 )
TileWalk ( mx, my, ISO_NORTH )
cy = cy + 1
Wend

don't work this way if TileWalk is a array it needs to be defined if its a functoin there has to be a function built for it... hmm it must be hard to convert this

[EDIT]

Sorry I didn't read the rest of the post tha twell okay I see that the function to do tilewalk must be in the other tutorails thanks

[edited by - fbepyon on June 8, 2004 1:06:39 PM]

[edited by - fbepyon on June 8, 2004 1:20:59 PM]

[edited by - fbepyon on June 8, 2004 1:23:01 PM]

##### Share on other sites
Your mouse map loading function makes no sence and might not work in blitz

but from what I can see it doesn''t see that I can load a raw file into blitz and read it.. unless Im mistaking something and did something wrong

##### Share on other sites
Map() is your map data with height, floor/left/right/object tiles.

If I had some decent docs or even samples that shows how to open files then I could write a full blitz sample, but the samples that come with BlitzPlusDemo have no comments what so ever...

So if you could tell me how to do the following:

File operations (open, read a byte and close)
Multi-dimention arrays ( 2, 3 or 4 dirmentional)
Graphics I think I got, well I got something moving with the mouse...
How to pass values back from function calls where the values passed are changed
How to create custom varaible types

If I hadd the above info I could write a small example for you in a couple of days...

When I find my code in tons of trouble,
Friends and colleages come to me,
Speaking words of wisdom:
"Write in C."

##### Share on other sites
Im about done with the, conversion of your Code, but im still confused to where to find the TileWalk function if you could give me that code in C++ I should be able to handle most ot it..

the doc are very large for Blitz, you would have to email me for them.. thanks..

Basic Commands:

Arrays MultiD:

DIM Array(x,y,z,....)

Blitz comes with its own Array called Blitz Array, but only alows for one Array Type

Array[x]

Files Are a bit trick for even me to understand and there commands are long

handle = OpenFile(file$) handle = ReadFile(file$)
handle = WriteFile(file$) CloseFile(handle) int = ReadInt(handle WriteInt(handle,int) Graphics WOW yeah this is kinda a pain and easy at the sametime handle = loadimage(file$)
handle = loadanimimage(file$,sizex,sizey,frame0,framelast) drawimage handle,x,y,(frame optional) ; Frames are only used for LoadAnimImage And returning a varible thru a Function function blah(v) local v = 1000 return v end function How to create custom varaible types?? not Get Global Local Mostly used for Functions Const % - Int # - Float$ - String

this is the Blitz conversion of your code Steven plesae go thru it and tell me if this is right..

LoadMouseMap() might not be right because Im not sure if its a BYTE or INT or STRING thanks get back to me... Also the 0x0F is not supported by Blitz, but I don't know what it is if you could explain that also thanks..

One other thing is the .Height and .Floor are Classes right.. well Blitz doens't have classe only types so im not sure if that part is right also for it to work.

Once Again.. NULL only works for types in blitz so in order to find if something is there or not use 1 or 0 I usally do > 0 to see its there and just = 0 to check not there..

If fin = 0

RuntimeError "File not Found " + fin
Return False

Else

as you can see for the file function

http://www.filespace.org/fbepyon/ISO_C___to_Blitz

[edited by - fbepyon on June 10, 2004 1:47:42 AM]

[edited by - fbepyon on June 10, 2004 2:08:08 AM]

##### Share on other sites
Ok TileWalk() in pure C..

void Game::TileWalk(int &x, int &y, int Dir){	switch( Dir )	{	case ISO_NORTH:		{			x--;			y--;			break;		}	case ISO_NORTHEAST:		{			y--;			break;		}	case ISO_EAST:		{			x++;			y--;			break;		}	case ISO_SOUTHEAST:		{			x++;			break;		}	case ISO_SOUTH:		{			x++;			y++;			break;		}	case ISO_SOUTHWEST:		{			y++;			break;		}	case ISO_WEST:		{			x--;			y++;			break;		}	case ISO_NORTHWEST:		{			x--;			break;		}	}}

x and y are passed in and changed inside the fucntion then used outside the function as the new values (that''s what the & is for).

Ok your code problems...

0x0F is the hexidecimal for 15 so:

c = (ReadString$(fin) And 0x0F) Shl 4) + ReadString$(fin) And 0x0F

should be:

c = ( ( ReadByte(fin) And 15 ) Shl 4 ) + ( ReadByte(fin) And 15 )

You also missed a bracket set...
Err does readstring\$() return 1 character or a sting of chars???, answered this when readstring kept crashing and tried readint, then readbyte...

If your only doing one size of tile, then you can change all the if m_Size.... stuff to just use one size tile (as your mouse load proc is only setup for the 32x32 mouse maps...

and the rest looks right to me, I''m still fighting with blitz just to get it to say hello world without crashing the laptop...

I also think that some of the problems you have with my article is that it was written as an extention to TANSTAAFL''s Iso programing book, in that it explains everything (including the tile walk code). What I sugest you do is down load the sample from th article and pick apart the game.cpp file as that has all the missing functions in it. I''ll still battle blitz over the next couple of days, but it''s soo unstable on my laptop that I actually want to hit something hard....

When I find my code in tons of trouble,
Friends and colleages come to me,
Speaking words of wisdom:
"Write in C."

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634059
• Total Posts
3015296
×