Jump to content
Sign in to follow this  
PunProgram

Simple Shooting Game

Recommended Posts

PunProgram

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=pun.ico
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("MouseCoordMode", 2)
$maxX = 800
$maxY = 600
$start = 0
$star = 0
$a=0
HotKeySet("{Esc}","esc")
Global $sh = 0
Global $x =  0
Global $y = 750
Global $xpos = 300
Global $ypos = 0
Global $sp = 10
$gui = GUICreate("game",$maxX,$maxY,-1,-1,0x00020000+0x00C00000+0x00080000)
$p = GUICtrlCreateButton("P1",$x,$y,50,50)
$target = GUICtrlCreateButton("Target",$xpos,$ypos,50,50)
GUICtrlSetBkColor($gui,0x00ff00)
GUISetState()
  MouseMove(0,575)
While 1
$c=MouseGetPos()
if $c[1] = 575  Then
$c[1]=575
Else
$c[1]=575
EndIf
    if $c[0] < 0 Then
    $c[0] = 0
   EndIf
     if $c[0] > $maxX-50 Then
    $c[0] = $maxX-50
   EndIf
    if $y > $maxY-50 Then
    $y = $maxY-50
   EndIf
    if $y < 0 Then
    $y = 0
   EndIf
$x=$c[0]
   $m = GUIGetMsg()
if $m=$p Then
  shoot()
  EndIf
   GUICtrlSetPos($p,$x,$y)
   if $m = -3 Then
    Exit
   EndIf
   if $sh = 1 Then
    $sh = 0
    $mu = GUICtrlCreateButton("Shoot",$x,$maxY,50,50)
    For $ymu = $maxY to -50 Step -1
     GUICtrlSetPos($mu,$x,$ymu)
     If $xpos > $x - 50 And $xpos < $x + 50 And $ypos = $ymu Then
      $a=$a+1
      TrayTip("Scores",$a,10)
      EndIf
    Next
    EndIf
  $dif = TimerDiff($star)
  if $dif > 1500 Then
  $num = Random(0,750)
  $xpos=$num
  GUICtrlSetPos($target,$xpos,0)
   $star = TimerInit()
  EndIf
WEnd
Func left()
  $x = $x-$sp
EndFunc
Func right()
  $x = $x+$sp
EndFunc
Func shoot()
  $sh = 1
EndFunc
Func esc()
Exit
EndFunc

Just move & click on the P1 button.

Edited by PunProgram

Share this post


Link to post
Share on other sites
PunProgram

How can I make P1 move while the shot is moving?

Share this post


Link to post
Share on other sites
JohnOne

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=pun.ico
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("MouseCoordMode", 2)
$maxX = 800
$maxY = 600
$start = 0
$star = 0
$a = 0
HotKeySet("{Esc}", "esc")
Global $sh = 0
Global $x = 0
Global $y = 750
Global $xpos = 300
Global $ypos = 0
Global $sp = 10
$gui = GUICreate("game", $maxX, $maxY, -1, -1, 0x00020000 + 0x00C00000 + 0x00080000)
$p = GUICtrlCreateButton("P1", $x, $y, 50, 50)
$target = GUICtrlCreateButton("Target", $xpos, $ypos, 50, 50)
GUICtrlSetBkColor($gui, 0x00ff00)
GUISetState()
MouseMove(0, 575)
While 1
    $c = MouseGetPos()
    If $c[1] = 575 Then
        $c[1] = 575
    Else
        $c[1] = 575
    EndIf
    If $c[0] < 0 Then
        $c[0] = 0
    EndIf
    If $c[0] > $maxX - 50 Then
        $c[0] = $maxX - 50
    EndIf
    If $y > $maxY - 50 Then
        $y = $maxY - 50
    EndIf
    If $y < 0 Then
        $y = 0
    EndIf
    $x = $c[0]
    $m = GUIGetMsg()
    If $m = $p Then
        shoot()
    EndIf
    GUICtrlSetPos($p, $x, $y)
    If $m = -3 Then
        Exit
    EndIf
    If $sh = 1 Then
        $sh = 0
        $mu = GUICtrlCreateButton("Shoot", $x, $maxY, 50, 50)
        For $ymu = $maxY To -50 Step -1
            GUICtrlSetPos($mu, $x, $ymu)
            $dif = TimerDiff($star)
            If $dif > 1500 Then
                _MyFunc()
            EndIf
            If $xpos > $x - 50 And $xpos < $x + 50 And $ypos = $ymu Then
                $a = $a + 1

                TrayTip("Scores", $a, 10)
            EndIf
        Next
    EndIf
    $dif = TimerDiff($star)
    If $dif > 1500 Then
        _MyFunc()
    EndIf
WEnd
Func _MyFunc()
    $num = Random(0, 750)
    $xpos = $num
    GUICtrlSetPos($target, $xpos, 0)
    $star = TimerInit()
EndFunc   ;==>_MyFunc
Func left()
    $x = $x - $sp
EndFunc   ;==>left
Func right()
    $x = $x + $sp
EndFunc   ;==>right
Func shoot()
    $sh = 1
EndFunc   ;==>shoot
Func esc()
    Exit
EndFunc   ;==>esc


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
PunProgram

Thank a lot for your reply but P1 still can't move while the shot is moving.

Share this post


Link to post
Share on other sites
JohnOne

I see, I had it in my head you wanted the target to be able to move

while the shot is moving, that was easy because that is an instant movement.

But autoit is single threaded, meaning only one thing at a time can occur.

I'm sure it's acheivable with some crazy coding but I certainly don't have the time to

put into it.

Another process to move the shot is one way.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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  

×