Jump to content

TANK 1990 PEGASUS [NES] game v.0.0.2 + Multi by LAN +MapEditor!


Uriziel01
 Share

Recommended Posts

Hi everyone :) Today some "simple" game from 8-bit console Pegasus (This is name in Poland, you probably now it as some NES console variant? ;) ) as for now I had to disable sound because of some random crashes because of it (but will solve it soon) and still having problems with blinking in prospeed and using .png when more that one texture is moving in the same moment (I have asked about that on Forum but no answer). Brown bricks are destroyable and you can hide in the green grass, you can shoot by the water, ice and grass, but cant drive by water. Will include a nice WYSIWYG map editor today night for some fun B)

Just put in in main game folder and run, or compile the source code !

Ok some screen's:

Posted Image

Video from gameplay

http://www.youtube.com/watch?v=JHmQGWFB01A

And Download

Tank.zip v.0.0.2 - [886KB] dont have to wait or enter any captcha code B)

EDIT:

OK! And now as I had prommised an MapEditor(Creator) it is tile WYSIWYG editor, giving abilities to make some new or edit existing maps B) Have fun

MapEditor v.1.0.2

Oh, sorry I didnt uploaded all files from editor :D Please copy MapCreator.exe to the game directory, and files from GFX put in GFX dir in game folder. Sorry again B)

New, version:

MapEditor_v.1.0.3.rar

EDIT:

Ok, Ok. Here have you the source codes :D

Game:

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include "Prospeed30.au3"
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <String.au3>
#include <ComboConstants.au3>
$dll = DllOpen("user32.dll")
$res_x_start = @DesktopWidth
$res_y_start = @DesktopHeight
$ver = "v.0.0.2"
$y1 = Random(1, 490, 1)
;$gui_main=GUICreate("Survivors "&$ver,800,600,-1,-1)
#include <ScreenCapture.au3>
guicreate("Opcje",450,150,-1,-1)
GUISetFont(9,700,1)
    $full_screen = GUICtrlCreateCheckbox("FullScreen?", 10, 10, 120, 20)
       $game_mode=GUICtrlCreateCombo("SinglePlayer", 10, 50,110,25,$CBS_DROPDOWNLIST) ; create first item
    GUICtrlSetData(-1, "Host|Client", "") ; add
    $first=FileFindFirstFile(@ScriptDir&"\*.tmf")
    Global $i=0,$map_list[1],$tmp
    While 1
    $tmp=   FileFindNextFile($first)
      If @error Then ExitLoop
     _ArrayAdd($map_list,$tmp)
    $i+=1

WEnd
FileClose($first)
      $map_name=GUICtrlCreateCombo($map_list[1], 150, 50,110,25,$CBS_DROPDOWNLIST) ; create first item
      for $i=1 to UBound($map_list)-1
              GUICtrlSetData(-1, $map_list[$i], $map_list[$i]) ; add
          Next
$Start=GUICtrlCreateButton("Start>",390,120,50,25)
GUISetState(@SW_SHOW)
while 1
    sleep(5)
    $msg=GUIGetMsg()
if $msg=$GUI_EVENT_CLOSE Then
    _exit()
EndIf
if $msg=$Start then ExitLoop 1
WEnd
if GUICtrlRead($full_screen)=$GUI_CHECKED then
    _ChangeScreenRes(800, 600, 32, 60)
    Sleep(600)
    If @error Then
        MsgBox(262160, "ERROR", "Nie mozna zmienic rozdzielczosci ekranu")
    EndIf
endif
$map_name=GUICtrlRead($map_name)
$game_mode=GUICtrlRead($game_mode)
GUIDelete()

Opt("GUIOnEventMode", 1)
HotKeySet("{Esc}", "_Exit")
Global  $map_array[21][16], $bullet = 0, $explosion = 0, $direction = 2, $x_bullet = 60, $y_bullet = 60,$direction2=1,$recv_temp[1]
Global $amount = 7, $FPS, $loop = 0, $sleep = 1, $edit = 0, $speed = 1, $bullet_direction = 2,$map_update=""
$hdc = GUICreate("TANK PEGASUS KLON :) -"&$game_mode, 800, 600)
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
GUISetState(@SW_SHOW, $hdc)
GetHDC()
GUIRegisterMsg(0x020A, "_Mousewheel")
CreateBuffer(800, 600)

