putting tiles on board
Blitz3D Forums/Blitz3D Programming/putting tiles on board
| ||
O so I am alternating between an Othello game and a chess game and I have run in to a bit of a tedious problem. Putting tiles. This is a sample of what I had done: empty=LoadMesh("square.b3d") PositionEntity empty,-45,.15,-45 EntityPickMode empty,2 emp2=CopyEntity (empty) PositionEntity emp2,-45,.15,-35 EntityPickMode emp2,2 emp3=CopyEntity (empty) PositionEntity emp3,-45,.15,-25 EntityPickMode emp3,2 emp4=CopyEntity (empty) PositionEntity emp4,-45,.15,-15 EntityPickMode emp4,2 emp5=CopyEntity (empty) PositionEntity emp5,-45,.15,-5 EntityPickMode emp5,2 emp6=CopyEntity (empty) PositionEntity emp6,-45,.15,5 EntityPickMode emp6,2 emp7=CopyEntity (empty) PositionEntity emp7,-45,.15,15 EntityPickMode emp7,2yadda yadda... I have 100 of these to do the hard way and then I thought about it... for next... DUH!!! So I did this: For empnumb = 2 To 100 emp+empnumb = CopyEntity (empty) Nextbut it tells me emp is not a function. I tried it with emp(empnumb) and it told me the same thing... D'oh!!! How can I do this without typing my wrists off??? -Rook |
| ||
do this: dim emp(100) - outside of your main loop (where you declare all your other global variables) for empnumb=2 to 100 emp(empnumb)=copyentity(empty) next However, if you are doing chess then it may be better to simply have a single flat quad and texture it with a chess board pattern. Is there a reason why you want to have an entity for each individual square on the board? |
| ||
Rook, unless you specifically NEED each square to be made of a different entity, then just do as Matty said and use a single quad. |
| ||
Actually I tried to do it with types. Didn't work right. The locations on the board as well as the screen are -45 to 45 X and -45 to 45 Z. Stepping by 10. SO I did this: empty=LoadMesh("square.b3d") PositionEntity empty,-45,.15,-45 EntityPickMode empty,2 HideEntity empty Type empty Field entity Field ex Field ey Field ez Field Color End Type For space = 1 To 100 For locx = -45 To 45 Step 10 For locz = -45 To 45 Step 10 n.empty = New empty n\entity = CopyEntity(empty) n\ex = locx n\ey = .15 n\ez = locz Next Next NextBut for some reason that won't display all the squares... I think they overlap. Very slow. I put the empty squares with a function I call outside of the main program loop like this: Function put_empty() For n.empty = Each empty EntityType n\entity,2 EntityPickMode n\entity,2 PositionEntity n\entity,n\ex,n\ey,n\ez Next End FunctionSo what am I doing wrong??? -RZ |
| ||
I am not being clever enough... always my problem! But I have a new one... look:empty=LoadMesh("square.b3d") PositionEntity empty,45,.15,-45 RotateEntity empty,0,0,0 EntityPickMode empty,2 HideEntity empty Type empty Field entity Field ex Field ey Field ez Field kolor End Type For space = 1 To 25 For locx = 5 To 45 Step 10 For locz = 5 To 45 Step 10 n.empty = New empty n\entity = CopyEntity(empty) n\ex = locx n\ey = 1 n\ez = locz n\kolor = 0 Next Next Next For space = 1 To 25 For locx = -5 To -45 Step -10 For locz = 5 To 45 Step 10 n.empty = New empty n\entity = CopyEntity(empty) n\ex = locx n\ey = 1 n\ez = locz n\kolor = 0 Next Next Next For space = 1 To 25 For locx = 5 To 45 Step 10 For locz = -5 To -45 Step -10 n.empty = New empty n\entity = CopyEntity(empty) n\ex = locx n\ey = 1 n\ez = locz n\kolor = 0 Next Next Next For space = 1 To 25 For locx = -5 To -45 Step -10 For locz = -5 To -45 Step -10 n.empty = New empty n\entity = CopyEntity(empty) n\ex = locx n\ey = 1 n\ez = locz n\kolor = 0 Next Next NextThis covers all quads... positive and negative numbers are plunked correctly. BUT IT IS SO SLOW!!! I run this and it takes about 10 seconds before the square is highlighted by my mousepick routine. Is there no easier way??? |
| ||
Hi Rook, What does the 'For space=1 to 25' loop mean ? Looks like you are creating 25 meshes for each field of your board. Try deleting the 'Space=1 to 25' loop. Marcus |
| ||
Try this:Graphics3D 800,600,16 SetBuffer BackBuffer() cam=CreateCamera() PositionEntity cam,0,10,-80 lig=CreateLight() empty=CreateCube() PositionEntity empty,45,.15,-45 RotateEntity empty,0,0,0 EntityPickMode empty,2 HideEntity empty Type empty Field entity Field ex Field ey Field ez Field kolor End Type For locx = 5 To 45 Step 10 For locz = 5 To 45 Step 10 n.empty = New empty n\entity = CopyEntity(empty) n\ex = locx n\ey = 1 n\ez = locz n\kolor = 0 Next Next For locx = -5 To -45 Step -10 For locz = 5 To 45 Step 10 n.empty = New empty n\entity = CopyEntity(empty) n\ex = locx n\ey = 1 n\ez = locz n\kolor = 0 Next Next For locx = 5 To 45 Step 10 For locz = -5 To -45 Step -10 n.empty = New empty n\entity = CopyEntity(empty) n\ex = locx n\ey = 1 n\ez = locz n\kolor = 0 Next Next For locx = -5 To -45 Step -10 For locz = -5 To -45 Step -10 n.empty = New empty n\entity = CopyEntity(empty) n\ex = locx n\ey = 1 n\ez = locz n\kolor = 0 Next Next For n=Each empty PositionEntity n\entity,n\ex,n\ey,n\ez Next While Not KeyDown(1) UpdateWorld RenderWorld Flip Wend Marcus |
| ||
Dude! just do this:Graphics3D 800, 600, 16, 0 SetBuffer BackBuffer() cam = CreateCamera() PositionEntity cam, 0, 10, -80 light = CreateLight() ;create a square board = CreateMesh() boardsurf = CreateSurface(board) v1 = AddVertex boardsurf, -1, 0, -1 v2 = AddVertex boardsurf, -1, 0, 1 v3 = AddVertex boardsurf, 1, 0, -1 v4 = AddVertex boardsurf, 1, 0, 1 AddTriangle, boardsurf, v1, v2, v3 AddTriangle, boardsurf, v3, v2, v4 ScaleEntity board, 45, 0, 45 boardtex = LoadTexture("checkered_board.png") TextureEntity board, boardtexI typed this into the reply box so I don't know if it contains errors... Like I said before, unless you specifically NEED each square to be made of a different entity, then just create one entity textured with the checker pattern as in the code above. |
| ||
Mighty Mac and Wolron... Thanks.... Both solutions work. I want the squares to be mouse pickable so you can plunk game pieces down on the board in 3d. I have to work out a way to pass that location to the game engine simply and cleanly. I thought of doing the Othello type (well several people suggested it before I thought of it truly) because the game idea I have would use pieces. They would not flip or anything but similar checking would occour in the game AI. Playing with both ideas more... Sure to learn much! MightyMac... Your idea works but I cannot see the mouse... Hmmm... I can see the entitypicked when I run the mouse over what I think is the board. Look: Oy! :] But great help... I have to shut down the CPU now... horrible rains in Houston.... We are 22+ inches for the year!!! -Rook |
| ||
Well I buffed and modded this... I tried to create three arrays to hold info. First array called gameboard to hold state of gameboard and hopefully be reconfigurable... Seconf array called boardx to hold X addresses for each piece so I could pass that info back and forth both to update the gameboard and put new pieces in proper location... Third array is much like seconf only holds Z addresses... But I only see 2 pieces. ; Hexathello (OK Othello but I hope to get the square thing figured out ; then nail a hex thing! ; Ralph Dunn Graphics3D 800,600,16,2 SetBuffer BackBuffer() player=CreatePivot() camera=CreateCamera(player) light=CreateLight() RotateEntity light,45,45,0 AmbientLight 48,48,48 ; was 32,32,32 EntityType camera,1 PositionEntity camera,0,53,-69 RotateEntity camera,35,0,0 Global square Dim boardarea(10,10) Dim boardx(10,10) Dim boardz(10,10) For fun=0 To 9 boardx(fun,0)=-45 boardx(fun,1)=-35 boardx(fun,2)=-25 boardx(fun,3)=-15 boardx(fun,4)=-5 boardx(fun,5)=5 boardx(fun,6)=15 boardx(fun,7)=25 boardx(fun,8)=35 boardx(fun,9)=45 Next For fu=0 To 9 boardz(fu,0)=-45 boardz(fu,1)=-35 boardz(fu,2)=-25 boardz(fu,3)=-15 boardz(fu,4)=-5 boardz(fu,5)=5 boardz(fu,6)=15 boardz(fu,7)=25 boardz(fu,8)=35 boardz(fu,9)=45 Next ; ####################################### Load Mesh Objects gameboard=LoadMesh("squareboard.b3d") UpdateNormals gameboard EntityFX gameboard,0 ScaleEntity gameboard,5.5,5.5,5.5 empty=LoadMesh("square.b3d") EntityPickMode empty,2 HideEntity empty wpiece=LoadMesh("piece.b3d") UpdateNormals wpiece EntityShininess wpiece,1 PositionEntity wpiece,5,3,-5 bpiece=CopyMesh(wpiece) RotateEntity bpiece,180,0,0 UpdateNormals bpiece EntityShininess bpiece,1 PositionEntity bpiece,-5,3,5 ; ###################################### Plunk Tiles ; -----------------> Thanks Mighty Mac and Wolron Type empty Field entity Field kolor End Type For tiles = 1 To 100 n.empty = New empty n\entity = CopyEntity(empty) n\kolor = 0 Next ; now create an array called boardarea of 10 by 10 and ; fill in the entire matrix with 0 For fillx = 0 To 9 For fillz=0 To 9 boardarea(fillx,fillz)=0 Next Next ; Now read it and put an new entity in that location... ; Somehow I get ONLY 2 entitys on the gameboard!!! For row = 0 To 9 For col=0 To 9 If boardarea(row,col) = 0 PositionEntity n\entity,boardx(row,col),1,boardz(row,col) EndIf Next Next ; ############################################## ShowPointer While Not KeyDown(1) x=MouseX() y=MouseY() e=CameraPick(camera,x,y) If e<>entity# If entity Then EntityColor entity,255,255,255 ; was 255,255,255 entity#=e EndIf If MouseHit(1) ; push L/mousebutton and get the piece or location Select empty ; I can select a type according to docs Case empty ; I can't use n\entity... OBJECT DOES NOT EXIST thing$=" "+boardx ; but NOTHING seems to be returned but 0,0 thing2$=" "+boardz ; I tried n\ex, ex, and locx... (also n\ez...) Default ; with x and y I get the mouse values... ALL OVER THE MAP thing$="NADA" thing2$="ZIP" End Select End If If entity# EntityColor entity,0,120,255 ; 73,253,146 lime 254,216,38 gold 254,80,232 magenta EndIf UpdateWorld RenderWorld Text 0,10,"X: "+x Text 0,20,"Y: "+y Text 0,30,"Z: "+z Text 0,50,"THING: "+thing$ Text 0,60,"THING2: "+thing2$ Flip Wend End I can't even get it to communicate anymore!!! Oy!!! I know I am close... how close??? It may be a polar thing. Hmmm if I bumped everything over so it is all positive numbers would that help??? Terminally confused... -ROOK |
| ||
Couple of things I noticed - there may be others :); now create an array called boardarea of 10 by 10 and ; fill in the entire matrix with 0 For fillx = 0 To 9 For fillz=0 To 9 boardarea(fillx,fillz)=0 Next Next This code isn't needed since integer arrays are automatically 'zeroed'. ; Now read it and put an new entity in that location... ; Somehow I get ONLY 2 entitys on the gameboard!!! For row = 0 To 9 For col=0 To 9 If boardarea(row,col) = 0 PositionEntity n\entity,boardx(row,col),1,boardz(row,col) EndIf Next Next The problem is you're continually (re)positioning the same entity (n\entity) every time through the loop. |
| ||
Yes Big10p!!! I just solved it too... it was my boardx(10,10) and my boardx(10,10)... too much data and too much the same data... GIGO Now if I could just solve the mousepick issue... Would y'all mind trying this? I may be on the right track!!! If I can get the mousepick to access the coordinates AND update gameboard then all is right with the universe. :] How can I return information instead of a series of numbers with this??? -RZ |
| ||
Rook, TBH, I think things are going to get messy doing it this way. Why not just keep everything nice and compact in an array of types? Something like:Type squareT Field entity Field x#, z# Field kolor End Type Dim board.squareT(9,9) ; A 10x10 board row_pos# = -45 For row = 0 To 9 col_pos# = -45 For col = 0 To 9 n.squareT = New squareT n\entity = CopyEntity(empty) n\x = col n\z = row n\kolor = 0 board(row,col) = n EntityPickMode n\entity,2 PositionEntity n\entity,n\x,1,n\z col_pos = col_pos + 10 Next row_pos = row_pos + 10 Next |
| ||
Yeah I see what you did... but squares go from -45,-45 to 45,45... wait wait wait... I see how you did that. How would this work with my pickentity command... only one way to find out! Let me run it :] -RZ |
| ||
Had to fix: n\x = row n\z = col to n\x = row_pos n\z = col_pos EDIT:::: It worketh!!!! Its Alive... ALIVE!!! I fixed the code thussly: It returns location so the program knows where toplace the new piece... now to make it update the array and check for stuff... I learned a lot creating this. Maybe another tutorial on how to create a simple mouse selected boardgame should be written... To help noobs like me??? Nah... IMO most noobs don't seem to realize there is a TUTORIALS forum. :] -RZ |
| ||
Had to fix: n\x = row n\z = col to n\x = row_pos n\z = col_pos Yeah, sorry about that. Strangest thing is, I had just put my head down to go to sleep last night when this bug suddenly popped into my head. Bizarre. :) Note that you now don't need the boardx and boardz arrays as they're redundant. I see you intend to change to using a hex-tiled board at some point so I put this little demo together. Hope it's of some use. |
| ||
Big10p... Ohhh it is scary... answering questions I intend to ask BEFORE I ask them!!! ;] And while I am at it... VERY COOL DEMO!!!! I give you 12 stars out of 5!!! -Rook |
| ||
Maybe I'm psychic ...or, maybe I read the comment in your code mentioning you intend to move to using a hex-tile board. :) Actually, doing that demo has given me the beginnings of an idea for a game (not a board game). :) |