Sign in to follow this  
Followers 0
gottygolly

Need help testing and seeing if there is an error.

4 posts in this topic

I've been working on this little script for awhile now (mainly because my brother has fun playing it).

I have a problem with it though and im not sure if its the computer the the actual script.

On lines 135-161 is the code for the movement of the obj nicknamed "target" and on lines 203-228 is the code for the obj nicknamed "box"

The problem is with the movement of the 2 objs, when they are moving up or to the left (X - 1,Y -1) they move faster than when theyre going down or to the right (X + 1,Y + 1).

I've looked through the code numerous times but i might have missed the error or it could just be the computer im running it on.

If someone could run the game and see if you run into the same error and let me know ill keep looking but if its just the computer then ill have to figure something else out i guess, thanks in advance for any support/help!

#include<misc.au3>
#include<guiconstants.au3>
#include<gdiplus.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIToolTip.au3>
#include<Array.au3>
Global $pause_menu,$dead_bar
$hour = 0
$min = 0
$time = 0
$gui = GUICreate("Time: "&$hour&"h"&":"&$min&"m"&":"&$time&"s",640,480,-1,-1)
GUISetBkColor(0x000000)
Opt("GUIOnEventMode",1)
GUISetOnEvent(-3,"_Exit")
$bk_con = GUICtrlCreateLabel("",0,0,640,50)
GUICtrlSetBkColor($bk_con,0x555555)
Local $sec = @SEC
Local $tsec = @SEC
$xc = Random(1,590)
$yc = Random(50,210)
$xt = Random(1,590)
$yt = Random(220,430)
$food_x = Random(1,590)
$food_y = Random(50,430)
$random_x = Round(Random(1,590),0)
$random_y = Round(Random(50,430),0)
If $xc >= $xt And $yc >= $yt Then
$box = GUICtrlCreateButton("",$xc,$yc,50,50)
Else
   $box = GUICtrlCreateButton("",Random(1,590),Random(50,430),50,50)
EndIf
$target = GUICtrlCreateButton("",$xt,$yt,50,50)
If $food_x >= $xt Or $xc And $food_y >= $yc or $yt Then
$food = GUICtrlCreateButton("",$food_x,$food_y,15,15)
Else
   $food = GUICtrlCreateButton("",Random(1,590),Random(50,430),15,15)
   EndIf
GUICtrlSetBkColor($food,0xAAFF5)
GUICtrlSetState($food,$gui_disable)
GUICtrlSetBkColor($box,0x008800)
GUICtrlSetBkColor($target,0x880000)
$hits = 0
$hit = GUICtrlCreateLabel("Hits: "&$hits,5,5,100,25)
GUICtrlSetFont($hit,20,700)
GUICtrlSetColor($hit,0xFFFFFF)
GUICtrlSetBkColor($hit,0x555555)
$move = True
$i = 0
$stopped = False
$t_pos_x = $random_x
$t_pos_y = $random_y
$edge = False
$pause_game = True
$speed = 2
$speed_box = 1
$dead = False
$speed_lab = GUICtrlCreateLabel("Speed Target: "&$speed&@crlf&"Speed Box: "&$speed_box,500,5,150,40)
GUICtrlSetColor($speed_lab,0xFFFFFF)
GUICtrlSetFont($speed_lab,12,700)
GUICtrlSetBkColor($speed_lab,0x555555)
$start_time = 5
$starting = GUICtrlCreateLabel("Starting..."&$Start_time,0,150,640,150,$ss_center)
GUICtrlSetColor($starting,0xFFFFFF)
GUICtrlSetFont($starting,90,700)
GUICtrlSetBkColor($starting,0x000055)
$cdwn = True
$score = 0
$score_lab = GUICtrlCreateLabel("Score: "&$score,150,5,150,25)
GUICtrlSetColor($score_lab,0xFFFFFF)
GUICtrlSetFont($score_lab,20,700)
GUICtrlSetBkColor($score_lab,0x555555)
$highsc = IniRead(@scriptdir&"\HighScore.ini","Highscore","HighScore","0")
$highscore_lab = GUICtrlCreateLabel("Highscore: "&$highsc,250,100,100,20)
$no = 0
$boost = False
GUISetState()
$paused = GUICtrlCreateLabel("PAUSED",0,150,640,150,$ss_center)
GUICtrlSetBkColor($paused,0x0E6E3F)
GUICtrlSetState($paused,$gui_hide)
GUICtrlSetColor($paused,0xFFFFFF)
GUICtrlSetFont($paused,100,700)
;$hwnd = _GDIPlus_GraphicsCreateFromHWND($gui)
;$pen = _GDIPlus_PenCreate(0xFFFFFFFF, 2)
$tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, "Left", 0)
    DllStructSetData($tRect, "Top", 0)
    DllStructSetData($tRect, "Right", 640)
    DllStructSetData($tRect, "Bottom", 480)
