Jump to content

Arcade game


Recommended Posts

Here is an arcade game that I made. It's really short, but it's kind of fun. Attached is the zip. Any suggestions are welcome.

#include <GUIConstants.au3>
#include <Misc.au3>
#include <Array.au3>
#comments-start
  25 LEFT ARROW key
  26 UP ARROW key
  27 RIGHT ARROW key
  28 DOWN ARROW key
  20 SPACE BAR key
#comments-end
Global $shleft = 90
Global $shtop = 170
Global $smtop = 10
Global $smleft = 10
Global $fired = 0
Global $fitop = 0
Global $filef = 0
Global $fire = "fdjka"
Global $movet = Random(-4, 4, 1)
Global $movel = Random(-4, 4, 1)
Global $smdelete = 0
Global $extime = "fhdja"
$n1created = 0
$lcoords = _ArrayCreate("", "", "", "", "")
$tcoords = _ArrayCreate("", "", "", "", "")
$widthco = _ArrayCreate("", "", "", "", "")
$heightc = _ArrayCreate("", "", "", "", "")
$controls = _ArrayCreate("", "", "", "", "")
$enemk = _ArrayCreate(0, 0, 0, 0, 0, 0, 0, 0)
$enemn = _ArrayCreate("", "", "", "", "")
$firsttime = 1
$lcoords[0] = 10
$tcoords[0] = 10
$widthco[0] = 30
$heightc[0] = 30
$end = 0
$lv3 = 0
$score = 0
$enemk[0] = 0
$enemk[1] = 0
$enemk[2] = 0
$enemys = 1
$pressed = 0
$dead = 0
$gtime = TimerInit()
$guydead = 0
$explosion = "fjdioaja"
$timer = TimerInit ()
$move = "Right"
$moveh = "Right"
$movev = "Down"
$kills = 0
$lv3time = "hgfkaf"
$firsttime2 = 1
$gui = GUICreate("Space Blaster", 200, 200)
GUISetBkColor(0x000000)
$shooter = GUICtrlCreatePic(@ScriptDir & "\shipbang.JPG", 90, 170, 20, 20)
$controls[0] = GUICtrlCreatePic(@ScriptDir & "\badguy.JPG", 10, 10, 30, 30)
$enemn[0] = 0
GUISetState(@SW_SHOW)
SoundPlay(@ScriptDir & "\newgame1.wav")