$wild1 = ImportPng(1, "GFX\wild1.png")
$steel1 = ImportPng(2, "GFX\steel1.png")
$water1 = ImportPng(3, "GFX\water1.png")
$ice1 = ImportPng(4, "GFX\ice1.png")
$wall1 = ImportPng(5, "GFX\wall1.png")
$clouds1 = ImportPng(6, "GFX\clouds1.png")
$tank1 = ImportPng(7, "GFX\tank1.png")
$eagle1 = ImportPng(8, "GFX\eagle.png")
$eagle2 = ImportPng(9, "GFX\eagle.png")
$bullet1 = ImportPng(19, "GFX\bullet1.png")
$bullet2 = ImportPng(12, "GFX\bullet1.png")
$tank2 = ImportPng(13, "GFX\tank1.png")
$explosion1 = ImportPng(10, "GFX\explosion.png")
$map = StringSplit(FileRead(@ScriptDir & "\"&$map_name), ":")
$terrain=$map[1]
if $game_mode="SinglePlayer" Then
        $x_player1=$map[2]
$y_player1=$map[3]
    $y_player2=$map[4]
$x_player2=$map[5]
    endif
if $game_mode="Host" Then
    $x_player1=$map[2]
$y_player1=$map[3]
    $y_player2=$map[4]
$x_player2=$map[5]
    TCPStartUp()
$MainSocket = TCPListen(@IPAddress1, 65432)
If $MainSocket = -1 Then Exit
   Do
        $ConnectedSocket = TCPAccept($MainSocket)
        TrayTip("Czekam","Czekam na KLIENTA",5)
    Until $ConnectedSocket <> -1
endif
if $game_mode="Client" then
        $x_player1=$map[4]
$y_player1=$map[5]
    $y_player2=$map[2]
$x_player2=$map[3]
$ip_host=inputbox("Podaj IP HOSTa","Podaj IP HOSTa")
if StringLen($ip_host)<3 then exit
TCPStartUp()
$socket = TCPConnect( $ip_host, 65432 )
If $socket = -1 Then
    TrayTip("BÅ‚Ä…d!","Proba polaczenia, nieudana",5)
Exit
endif
EndIf
_ArrayDelete($map,1)
_ArrayDelete($map,1)
_ArrayDelete($map,1)
_ArrayDelete($map,1)
_ArrayDelete($map,1)
dim $map_temp
$map_temp=$map[1]
_ArrayDelete($map,6)
$map=StringSplit($map_temp,"")
switch $terrain
    case 1
        $terrain="grass"
    case 2
        $terrain="rock2"
    case 3
        $terrain="rock"
    case 4
        $terrain="desert"
    case 5
        $terrain="alien1"
EndSwitch
$loop = 0
$grass = ImportPng(11, "GFX\"&$terrain&".png")
For $i = 0 To 19
    For $ii = 0 To 14
        $loop += 1
        PaintPng(11, $hdc, $i * 40, $ii * 40, $grass, 0)
    Next
Next
$loop = 0
For $ii = 0 To 14
    For $i = 0 To 19
        $loop += 1
        Switch $map[$loop]
            Case 1
                PaintPng(1, $hdc, $i * 40, $ii * 40, $wild1, 0)
                $map_array[$i][$ii] = 1
            Case 2
                PaintPng(2, $hdc, $i * 40, $ii * 40, $steel1, 0)
                $map_array[$i][$ii] = 2
            Case 3
                PaintPng(3, $hdc, $i * 40, $ii * 40, $water1, 0)
                $map_array[$i][$ii] = 3
            Case 4
                PaintPng(4, $hdc, $i * 40, $ii * 40, $ice1, 0)
                $map_array[$i][$ii] = 4
            Case 5
                PaintPng(5, $hdc, $i * 40, $ii * 40, $wall1, 0)
                $map_array[$i][$ii] = 5
            Case 7
                $map_array[$i][$ii] = 7
                PaintPng(7, $hdc, $i * 40, $ii * 40, $tank1, 0)
            Case 8
                $map_array[$i][$ii] = 8
                PaintPng(8, $hdc, $i * 40, $ii * 40, $eagle1, 0)
                            Case 9
                $map_array[$i][$ii] = 9
                PaintPng(9, $hdc, $i * 40, $ii * 40, $eagle2, 0)
        EndSwitch
    Next
Next
;$s1s=Sprite($s1, $hdc, 0, 0, 40, 40, 1, 1, 9,$x_player1,$y_player1)
;setspritespeed($s1s,6,6)
SetText($hdc, "FPS:" & $FPS, 5, 5, "0x000000", "0xffffff", 12, 1, "Fixedsys")
SetBuffer($hdc)
$loop = -300
Global $FPS_loop = 0
$timer = TimerInit()
Global $x_player1_old = $x_player1, $y_player1_old = $y_player1, $move_timer = TimerInit(),$dead=0
sleep(160)
While 1
    if $map_update<>0 then TrayTip("mapUpdate",$map_update,6)
    If _IsPressed("25", $dll) And $x_player1 = $x_player1_old And $y_player1 = $y_player1_old and $dead=0 Then
        $x_player1 -= 40
        $tank1 = ImportPng(7, "GFX\tank1c.png")
        $direction = 1
    EndIf
    If _IsPressed("26", $dll) And $y_player1 = $y_player1_old And $x_player1 = $x_player1_old and $dead=0 Then
        $y_player1 -= 40
        $tank1 = ImportPng(7, "GFX\tank1.png")
        $direction = 2
    EndIf
    If _IsPressed("27", $dll) And $x_player1 = $x_player1_old And $y_player1 = $y_player1_old and $dead=0 Then
        $x_player1 += 40
        $tank1 = ImportPng(7, "GFX\tank1d.png")
        $direction = 3
    EndIf
    If _IsPressed("28", $dll) And $y_player1 = $y_player1_old And $x_player1 = $x_player1_old and $dead=0 Then
        $y_player1 += 40
        $tank1 = ImportPng(7, "GFX\tank1b.png")
        $direction = 4
    EndIf
    If _IsPressed("20", $dll) And $bullet = 0 And $explosion = 0 and $dead=0 Then
        $bullet = 1
        $x_bullet = $x_player1_old + 10
        $y_bullet = $y_player1_old + 10
        $bullet_direction = $direction
    EndIf
    $FPS_loop += 1
    $loop += 2
    If $loop > 800 Then
        $loop = -400
        $y1 = Random(1, 550, 1)
    EndIf
    Sleep(4)
    If TimerDiff($move_timer) > 350 Then
        $move_timer = TimerInit()
        If $x_player1 >= 0 And $y_player1 >= 0 And $x_player1 < 800 And $y_player1 < 600 And $map_array[$x_player1 / 40][$y_player1 / 40] <> 2 And $map_array[$x_player1 / 40][$y_player1 / 40] <> 5 And $map_array[$x_player1 / 40][$y_player1 / 40] <> 7 And $map_array[$x_player1 / 40][$y_player1 / 40] <> 8  And $map_array[$x_player1 / 40][$y_player1 / 40] <> 3 Then
        $x_player1_old = $x_player1
            $y_player1_old = $y_player1
        Else
            $x_player1 = $x_player1_old
            $y_player1 = $y_player1_old
        EndIf
    EndIf
    PaintNew()
    switch $game_mode
        case "SinglePlayer"
        case "Host"
$recv=TCPRecv($ConnectedSocket,64)
ConsoleWrite("Recv:"&$recv&@CRLF)
if $recv<>"" and StringInStr($recv,"#") and StringInStr($recv,"$") and stringlen($recv)>6 Then
    $recv_temp=_StringBetween($recv,"$","#")
    $recv=$recv_temp[0]
    ConsoleWrite("Recv_final:"&$recv&@CRLF)
    $recv=stringsplit($recv,",")
    $x_player2=$recv[1]
    $y_player2=$recv[2]
    $direction2=$recv[3]
    switch $direction2
        case 1
            $tank2 = ImportPng(13, "GFX\tank1c.png")
        case 2
            $tank2 = ImportPng(13, "GFX\tank1.png")
        case 3
            $tank2 = ImportPng(13, "GFX\tank1d.png")
        case 4
            $tank2 = ImportPng(13, "GFX\tank1b.png")
    EndSwitch
if UBound($recv)>4 then
                PaintNew()
                local $temp1=$recv[4],$temp2=$recv[5]
                if $map_array[$temp1][$temp2]=8 and $game_mode="Host" Then
                    MsgBox(0,"WINER!","Wygrales te gre! Gratulacje :/")
                    _exit()
                    endif
                if $map_array[$temp1][$temp2]=9 and $game_mode="Host" Then
                    MsgBox(0,"LOSER!","Przegrales te gre! Powodzenia kolejnym razem :/")
                    _exit()
                    endif
                $map_array[$temp1][$temp2]=0
            PaintPng(11, $hdc, $recv[4]*40 ,$recv[5]*40, $grass, 0)
            SetBuffer($hdc)
    endif
PaintPng(13, $hdc, $x_player2, $y_player2, $tank2, $hdc)
EndIf
TCPSend($ConnectedSocket, "$"&$x_player1_old&","&$y_player1_old&","&$direction&$map_update&"#")
ConsoleWrite("Send:"&"$"&$x_player1_old&","&$y_player1_old&","&$direction&$map_update&"#"&@CRLF)
case "Client"
    $recv=TCPRecv($Socket,64)
    ConsoleWrite("Recv:"&$recv&@CRLF)
if $recv<>"" and StringInStr($recv,"#") and StringInStr($recv,"$") and stringlen($recv)>6 Then
    $recv_temp=_StringBetween($recv,"$","#")
    $recv=$recv_temp[0]
        ConsoleWrite("Recv_final:"&$recv&@CRLF)
    $recv=stringsplit($recv,",")
    $x_player2=$recv[1]
    $y_player2=$recv[2]
    $direction2=$recv[3]
    if UBound($recv)>4 then
                PaintNew()
                local $temp1=$recv[4],$temp2=$recv[5]
                if $map_array[$temp1][$temp2]=9 and $game_mode="Host" Then
                    MsgBox(0,"LOSER!","Przegrales te gre! Powodzenia kolejnym razem :/")
                    _exit()
                endif
                if $map_array[$temp1][$temp2]=8 and $game_mode="Host" Then
                    MsgBox(0,"Winer!","Wygrales te gre!")
                    _exit()
                    endif
                $map_array[$temp1][$temp2]=0
            PaintPng(11, $hdc, $recv[4]*40 ,$recv[5]*40, $grass, 0)
            SetBuffer($hdc)
        endif
            switch $direction2
        case 1
            $tank2 = ImportPng(13, "GFX\tank1c.png")
        case 2
            $tank2 = ImportPng(13, "GFX\tank1.png")
        case 3
            $tank2 = ImportPng(13, "GFX\tank1d.png")
        case 4
            $tank2 = ImportPng(13, "GFX\tank1b.png")
    EndSwitch
    PaintPng(13, $hdc, $x_player2, $y_player2, $tank2, $hdc)
EndIf
    TCPSend($Socket, "$"&$x_player1_old&","&$y_player1_old&","&$direction&$map_update&"#")
    ConsoleWrite("Send:"&"$"&$x_player1_old&","&$y_player1_old&","&$direction&$map_update&"#"&@CRLF)
EndSwitch
if $dead>0 Then
    $dead-=0.001
    if $dead<0.01 then $dead=0
    endif
    If $bullet <> 0 Then
        If abs($x_player2-$x_bullet)<2 and abs($y_player2-$y_bullet)<2 then MsgBox(0,"","Trafiles przeciwnika !")
        Switch $bullet_direction
            Case 1
                $x_bullet -= 8
                If $map_array[$x_bullet / 40][$y_bullet / 40] = 2 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 5 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 7 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 8 Then $explosion = 1
            Case 2
                $y_bullet -= 8
                If $map_array[$x_bullet / 40][$y_bullet / 40] = 2 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 5 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 7 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 8 Then $explosion = 1
            Case 3
                $x_bullet += 8
                If $map_array[$x_bullet / 40][$y_bullet / 40] = 2 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 5 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 7 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 8 Then $explosion = 1
            Case 4
                $y_bullet += 8
                If $map_array[$x_bullet / 40][$y_bullet / 40] = 2 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 5 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 7 Or $map_array[$x_bullet / 40][$y_bullet / 40] = 8 Then $explosion = 1
        EndSwitch
        PaintPng(19, $hdc, $x_bullet, $y_bullet, $bullet1, $hdc)
        If $x_bullet > 800 Or $x_bullet < 0 Or $y_bullet > 600 Or $y_bullet < 0 Then $bullet = 0
    EndIf
    ;TrayTip("explosion",$explosion,2)
    If $explosion > 0 Then
        If $explosion = 1 And $map_array[Floor($x_bullet / 40)][Floor($y_bullet / 40)] = 9 and $game_mode="Client" Then
            if $game_mode<>"SinglePlayer" then $map_update=","&Floor($x_bullet / 40)&","&Floor($y_bullet / 40)
            MsgBox(0,"WINNER!","Wygrales te rozgrywkÄ™! =)")
            _exit()
        endif
        If $explosion = 1 And $map_array[Floor($x_bullet / 40)][Floor($y_bullet / 40)] = 8 and $game_mode="Host" Then
            if $game_mode<>"SinglePlayer" then $map_update=","&Floor($x_bullet / 40)&","&Floor($y_bullet / 40)
            MsgBox(0,"WINNER!","Wygrales te rozgrywkÄ™! =)")
            _exit()
            endif
        If $explosion = 1 And $map_array[Floor($x_bullet / 40)][Floor($y_bullet / 40)] = 5 Then
            $map_array[Floor($x_bullet / 40)][Floor($y_bullet / 40)] = 0
            PaintNew()
            PaintPng(11, $hdc, Floor($x_bullet / 40) * 40, Floor($y_bullet / 40) * 40, $grass, 0)
            if $game_mode<>"SinglePlayer" then $map_update=","&Floor($x_bullet / 40)&","&Floor($y_bullet / 40)
            SetBuffer($hdc)
        EndIf
        $explosion -= 0.05
        If $explosion < 0 Then $explosion = 0
        $bullet = 0
        PaintPng(10, $hdc, $x_bullet - 10, $y_bullet - 5, $explosion1, $hdc)
        If $explosion = 0 Then $x_bullet = 990
    EndIf
    ;Movesprite($s1s, $x_player1_old,$y_player1_old)
    if $x_player1 >= 0 And $y_player1 >= 0 And $x_player1 < 800 And $y_player1 < 600 And $map_array[$x_player1 / 40][$y_player1 / 40] <>1 then PaintPng(7, $hdc, $x_player1_old, $y_player1_old, $tank1, $hdc);PaintPng(11, $hdc, $x_player1_old, $y_player1_old, $grass, $hdc)
    PaintPng(6, $hdc, 29 + $loop, $y1, $clouds1, 0)
    SetText($hdc, "FPS:" & $FPS, 5, 5, "0x000000", "0xffffff", 12, 1, "Fixedsys")
    If TimerDiff($timer) > 1009 Then
        $FPS = $FPS_loop
        $FPS_loop = 0
        $timer = TimerInit()
    EndIf
WEnd
Func _exit()
    _ChangeScreenRes($res_x_start, $res_y_start, 32, 60)
    DestroyBuffer()
    Close_DLL()
    Exit
EndFunc   ;==>_exit

Func _ChangeScreenRes($width, $height, $bpp, $freq)
    Local Const $DM_PELSWIDTH = 0x00080000
    Local Const $DM_PELSHEIGHT = 0x00100000
    Local Const $DM_BITSPERPEL = 0x00040000
    Local Const $DM_DISPLAYFREQUENCY = 0x00400000
    Local Const $CDS_TEST = 0x00000002
    Local Const $CDS_UPDATEREGISTRY = 0x00000001
    Local Const $DISP_CHANGE_RESTART = 1
    Local Const $DISP_CHANGE_SUCCESSFUL = 0
    Local Const $HWND_BROADCAST = 0xffff
    Local Const $WM_DISPLAYCHANGE = 0x007E

    Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")

    Local $b = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DllStructGetPtr($DEVMODE))
    If @error Then
        $b = 0
    Else
        $b = $b[0]
    EndIf
    If $b <> 0 Then
        DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5)
        DllStructSetData($DEVMODE, 4, $width, 2)
        DllStructSetData($DEVMODE, 4, $height, 3)
        DllStructSetData($DEVMODE, 4, $bpp, 1)
        DllStructSetData($DEVMODE, 4, $freq, 5)

        $b = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_TEST)

        If @error Then
            $b = -1
        Else
            $b = $b[0]
        EndIf

        Select
            Case $b = $DISP_CHANGE_RESTART
                $DEVMODE = 0
                Return 2
            Case $b = $DISP_CHANGE_SUCCESSFUL
                DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_UPDATEREGISTRY)
                DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _
                        "int", $bpp, "int", $height * 2 ^ 16 + $width)
                $DEVMODE = 0
                Return 1
            Case Else
                $DEVMODE = 0
                Return $b
        EndSelect
    EndIf