While 1
   If $dead = True Then
      If _IsPressed("20") Then
              $pause_game = False
              $dead = False
              GUICtrlDelete($dead_bar)
           EndIf
        EndIf
        #cs
        If _IsPressed("09") Then
           $boost = True
           If $boost = True Then
              $speed += 1
              Sleep(100)
              $boost = False
           EndIf
           If $boost = False Then
              $speed = $speed_box+1
           EndIf
           EndIf
           #ce
   If _IsPressed("50") Then
      If $pause_game = False Then
      GUICtrlSetState($paused,$gui_show)
      EndIf
      $pause_game = True
   EndIf
   If _IsPressed("24") Then
      GUICtrlSetState($paused,$gui_hide)
      $pause_game = False
   EndIf
   $t = @SEC
   If $t <> $tsec Then
      If $cdwn = True Then
      $start_time -= 1
      GUICtrlSetData($starting,"Starting..."&$Start_time)
      EndIf
      If $start_time = 0 Then
         GUICtrlDelete($starting)
         $start_time = 5
         $pause_game = False
         $cdwn = False
      EndIf
      $tsec = $t
      EndIf
   If $pause_game = False Then
   $cp5 = ControlGetPos($gui,"",$target)
   $cp25 = ControlGetPos($gui,"",$box)
   If _IsPressed("25") And $cp5[0] > 0 Then
      ControlMove($gui,"",$target,$cp5[0]-$speed,$cp5[1])
   EndIf
   If _IsPressed("27")  And $cp5[0]+$cp5[2] < 640 Then
      ControlMove($gui,"",$target,$cp5[0]+$speed,$cp5[1])
   EndIf
   If _IsPressed("26") And $cp5[1] > 50 Then
      ControlMove($gui,"",$target,$cp5[0],$cp5[1]-$speed)
   EndIf
   If _IsPressed("28") And $cp5[1]+$cp5[3] < 480 Then
      ControlMove($gui,"",$target,$cp5[0],$cp5[1]+$speed)
   EndIf
   If _IsPressed("25") And _IsPressed("26") And $cp5[0] > 0 And $cp5[1] > 50 Then
      ControlMove($gui,"",$target,$cp5[0]-$speed,$cp5[1]-$speed)
   EndIf
   If _IsPressed("27") And _IsPressed("26") And $cp5[0]+$cp5[2] < 640 And $cp5[1] > 50 Then
      ControlMove($gui,"",$target,$cp5[0]+$speed,$cp5[1]-$speed)
   EndIf
   If _IsPressed("28") And _IsPressed("25") And $cp5[0] > 0 And $cp5[1]+$cp5[3] < 480 Then
      ControlMove($gui,"",$target,$cp5[0]-$speed,$cp5[1]+$speed)
   EndIf
   If _IsPressed("28") And _IsPressed("27") And $cp5[0]+$cp5[2] < 640 And $cp5[1]+$cp5[3] < 480 Then
      ControlMove($gui,"",$target,$cp5[0]+$speed,$cp5[1]+$speed)
   EndIf
   $mp = GUIGetCursorInfo($gui)
   $s = @SEC
   If $s <> $sec Then
      If $i >= 15 Then
         $speed += 0.2
         $speed_box += 0.2
         GUICtrlSetData($speed_lab,"Speed Target: "&$speed&@crlf&"Speed Box: "&$speed_box)
      $random_x = Round(Random(1,590),0)
   $random_y = Round(Random(1,430),0)
   $i = 0
   $stopped = False
   EndIf
      $i += 1
      If $time >= 60 Then
         $time = 0
         $min += 1
         EndIf
      $time += 1
      WinSetTitle($gui,"","Time: "&$hour&"h"&":"&$min&"m"&":"&$time&"s")
      $sec = $s
   EndIf
   attack()
   If $move = False Then
      test()
   EndIf
    If _IsPressed("01") Then
       test()
    EndIf
    EndIf
   Sleep(1)
