KometPlanet - Planetenspiel (Update 2 17.12.2011)

  • Hi liebe Leute, moin alle miteinander,
    ich bin auch mal wieder im Haus :)

    Mein neuestes Werk:
    Man muss einen Komet um Planeten herum zu einem Zielort möglichst nah heranwerfen.

    Zitat von Story

    Die Erde ist schon lange durch die Klimaerwärmung verbrannt, alle Menschen sind auf andere Planeten geflohen. Du willst auf deinem Planeten in Ruhe ein Nickerchen machen, als dein blöder Nachbar mal wieder die Musik total aufgedreht hat und nebenbei seine grottenschlechte Band übt. Du bist total genervt und beschließt ihn mit einem Kometen abzubewerfen, damit er Ruhe gibt. Das stellt sich aber leider nicht als ganz einfach heraus..

    Bringe die Maus in die richtige Position um Richtung und Stärke anzugeben. Wenn du klickst wirfst du den Kometen. Treffe sein Haus.
    Größere Planeten haben größere Anziehungskräfte!
    Mit Esc kann man eine andere Map auswählen

    Eine Anleitung um Maps zu erstellen ist dabei. Verschiedene Maps und Texturen sind auch schon drin.

    Screenshot

    Man kann den Kometen auch ziemlich lange wie die Erde um die Sonne kreisen lassen ^^
    (Karte erde / zwei)
    Wunderbar, alle nötigen Sachen sind in der zip (alle selber gemacht, GDIP nicht), viel Spaß beim Spielen :thumbup:
    Würde mich über Feedback freuen :)

    mfg


    EDIT:
    Hier noch der Source:

    Spoiler anzeigen
    [autoit]

    #NoTrayIcon
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=data\_icon.ico
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GDIP.au3>
    #include <GUIConstantsEx.au3>
    #include <Misc.au3>
    #include <Array.au3>
    #include <GUIListBox.au3>
    #include <File.au3>

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

    ;## by TheShadowAE 14.12.2011

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

    Global Const $P180=ACos(-1)/180
    Global $font,$format

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

    $datadir=@ScriptDir&"\data\"

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

    _GDIPlus_Startup()
    $Form1 = GUICreate("KometPlanet by TheShadowAE", 800, 600)
    GUISetState(@SW_SHOW)
    Opt("GUIOnEventMode",1)
    Opt("GUICloseOnESC",0)
    GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
    $gra=_GDIPlus_GraphicsCreateFromHWND($Form1)
    $buffer=_GDIPlus_BitmapCreateFromGraphics(800,600,$gra)
    $backgra=_GDIPlus_ImageGetGraphicsContext($buffer)
    _GDIPlus_GraphicsSetSmoothingMode($backgra,2)

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

    $hg=_GDIPlus_ImageLoadFromFile($datadir&"_hintergrund.png")
    $_kom=_GDIPlus_ImageLoadFromFile($datadir&"_komet.png")
    $_haus=_GDIPlus_ImageLoadFromFile($datadir&"_haus.png")
    $_kreuz=_GDIPlus_ImageLoadFromFile($datadir&"_kreuz.png")

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

    $planbmp=_GDIPlus_BitmapCreateFromGraphics(800,600,$gra)
    $plangra=_GDIPlus_ImageGetGraphicsContext($planbmp)
    _GDIPlus_GraphicsSetSmoothingMode($plangra,2)

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

    $brush=_GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $pen=_GDIPlus_PenCreate(0xFFFF0000,2)
    $cap=_GDIPlus_ArrowCapCreate(6,3,True)
    _GDIPlus_PenSetCustomEndCap($pen,$cap)

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

    _DSStart("Arial",10,0)

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

    $maxkraft=150

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

    $map=""
    $score="---"
    $lastscore="---"
    $kraft=0
    $winkel=0
    Local $shootpoint[2]=[0,0],$shootw=0
    Local $zielpos[2]=[0,0]
    $flying=False
    Local $pos[2],$mps
    Local $planet[1]=[0] ;Num,x,y,r,x,y,r
    Local $komx=-10,$komy=-10
    Local $vecx,$vecy

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

    While 1
    While Not WinActive($Form1)
    Sleep(10)
    WEnd

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

    If _IsPressed("1B") Or $map="" Then
    Local $name=_AuswahlBox($map)
    If $name="exit" Then _Exit()
    If FileExists($datadir&$name&".map") Then
    _MapChange($name)
    ElseIf $name<>"" Then
    MsgBox(0,"Achtung","Map nicht gefunden! Sicher dass die Map existiert und unter data gespeichert ist?")
    EndIf
    EndIf

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

    _GDIPlus_GraphicsDrawImageRect($backgra,$hg,0,0,800,600)
    _GDIPlus_GraphicsDrawImageRect($backgra,$planbmp,0,0,800,600)

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

    $mps=_WinAPI_GetMousePos(True,$Form1)
    $pos[0]=DllStructGetData($mps,"X")
    $pos[1]=DllStructGetData($mps,"Y")

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

    $winkel=_AngelFromPoints($shootpoint[0],$shootpoint[1],$pos[0],$pos[1])
    If $winkel>$shootw+180 Then $winkel-=360
    If $winkel<$shootw-180 Then $winkel+=360
    If Abs($winkel-$shootw)>90 Then $winkel=_Iif($winkel-$shootw<0,$shootw-90,$shootw+90)
    $kraft=Round(Sqrt(($shootpoint[0]-$pos[0])^2+($shootpoint[1]-$pos[1])^2),0)
    If $kraft>$maxkraft Then $kraft=$maxkraft

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

    _DrawString($backgra,"Winkel: "&$winkel-$shootw&"°",5,5,$brush)
    _DrawString($backgra,"Stärke: "&Round($kraft*100/$maxkraft,0)&"%",5,20,$brush)
    _DrawString($backgra,"Highscore: "&$score&" m",670,5,$brush)
    _DrawString($backgra,"Last score: "&$lastscore&" m",670,20,$brush)

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

    Local $draw[2]
    $draw[0]=$shootpoint[0]+$kraft*Cos($winkel*$P180)
    $draw[1]=$shootpoint[1]+$kraft*Sin($winkel*$P180)
    _GDIPlus_GraphicsDrawLine($backgra,$shootpoint[0],$shootpoint[1],$draw[0],$draw[1],$pen)

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

    If $flying Then
    ;Gravity
    For $x=1 To $planet[0]
    Local $dist=Round(Sqrt(($komx-$planet[$x*3-2])^2+($komy-$planet[$x*3-1])^2),0)
    If $dist<=$planet[$x*3]*5 Then
    $dist-=$planet[$x*3]
    $dist=$planet[$x*3]*4-$dist
    $dist=($dist/($planet[$x*3]*4))*$planet[$x*3]/2
    $dist/=100 ;100 normal,150,250,500 //Gravity, je höher desto weniger
    Local $w=_AngelFromPoints($planet[$x*3-2],$planet[$x*3-1],$komx,$komy)*$P180
    Local $wayx=Cos($w)*$dist
    Local $wayy=Sin($w)*$dist
    $vecx-=$wayx
    $vecy-=$wayy
    EndIf
    Next
    ;Move + Check
    $komx+=$vecx
    $komy+=$vecy
    Local $dist=Round(Sqrt(($shootpoint[0]-$komx)^2+($shootpoint[1]-$komy)^2),0)
    If $dist>30 Then _CheckKometHit($komx,$komy)
    EndIf

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

    If Not $flying And _IsPressed("01") Then
    $flying=True
    $kraft/=15
    $komx=$shootpoint[0]
    $komy=$shootpoint[1]
    $vecx=$kraft*Cos($winkel*$P180)
    $vecy=$kraft*Sin($winkel*$P180)
    EndIf

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

    _GDIPlus_GraphicsDrawImageRect($backgra,_Iif($flying,$_kom,$_kreuz),$komx-5,$komy-5,10,10)
    _GDIPlus_GraphicsDrawImageRect($gra,$buffer,0,0,800,600)
    Sleep(10)
    WEnd

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

    Func _AuswahlBox($map)
    Local $name=""
    Opt("GUIOnEventMode",0)
    #Region ### START Koda GUI section ### Form=
    Local $Form2 = GUICreate("Map auswählen", 187, 313, Default, Default, -1, -1, $Form1)
    Local $List1 = GUICtrlCreateList("", 8, 32, 169, 240)
    GUICtrlCreateLabel("Maps:", 8, 8, 33, 17)
    Local $Spielen = GUICtrlCreateButton("Spielen", 8, 280, 81, 25)
    Local $Abbrechen = GUICtrlCreateButton("Abbrechen", 96, 280, 81, 25)
    Local $Exit = GUICtrlCreateButton("Exit", 104, 3, 73, 25)
    #EndRegion ### END Koda GUI section ###
    Local $liste="",$x,$sel=-1
    Local $f=_FileListToArray(StringTrimRight($datadir,1),"*.map",1)
    _ArraySort($f,0,1)
    If @error Then
    MsgBox(0,"Achtung","Keine Map gefunden!")
    Else
    For $x=1 To $f[0]
    Local $temp=StringTrimRight($f[$x],4)
    If $map=$temp Then $sel=$x-1
    $liste&="|"&$temp
    Next
    EndIf
    GUICtrlSetData($List1,$liste)
    If $sel<>-1 Then _GUICtrlListBox_SetCurSel($List1,$sel)
    GUISetState(@SW_SHOW,$Form2)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE, $Abbrechen
    ExitLoop
    Case $Exit
    $name="exit"
    ExitLoop
    Case $Spielen
    $name=_GUICtrlListBox_GetText($List1,_GUICtrlListBox_GetCurSel($List1))
    If $name="0" Then $name=""
    ExitLoop
    EndSwitch
    Sleep(10)
    WEnd

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

    GUIDelete($Form2)
    Opt("GUIOnEventMode",1)
    Return $name
    EndFunc

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

    Func _Exit()
    _DSEnd()
    _GDIPlus_ImageDispose($_kreuz)
    _GDIPlus_ArrowCapDispose($cap)
    _GDIPlus_PenDispose($pen)
    _GDIPlus_ImageDispose($_haus)
    _GDIPlus_ImageDispose($_kom)
    _GDIPlus_GraphicsDispose($plangra)
    _GDIPlus_BitmapDispose($planbmp)
    _GDIPlus_BrushDispose($brush)
    _GDIPlus_ImageDispose($hg)
    _GDIPlus_GraphicsDispose($gra)
    _GDIPlus_GraphicsDispose($backgra)
    _GDIPlus_BitmapDispose($buffer)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

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

    Func _CheckKometHit($komx,$komy)
    Local $komr=8
    If $komx-$komr<=0 Or $komx+$komr>=800 Or $komy-$komr<=0 Or $komy+$komr>=600 Then
    $flying=False
    $dist=Round(Sqrt(($zielpos[0]-$komx)^2+($zielpos[1]-$komy)^2),0)-$komr
    If $dist<0 Then $dist=0
    $lastscore=$dist
    If $dist<$score Or $score="---" Then
    $score=$dist
    IniWrite(@ScriptDir&"\scores.ini","Scores",$map,$score)
    EndIf
    Return
    EndIf
    Local $x
    For $x=1 To $planet[0]
    Local $dist=Round(Sqrt(($komx-$planet[$x*3-2])^2+($komy-$planet[$x*3-1])^2),0)
    If $dist<=$komr+$planet[$x*3] Then
    $flying=False
    $dist=Round(Sqrt(($zielpos[0]-$komx)^2+($zielpos[1]-$komy)^2),0)-$komr
    If $dist<0 Then $dist=0
    $lastscore=$dist
    If $dist<$score Or $score="---" Then
    $score=$dist
    IniWrite(@ScriptDir&"\scores.ini","Scores",$map,$score)
    EndIf
    Return
    EndIf
    Next
    EndFunc

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

    Func _MapChange($name)
    If $name="" Then Return
    $kraft=0
    $winkel=0
    $flying=False
    $komx=-10
    $komy=-10
    ReDim $planet[1]
    $planet[0]=0
    $map=$name
    $score=IniRead(@ScriptDir&"\scores.ini","Scores",$map,"---")
    $lastscore="---"
    Local $data=FileRead($datadir&$name&".map")
    Local $split=StringSplit($data,@CRLF&@CRLF,1)
    If @error Then
    $map=""
    MsgBox(0,"Achtung","Map ungültig! Beachte das HowTo zu Maps!")
    Return
    EndIf
    Local $planeten=StringRegExp($split[1]&@CRLF,"(\d+?):(\d+?),(\d+?),(\d+?);(.+\..+)\r\n",3)
    $split=StringRegExp($split[2],"(\d+?);(\d+)",3)
    _GDIPlus_GraphicsClear($plangra,0x00000000)
    Local $x,$lg,$lb=_GDIPlus_BitmapCreateFromGraphics(800,600,$backgra)
    $lg=_GDIPlus_ImageGetGraphicsContext($lb)
    For $x=0 To UBound($planeten)/5-1
    $planet[0]+=1
    _ArrayAdd($planet,$planeten[$x*5+1])
    _ArrayAdd($planet,$planeten[$x*5+2])
    _ArrayAdd($planet,$planeten[$x*5+3])
    Local $bmp=_GDIPlus_ImageLoadFromFile($datadir&$planeten[$x*5+4])
    _GDIPlus_GraphicsClear($lg,0x00000000)
    _GDIPlus_GraphicsDrawImageRect($lg,$bmp,$planeten[$x*5+1]-$planeten[$x*5+3],$planeten[$x*5+2]-$planeten[$x*5+3],$planeten[$x*5+3]*2,$planeten[$x*5+3]*2)
    Local $b=_GDIPlus_TextureCreate($lb)
    _GDIPlus_GraphicsFillEllipse($plangra,$planeten[$x*5+1]-$planeten[$x*5+3],$planeten[$x*5+2]-$planeten[$x*5+3],$planeten[$x*5+3]*2,$planeten[$x*5+3]*2,$b)
    _GDIPlus_BrushDispose($b)
    _GDIPlus_ImageDispose($bmp)
    If $planeten[$x*5]=$split[0] Then
    ;Start
    $shootw=$split[1]
    $shootpoint[0]=$planeten[$x*5+1]+$planeten[$x*5+3]*Cos($shootw*$P180)
    $shootpoint[1]=$planeten[$x*5+2]+$planeten[$x*5+3]*Sin($shootw*$P180)
    EndIf
    If $planeten[$x*5]=$split[2] Then
    ;Ziel
    $zielpos[0]=$planeten[$x*5+1]+$planeten[$x*5+3]*Cos($split[3]*$P180)
    $zielpos[1]=$planeten[$x*5+2]+$planeten[$x*5+3]*Sin($split[3]*$P180)
    Local $drawpos[2]
    $drawpos[0]=$planeten[$x*5+1]+($planeten[$x*5+3]+8)*Cos($split[3]*$P180)
    $drawpos[1]=$planeten[$x*5+2]+($planeten[$x*5+3]+8)*Sin($split[3]*$P180)
    _DrawTurned($plangra,$_haus,$split[3],$drawpos[0]-10,$drawpos[1]-10)
    EndIf
    Next
    _GDIPlus_BitmapDispose($lb)
    _GDIPlus_GraphicsDispose($lg)
    EndFunc

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

    ;Funktionen

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

    Func _AngelFromPoints($mx,$my,$px,$py)
    Local $angel=Round(ATan2($py-$my,$px-$mx)/$P180,0)
    If $px<$mx Then
    $angel+=180
    EndIf
    If $my>$py And $px=$mx Then $angel-=180
    Return Mod($angel+360,360)
    EndFunc

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

    Func ATan2($x,$y)
    If $x=0 Then Return 0
    If $y=0 Then Return 1.5707963267949
    Return ATan($x/$y)
    EndFunc

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

    Func _DSStart($face="Arial",$size=12,$style=0) ;Um auch Brush angeben zu können
    Local $family=_GDIPlus_FontFamilyCreate($face)
    $font=_GDIPlus_FontCreate($family,$size,$style)
    _GDIPlus_FontFamilyDispose($family)
    $format=_GDIPlus_StringFormatCreate()
    EndFunc

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

    Func _DrawString($gra,$str,$x=0,$y=0,$brush=0)
    Local $layout=_GDIPlus_RectFCreate($x,$y)
    _GDIPlus_GraphicsDrawStringEx($gra,$str,$font,$layout,$format,$brush)
    EndFunc

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

    Func _DSEnd()
    _GDIPlus_FontDispose($font)
    _GDIPlus_StringFormatDispose($format)
    EndFunc

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

    Func _DrawStr($gra,$str,$x=0,$y=0,$brush=0,$size=12,$flag=0,$face="Arial") ;Wenn man es nicht schnell braucht und nur 1 Befehl haben will
    Local $family=_GDIPlus_FontFamilyCreate($face)
    Local $font=_GDIPlus_FontCreate($family,$size,$flag)
    _GDIPlus_FontFamilyDispose($family)
    Local $format=_GDIPlus_StringFormatCreate()
    Local $layout=_GDIPlus_RectFCreate($x,$y)
    _GDIPlus_GraphicsDrawStringEx($gra,$str,$font,$layout,$format,$brush)
    _GDIPlus_FontDispose($font)
    _GDIPlus_StringFormatDispose($format)
    EndFunc

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

    Func _DrawTurned($backgra,$img,$winkel,$x,$y,$w=20,$h=20)
    If $img=0 Then Return 0
    $winkel+=90
    Local $matrix=_GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($matrix,$x+$w/2,$y+$h/2)
    _GDIPlus_MatrixRotate($matrix,$winkel)
    _GDIPlus_GraphicsSetTransform($backgra,$matrix)
    _GDIPlus_GraphicsDrawImageRect($backgra,$img,-$w/2,-$h/2,$w,$h)
    _GDIPlus_MatrixRotate($matrix,-$winkel)
    _GDIPlus_MatrixTranslate($matrix,-$x-$w/2,-$y-$h/2)
    _GDIPlus_GraphicsSetTransform($backgra,$matrix)
    _GDIPlus_MatrixDispose($matrix)
    Return 1
    EndFunc

    [/autoit]

    EDIT:
    UPDATE 2:
    Highscores werden gespeichert, Auswahlliste für Maps ;)
    Es gibt jetzt eine Anzeige wie weit der letzte Treffer entfernt war, damit man weiß wie nah man am Knacken des Highscores ist :)

    Danke für die 50 Downloads :thumbup:

    Jetzt hab ich noch 3 Maps und meine Highscores hinzugefügt :D

  • Sehr schönes Spiel, nur leider ist die Anfangsform nicht soooo schön. Anstatt dort eine von Eigenhand geschriebene Form reinzuklatschen könntest du einfach mit dem Koda arbeiten... Sonst klasse :)

  • Macht wirklich Spaß! Hab auch schon oft mit Anziehungen gearbeitet (Sogar grade im Moment als kleiner Zusatz) und ich muss sagen das es immer Spaß macht.
    Gefällt mir :thumbup:

    mfg BB

    "IF YOU'RE GOING TO KILL IT
    OPEN SOURCE IT!"

    by Phillip Torrone

    Zitat von Shoutbox

    [Heute, 11:16] Andy: ....böseböseböseböse....da erinnere ich mich daran, dass man den Puschelschwanz eines KaRnickels auch "Blume" nennt....ob da eins zum anderen passt? :rofl: :rofl: :rofl: :rofl:

    https://autoit.de/index.php?page…leIt#post251138

    Neon Snake

  • hehe cooles game:D

    also ich habs auf der zweiten map geschafft mit

    Spoiler anzeigen

    60 / 61.


    Gibt es mehrer Möglichkeiten?

  • Hi, coole Idee! :thumbup:
    Ich würde aber eher eine Auswahlliste der verfügbaren Maps vorziehen.
    Einige Karten sind ziemlich schwer^^

  • Danke für das große Lob und nette Feedback :)

    Ich hab mich direkt rangesetzt und eine schöne Auswahlliste für die Maps gebastelt und zusätzlich noch eine Highscoreliste gebaut, auch wenn das keiner verlangt hat ^^

    Jetzt dürften keine Makel mehr zu finden sein :P

  • Danke :)
    Naja Vektoren addieren würde auch in weniger Code gehen ;)


    Sorry das das jetzt so kurzfristig nochmal kommt, aber es ist noch ein Update, das Letzte (wahrscheinlich) ;)
    Es gibt jetzt eine Anzeige wie weit der letzte Treffer entfernt war, damit man weiß wie nah man am Knacken des Highscores ist :)