EndFunc   ;==>_ChangeScreenRes
Func _Mousewheel($hWnd, $msg, $l, $r)
    If $l = 0xFF880000 Then
        If $amount > 3 Then $edit -= 1
    Else ;
        If $amount < 190 Then $edit += 1
    EndIf
EndFunc   ;==>_Mousewheel

And the MapEditor:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include <Array.au3>
#include <File.au3>
Opt("MouseCoordMode", 2)
$dll = DllOpen("user32.dll")
GUICreate("Mode",320,70,-1,-1)
$new_map=GUICtrlCreateButton("Make New Map",10,20,100,25)
$edit_map=GUICtrlCreateButton("Edit existing  Map",110,20,100,25)
$quit=GUICtrlCreateButton("Exit from Editor",210,20,100,25)
GUISetState()
Global $mode
Do
    sleep(5)
    $msg=GUIGetMsg()
    if $msg=$quit then ExitLoop
    if $msg=$new_map Then
        $mode=1
        ExitLoop
    EndIf
    if $msg=$edit_map Then
        $mode=2
        ExitLoop
        endif
    until GUIGetMsg() = $GUI_EVENT_CLOSE
    if $mode<>1 and $mode<>2 then Exit
GUIDelete()

if $mode=1 Then
    $plik=InputBox("Please neter new map name","name of the map")
    $plik=@ScriptDir&"\"&$plik&".tmf"