WEnd

Func _Exit()
   Exit
EndFunc

Func attack()
   If $pause_game = False Then
   $cp = ControlGetPos($gui,"",$target)
   $cp2 = ControlGetPos($gui,"",$box)
   $food_pos = ControlGetPos($gui,"",$food)
   If $move = True Then
;~
   If $cp2[0] > $cp[0] Then
      ControlMove($gui,"",$box,$cp2[0]-$speed_box,$cp2[1])
   EndIf
   If $cp2[1] > $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0],$cp2[1]-$speed_box)
   EndIf
   If $cp2[0] < $cp[0] Then
      ControlMove($gui,"",$box,$cp2[0]+$speed_box,$cp2[1])
   EndIf
   If $cp2[1] < $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0],$cp2[1]+$speed_box)
   EndIf
   If $cp2[0] > $cp[0] And $cp2[1] < $cp[1] Then ;Left Corner
      ControlMove($gui,"",$box,$cp2[0]-$speed_box,$cp2[1]+$speed_box)
   EndIf
   If $cp2[0] < $cp[0] And $cp2[1] < $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0]+$speed_box,$cp2[1]+$speed_box)
   EndIf
   If $cp2[0] > $cp[0] And $cp2[1] > $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0]-$speed_box,$cp2[1]-$speed_box)
   EndIf
   If $cp2[0] < $cp[0] And $cp2[1] > $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0]+$speed_box,$cp2[1]-$speed_box)
      EndIf
;~
;~
If $food_pos[0]+$food_pos[2] >= $cp[0] And $food_pos[1]+$food_pos[3] >= $cp[1] And $food_pos[0] <= $cp[0]+$cp[2] And $food_pos[1] <= $cp[1]+$cp[3] Then
   $food_x = Random(1,590)
   $food_y = Random(50,430)
   $score = $score + 1
   GUICtrlSetData($score_lab,"Score: "&$score)
   ControlMove($gui,"",$food,1000,1000)
   ControlMove($gui,"",$food,$food_x,$food_y)
EndIf
     If $cp2[0] <= $cp[0]+$cp[2] And $cp2[1] <= $cp[1]+$cp[3] And $cp2[0]+$cp2[2] >= $cp[0] And $cp2[1]+$cp2[3] >= $cp[1] Then
           $pause_game = True
           $dead = True
           If $dead = True Then
              $dead_bar = GUICtrlCreateLabel("Dead",0,150,640,150,$ss_center)
              GUICtrlSetColor($dead_bar,0xFFFFFF)
              GUICtrlSetBkColor($dead_bar,0xFF0000)
              GUICtrlSetFont($dead_bar,95,700)
             ; $noj = IniReadSection(@scriptdir&"\highscore.ini","HighScore")
              ;$no += $noj[0][0] + 1
              ;IniWrite(@scriptdir&"\HighScore.ini","HighScore","Score"&$no,$score)
            ;  $isi = IniRead(@scriptdir&"\HighScore.ini","HighScore","score"&$no,"Error")
            ;  MsgBox(0,"",_ArrayMax($isi))
              $cwnd = True
              $pause_game = True
              EndIf
        ControlMove($gui,"",$target,9999,-9999)
        $cp_box = ControlGetPos($gui,"",$box)
        If $cp_box[1] > 220 Then
        ControlMove($gui,"",$target,Random(1,590),Random(50,210))
     Else
        ControlMove($gui,"",$target,Random(1,590),Random(220,430))
        EndIf
        $hits = $hits + 1
        GUICtrlSetData($hit,"Hits: "&$hits)
        $speed = 2
        $speed_box = 1
        GUICtrlSetData($speed_lab,"Speed Target: "&$speed&@crlf&"Speed Box: "&$speed_box)
        MsgBox(0,"Game Over!","Game Over!"&@CRLF&"You survived for "&"Time: "&$hour&"h"&":"&$min&"m"&":"&$time&"s"&@CRLF&"You scored "&$score&" points")
        $score = 0
        GUICtrlSetData($score_lab,"Score: "&$score)
        $hour = 0
        $min = 0
        $time = 0
        WinSetTitle($gui,"","Time: "&$hour&"h"&":"&$min&"m"&":"&$time&"s")
        ;$random_x = Round(Random(1,590),0)
   ;$random_y = Round(Random(1,430),0)
   $i = 0
  ; GUICtrlSetData($t_pos,"Target Pos: "&$random_x&","&$random_y)
   $stopped = False
     EndIf
  EndIf
  EndIf
  EndFunc

  Func test()
     If $pause_game = False Then
     $cp = ControlGetPos($gui,"",$box)
     $mp = GUIGetCursorInfo($gui)
     If $mp[0] >= $cp[0] And $mp[1] >= $cp[1] And $mp[0] <= $cp[0]+$cp[2] And $mp[1] <= $cp[1]+$cp[3] Then
     ControlMove($gui,"",$box,$mp[0]-25,$mp[1]-25)
  EndIf
  EndIf
  EndFunc

  #cs
