Carrunner - (Mini)-Game

  • Ich bin mit meinem nächsten Minigame fertig, wieder ein Highscorespiel.
    Code der Hauptdatei:

    Spoiler anzeigen
    [autoit]


    #NoTrayIcon
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=x.ico
    #AutoIt3Wrapper_Res_Comment=A little Mini-Race-Game
    #AutoIt3Wrapper_Res_Description=Minigame
    #AutoIt3Wrapper_Res_Fileversion=1.1.0.7
    #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
    #AutoIt3Wrapper_Res_LegalCopyright=TheShadowAE
    #AutoIt3Wrapper_Res_Language=1031
    #AutoIt3Wrapper_Res_Field=Made by|TheShadowAE
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <checkexists.au3>
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    global $name=inputbox("Info","Steuerungen:"&@CRLF&"Leertaste - Geist"&@CRLF&"Pfeiltasten - Auto"&@CRLF&"Enter - Pause bei Gameover weg"&@CRLF&@CRLF&"Namen eingeben (kein Name-keine Highscore):")
    $load=loadscore()
    if $load<>"" then msgbox(0,"Highscore",$load)
    if fileexists("Carrunner!Score.dat") Then
    $load = MsgBox(260, "Highscore", "Möchtest du die Highscore löschen?")
    if $load=6 then
    filedelete("Carrunner!Score.dat")
    EndIf
    EndIf
    $check=checkexists("car0.png,car1.png,car2.png,car3.png,street.png,carg.png")
    if $check=-1 then ConsoleWriteError("Error at Existsinput")
    if $check=0 then exit MsgBox(48,"Fehler","Bild(er) nicht gefunden")
    global $winx=200
    global $winy=300
    global $title="Carrunner - TheShadowAE"

    [/autoit] [autoit][/autoit] [autoit]

    global $user32=DllOpen("user32.dll") ;for _IsPressed()
    _GDIPlus_Startup()
    dim $img[4]
    $img[0]=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\car0.png")
    $img[1]=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\car1.png")
    $img[2]=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\car2.png")
    $img[3]=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\car3.png")
    global $street=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\street.png")
    global $carg=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\carg.png")
    global $imgx=_GDIPlus_ImageGetWidth($img[0])
    global $imgy=_GDIPlus_ImageGetHeight($img[0])
    global $streetspeed
    global const $normstreetspeed=3
    global $streety1=0,$streety2=-1*$winy
    global $spuren=3 ;###########################Wems besser mit anderer zahl geällt: nur das verändern (evtl. auch das Bild der Straße)
    global $playerspeed=2
    global $score=0
    global $maxspeed=3
    global $minspeed=1
    global $wechselspeed=2
    dim $autos[$spuren][4] ;5 autos ;spur,y,speed,welches
    dim $player[4] ;spur,x,y,wechsel
    $player[0]=Floor($spuren/2)+1
    $player[1]=round($player[0]*$winx/$spuren-40,0)
    $player[2]=$winy-$imgy-50
    global $ghosts=0
    global $ghosttimer=TimerInit()
    global $ghostskill=0
    global $ghostdiff=0
    global $ghostrate=30000
    global $ghoston=0
    global $ghostlen=5000
    $ghostgood=0

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate($title, $winx, $winy)
    GUISetIcon("x.ico")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    Opt("GUIOnEventMode",1)
    GUISetOnEvent($GUI_EVENT_CLOSE,"ende")
    global $gra=_GDIPlus_GraphicsCreateFromHWND($Form1)
    global $buffer=_GDIPlus_BitmapCreateFromGraphics($winx,$winy,$gra)
    global $backgra=_GDIPlus_ImageGetGraphicsContext($buffer)
    _GDIPlus_GraphicsSetSmoothingMode($backgra,2)
    global $timer=TimerInit()
    global $skill=0
    reset()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    ;Pause
    if WinActive($title)=0 then
    WinWaitActive($title)
    $skill=TimerDiff($timer)
    $ghostskill=TimerDiff($ghosttimer)
    EndIf
    ;Tasten
    if _IsPressed("1B",$user32) then ende()
    if _IsPressed("26",$user32) Then $player[2]-=$playerspeed
    if _IsPressed("28",$user32) Then $player[2]+=$playerspeed
    if _IsPressed("27",$user32) and $player[3]=0 then ;##############################################
    $player[0]+=1
    if $player[0]>$spuren then $player[0]=$spuren
    $player[3]=$wechselspeed
    ;~ $player[1]+=1 ;######## 1 ########
    EndIf
    if _IsPressed("25",$user32) and $player[3]=0 then ;##############################################
    $player[0]-=1
    if $player[0]<1 then $player[0]=1
    $player[3]=$wechselspeed*-1
    ;~ $player[1]-=1 ;######## 1 ########
    EndIf ;###############################################################################################
    if _IsPressed("20",$user32) and $ghosts>0 and $ghoston=0 Then
    $ghostgood=TimerDiff($ghosttimer)
    $ghoston=1
    $ghosts-=1
    EndIf
    ;Bewegung
    updatecars()
    if TimerDiff($ghosttimer)-$ghostgood>=$ghostlen and $ghoston=1 Then
    $ghoston=0
    $ghostgood=TimerDiff($ghosttimer)
    EndIf
    $streety1+=$streetspeed
    $streety2+=$streetspeed
    if $streety1>=$winy then $streety1=$winy*-1
    if $streety2>=$winy then $streety2=$winy*-1
    if $player[3]<>0 Then
    if round($player[0]*$winx/$spuren-40,0)=$player[1] or round($player[0]*$winx/$spuren-40,0)=$player[1]-1 or round($player[0]*$winx/$spuren-40,0)=$player[1]+1 then $player[3]=0
    $player[1]+=$player[3]
    EndIf
    $diff=TimerDiff($timer)-$skill
    $skill=TimerDiff($timer)
    $score+=round($diff,0)
    $diff=TimerDiff($ghosttimer)-$ghostskill
    $ghostskill=TimerDiff($ghosttimer)
    $ghostdiff+=$diff
    if $ghostdiff>=$ghostrate Then
    $ghostdiff=0
    $ghosts+=1
    EndIf
    for $x=0 to ubound($autos,1)-1
    if $autos[$x][1]>$winy then redrawcar($x)
    Next
    if $player[2]<0 then $player[2]=0
    if $player[2]+$imgy>$winy then $player[2]=$winy-$imgy
    if $score>=20000 and $score<30000 Then
    $maxspeed=4
    $streetspeed=$normstreetspeed+1
    EndIf
    if $score>=30000 then
    $maxspeed=5
    $streetspeed=$normstreetspeed+2
    EndIf
    ;Grafik
    _WinAPI_RedrawWindow($Form1, "", "", $RDW_UPDATENOW + $RDW_FRAME)
    _GDIPlus_GraphicsClear($backgra,0xFF808080)
    _GDIPlus_GraphicsDrawImage($backgra,$street,0,$streety1)
    _GDIPlus_GraphicsDrawImage($backgra,$street,0,$streety2)
    for $x=0 to UBound($autos,1)-1
    _GDIPlus_GraphicsDrawImage($backgra,$img[$autos[$x][3]],round($autos[$x][0]*$winx/$spuren-40,0),$autos[$x][1])
    Next
    if $ghoston=0 Then
    _GDIPlus_GraphicsDrawImage($backgra,$img[0],$player[1],$player[2])
    Else
    _GDIPlus_GraphicsDrawImage($backgra,$carg,$player[1],$player[2])
    _GDIPlus_GraphicsDrawString($backgra,"Noch Ghost: "&round($ghostlen-(TimerDiff($ghosttimer)-$ghostgood),0),5,32,"Arial",10)
    EndIf
    _GDIPlus_GraphicsDrawString($backgra,"Score: "&$score,5,5,"Arial",12)
    _GDIPlus_GraphicsDrawString($backgra,"Ghosts: "&$ghosts,5,20,"Arial",10)
    _GDIPlus_GraphicsDrawImageRect($gra,$buffer,0,0,$winx,$winy)
    ;check if dead
    if $ghoston=0 Then
    for $x=0 to ubound($autos,1)-1
    if isover($player[1]+3,$player[2]+2,$imgx-3,$imgy-2,round($autos[$x][0]*$winx/$spuren-40,0)+3,$autos[$x][1]+2,$imgx-3,$imgy-2) Then
    death()
    EndIf
    Next
    EndIf
    sleep(10)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    func reset()
    $score=0
    $streetspeed=$normstreetspeed
    $streety1=0
    $streety2=-1*$winy
    $playerspeed=2
    $player[0]=Floor($spuren/2)+1
    $player[1]=round($player[0]*$winx/$spuren-40,0)
    $player[2]=$winy-$imgy-50
    $skill=TimerDiff($timer)
    $ghostskill=TimerDiff($ghosttimer)
    $ghoston=0
    $maxspeed=3
    for $x=0 to ubound($autos,1)-1
    $tmp=newcar(1)
    $autos[$x][0]=$tmp[0]
    $autos[$x][1]=$tmp[1]
    $autos[$x][2]=$tmp[2]
    $autos[$x][3]=$tmp[3]
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func ende()
    for $x=0 to ubound($img)-1
    _GDIPlus_ImageDispose($img[$x])
    Next
    _GDIPlus_ImageDispose($street)
    _GDIPlus_ImageDispose($carg)
    _GDIPlus_GraphicsDispose($backgra)
    _GDIPlus_BitmapDispose($buffer)
    _GDIPlus_GraphicsDispose($gra)
    _GDIPlus_Shutdown()
    DllClose($user32)
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func isover($x1,$y1,$lx1,$ly1,$x2,$y2,$lx2,$ly2)
    if $x1+$lx1>=$x2 and $x1<=$x2+$lx2 and $y1+$ly1>=$y2 and $y1<=$y2+$ly2 Then Return 1
    Return 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func newcar($flag=0) ;0 im spiel, 1 bei reset 2 bei farb+spurwechsel
    local $newcar[4] ;spur,y,speed,welches
    $newcar[0]=Random(1,$spuren,1)
    if $flag=0 Then
    $newcar[1]=-1*$imgy
    $newcar[2]=Random($minspeed,$maxspeed,1)
    Elseif $flag=1 Then
    if $newcar[0]<>Floor($spuren/2)+1 Then
    $newcar[1]=Random($imgy*-1,$winy-$imgy,1)
    Else
    $newcar[1]=Random($imgy*-1,$winy-$imgy-Round($winy/2,0)-100,1)
    EndIf
    $newcar[2]=Random($minspeed,$maxspeed,1)
    EndIf ;else nothing
    $newcar[3]=Random(1,ubound($img)-1,1)
    return $newcar
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func redrawcar($car)
    $tmp=newcar(0)
    $autos[$car][0]=$tmp[0]
    $autos[$car][1]=$tmp[1]
    $autos[$car][2]=$tmp[2]
    $autos[$car][3]=$tmp[3]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func updatecars()
    For $x=0 to ubound($autos,1)-1
    $autos[$x][1]+=$autos[$x][2]
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func death()
    savescore()
    _GDIPlus_GraphicsDrawString($backgra,"Game",-5,50,"Arial",50)
    _GDIPlus_GraphicsDrawString($backgra,"over",10,100,"Arial",50)
    _GDIPlus_GraphicsDrawImageRect($gra,$buffer,0,0,$winx,$winy)
    while not _IsPressed("0D",$user32)
    if WinActive($title)=0 then
    WinWaitActive($title)
    $skill=TimerDiff($timer)
    EndIf
    _WinAPI_RedrawWindow($Form1, "", "", $RDW_UPDATENOW + $RDW_FRAME)
    _GDIPlus_GraphicsDrawImageRect($gra,$buffer,0,0,$winx,$winy)
    sleep(30)
    WEnd
    reset()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func savescore()
    if $name="" then Return
    $file=FileOpen("Carrunner!Score.dat",1)
    FileWrite($file,$name&" hat "&round($score,0)&" Punkte erreicht"&@CRLF)
    FileClose($file)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func loadscore()
    local $txt=""
    if FileExists("Carrunner!Score.dat") Then
    $file=FileOpen("Carrunner!Score.dat",0)
    while 1
    $txt&=FileReadLine($file)&@CRLF
    if @error=-1 then ExitLoop
    WEnd
    FileClose($file)
    EndIf
    return $txt
    EndFunc

    [/autoit]

    Screen: autoit.de/wcf/attachment/8045/

    Downloads


    Alt:
    Installationsdatei:http://solidfiles.com/d/UEhg
    Komplett: http://solidfiles.com/d/FYmf
    Neu [Links funktionieren nicht.. xD]
    (
    Bugs die wenn Links nicht funktionieren ihr machen könnt:
    Zeile 161 wird zu: _GDIPlus_GraphicsDrawString($backgra,"Noch Ghost: "&round($ghostlen-(TimerDiff($ghosttimer)-$ghostgood),0),5,32,"Arial",10)
    In die Funktion reset() reinschreiben: $maxspeed=3
    )
    Installationsdatei: http://solidfiles.com/d/GkIW
    Komplett: http://solidfiles.com/d/Tp2b

    Freue mich über Kritik usw.

  • Ok geändert: Es wird angezeigt wie lange man noch Ghost hat, schnelleres lenken, und vielleicht noch ein paar kleinere Sachen. Siehe Post1 î

    EDIT: Er hat eins noch nicht gerundet, verbessert, Post 1

    Einmal editiert, zuletzt von TheShadowAE (6. März 2010 um 17:53)

  • Warscheinlich habe ich wieder mal genau da editiert.. nochmal versuchen.

    EDIT:
    Bug behoben - Ghostdaueranzeige behoben
    Sorry das es gerade so oft wird.
    Siehe Post 1, ich denke das waren jetzt alle Bugs

    Und thx fürs probieren und Kritik und Lobe sagen :)

    2 Mal editiert, zuletzt von TheShadowAE (6. März 2010 um 20:47)