Jump to content

Recommended Posts

Posted (edited)

I've problem with my game, in game we driving tank and shoot to other tanks.

But when I press space shoot fly how i want but first graphic not disappear. I don't know why :C (I think u can not understand, just use code and download graphics)

#include <GUIConstantsEx.au3>
#include <misc.au3>
#include <array.au3>
#include <timers.au3>

Global $vDLL = "user32.dll"

;--------------------------------------------------------------------------------------------------Kreator mapy--------------------------------------------------------------------------------------------------;

$aw = 0
$as = 0

While 1
    $s = InputBox("Rozmiar mapy", "Podaj poziomy rozmiar mapy" & @CRLF & "- Minimum 3" & @CRLF & "- Maksimum 50", 15)
    If (@error = 1) Then Exit
    If (StringIsDigit($s) = 1) And (($s > 50) = 0) And (($s < 3) = 0) Then ExitLoop
WEnd

While 1
    $w = InputBox("Rozmiar mapy", "Podaj pionowy rozmiar mapy" & @CRLF & "- Minimum 3" & @CRLF & "- Maksimum 50", 15)
    If (@error = 1) Then Exit
    If (StringIsDigit($w) = 1) And (($w > 50) = 0) And (($w < 3) = 0) Then ExitLoop
WEnd

While 1
    $roz = InputBox("Rozmiar czołgu", "Podaj rozmiar czołgu w pixelach" & @CRLF & "- Minimum 20" & @CRLF & "- Maksimum 500", 60)
    If (@error = 1) Then Exit
    If (StringIsDigit($roz) = 1) And (($roz > 500) = 0) And (($roz < 20) = 0) Then ExitLoop
WEnd

While 1
    $zdrowie = InputBox("Zdrowie czołgu", "Podaj startowe zdrowie czołgu", 100)
    If (@error = 1) Then Exit
    If (StringIsDigit($s) = 1) Then ExitLoop
WEnd