If $stopped = False Then
   If $cp[0] > $random_x Then
      ControlMove($gui,"",$target,$cp[0]-1,$cp[1])
   EndIf
   If $cp[1] > $random_y Then
      ControlMove($gui,"",$target,$cp[0],$cp[1]-1)
   EndIf
   If $cp[0] < $random_x Then
      ControlMove($gui,"",$target,$cp[0]+1,$cp[1])
   EndIf
   If $cp[1] < $random_y Then
      ControlMove($gui,"",$target,$cp[0],$cp[1]+1)
   EndIf
   If $cp[0] = $random_x And $cp[1] = $random_y Then
      $stopped = True
      EndIf
   EndIf
   #ce

   Func pause_menu()
      GUICtrlSetState($pause_menu,$gui_show)
EndFunc 

Share this post


Link to post
Share on other sites



Im not sure that this is allowed on this forum. Something to do with gaming. I may be wrong. Can you comment your code? I've never made a game in autoit before its pretty good. Can you comment your code and maybe add some comments on the top to identify what restarts the game and other important info?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

Something like this?

Sorry if it's not what you want i'm going to bed so i wont respond to any post for a while.

Thanks.

#include<misc.au3>
#include<guiconstants.au3>
#include<gdiplus.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIToolTip.au3>
#include<Array.au3>
Global $pause_menu,$dead_bar
$hour = 0
$min = 0
$time = 0
$gui = GUICreate("Time: "&$hour&"h"&":"&$min&"m"&":"&$time&"s",640,480,-1,-1)
GUISetBkColor(0x000000)
Opt("GUIOnEventMode",1)
GUISetOnEvent(-3,"_Exit")
$bk_con = GUICtrlCreateLabel("",0,0,640,50)
GUICtrlSetBkColor($bk_con,0x555555)
Local $sec = @SEC
Local $tsec = @SEC
$xc = Random(1,590)
$yc = Random(50,210)
$xt = Random(1,590)
$yt = Random(220,430)
$food_x = Random(1,590)
$food_y = Random(50,430)
$random_x = Round(Random(1,590),0)
$random_y = Round(Random(50,430),0)
If $xc >= $xt And $yc >= $yt Then
$box = GUICtrlCreateButton("",$xc,$yc,50,50) ;Green box that follows you.
Else
   $box = GUICtrlCreateButton("",Random(1,590),Random(50,430),50,50)
EndIf
$target = GUICtrlCreateButton("",$xt,$yt,50,50) ;Red box that you control and if hit you lose.
If $food_x >= $xt Or $xc And $food_y >= $yc or $yt Then
$food = GUICtrlCreateButton("",$food_x,$food_y,15,15) ;Score keeper
Else
   $food = GUICtrlCreateButton("",Random(1,590),Random(50,430),15,15)
   EndIf