While 1
    $msg = GUIGetMsg ()
    If TimerDiff($extime) > 300 Then
        GUICtrlDelete($explosion)
    EndIf
    If $end = 1 Then
        GUICtrlSetPos($label, 70, 60, 200, 20)
        $shtop = $shtop - 4
    EndIf
    Select
        Case _IsPressed("01")
            Exit
        Case BitAND(_IsPressed("25"), _IsPressed("26"), _IsPressed("27"), _IsPressed("28"))
            SplashTextOn("COLIN ROOLZ!!!", "WUHU 4 ME!!!")
            Sleep(500)
            SplashOff ()
        Case _IsPressed("1B")
            If @Compiled = 1 Then
                Run(@ScriptFullPath)
                Exit
            Else
                Run(@AutoItExe & " " & @ScriptName)
                Exit
            EndIf
        Case _IsPressed("20")
            If BitAND($pressed = 0, $dead = 0) Then
                SoundPlay(@ScriptDir & "\shot1.wav")
                GUICtrlDelete($fire)
                $fired = 1
                $fire = GUICtrlCreatePic(@ScriptDir & "\fire.JPG", $shleft + 5, $shtop, 10, 10)
                $filef = $shleft + 5
                $fitop = $shtop
                $pressed = 1
            EndIf
        Case BitAND($end = 1, _IsPressed("0D"))
            If @Compiled = 1 Then
                Run(@ScriptFullPath)
                Exit
            Else
                Run(@AutoItExe & " " & @ScriptName)
                Exit
            EndIf
        Case _IsPressed("25")
            $shleft = $shleft - 3
        Case _IsPressed("26")
            $shtop = $shtop - 3
        Case _IsPressed("27")
            $shleft = $shleft + 3
        Case _IsPressed("28")
            $shtop = $shtop + 3
        Case _IsPressed("20") = 0
            $pressed = 0
    EndSelect
    GUICtrlSetPos($shooter, $shleft, $shtop)
    If $enemk[0] = 0 Then
        Call("Move1")
    EndIf
    If BitAND($enemk[0] = 1, $enemk[1] = 0) Then
        Call("Move2", 0)
    EndIf
    If BitAND($enemk[0] = 1, $enemk[2] = 0) Then
        Call("Move2", 1)
    EndIf
    If BitAND($lv3 = 1, $enemk[3] = 0, TimerDiff($lv3time) > 0) Then
        Call("Move3", 0)
    EndIf
    If BitAND($lv3 = 1, $enemk[4] = 0, TimerDiff($lv3time) > 100) Then
        Call("Move3", 1)
    EndIf
    If BitAND($lv3 = 1, $enemk[5] = 0, TimerDiff($lv3time) > 200) Then
        Call("Move3", 2)
    EndIf
    If BitAND($lv3 = 1, $enemk[6] = 0, TimerDiff($lv3time) > 300) Then
        Call("Move3", 3)
    EndIf
    If BitAND($lv3 = 1, $enemk[7] = 0, TimerDiff($lv3time) > 400) Then
        Call("Move3", 4)
    EndIf
    If $fired = 1 Then
        $fitop = $fitop - 4
        GUICtrlSetPos($fire, $filef, $fitop)
        If $fitop < 0 Then
            GUICtrlDelete($fire)
            $fired = 0
        EndIf
            If _ShotHit() <> 0 Then
                If BitOR(BitAND($enemk[0] = 0, $dead = 0), BitAND($enemk[1] = 0, $dead = 0), BitAND($enemk[2] = 0, $dead = 0), BitAND($enemk[3] = 0, $dead = 0), BitAND($enemk[4] = 0, $dead = 0), BitAND($enemk[5] = 0, $dead = 0), BitAND($enemk[6] = 0, $dead = 0), BitAND($enemk[7] = 0, $dead = 0)) Then
                    If $enemk[$enemn[_ShotHit() - 1]] = 0 Then
                    SoundPlay(@ScriptDir & "\explosion.wav")
                    $explosion = GUICtrlCreatePic(@ScriptDir & "\splozin.jpg", $lcoords[_ShotHit() - 1], $tcoords[_ShotHit() - 1], 30, 30)
                    $extime = TimerInit()
                    $fired = 0
                    GUICtrlDelete($controls[_ShotHit() - 1])
                    GUICtrlDelete($fire)
                    $score = $score + 100
                    $guydead = 1
                    $smdelete = 1
                    $enemys = $enemys + 1
                    $prev = _ShotHit ()
                    $kills = 1
                    $enemk[$enemn[$prev - 1]] = 1
                    If $firsttime = 1 Then
                        $controls[$prev - 1] = GUICtrlCreatePic(@ScriptDir & "\badguysm1.JPG", 20, 10, 20, 20)
                        $lcoords[$prev - 1] = 20
                        $tcoords[$prev - 1] = 10
                        $widthco[$prev - 1] = 20
                        $heightc[$prev - 1] = 20
                        $n1created = 1
                        $controls[$prev] = GUICtrlCreatePic(@ScriptDir & "\badguysm1.JPG", 160, 10, 20, 20)
                        $lcoords[$prev] = 160
                        $tcoords[$prev] = 10
                        $widthco[$prev] = 20
                        $heightc[$prev] = 20
                        $n1created = 1
                        $enemk[0] = 1
                        $enemk[1] = 0
                        $enemk[2] = 0
                        $firsttime = 0
                        $enemn[0] = 1
                        $enemn[1] = 2
                    EndIf
                    If BitAND($enemk[0] = 1, $enemk[1] = 1, $enemk[2] = 1, $firsttime2 = 1) Then
                        $controls[0] = GUICtrlCreatePic(@ScriptDir & "\badguysm2.JPG", 10, 10, 20, 20)
                        $enemn[0] = 3
                        $controls[1] = GUICtrlCreatePic(@ScriptDir & "\badguysm2.JPG", 45, 10, 20, 20)
                        $enemn[1] = 4
                        $controls[2] = GUICtrlCreatePic(@ScriptDir & "\badguysm2.JPG", 90, 10, 20, 20)
                        $enemn[2] = 5
                        $controls[3] = GUICtrlCreatePic(@ScriptDir & "\badguysm2.JPG", 135, 10, 20, 20)
                        $enemn[3] = 6
                        $controls[4] = GUICtrlCreatePic(@ScriptDir & "\badguysm2.JPG", 180, 10, 20, 20)
                        $enemn[4] = 7
                        $lcoords[0] = 10
                        $lcoords[1] = 45
                        $lcoords[2] = 90
                        $lcoords[3] = 135
                        $lcoords[4] = 180
                        $tcoords[0] = 10
                        $tcoords[1] = 10
                        $tcoords[2] = 10
                        $tcoords[3] = 10
                        $tcoords[4] = 10
                        $widthco[0] = 20
                        $widthco[1] = 20
                        $widthco[2] = 20
                        $widthco[3] = 20
                        $widthco[4] = 20
                        $heightc[0] = 20
                        $heightc[1] = 20
                        $heightc[2] = 20
                        $heightc[3] = 20
                        $heightc[4] = 20
                        $lv3time = TimerInit()
                        $lv3 = 1
                        $firsttime2 = 0
                    EndIf
                    EndIf
                EndIf
            EndIf
    EndIf
    If BitAND(_Touched() <> 0, $dead = 0) Then
        GUICtrlDelete($explosion)
        $t = _Touched()
        If $enemk[$enemn[$t - 1]] = 0 Then
            SoundPlay(@ScriptDir & "\explosion.wav")
            $extime = TimerInit()
            $explosion = GUICtrlCreatePic(@ScriptDir & "\splozin.jpg", $shleft, $shtop, 20, 20)
            GUICtrlDelete($shooter)
            $dead = 1
        EndIf
    EndIf
    If BitAND($enemk[3] = 1, $enemk[4] = 1, $enemk[5] = 1, $enemk[6] = 1, $enemk[7] = 1, $end = 0, $dead = 0) Then
        SoundPlay(@ScriptDir & "\won1.wav")
        $label = GUICtrlCreateLabel("HI-SCORES", 70, 60, 200, 20)
        GUICtrlSetFont($label, 8.5, -1, -1, "OCR A Extended")
        $label2 = GUICtrlCreateLabel("1 - " & Round(($score * 10) + TimerDiff($gtime), 0), 80, 80, 200)
        GUICtrlSetFont($label2, 8.5, -1, -1, "OCR A Extended")
        $label3 = GUICtrlCreateLabel("PRESS START", 70, 140)
        GUICtrlSetFont($label3, 8.5, -1, -1, "OCR A Extended")
        GUICtrlSetColor($label, 0xF8F8FF)
        GUICtrlSetColor($label2, 0xF8F8FF)
        GUICtrlSetColor($label3, 0xF8F8FF)
        GUICtrlSetPos($label, 70, 60, 200, 20)
        $end = 1
    EndIf