_FileCreate($plik)
sleep(90)
FileWrite($plik,"1:100:100:200:200:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
EndIf
if $mode=2 then
$plik = FileOpenDialog("Choose a map:", @ScriptDir, "TankMapFiles (*.tmf)")
if $plik="" then Exit
endif
Global $hGUI, $hImage[20][15], $map_array[20][16], $hGraphic, $hImage1
$hGUI = GUICreate("TankMapEditor", 800, 700)
GUISetBkColor("0x999999", $hGUI)
$combo1 = GUICtrlCreateCombo("steel1", 15, 650) ; create first item
GUICtrlSetData(-1, "grass|wild1|ice1|water1|wall1|tank1|eagle|Player1|Player2", "") ;
_GDIPlus_Startup()
Global $map_main = StringSplit(FileRead($plik), ":"), $loop = 0,$tile=""
Global $map=StringSplit($map_main[6],"")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    For $ii = 0 To 14
For $i = 0 To 19
        $loop += 1
        Switch $map[$loop]
            Case 0
                $hImage[$i][$ii] = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\grass.png")
            Case 1
                $hImage[$i][$ii] = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\wild1.png")
            Case 2
                $hImage[$i][$ii] = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\steel1.png")
            Case 3
                $hImage[$i][$ii] = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\water1.png")
            Case 4
                $hImage[$i][$ii] = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\ice1.png")
            Case 5
                $hImage[$i][$ii] = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\wall1.png")
            Case 7
                $hImage[$i][$ii] = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\tank1.png")
            Case 8
                $hImage[$i][$ii] = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\eagle.png")
        EndSwitch
    Next
Next
GUISetState()
redraw()
$main_timer = TimerInit()
Do
    if GUICtrlRead($combo1)<>$tile Then
        $tile=GUICtrlRead($combo1)
        _GDIPLus_GraphicsDrawImageRect($hGraphic, _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\grey.png"), 240, 650,41,41)
    _GDIPLus_GraphicsDrawImageRect($hGraphic, _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\"&GUICtrlRead($combo1)&".png"), 240, 650,40,40)
    EndIf
    If TimerDiff($main_timer) > 1500 Then

redraw()
$size = WinGetPos("[active]")
if PixelGetColor($size[0]+26,$size[1]+70)="0x999999" then redraw()
        $main_timer = TimerInit()
        _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    EndIf


    Sleep(10)
    If _IsPressed("01", $dll) And WinActive("TankMapEditor") And MouseGetPos(0) < 800 And MouseGetPos(0) > 1 And MouseGetPos(1) > 10 And MouseGetPos(1) < 599 Then
        $pos = MouseGetPos()
        $x = Floor($pos[0] / 40)
        $y = Floor($pos[1] / 40)
        _GDIPlus_ImageDispose($hImage[$x][$y])
        if $map[$y * 19 + $x+$y+1]=0 and GUICtrlRead($combo1)="Player1" then
            $map_main[2]=$x*40
            $map_main[3]=$y*40
        endif
                if $map[$y * 19 + $x+$y+1]=0 and GUICtrlRead($combo1)="Player2" then
            $map_main[4]=$x*40
            $map_main[5]=$y*40
            endif
        $hImage[$x][$y] = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\GFX\" & GUICtrlRead($combo1) & ".png")
        _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage[$x][$y], $x * 40, $y * 40,40,40)
            _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
        ;MsgBox(0,"",($y * 19)+$x+$y+1)
        Switch GUICtrlRead($combo1)
            case "grass"
                $map[$y * 19 + $x+$y+1] = 0
            Case "wild1"
                $map[$y * 19 + $x+$y+1] = 1
            Case "steel1"
                $map[$y * 19 + $x+$y+1] = 2
            Case "ice1"
                $map[$y * 19 + $x+$y+1]= 4
            Case "water1"
                $map[$y * 19 + $x+$y+1] = 3
            Case "wall1"
                $map[$y * 19 + $x+$y+1] = 5
            Case "tank1"
                $map[$y * 19 + $x+$y+1] = 7
                    Case "eagle"
                $map[$y * 19 + $x+$y+1] = 8
        EndSwitch
    EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_GDIPlus_GraphicsDispose($hGraphic)
$map_string=_ArrayToString($map,"",1,301)
$map_main=_ArrayToString($map_main,":",1,60)
_ArrayDelete($map_main,6)
$map_string=$map_main&":"&$map_string
$plik_h=FileOpen($plik,2)
FileWrite($plik_h,$map_string)
FileClose($plik_h)
For $i = 0 To 19
    For $ii = 0 To 14
        _GDIPlus_ImageDispose($hImage[$i][$ii])
    Next
Next
_GDIPlus_Shutdown()
Func redraw()
    For $ii = 0 To 14
    For $i = 0 To 19
            ;_GDIPlus_GraphicsDrawImage($hGraphic, $hImage[$i][$ii], $i * 40, $ii * 40)
            _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage[$i][$ii], $i * 40, $ii * 40,40,40)
        Next
    Next
EndFunc   ;==>redraw
Edited by Uriziel01
Link to comment
Share on other sites

Very cool. It reminds me an old lan game I had for win 95.I can't recall the name though. Also any chance of sharing the source?

Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Nice to see the source. Just a word of advice. Change the code tags to autoit tags. Much easier on the eyes.

For Example:

MsgBox(0,"This is AutoIt","Hello")

looks much nicer (IMO) than:

MsgBox(0,"This is AutoIt","Hello")
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

I have checket it under windows Seven (it should work under Vista). Are you running it from main game directory? You have to put it with game .exe because it is using the same graphics files as the game :)

EDIT:

Oh s*it I have forgotten to add plyer1.png and player2.png files to the editor, wait a second and I will upload them again ;) Sorry.

Edited by Uriziel01
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...