GUICtrlSetBkColor($food,0xAAFF5)
GUICtrlSetState($food,$gui_disable)
GUICtrlSetBkColor($box,0x008800)
GUICtrlSetBkColor($target,0x880000)
$hits = 0
$hit = GUICtrlCreateLabel("Hits: "&$hits,5,5,100,25) ;Amount of times you've died/been hit.
GUICtrlSetFont($hit,20,700)
GUICtrlSetColor($hit,0xFFFFFF)
GUICtrlSetBkColor($hit,0x555555)
$move = True
$i = 0
$stopped = False
$t_pos_x = $random_x
$t_pos_y = $random_y
$edge = False
$pause_game = True
$speed = 2
$speed_box = 1
$dead = False
$speed_lab = GUICtrlCreateLabel("Speed Target: "&$speed&@crlf&"Speed Box: "&$speed_box,500,5,150,40) ;Speed indicater of both objs.
GUICtrlSetColor($speed_lab,0xFFFFFF)
GUICtrlSetFont($speed_lab,12,700)
GUICtrlSetBkColor($speed_lab,0x555555)
$start_time = 5
$starting = GUICtrlCreateLabel("Starting..."&$Start_time,0,150,640,150,$ss_center) ;Start timer
GUICtrlSetColor($starting,0xFFFFFF)
GUICtrlSetFont($starting,90,700)
GUICtrlSetBkColor($starting,0x000055)
$cdwn = True
$score = 0
$score_lab = GUICtrlCreateLabel("Score: "&$score,150,5,150,25) ;Score keeper
GUICtrlSetColor($score_lab,0xFFFFFF)
GUICtrlSetFont($score_lab,20,700)
GUICtrlSetBkColor($score_lab,0x555555)
;$highsc = IniRead(@scriptdir&"\HighScore.ini","Highscore","HighScore","0") ;Future plans
;$highscore_lab = GUICtrlCreateLabel("Highscore: "&$highsc,250,100,100,20)
$no = 0
$boost = False
GUISetState()
$paused = GUICtrlCreateLabel("PAUSED",0,150,640,150,$ss_center) ;Pause feature
GUICtrlSetBkColor($paused,0x0E6E3F)
GUICtrlSetState($paused,$gui_hide)
GUICtrlSetColor($paused,0xFFFFFF)
GUICtrlSetFont($paused,100,700)
;$hwnd = _GDIPlus_GraphicsCreateFromHWND($gui)
;$pen = _GDIPlus_PenCreate(0xFFFFFFFF, 2)
$tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, "Left", 0)
    DllStructSetData($tRect, "Top", 0)
    DllStructSetData($tRect, "Right", 640)
    DllStructSetData($tRect, "Bottom", 480)