Dim $check[$s * $w + 1] ;[numer checkbox'a]

$mapa = GUICreate("Kreator mapy", $s * $roz, $w * $roz, 4, 4)

For $l = 0 To $s * $w - 1
    If ($as >= $s) Then
        $as = 0
        $aw += 1
    EndIf
    If $l = 0 Or $l = $s - 1 Or $l = $s * $w - 1 Or $l = $s * $w - $s Then
        $as += 1
        ContinueLoop
    EndIf
    $check[$l + 1] = GUICtrlCreateCheckbox("", $roz * $as, $roz * $aw, 20, 20)
    $as += 1
Next


GUISetState(@SW_SHOW)
While 1
    If (GUIGetMsg() = $GUI_EVENT_CLOSE) Then
        For $k = 1 To UBound($check) - 1
            $check[$k] = GUICtrlRead($check[$k])
        Next
        GUIDelete($mapa)
        ExitLoop
    EndIf
WEnd

;--------------------------------------------------------------------------------------------------Generator mapy--------------------------------------------------------------------------------------------------;

Dim $pol[$s * $w + 1][4 + 1] ;[numer pola][uchwyt, kamień, położenie1, położenie2]
Dim $pczol[4 + 1][9 + 1] ;[numer czołgu][numer pola, uchwyt, kierunek, zdrowie, czy strzela, uchwyt do strzału, numer pola strzału, kierunek strzału, siła]
$aw = 0
$as = 0

;~ _ArrayDisplay($check)

$czolgi = GUICreate("Czołgi", $s * $roz, $w * $roz, 4, 4)

For $i = 0 To $s * $w - 1

    If ($as >= $s) Then
        $as = 0
        $aw += 1
    EndIf

    Switch $check[$i + 1]
        Case 1
            $pol[$i + 1][1] = GUICtrlCreatePic("mapa2.jpg", $roz * $as, $roz * $aw, $roz, $roz)
            $pol[$i + 1][2] = 1
            $pol[$i + 1][3] = $roz * $as
            $pol[$i + 1][4] = $roz * $aw
        Case 0, 4
            $pol[$i + 1][1] = GUICtrlCreatePic("mapa.jpg", $roz * $as, $roz * $aw, $roz, $roz)
            $pol[$i + 1][2] = 0
            $pol[$i + 1][3] = $roz * $as
            $pol[$i + 1][4] = $roz * $aw
    EndSwitch

    $as += 1
Next

;~ _ArrayDisplay($pol)


$pczol[1][1] = 1
$pczol[2][1] = $s
$pczol[3][1] = $s * $w
$pczol[4][1] = $s * $w - $s + 1

$pczol[1][2] = GUICtrlCreatePic("czolg1p.jpg", $pol[$pczol[1][1]][3], $pol[$pczol[1][1]][4], $roz, $roz)
$pczol[2][2] = GUICtrlCreatePic("czolg2d.jpg", $pol[$pczol[2][1]][3], $pol[$pczol[2][1]][4], $roz, $roz)
$pczol[3][2] = GUICtrlCreatePic("czolg3l.jpg", $pol[$pczol[3][1]][3], $pol[$pczol[3][1]][4], $roz, $roz)
$pczol[4][2] = GUICtrlCreatePic("czolg4g.jpg", $pol[$pczol[4][1]][3], $pol[$pczol[4][1]][4], $roz, $roz)

$pczol[1][3] = "p"
$pczol[2][3] = "d"
$pczol[3][3] = "l"
$pczol[4][3] = "g"

$pczol[1][4] = $zdrowie
$pczol[2][4] = $zdrowie
$pczol[3][4] = $zdrowie
$pczol[4][4] = $zdrowie

For $x = 1 To 4
    $pczol[$x][5] = 0
    $pczol[$x][6] = 0
    $pczol[$x][7] = 0
    $pczol[$x][8] = 0
Next


GUICtrlDelete($pol[$pczol[1][1]][1])
GUICtrlDelete($pol[$pczol[2][1]][1])
GUICtrlDelete($pol[$pczol[3][1]][1])
GUICtrlDelete($pol[$pczol[4][1]][1])


;~ _ArrayDisplay($pczol)


Func czolg($NumCzolgu, $rzadanie)

    If ($NumCzolgu > 4) Or ($NumCzolgu < 1) Then
        MsgBox(16, "BŁAD", "Niepoprawny numer czołgu", 5)
        Return ""
    EndIf

    $NumPola = $pczol[$NumCzolgu][1]
    $RzadanePole = $NumPola + $rzadanie
    $CzyPoleZajete = 0

    If IsInt($NumPola / $s) And $RzadanePole = $NumPola + 1 Then $CzyPoleZajete = 1
    If IsInt(($NumPola - 1) / $s) And $RzadanePole = $NumPola - 1 Then $CzyPoleZajete = 1
    If $RzadanePole > $w * $s Or $RzadanePole < 1 Then $CzyPoleZajete = 1
    If $RzadanePole = $pczol[1][1] Or $RzadanePole = $pczol[2][1] Or $RzadanePole = $pczol[3][1] Or $RzadanePole = $pczol[4][1] Then $CzyPoleZajete = 1

    Switch $rzadanie
        Case $s
            $RzadanieKierunku = "d"
        Case -$s
            $RzadanieKierunku = "g"
        Case 1
            $RzadanieKierunku = "p"
        Case -1
            $RzadanieKierunku = "l"
        Case Else
            MsgBox(16, "BŁĄD", "Niepoprawne żadanie kierunku", 5)
            Return ""
    EndSwitch

    $CzyUsunietyStaryCzolg = GUICtrlDelete($pczol[$NumCzolgu][2])

    If $pczol[$NumCzolgu][3] = $RzadanieKierunku And $CzyPoleZajete = 0 And $pol[$RzadanePole][2] = 0 Then
;~          $ifelse = "if"
        $pczol[$NumCzolgu][1] = $RzadanePole
        $pol[$NumPola][1] = GUICtrlCreatePic("mapa.jpg", $pol[$NumPola][3], $pol[$NumPola][4], $roz, $roz)
        GUICtrlDelete($pol[$RzadanePole][1])
        $pol[$RzadanePole][1] = "del"
        $pczol[$NumCzolgu][2] = GUICtrlCreatePic("czolg" & $NumCzolgu & $RzadanieKierunku & ".jpg", $pol[$RzadanePole][3], $pol[$RzadanePole][4], $roz, $roz)
    Else
;~          $ifelse = "else"
        $pczol[$NumCzolgu][3] = $RzadanieKierunku
        $pczol[$NumCzolgu][2] = GUICtrlCreatePic("czolg" & $NumCzolgu & $RzadanieKierunku & ".jpg", $pol[$pczol[$NumCzolgu][1]][3], $pol[$pczol[$NumCzolgu][1]][4], $roz, $roz)
    EndIf

    Sleep(400)

;~  MsgBox(0, "", "NumCzolgu = " & $NumCzolgu & @CRLF & "rzadanie: " & $rzadanie & @CRLF & "NumPola: " & $NumPola & @CRLF & "RzadanePole: " & $RzadanePole & @CRLF & "RzadanieKierunku: " & $RzadanieKierunku & @CRLF & "CzyUsunietoStaryCzolg: " & $CzyUsunietyStaryCzolg & @CRLF & "if/else: " & $ifelse & @CRLF & "Numer pola po zmianie(istotne przy if): " & $pczol[$NumCzolgu][1] & @CRLF & "Uchwyt starej lokalizacji czołgu (teraz mapa)(istotne przy if): " & $pol[$NumPola][1] & @CRLF & "Uchwyt pola mapy na którym jest czołg (del)(istotne przy if): " & $pol[$RzadanePole][1] & @CRLF & "Uchwyt nowej grafiki czołgu: " & $pczol[$NumCzolgu][2] & @CRLF & "Kierunek czołgu (istotne przy else): " & $pczol[$NumCzolgu][3])
EndFunc   ;==>czolg

Func strzal($NumCzolgu)

    If ($NumCzolgu > 4) Or ($NumCzolgu < 1) Then
        MsgBox(16, "BŁAD", "Niepoprawny numer czołgu", 5)
        Return ""
    EndIf

    $NumPola = $pczol[$NumCzolgu][1]
    $KierunekCzolgu = $pczol[$NumCzolgu][3]

    Switch $KierunekCzolgu
        Case "g"
            $KierunekStrzalu = -$s
        Case "d"
            $KierunekStrzalu = $s
        Case "l"
            $KierunekStrzalu = -1
        Case "p"
            $KierunekStrzalu = 1
    EndSwitch

    $RzadanePole = $NumPola + $KierunekStrzalu

    If IsInt($NumPola / $s) And $RzadanePole = $NumPola + 1 Then Return ""
    If IsInt(($NumPola - 1) / $s) And $RzadanePole = $NumPola - 1 Then Return ""
    If $RzadanePole > $w * $s Or $RzadanePole < 1 Then Return ""

    If $pol[$RzadanePole][2] = 1 Then Return ""

    Switch $RzadanePole
        Case $pczol[1][1]
            $pczol[1][4] -= 100
            Return ""
        Case $pczol[2][1]
            $pczol[2][4] -= 100
            Return ""
        Case $pczol[3][1]
            $pczol[3][4] -= 100
            Return ""
        Case $pczol[4][1]
            $pczol[4][4] -= 100
            Return ""
    EndSwitch


    $pczol[$NumCzolgu][5] = 1

    GUICtrlDelete($pol[$RzadanePole][1])
    $pol[$RzadanePole][1] = "del"

    $pczol[$NumCzolgu][6] = GUICtrlCreatePic("strzal100.jpg", $pol[$RzadanePole][3], $pol[$RzadanePole][4], $roz, $roz)
    $pczol[$NumCzolgu][7] = $RzadanePole
    $pczol[$NumCzolgu][8] = $KierunekStrzalu
    $pczol[$NumCzolgu][9] = 100


    AdlibRegister("strzal" & $NumCzolgu)

EndFunc   ;==>strzal

;[numer czołgu][numer pola, uchwyt, kierunek, zdrowie, czy strzela, uchwyt do strzału, numer pola strzału, kierunek strzału, siła]

Func strzal1()
;~  _ArrayDisplay($pczol, "pczol")
;~  _ArrayDisplay($pol, "pol")

    $NumPola = $pczol[1][7]
    $RzadanePole = $NumPola + $pczol[1][8]
    $Sila = $pczol[1][9] - 25

    If $RzadanePole > $w * $s Or $RzadanePole < 1 Then
        $pczol[1][5] = 0
        AdlibUnRegister("strzal1")
        Return ""
    EndIf

    If $pol[$RzadanePole][2] = 1 Then
        AdlibUnRegister("strzal1")
        $pczol[1][5] = 0
        GUICtrlDelete($pczol[1][6])
        $pczol[1][6] = "del"
        $pol[$NumPola][1] = GUICtrlCreatePic("mapa.jpg", $pol[$NumPola][3], $pol[$NumPola][4], $roz, $roz)
        Return ""
    EndIf

    If $pczol[1][9] = 25 Then
        AdlibUnRegister("strzal1")
        $pczol[1][5] = 0
        GUICtrlDelete($pczol[1][6])
        $pczol[1][6] = "del"
        $pol[$NumPola][1] = GUICtrlCreatePic("mapa.jpg", $pol[$NumPola][3], $pol[$NumPola][4], $roz, $roz)
        Return ""
    EndIf

;~  MsgBox(0,"",$pczol[1][6])
    $a = GUICtrlDelete($pczol[1][6])
;~  ConsoleWrite($Sila & @CRLF & $a & @CRLF)
    $pczol[1][6] = "del"

;~  MsgBox(0,"",$a)

    $pol[$NumPola][1] = GUICtrlCreatePic("mapa.jpg", $pol[$NumPola][3], $pol[$NumPola][4], $roz, $roz)

    If IsInt($NumPola / $s) And $RzadanePole = $NumPola + 1 Then
        $pczol[1][5] = 0
        AdlibUnRegister("strzal1")
        Return ""
    EndIf
    If IsInt(($NumPola - 1) / $s) And $RzadanePole = $NumPola - 1 Then
        $pczol[1][5] = 0
        AdlibUnRegister("strzal1")
        Return ""
    EndIf

    Switch $RzadanePole
        Case $pczol[1][1]
            $pczol[1][4] -= $Sila
            $pczol[1][5] = 0
            AdlibUnRegister("strzal1")
            Return ""
        Case $pczol[2][1]
            $pczol[2][4] -= $Sila
            $pczol[1][5] = 0
            AdlibUnRegister("strzal1")
            Return ""
        Case $pczol[3][1]
            $pczol[3][4] -= $Sila
            $pczol[1][5] = 0
            AdlibUnRegister("strzal1")
            Return ""
        Case $pczol[4][1]
            $pczol[4][4] -= $Sila
            $pczol[1][5] = 0
            AdlibUnRegister("strzal1")
            Return ""
    EndSwitch

    GUICtrlDelete($pol[$RzadanePole][1])
    $pol[$RzadanePole][1] = "del"

    $pczol[1][6] = GUICtrlCreatePic("strzal" & $Sila & ".jpg", $pol[$RzadanePole][3], $pol[$RzadanePole][4], $roz, $roz)
    $pczol[1][7] = $RzadanePole
    $pczol[1][9] = $Sila

EndFunc   ;==>strzal1

Func strzal2()
    Sleep(1000)
EndFunc   ;==>strzal2

Func strzal3()
    Sleep(1000)
EndFunc   ;==>strzal3

Func strzal4()
    Sleep(1000)
EndFunc   ;==>strzal4


GUISetState(@SW_SHOW)


;--------------------------------------------------------------------------------------------------Pętla i Multiplayer--------------------------------------------------------------------------------------------------;
;~ Func komendy($kom)
;~  $kom = StringSplit($kom, ":")

;~  Switch $kom[1]
;~      Case "connect"

;~  EndSwitch
;~ EndFunc

While 1
    If (GUIGetMsg() = $GUI_EVENT_CLOSE) Then ExitLoop
    If _IsPressed("1B", $vDLL) And WinActive($czolgi) Then Exit
    If _IsPressed("25", $vDLL) And WinActive($czolgi) Then czolg(1, -1)
    If _IsPressed("26", $vDLL) And WinActive($czolgi) Then czolg(1, -$s)
    If _IsPressed("27", $vDLL) And WinActive($czolgi) Then czolg(1, 1)
    If _IsPressed("28", $vDLL) And WinActive($czolgi) Then czolg(1, $s)
    If _IsPressed("20", $vDLL) And WinActive($czolgi) Then strzal(1)

    ;If _IsPressed("41", $vDLL) And WinActive($czolgi) Then czolg(2, -1)
    ;If _IsPressed("57", $vDLL) And WinActive($czolgi) Then czolg(2, -$s)
    ;If _IsPressed("44", $vDLL) And WinActive($czolgi) Then czolg(2, 1)
    ;If _IsPressed("53", $vDLL) And WinActive($czolgi) Then czolg(2, $s)

    ;If $pczol[1][4] < 1 Then ;komenda do odłączenia czołgu 1
    ;If $pczol[2][4] < 1 Then ;komenda do odłączenia czołgu 2
    ;If $pczol[3][4] < 1 Then ;komenda do odłączenia czołgu 3
    ;If $pczol[4][4] < 1 Then ;komenda do odłączenia czołgu 4
WEnd

;~ Dim $Gracz[4 + 1][3 + 1] ;[numer gracza][ip, port, socket]
;~ Dim $Serv[3 + 1] = ["25.69.134.219", "21917"] ;[ip, port, socket]
;~ Dim $Komenda

;~ UDPStartup()
;~ $Serv[3] = UDPBind($Serv[1], $Serv[2])

;~ While 1
;~  If (GUIGetMsg() = $GUI_EVENT_CLOSE) Then ExitLoop

;~  $Komenda = UDPRecv($Serv[3], 2048)
;~  If $Komenda <> "" Then
;~      komendy($Komenda)
;~  EndIf

;~ WEnd

(I think problem is in "strzal" or "strzal1" functions)

 

Edited by Melba23
  • Moderators
Posted

Turtlix21,

You appear not to have read the Forum rules since your arrival. Please do read them - particularly the bit about not discussing game automation - before you post again.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted

Turtlix21,

I have just been reminded that your last thread was about your own game written in AutoIt - and I have just been interrupted by your PM telling me the same thing. Apologies - thread reopened.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Please post zip with jpg. It should be much easy to help you. 

I will cleanup & check your script.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

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