WEnd

Func _IsOn ($left1, $top1, $width1, $height1, $left2, $top2, $width2, $height2)
    If StringIsAlNum($left1 & $top1 & $width1 & $height1 & $left2 & $top2 & $width2 & $height2) = 0 Then
        Return -1
    EndIf
    $lewi1 = $left1 + $width1
    $tohi1 = $height1 + $top1
    $lewi2 = $left2 + $width2
    $tohi2 = $height2 + $top2
    If BitAND($left1 < $lewi2, $lewi1 > $left2, $tohi1 > $top2, $top1 < $tohi2) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

Func _ShotHit ()
        If _IsOn($filef, $fitop, 10, 10, $lcoords[0], $tcoords[0], $widthco[0], $heightc[0]) = 1 Then
            Return 1
        ElseIf _IsOn($filef, $fitop, 10, 10, $lcoords[1], $tcoords[1], $widthco[1], $heightc[1]) = 1 Then
            Return 2
        ElseIf _IsOn($filef, $fitop, 10, 10, $lcoords[2], $tcoords[2], $widthco[2], $heightc[2]) = 1 Then
            Return 3
        ElseIf _IsOn($filef, $fitop, 10, 10, $lcoords[3], $tcoords[3], $widthco[3], $heightc[3]) = 1 Then
            Return 4
        ElseIf _IsOn($filef, $fitop, 10, 10, $lcoords[4], $tcoords[4], $widthco[4], $heightc[4]) = 1 Then
            Return 5
        Else
            Return 0
        EndIf
EndFunc