While 1
   If $dead = True Then ;Restart if killed.
      If _IsPressed("20") Then
              $pause_game = False
              $dead = False
              GUICtrlDelete($dead_bar)
           EndIf
        EndIf
        #cs
        If _IsPressed("09") Then
           $boost = True
           If $boost = True Then
              $speed += 1
              Sleep(100)
              $boost = False
           EndIf
           If $boost = False Then
              $speed = $speed_box+1
           EndIf
           EndIf
           #ce
   If _IsPressed("50") Then ;Pauses the game
      If $pause_game = False Then
      GUICtrlSetState($paused,$gui_show)
      EndIf
      $pause_game = True
   EndIf
   If _IsPressed("24") Then ;Unpauses the game.
      GUICtrlSetState($paused,$gui_hide)
      $pause_game = False
   EndIf
   $t = @SEC
   If $t <> $tsec Then ;Countdown till start
      If $cdwn = True Then
      $start_time -= 1
      GUICtrlSetData($starting,"Starting..."&$Start_time)
      EndIf
      If $start_time = 0 Then
         GUICtrlDelete($starting)
         $start_time = 5
         $pause_game = False
         $cdwn = False
      EndIf
      $tsec = $t
      EndIf
   If $pause_game = False Then ;movement for the target (red box)
   $cp5 = ControlGetPos($gui,"",$target)
   $cp25 = ControlGetPos($gui,"",$box)
   If _IsPressed("25") And $cp5[0] > 0 Then
      ControlMove($gui,"",$target,$cp5[0]-$speed,$cp5[1])
   EndIf
   If _IsPressed("27")  And $cp5[0]+$cp5[2] < 640 Then
      ControlMove($gui,"",$target,$cp5[0]+$speed,$cp5[1])
   EndIf
   If _IsPressed("26") And $cp5[1] > 50 Then
      ControlMove($gui,"",$target,$cp5[0],$cp5[1]-$speed)
   EndIf
   If _IsPressed("28") And $cp5[1]+$cp5[3] < 480 Then
      ControlMove($gui,"",$target,$cp5[0],$cp5[1]+$speed)
   EndIf
   If _IsPressed("25") And _IsPressed("26") And $cp5[0] > 0 And $cp5[1] > 50 Then
      ControlMove($gui,"",$target,$cp5[0]-$speed,$cp5[1]-$speed)
   EndIf
   If _IsPressed("27") And _IsPressed("26") And $cp5[0]+$cp5[2] < 640 And $cp5[1] > 50 Then
      ControlMove($gui,"",$target,$cp5[0]+$speed,$cp5[1]-$speed)
   EndIf
   If _IsPressed("28") And _IsPressed("25") And $cp5[0] > 0 And $cp5[1]+$cp5[3] < 480 Then
      ControlMove($gui,"",$target,$cp5[0]-$speed,$cp5[1]+$speed)
   EndIf
   If _IsPressed("28") And _IsPressed("27") And $cp5[0]+$cp5[2] < 640 And $cp5[1]+$cp5[3] < 480 Then
      ControlMove($gui,"",$target,$cp5[0]+$speed,$cp5[1]+$speed)
   EndIf
   $mp = GUIGetCursorInfo($gui)
   $s = @SEC ;Speeds up after 15 seconds of game play.
   If $s <> $sec Then
      If $i >= 15 Then
         $speed += 0.2
         $speed_box += 0.2
         GUICtrlSetData($speed_lab,"Speed Target: "&$speed&@crlf&"Speed Box: "&$speed_box)
      $random_x = Round(Random(1,590),0)
   $random_y = Round(Random(1,430),0)
   $i = 0
   $stopped = False
   EndIf
      $i += 1
      If $time >= 60 Then
         $time = 0
         $min += 1
         EndIf
      $time += 1
      WinSetTitle($gui,"","Time: "&$hour&"h"&":"&$min&"m"&":"&$time&"s") ;Time
      $sec = $s
   EndIf
   attack()
   If $move = False Then
      test()
   EndIf
    If _IsPressed("01") Then
       test()
    EndIf
    EndIf
   Sleep(1)
WEnd

Func _Exit()
   Exit
EndFunc

Func attack() ;Movement of the green box/Food hit detector
   If $pause_game = False Then
   $cp = ControlGetPos($gui,"",$target)
   $cp2 = ControlGetPos($gui,"",$box)
   $food_pos = ControlGetPos($gui,"",$food)
   If $move = True Then
;~
   If $cp2[0] > $cp[0] Then
      ControlMove($gui,"",$box,$cp2[0]-$speed_box,$cp2[1])
   EndIf
   If $cp2[1] > $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0],$cp2[1]-$speed_box)
   EndIf
   If $cp2[0] < $cp[0] Then
      ControlMove($gui,"",$box,$cp2[0]+$speed_box,$cp2[1])
   EndIf
   If $cp2[1] < $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0],$cp2[1]+$speed_box)
   EndIf
   If $cp2[0] > $cp[0] And $cp2[1] < $cp[1] Then ;Left Corner
      ControlMove($gui,"",$box,$cp2[0]-$speed_box,$cp2[1]+$speed_box)
   EndIf
   If $cp2[0] < $cp[0] And $cp2[1] < $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0]+$speed_box,$cp2[1]+$speed_box)
   EndIf
   If $cp2[0] > $cp[0] And $cp2[1] > $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0]-$speed_box,$cp2[1]-$speed_box)
   EndIf
   If $cp2[0] < $cp[0] And $cp2[1] > $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0]+$speed_box,$cp2[1]-$speed_box)
      EndIf
;~
;~
If $food_pos[0]+$food_pos[2] >= $cp[0] And $food_pos[1]+$food_pos[3] >= $cp[1] And $food_pos[0] <= $cp[0]+$cp[2] And $food_pos[1] <= $cp[1]+$cp[3] Then
   $food_x = Random(1,590)
   $food_y = Random(50,430)
   $score = $score + 1
   GUICtrlSetData($score_lab,"Score: "&$score)
   ControlMove($gui,"",$food,1000,1000)
   ControlMove($gui,"",$food,$food_x,$food_y)
EndIf
     If $cp2[0] <= $cp[0]+$cp[2] And $cp2[1] <= $cp[1]+$cp[3] And $cp2[0]+$cp2[2] >= $cp[0] And $cp2[1]+$cp2[3] >= $cp[1] Then
           $pause_game = True
           $dead = True
           If $dead = True Then
              $dead_bar = GUICtrlCreateLabel("Dead",0,150,640,150,$ss_center)
              GUICtrlSetColor($dead_bar,0xFFFFFF)
              GUICtrlSetBkColor($dead_bar,0xFF0000)
              GUICtrlSetFont($dead_bar,95,700)
             ; $noj = IniReadSection(@scriptdir&"\highscore.ini","HighScore")
              ;$no += $noj[0][0] + 1
              ;IniWrite(@scriptdir&"\HighScore.ini","HighScore","Score"&$no,$score)
            ;  $isi = IniRead(@scriptdir&"\HighScore.ini","HighScore","score"&$no,"Error")
            ;  MsgBox(0,"",_ArrayMax($isi))
              $cwnd = True
              $pause_game = True
              EndIf
        ControlMove($gui,"",$target,9999,-9999)
        $cp_box = ControlGetPos($gui,"",$box)
        If $cp_box[1] > 220 Then
        ControlMove($gui,"",$target,Random(1,590),Random(50,210))
     Else
        ControlMove($gui,"",$target,Random(1,590),Random(220,430))
        EndIf
        $hits = $hits + 1
        GUICtrlSetData($hit,"Hits: "&$hits)
        $speed = 2
        $speed_box = 1
        GUICtrlSetData($speed_lab,"Speed Target: "&$speed&@crlf&"Speed Box: "&$speed_box)
        MsgBox(0,"Game Over!","Game Over!"&@CRLF&"You survived for "&"Time: "&$hour&"h"&":"&$min&"m"&":"&$time&"s"&@CRLF&"You scored "&$score&" points")
        $score = 0
        GUICtrlSetData($score_lab,"Score: "&$score)
        $hour = 0
        $min = 0
        $time = 0
        WinSetTitle($gui,"","Time: "&$hour&"h"&":"&$min&"m"&":"&$time&"s")
        ;$random_x = Round(Random(1,590),0)
   ;$random_y = Round(Random(1,430),0)
   $i = 0
  ; GUICtrlSetData($t_pos,"Target Pos: "&$random_x&","&$random_y)
   $stopped = False
     EndIf
  EndIf
  EndIf
  EndFunc

  Func test()
     If $pause_game = False Then
     $cp = ControlGetPos($gui,"",$box)
     $mp = GUIGetCursorInfo($gui)
     If $mp[0] >= $cp[0] And $mp[1] >= $cp[1] And $mp[0] <= $cp[0]+$cp[2] And $mp[1] <= $cp[1]+$cp[3] Then
     ControlMove($gui,"",$box,$mp[0]-25,$mp[1]-25)
  EndIf
  EndIf
  EndFunc

  #cs
If $stopped = False Then
   If $cp[0] > $random_x Then
      ControlMove($gui,"",$target,$cp[0]-1,$cp[1])
   EndIf
   If $cp[1] > $random_y Then
      ControlMove($gui,"",$target,$cp[0],$cp[1]-1)
   EndIf
   If $cp[0] < $random_x Then
      ControlMove($gui,"",$target,$cp[0]+1,$cp[1])
   EndIf
   If $cp[1] < $random_y Then
      ControlMove($gui,"",$target,$cp[0],$cp[1]+1)
   EndIf
   If $cp[0] = $random_x And $cp[1] = $random_y Then
      $stopped = True
      EndIf
   EndIf
   #ce

   Func pause_menu()
      GUICtrlSetState($pause_menu,$gui_show)
EndFunc

Share this post


Link to post
Share on other sites

I notice a significant speed change when moving up the Y axis, though I don't see a difference in the movement coding.


If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Share this post


Link to post
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
Sign in to follow this  
Followers 0