|
-
Jun 22nd, 2003, 02:31 PM
#1
Thread Starter
New Member
Isometric Engine Problem
Hi!
I have a big problem. I have an Isometric Engine. My problem is that I dont know how to make that when I click on a tile, that then the Tile gets an other Texture. Can you help me?? I hope so. Thanks
Elessar
P.S. Here is my code of the Engine:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then arret = 1
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then arret = 1
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Droite = False: Gauche = False: Haut = False: Bas = False
If X > 600 Then Droite = True
If Y > 450 Then Bas = True
If X < 40 Then Gauche = True
If Y < 50 Then Haut = True
End Sub
Public DirectX As New DirectX7
Public DD As DirectDraw7
Public Primary As DirectDrawSurface7
Public Backbuffer As DirectDrawSurface7
Public Display As DirectDrawSurface7
Public Tile(50) As DirectDrawSurface7
Public T(50, 50) As Integer
Public xpos, ypos, arret
Public Gauche As Boolean, Droite As Boolean, Haut As Boolean, Bas As Boolean
Sub AfficheEcran(xa, ya) 'Display tiles (grass and paths)
On Error Resume Next
Backbuffer.BltColorFill DDRect(0, 400, 1024, 768), 0
Display.BltColorFill DDRect(0, 0, 1024, 768), 0
Display.SetFontTransparency True
Display.SetForeColor RGB(256, 256, 0)
For Y = -20 To 80
For X = 0 To 40
xd = (X * 31) - (Y * 31)
yd = (Y * 16) + (X * 16)
Display.BltFast xd, yd, Tile(T(X + xa, Y + ya + 10)), DDRect(0, 0, 63, 63), DDBLTFAST_SRCCOLORKEY Or DDBLTFAST_WAIT
' " Display.DrawText xd, yd, CStr(X - 15 + xa) + " " + CStr(Y - 15 + ya), False
Next X
Next Y
'
' On a besoin de faire ça parce que si on blitte quelque chose avec une position x ou y négative
' ça ne marche pas. Donc c'est pour faire joli.
'
' You needs do this, because if you "blit" something with a negativ x or y position, it don't run.
'
Backbuffer.BltFast 0, 0, Display, DDRect(30, 30, 980, 700), DDBLTFAST_WAIT
Backbuffer.SetForeColor RGB(256, 0, 0)
End Sub
Function DDRect(X, Y, x1, y1) As RECT
DDRect.Bottom = y1
DDRect.Top = Y
DDRect.Left = X
DDRect.Right = x1
End Function
Sub Main()
Set DD = DirectX.DirectDrawCreate("")
DD.SetCooperativeLevel FS.hWnd, DDSCL_ALLOWREBOOT Or DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN
DD.SetDisplayMode 1024, 768, 16, 0, DDSDM_DEFAULT
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
ddsd.lBackBufferCount = 1
ddsd.ddscaps.lCaps = DDSCAPS_COMPLEX Or DDSCAPS_FLIP Or DDSCAPS_PRIMARYSURFACE Or DDSCAPS_VIDEOMEMORY
Set Primary = DD.CreateSurface(ddsd)
Dim ddscaps As DDSCAPS2
ddscaps.lCaps = DDSCAPS_BACKBUFFER
Set Backbuffer = Primary.GetAttachedSurface(ddscaps)
Backbuffer.BltColorFill DDRect(0, 0, 1024, 768), 0
Dim ddsd2 As DDSURFACEDESC2
ddsd2.ddscaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_VIDEOMEMORY
ddsd2.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd2.lWidth = 1024
ddsd2.lHeight = 768
Set Display = DD.CreateSurface(ddsd2)
Display.BltColorFill DDRect(0, 0, 1024, 768), 0
Dim ddr As DDSURFACEDESC2
Dim ddrec As RECT
ddrec.Bottom = 64
ddrec.Left = 0
ddrec.Right = 64
ddrec.Top = 0
Dim ck As DDCOLORKEY
ck.high = RGB(256, 256, 256)
ck.low = RGB(256, 256, 256)
For i = 1 To 6
Set Tile(i) = DD.CreateSurfaceFromFile(App.Path + "\tile" + CStr(i) + ".bmp", ddr)
Tile(i).SetColorKey DDCKEY_SRCBLT, ck
Next i
Randomize
'Fill the area with the filedata.
Open App.Path + "\iso.dat" For Input As 1
For Y = 1 To 50
Line Input #1, li$
For X = 1 To 50
T(X, Y) = Val(Mid(li$, X, 1))
Next X
Next Y
AfficheEcran 0, 0
' Boucle / looping
ok% = 1
Do
DoEvents
AfficheEcran xpos, ypos
If ok% = 0 Then
If Gauche = True Then
ok% = 1: xpos = xpos - 1
End If
If Droite = True Then
ok% = 1: xpos = xpos + 1
End If
If Haut = True Then
ok% = 1: ypos = ypos - 1
End If
If Bas = True Then
ok% = 1: ypos = ypos + 1
End If
End If
If anc + 50 < DirectX.TickCount Then
ok% = 0
anc = DirectX.TickCount
End If
Primary.Flip Nothing, DDFLIP_WAIT
Loop Until arret = 1
Set Primary = Nothing
Set Backbuffer = Nothing
Set DD = Nothing
Set DirectX = Nothing
End
End Sub
-
Jun 22nd, 2003, 06:04 PM
#2
Lively Member
Sorry, but I don't understand your question. Please restate it and i'll see if I can help you.
Zach
-
Jun 22nd, 2003, 08:03 PM
#3
Frenzied Member
i believe that he wants the player to be able to click a tile and then the tile changes its texture...
-
Jun 23rd, 2003, 10:23 AM
#4
Thread Starter
New Member
Yeah, exactly thats my problem.
-
Sep 21st, 2004, 06:09 AM
#5
Banned
i have the same problem :S
-
Sep 21st, 2004, 06:16 AM
#6
Not NoteMe
Originally posted by nareth
i have the same problem :S
Post a screenshot of the tiles, and i'll see if i can come up with anything.
<><>
><><
If these are tiles (but joined together), i'd need to know the angle that the lines were at.
Code for how you draw them to the screen would be helpfull as well.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 06:20 AM
#7
Banned
VB Code:
1 Let tX = Header.Width * TILE_WIDTH / 2
2 For L = 0 To LayerMax
3 For X = 0 To Header.Width
4 Let dX = tX
5 Let dY = tY
6 For Y = 0 To Header.Height
7 Let oRect.Left = Tiles(L, X, Y).X * TILE_WIDTH
8 Let oRect.Right = oRect.Left + TILE_WIDTH
9 Let oRect.Top = Tiles(L, X, Y).Y * TILE_HEIGHT
10 Let oRect.Bottom = oRect.Top + TILE_HEIGHT
11 Call DDSTiles.BlitFast(DDSDest, dX, dY, oRect)
12 Let dX = dX + TILE_WIDTH / 2
13 Let dY = dY + TILE_BASE_HEIGHT / 2
14 Next Y
15 Let tX = tX - TILE_WIDTH / 2
16 Let tY = tY + TILE_BASE_HEIGHT / 2
17 Next X
18 Next L
and dont please make a comment about me using let 
-
Sep 21st, 2004, 06:49 AM
#8
Not NoteMe
Right, you'll need to make a function to hilight/indicate the tile that we're selecting for debugging purposes.
Once you've done that try this as a start:
First we'll try and work out what tile the mouse is in (ignoring the fact that it's part transparent).
I think it'll be something like this:
Tile(Mouse.X/TILE_WIDTH +1, Mouse.Y/TILE_HEIGHT + 1)
Assuming tile(1,1) is the top-left most tile.
What you then need to do, is work out a way of telling when the mouse is in the transparent part of the tile (and which transparent part). This will be done by getting the x and y position of the mouse relative to the centre of the tile, then using an if statement using those values (not exactly sure what it'll be).
Once you can work out if the mouse is in a transparent part, then you add/subtract a number from the index you've just calculated accordingly (so you select the appropriate tile (that is on the transparent area of our current one)).
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 06:52 AM
#9
Banned
why +1? and why no int()? :S
-
Sep 21st, 2004, 06:56 AM
#10
Not NoteMe
+1 if your array starts at (1,1) and because VB rounds down (i think). - you may have to play around with it, but if you make your function to change/highlight a tile you should easily be able to alter it so it works.
I didn't use int because i havn't used VB in a while. :P
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 07:00 AM
#11
Banned
my array is defined:
VB Code:
ReDim Tiles(LayerMax, Header.Width, Header.Height) As TileType
-
Sep 21st, 2004, 07:07 AM
#12
Not NoteMe
In that case it depends on the options you've got set in VB (since you don't explicitly say whether it starts from 0 or from 1).
Looking at your drawing code i guess it starts from 0, so you may not need the +1, but you'd have easily discovered that yourself if you had just tried my code.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 07:08 AM
#13
Banned
i just talked to merri and i dont use masks so i cant decided trans part...
-
Sep 21st, 2004, 07:13 AM
#14
Not NoteMe
You could work it out using a formula though. While i puzzle over that i suggest making a function to test it.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 07:24 AM
#15
Not NoteMe
-
Sep 21st, 2004, 07:27 AM
#16
Banned
hmm when i decide a rect. i can use mouse y to decide if it is on the actual rhomb or not. does that makes sense?
each y from the center is 2 pixels away from rhomb.
and i think its the same with x...
please tell me that i got it right!
-
Sep 21st, 2004, 07:30 AM
#17
Not NoteMe
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 07:30 AM
#18
Banned
you posted just before me..
abs
-
Sep 21st, 2004, 07:32 AM
#19
Banned
you know thast diamond shaped thing. but i think your formula is better. i think i get it . but i dont know what abs does
-
Sep 21st, 2004, 07:32 AM
#20
Not NoteMe
Originally posted by nareth
you posted just before me..
abs
A VB function to find the absolute value of it's parameter.
i.e. abs(1) = 1
abs(-1) = 1
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 07:37 AM
#21
Banned
err i dont really get that
-
Sep 21st, 2004, 07:40 AM
#22
Not NoteMe
abs returns the size of the number it's given.
Here's an equivilent:
if (Number < 0) then return Number * (-1) else return Number
More examples:
abs(136) = 136
abs(6209) = 6209
abs(-26) = 26
abs(-9832) = 9832
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 07:43 AM
#23
Banned
-
Sep 21st, 2004, 07:46 AM
#24
Banned
another problem the map is daimond shaped so how do i get the right rect? :P
-
Sep 21st, 2004, 07:50 AM
#25
Not NoteMe
rect.left = int(Mouse.X/TILE_WIDTH) * TILE_WIDTH
rect.right = (int(Mouse.X/TILE_WIDTH)+1) * TILE_WIDTH
rect.top = int(Mouse.Y/TILE_HEIGHT) * TILE_HEIGHT
rect.bottom = (int(Mouse.Y/TILE_HEIGHT)+1) * TILE_HEIGHT
I think.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 07:51 AM
#26
Not NoteMe
Actually, you could use this:
Tiles(L, X, Y).X * TILE_WIDTH
oRect.Left + TILE_WIDTH
Tiles(L, X, Y).Y * TILE_HEIGHT
oRect.Top + TILE_HEIGHT
since we've just worked out X and Y.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 07:56 AM
#27
Banned
nonono.. what i mean is. if you look at my screenshot you see the daimond shaped map. if you click at x 10 y 10 it will say that the clicked rect is 0,0 and x 70 y 70 rect 1,1
but rect 0, 0 is supose to start at the top corner
-
Sep 21st, 2004, 07:59 AM
#28
Banned
i just copy and pasted your code to test it
VB Code:
Let RegY = TILE_BASE_HEIGHT / 2 + Abs(X - TILE_WIDTH / 2) / TILE_WIDTH * TILE_BASE_HEIGHT / 2
MsgBox Regy
and it coems up with the numbers 20and21 and 22
-
Sep 21st, 2004, 08:03 AM
#29
Not NoteMe
Originally posted by nareth
and it coems up with the numbers 20and21 and 22
Can't tell if that's correct or not since it depends on where you clicked, and the values of tile height/width.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 08:04 AM
#30
Not NoteMe
Originally posted by nareth
nonono.. what i mean is. if you look at my screenshot you see the daimond shaped map. if you click at x 10 y 10 it will say that the clicked rect is 0,0 and x 70 y 70 rect 1,1
but rect 0, 0 is supose to start at the top corner
Ok, you've lost me.
If you could edit your screenshot writing the index if each/a few tiles that'd help my understanding of how your tiles are arranged.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 08:05 AM
#31
Banned
i tried with a map of size 0,0 and it gave those numbers.
-
Sep 21st, 2004, 08:17 AM
#32
Banned
ok i dont know if you get this but the arrows show in what order its drawn. and the grey sqaures are the rects. wich i need to get and then look at what triangle is clicked. but you see no rect at the top left. so when the user clicks there the rect will be calculated as rect 0,0.
-
Sep 21st, 2004, 08:20 AM
#33
Not NoteMe
So (1,0) would be the tile below and to the left of the one marked and (0,1) would be the one below and to the right of the one marked, or is it the other way round?
I gtg now, but if no-one else can help, i'll have another go later.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 08:23 AM
#34
Banned
-
Sep 21st, 2004, 09:47 AM
#35
Not NoteMe
Originally posted by SLH
So (1,0) would be the tile below and to the left of the one marked and (0,1) would be the one below and to the right of the one marked, or is it the other way round?
Is this correct?
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 09:52 AM
#36
Banned
hmm x goes first. so i think the right is 1,0 and below is 1,0 yep...
but . when you click on the black it would calc those as rects instead of the actual map
-
Sep 21st, 2004, 10:03 AM
#37
Not NoteMe
Originally posted by nareth
but . when you click on the black it would calc those as rects instead of the actual map
I don't understand what you mean.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 10:05 AM
#38
Addicted Member
A good way for doing it is this: Make a picture of one tile and use a different color for each side, like this:
Now, when a user clicks on your form/picturebox or whatever you are using, you can simply calculate on which of these tiles it is, and then look at the color to see the exact tile.
Hope that helps
-
Sep 21st, 2004, 10:07 AM
#39
Not NoteMe
Originally posted by Shell
A good way for doing it is this: Make a picture of one tile and use a different color for each side, like this:
Now, when a user clicks on your form/picturebox or whatever you are using, you can simply calculate on which of these tiles it is, and then look at the color to see the exact tile.
Hope that helps
That is probably the easiest way (as opposed to the formula method i gave), however it's calculating the tile the mouse is over to begin with that's the problem.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2004, 10:15 AM
#40
Banned
this sounbds impossible but games actually do it.
its just so hard and you cant expect a 15 year old to just poof make it...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|