Page 2 of 2

Re: Needs help with my isometric map editor

Posted: Wed Sep 30, 2009 6:11 pm
by Rook Zimbabwe
@Jared: No worries, this is a pretty crappy computer! :mrgreen:
@Bator: Nice ideas! :D

Re: Needs help with my isometric map editor

Posted: Wed Sep 30, 2009 8:09 pm
by Rook Zimbabwe
I did some things... The mouse works a bit faster now...

I learned the click routines form #NULL

Code: Select all

; ISOMETRIC by Cpl. Bator
; Modded by Rook Zimbabwe for the mouse event routines!
;
ExamineDesktops()
InitSprite() : InitKeyboard() : InitMouse()
OpenScreen(DesktopWidth(0),DesktopHeight(0),32,"")

Global Dim MyMap(9,9)

Restore Map2D
For y = 0 To 9
  For x = 0 To 9
    Read MyMap(x,y)
  Next 
Next 

Procedure DisplayMap2D(TileWidth.i=64)
Static mouseflag.b,Mx.f,My.f

Mx + MouseDeltaX()
My + MouseDeltaY()

StartDrawing(ScreenOutput())

For y = 0 To 9
  For x = 0 To 9
          
    ;Isometric formula
    Tile_width.i  = TileWidth     
    Tile_Height.i = Tile_width / 2
    
    
    scale_x.f = (x * Tile_Height)
    scale_y.f = (y * Tile_Height) 
    
    iso_x.f = (( scale_x - scale_y )     )       + DesktopWidth(0)/2
    iso_y.f = (( scale_x + scale_y ) / 2 )       + DesktopHeight(0)/4
    

    LineXY(iso_x,iso_y-Tile_Height/2,iso_x+Tile_width/2,iso_y,$0)
    LineXY(iso_x+Tile_width/2,iso_y,iso_x,iso_y+Tile_Height/2,$0)
    LineXY(iso_x,iso_y+Tile_Height/2,iso_x-Tile_width/2,iso_y,$0)
    LineXY(iso_x-Tile_width/2,iso_y,iso_x,iso_y-Tile_Height/2,$0)

        If MyMap(x,y)=1
          For angle = 0 To 360
           px.f = iso_x + (Tile_width/4) * Cos(angle*#PI/180)
           py.f = iso_y + (Tile_Height/4) * Sin(angle*#PI/180)
           If px=>0 And py=>0 And px<DesktopWidth(0)-1 And py<DesktopHeight(0)-1
            Plot(px,py,0)
           EndIf 
          Next 
        EndIf 
  Next 
Next 

    ;Convert mouse coord to iso mouse coord
    iso_mouse_y = ((2 * My) - Mx ) / 2
    iso_mouse_x = Mx + iso_mouse_y

    ; set the mouse coord with correction (screen centered)
    ScreenMouse_X = ( Mx + DesktopWidth(0)/2  )-Tile_width/2
    ScreenMouse_Y = ( My + DesktopHeight(0)/4 )-Tile_width/2
; ************ Learned from #NULL for windows!
lb_prev = lb
lb = GetAsyncKeyState_(#VK_LBUTTON)
rb_prev = rb
rb = GetAsyncKeyState_(#VK_RBUTTON)

  If lb & 1 ; MouseButton(#PB_MouseButton_Right) And mouseflag = 0
      ;Convert mousecoord to MyMap() coord
      DataX = (iso_mouse_x/Tile_Height)-1
      DataY = (iso_mouse_y/Tile_Height)
          ; Check overflow
          If DataX>=0 And DataX<=9 And  DataY>=0 And DataY<=9
            Res = MyMap(DataX,DataY)
            Res+1
            Res%2
            MyMap(DataX,DataY) = Res
            
          EndIf 
  EndIf 

  If rb & 1 ;MouseButton( #PB_MouseButton_Right) And mouseflag = 0
      ;Convert mousecoord to MyMap() coord
      DataX = (iso_mouse_x/Tile_Height)-1
      DataY = (iso_mouse_y/Tile_Height)
          ; Check overflow
          If DataX>=0 And DataX<=9 And  DataY>=0 And DataY<=9
            Res = MyMap(DataX,DataY)
            Res+1
            Res%2
            MyMap(DataX,DataY) = 0
            
          EndIf 
  EndIf 

Circle(ScreenMouse_X,ScreenMouse_Y,4,$0)
DrawText(10,10,"ISOMETRIC EXAMPLE BY CPL.BATOR, CLICK ON THE TILE,ESCAPE TO QUIT.")
DrawText(10,30,"Left CLICK: " + Str(lb))
DrawText(10,50,"Right CLICK: " + Str(rb))
StopDrawing()


EndProcedure


Zoom.f = 1
CLOCKFLAG = ElapsedMilliseconds()

Repeat
  ExamineKeyboard() : ExamineMouse()
    ClearScreen($FFFFFFFF)
    
    If MouseWheel()>0
      Zoom + 0.05
    EndIf 
   
   If MouseWheel()<0
      Zoom - 0.05
    EndIf 
   
    DisplayMap2D(Zoom*128)


    FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)




DataSection;10x10
Map2D:
Data.i 0,0,0,0,0,0,0,0,0,0
Data.i 0,0,0,0,0,0,0,0,0,0
Data.i 0,0,0,0,0,0,0,0,0,0
Data.i 0,0,0,0,1,0,0,0,0,0
Data.i 0,0,0,0,0,0,0,0,0,0
Data.i 0,0,0,0,0,0,0,0,0,0
Data.i 0,0,0,0,0,0,0,0,0,0
Data.i 0,0,0,0,0,0,0,0,0,0
Data.i 0,0,0,0,0,0,0,0,0,0
Data.i 0,0,0,0,0,0,0,0,0,0
EndDataSection
:mrgreen: