Jump to content

Any ideas on what I should add.


Recommended Posts

I've been working on this every now and then at work and so far this is what I have come up with.

#include <WinAPIGdi.au3>
#include <File.au3>
#include <iniread.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$gui = GUICreate("",640,600,-1,-1)
Opt("GUIOnEventMode",1)
GUISetOnEvent(-3,"_Exit")
$wall = ""
$left = GUICtrlCreateDummy()
$right = GUICtrlCreateDummy()
$down = GUICtrlCreateDummy()
$up = GUICtrlCreateDummy()
Local $arrow_keys[4][2] = [["{LEFT}",$left],["{RIGHT}",$right],["{Down}",$down],["{UP}",$up]]
GUISetAccelerators($arrow_keys,$gui)
For $i = 0 To 3
GUICtrlSetOnEvent($arrow_keys[$i][1],"_Keys")
Next
$color = 0x000000
$w = WinGetPos($gui)
$x = 0
$y = 0
Local $label[3072]
For $i = 0 To 3071
   $label[$i] = GUICtrlCreateLabel("",$x,$y,10,10)
   GUICtrlSetOnEvent($label[$i],"_Click")
   $x += 10
   If $x = 640 Then
      $y += 10
      $x = 0
   EndIf

GUICtrlSetBkColor($label[$i],0xFFFFFF)
Next
$char = GUICtrlCreateLabel("",200,200,10,10)
GUICtrlSetBkColor($char,0xa93838)
$green = GUICtrlCreateButton("Green",0,500,100,20)
GUICtrlSetOnEvent($green,"_Color")
$blue = GUICtrlCreateButton("Blue",0,525,100,20)
GUICtrlSetOnEvent($blue,"_Color")
$eraser = GUICtrlCreateButton("Erase",0,550,100,20)
GUICtrlSetOnEvent($eraser,"_Color")
$clear = GUICtrlCreateButton("Clear",105,500,100,20)
GUICtrlSetOnEvent($clear,"_Clear")
$brown = GUICtrlCreateButton("Brown",105,525,100,20)
GUICtrlSetOnEvent($brown,"_Color")
$default = GUICtrlCreateButton("Default",105,550,100,20)
GUICtrlSetOnEvent($default,"_Color")
$menu = GUICtrlCreateMenu("Options")
$save = GUICtrlCreateMenuItem("Save",-1)
GUICtrlSetOnEvent($save,"_Save")
$load = GUICtrlCreateMenuItem("Load",-1)
GUICtrlSetOnEvent($load,"_Load")
$tree_id = ""
$wood_total = 0
$wood = GUICtrlCreateLabel("Wood: x"&$wood_total,300,500)
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN,"_Right_Click")
$tree_pos = ""
$chopping = False
Local $sec = @SEC
$fishing = False
;$file_name = ""
$tree = ""
$fish_menu = ""
GUISetState()

While 1
   $new_Sec = @SEC
   If $new_sec <> $sec Then
      $Sec = $new_Sec
   EndIf

   If $chopping = True Then
      $cp = ControlGetPos($gui,"",$char)
      $tree_pos = ControlGetPos($gui,"",$tree_id)
      $cp2 = $tree_pos

      #cs

      If $char_pos[0] < $tree_pos[0] Then
         GUICtrlSetPos($char,$char_pos[0]+10,$char_pos[1])
         ElseIf $char_pos[0]-10 > $tree_pos[0] Then
         GUICtrlSetPos($char,$char_pos[0]-10,$char_pos[1])
         ElseIf $char_pos[1]+10 < $tree_pos[1] Then
         GUICtrlSetPos($char,$char_pos[0],$char_pos[1]+10)
         ElseIf $char_pos[1]+10 > $tree_pos[1] Then
         GUICtrlSetPos($char,$char_pos[0],$char_pos[1]-10)
      EndIf

      #ce

      If $cp2[0] < $cp[0] Then
         If $cp[0] = $cp2[0]+10 And $cp[1] = $cp2[1] Then
            _chop()
            $chopping = False
            Else
      GUICtrlSetPos($char,$cp[0]-2,$cp[1])
   EndIf

   EndIf

   If $cp2[1] < $cp[1] Then
      If $cp[1] = $cp2[1]+10 And $cp[0] = $cp2[0] Then
        _chop()
            $chopping = False
         Else
      GUICtrlSetPos($char,$cp[0],$cp[1]-2)
   EndIf

   EndIf

   If $cp2[0] > $cp[0] Then
      If $cp[0]+10 = $cp2[0] And $cp[1] = $cp2[1] Then
         _chop()
            $chopping = False
            Else
      GUICtrlSetPos($char,$cp[0]+2,$cp[1])
   EndIf

   EndIf

   If $cp2[1] > $cp[1] Then
      If $cp[1]+10 = $cp2[1] And $cp[0] = $cp2[0] Then
         _chop()
            $chopping = False
         Else
      GUICtrlSetPos($char,$cp[0],$cp[1]+2)
   EndIf

   EndIf

  ; #ce

   If $cp2[0] > $cp[0] And $cp2[1] < $cp[1] Then ;Left Corner
      GUICtrlSetPos($char,$cp[0]+2,$cp[1]-2)
   EndIf

   If $cp2[0] < $cp[0] And $cp2[1] < $cp[1] Then
      GUICtrlSetPos($char,$cp[0]-2,$cp[1]-2)
   EndIf

   If $cp2[0] > $cp[0] And $cp2[1] > $cp[1] Then
      GUICtrlSetPos($char,$cp[0]+2,$cp[1]+2)
   EndIf

   If $cp2[0] < $cp[0] And $cp2[1] > $cp[1] Then
      GUICtrlSetPos($char,$cp[0]-2,$cp[1]+2)
      EndIf

      ;$chopping = False
   EndIf

   If $fishing = True Then
       $cp = ControlGetPos($gui,"",$char)
      $tree_pos = ControlGetPos($gui,"",$tree_id)
      $cp2 = $tree_pos

      If $cp2[0] < $cp[0] Then
         If $cp[0] = $cp2[0]+10 And $cp[1] = $cp2[1] Then
            _fish()
            $fishing = False
         Else
      GUICtrlSetPos($char,$cp[0]-2,$cp[1])
   EndIf

   EndIf

   If $cp2[1] < $cp[1] Then
      If $cp[1] = $cp2[1]+10 And $cp[0] = $cp2[0] Then
        _fish()
            $fishing = False
         Else
      GUICtrlSetPos($char,$cp[0],$cp[1]-2)
   EndIf

   EndIf

   If $cp2[0] > $cp[0] Then
      If $cp[0]+10 = $cp2[0] And $cp[1] = $cp2[1] Then
         _fish()
            $fishing = False
            Else
      GUICtrlSetPos($char,$cp[0]+2,$cp[1])
   EndIf

   EndIf

   If $cp2[1] > $cp[1] Then
      If $cp[1]+10 = $cp2[1] And $cp[0] = $cp2[0] Then
         _fish()
            $fishing = False
         Else
      GUICtrlSetPos($char,$cp[0],$cp[1]+2)
   EndIf

   EndIf

   If $cp2[0] > $cp[0] And $cp2[1] < $cp[1] Then ;Left Corner
      GUICtrlSetPos($char,$cp[0]+2,$cp[1]-2)
   EndIf

   If $cp2[0] < $cp[0] And $cp2[1] < $cp[1] Then
      GUICtrlSetPos($char,$cp[0]-2,$cp[1]-2)
   EndIf

   If $cp2[0] > $cp[0] And $cp2[1] > $cp[1] Then
      GUICtrlSetPos($char,$cp[0]+2,$cp[1]+2)
   EndIf

   If $cp2[0] < $cp[0] And $cp2[1] > $cp[1] Then
      GUICtrlSetPos($char,$cp[0]-2,$cp[1]+2)
      EndIf

   EndIf

   Sleep(10)
WEnd



Func _Exit()
   Exit
EndFunc



Func _Color()
   $id = @GUI_CtrlHandle

   If $id = GUICtrlGetHandle($blue) Then
      $color = 0x000FF0
   ElseIf $id = GUICtrlGetHandle($green) Then
      $color = 0x00FF00
   ElseIf $id = GUICtrlGetHandle($eraser) Then
      $color = 0xFFFFFF
   ElseIf $id = GUICtrlGetHandle($brown) Then
      $color = 0x8B4513
   ElseIf $id = GUICtrlGetHandle($default) Then
      $color = 0x000000
   endif

EndFunc



Func _Click()
   $id = @GUI_CtrlId

   If $color = 0x8B4513 Then
      $tree = GUICtrlCreateContextMenu($id)
      $tree_menu = GUICtrlCreateMenuItem("Chop",$tree)
      GUICtrlSetOnEvent($tree_menu,"_Chop_Start")
   EndIf

   If $color = 0x000FF0 Then
      $fish_menu = GUICtrlCreateContextMenu($id)
      $fish_menu_item = GUICtrlCreateMenuItem("Fish",$fish_menu)
      GUICtrlSetOnEvent($fish_menu_item,"_Fish_Start")
   EndIf

   GUICtrlSetBkColor($id,$color)
   $item_pos = ControlGetPos($gui,"",$id)
   $char_pos = ControlGetPos($gui,"",$Char)
   $wall = $item_pos[0]+$item_pos[2] <= $char_pos[0]
EndFunc



Func _save()
   $file_name = InputBox("File name","Please specify the name of the file you wish to save."&@crlf&"Please do not put "&'".ini"'&" in the name it will mess me up.")
   For $i = 0 To UBound($label)-1
      GUICtrlSetData($blue,"Blue "&(UBound($label)-1)-$i)
      IniWrite(@ScriptDir&"\"&$file_name&".ini","Save",GUICtrlGetHandle($label[$i]),GUICtrlGetBkColor($label[$i]))
   Next
   MsgBox(0,"Success!","You have saved the layout!")
EndFunc



Func _Keys()
   $char_pos = ControlGetPos($gui,"",$Char)
   If @GUI_CtrlId = 3 And $char_pos[0] > 0 Then ;left
      GUICtrlSetPos($char,$char_pos[0]-2,$char_pos[1])
   ElseIf @GUI_CtrlId = 4 And $char_pos[0]+10 < 640 Then ;right
      GUICtrlSetPos($char,$char_pos[0]+2,$char_pos[1])
   ElseIf @GUI_CtrlId = 5 And $char_pos[1]+10 < 480 Then ;down
      GUICtrlSetPos($char,$char_pos[0],$char_pos[1]+2)
   ElseIf @GUI_CtrlId = 6 And $char_pos[1] > 0 Then ;up
      GUICtrlSetPos($char,$char_pos[0],$char_pos[1]-2)
   EndIf

EndFunc



Func _clear()
   For $i = 0 To UBound($label)-1
      GUICtrlSetBkColor($label[$i],0x036427)
      GUICtrlSetBkColor($label[$i],0xFFFFFF)
   Next
EndFunc



Func GUICtrlGetBkColor($hWnd)
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
    EndIf

    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $iColor = _WinAPI_GetPixel($hDC, 0, 0)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor

 EndFunc   ;==>GUICtrlGetBkColor



 Func _Load()
    $load_file = FileOpenDialog("Map ini",@scriptdir,"Text Files(*.ini)")
    $ini_read = _IniReadSectionEx($load_file,"Save")
    $p = 0
    For $i = 1 To $ini_read[0][0]-1
       GUICtrlSetBkColor($label[$p],$ini_read[$i][1])
       $p += 1
    Next
    MsgBox(0,"Success!","The load was successful!")
 EndFunc



 Func _Chop()
    $menu_id = @GUI_CtrlId

    For $i = 0 To 0
       GUICtrlSetBkColor($tree_id,0x8B4513)
       Sleep(100)
       GUICtrlSetBkColor($tree_id,0xbf7529)
       Sleep(100)
      GUICtrlSetBkColor($tree_id,0xc68441)
       Sleep(100)
       GUICtrlSetBkColor($tree_id,0xcd9359)
       Sleep(100)
       GUICtrlSetBkColor($tree_id,0xdbb288)
       Sleep(100)
       GUICtrlSetBkColor($tree_id,0xFFFFFF)
    Next
    $wood_total += Random(1,4,1)
    GUICtrlSetData($wood,"Wood: x"&$wood_total)
    GUICtrlDelete($tree)
 ;EndIf

 EndFunc



 Func _Fish()

 EndFunc



 Func _Right_Click()
    If $fishing = True Or $chopping = True Then
       Else
    $tree_find = GUIGetCursorInfo($gui)
    $tree_id = $tree_find[4]
 EndIf

 EndFunc



 Func _Chop_start()
    $chopping = True
 EndFunc



 Func _Fish_start()
    If GUICtrlGetBkColor($tree_id+63) = 0x000FF0 And GUICtrlGetBkColor($tree_id+65) = 0x000FF0 And GUICtrlGetBkColor($tree_id+64) = 0x000FF0 And GUICtrlGetBkColor($tree_id - 64) = 0x000FF0 And GUICtrlGetBkColor($tree_id - 1) = 0x000FF0 And GUICtrlGetBkColor($tree_id + 1) = 0x000FF0 Then
    $fishing = True
 EndIf
 EndFunc

For the most part it works but it uses controls instead of GDI which I hope to re-make this entire things in GDI I just want to make it simple like this before I get real technical with it.

I've added water(blue) and trees(brown). I am mainly posting this to get some feedback on it and see what others think of it.

In order to fish at a spot the water has to be 3x3, if you run the script you'll understand what I mean by 3x3.

I'm planning on trying to get collision detection for the water that way you can right click > fish anywhere on the water and it'll stop on the edge rather than going to the center.

Another plan is going to be an auto generated terrain type where it will auto place water and sand and it will also make trees that will regrow.

All this is future plans, I'm going to finish it using controls and once I finish here I'll switch over the GDI.

Let me know if I should change something to make it flow a lot more smoothly.

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...