Func _Touched ()
    If _IsOn($shleft, $shtop, 20, 20, $lcoords[0], $tcoords[0], $widthco[0], $heightc[0]) = 1 Then
        Return 1
    ElseIf _IsOn($shleft, $shtop, 20, 20, $lcoords[1], $tcoords[1], $widthco[1], $heightc[1]) = 1 Then
        Return 2
    ElseIf _IsOn($shleft, $shtop, 20, 20, $lcoords[2], $tcoords[2], $widthco[2], $heightc[2]) = 1 Then
        Return 3
    ElseIf _IsOn($shleft, $shtop, 20, 20, $lcoords[3], $tcoords[3], $widthco[3], $heightc[3]) = 1 Then
        Return 4
    ElseIf _IsOn($shleft, $shtop, 20, 20, $lcoords[4], $tcoords[4], $widthco[4], $heightc[4]) = 1 Then
        Return 5
    Else
        Return 0
    EndIf
EndFunc
Func Move2 ($ctrlnum)
    If $lcoords[$ctrlnum] > 180 Then
        $moveh = "Left"
    ElseIf $lcoords[$ctrlnum] < 0 Then
        $moveh = "Right"
    EndIf
    If $tcoords[$ctrlnum] > 180 Then
        $movev = "Up"
    ElseIf $tcoords[$ctrlnum] < 0 Then
        $movev = "Down"
    EndIf
    If $movev = "Up" Then
        $tcoords[$ctrlnum] = $tcoords[$ctrlnum] - 2
    ElseIf $movev = "Down" Then
        $tcoords[$ctrlnum] = $tcoords[$ctrlnum] + 2
    EndIf
    If $moveh = "Left" Then
        $lcoords[$ctrlnum] = $lcoords[$ctrlnum] - 2
    ElseIf $moveh = "Right" Then
        $lcoords[$ctrlnum] = $lcoords[$ctrlnum] + 2
    EndIf
    GUICtrlSetPos($controls[$ctrlnum], $lcoords[$ctrlnum], $tcoords[$ctrlnum])
EndFunc
Func Move1 ()
    If $lcoords[0] > 170 Then
        $move = "Left"
    ElseIf $lcoords[0] < 1 Then
        $move = "Right"
    EndIf
    If $move = "Right" Then
        $movel = 2
    ElseIf $move = "Left" Then
        $movel = -2
    EndIf
    $movet = 0
    $tcoords[0] = $tcoords[0] + $movet
    $lcoords[0] = $lcoords[0] + $movel
    GUICtrlSetPos($controls[0], $lcoords[0], $tcoords[0])
EndFunc
Func Move3 ($ctrlnum)
    $tcoords[$ctrlnum] = $tcoords[$ctrlnum] + 3
    GUICtrlSetPos($controls[$ctrlnum], $lcoords[$ctrlnum], $tcoords[$ctrlnum])
    If $tcoords[$ctrlnum] > 200 Then
        GUICtrlDelete($controls[$ctrlnum])
        $enemk[$enemn[$ctrlnum]] = 1
    EndIf
EndFunc

spaceblaster.zip

Link to comment
Share on other sites

I forgot to say how to exit. You just click anywhere on the screen except the close button :rolleyes:

And the controls are: Space to fire, arrow keys to move, Esc to restart, and the start button is Enter.

Edited by BananaFredSoft
Link to comment
Share on other sites

I forgot to say how to exit. You just click anywhere on the screen except the close button :rolleyes:

Quite nice, but pretty challenging, especially level 3....Well good job.

Edit: Typo

Edited by Generator
Link to comment
Share on other sites

Any tips? Suggestions? Comments?

yes,

1. If you can use oneventmode, so the controls don't freeze while in a loop

2. I think you could change mouse click exit, to click=fire, move=move, so you can use either mouse or keyboard control

3. When you die just it should restart the game.

4. If not too hard Make the levels via a file, that way you can create your own levels, speed, enemys ect.

5. Why do you use the call() function?

If $enemk[0] = 0 Then
        Call("Move1")
    EndIf
    If BitAND($enemk[0] = 1, $enemk[1] = 0) Then
        Call("Move2", 0)
    EndIf
...

Could be shortened to

If $enemk[0] = 0 Then Move1()
 If BitAND($enemk[0] = 1, $enemk[1] = 0) then Move2(0)
...

Anyways nice little game you have going there.

Edited by mrRevoked
Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
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...