[autoit]
_ArrayDisplay($Array, "mit einem Spaltennamen", -1 , 0 , "" , "|" , "Titel1|Titel2|Titel3")
[/autoit]Gruss Shadowigor
_ArrayDisplay($Array, "mit einem Spaltennamen", -1 , 0 , "" , "|" , "Titel1|Titel2|Titel3")
[/autoit]Gruss Shadowigor
So, und wiedereinmal gibt es eine neue Version. Ich habe mich jetzt dazu entschieden, dass sich das Raumschiff nicht automatisch bewegt. Dafür kann man jetzt auch mit der Maus lenken.
Sieht recht ordentlich aus. Für dein erstes Spiel find ichs recht gut.
Gruss Shadowigor
@xXxProGamerxXx: Meinst du, dass das Raumschiff erst langsamer wird und erst dann stillsteht, wenn man die Pfeiltaste loslässt?
@Marsi: Dass du TheBeginning gemeint hast war mir klar. Als Anregung finde ich es aber gut. Trotzdem hatte ich eigentlich vor, das Spiel in einer etwas anderen Richtung zu entwickeln, denn eigentlich wollte ich alles nur aus Polygonen machen und keine Bilder verwenden (von da kommt das "Poly"
). Das kommt daher, da ich mit diesem Spiel angefangen habe, um etwas über GDI+ zu lernen. Ob das eine gute Idee ist wird sich zeigen...
chesstiger : Gute Idee(en). Das mit der "Maussache" verstehe ich jetzt nicht ganz. Das ganze soll ja kein Steuerungsersatz sein. Ich hab nur mal xXxProGamerxXx's Idee ausprobiert, wovon ich aber noch nicht 100%ig überzeugt bin und deshalb wollte ich mal eure Meinung dazu hören.
@Marsi: Möglich ist vieles. Die Frage dabei ist für mich bloss der Zeitaufwand. Ich werde natürlich noch einige Zeit in dieses Projekt investieren, aber wie gross es am Ende dann wirklich wird weis ich noch nicht. Im Moment will ich einfach noch nicht in zu grossen Schritten denken aber wer weis, das kann ja noch kommen. Ich muss den schlussendlichen Rahmen des Projekts ja (hoffentlich) noch nicht jetzt festlegen. Aber danke für die Anregung (und das Beispiel).
So, und wieder mal gibt es eine neue Version.
@xXxProGamerxXx: Ich hoffe es ist so wie du es dir gedacht hast. Ich bin mir aber noch nicht so sicher ob ich es so lasse soll.
hellboy3: Das wäre eh gekommen. Hab mich selber genervt, dass ichs immer wieder neu starten musste ![]()
An Alle: Ich würde mich freuen wenn ihr mir eure Meinung zum selber Bewegen des Raumschiffs sagt. Und fleissig neue Ideen posten ![]()
Gute Idee. Ich werds mal versuchen. Und das mit den 3 Leben sollte eigentlich nicht so schwierig sein.
So, es gibt wieder mal eine neue Version. Für die Änderungen siehe Post #1. Viel Spass damit.
PS: Verbesserungsvorschläge sind natürlich nach wie vor erwünscht ![]()
Schau die die Hilfe an. Dort siehst du, dass MouseMove einen 3. Parameter hat und der heisst "speed". Und das ist so ziemlich das was du suchst oder?
Gruss Shadowigor
Es freut mich wikrich das es euch gefällt.
WASD geht eigentlich schon immer. An dem habe ich nichts geändert.
Ich hoffe ihr habt noch ein paar Ideen um es noch ein wenig aufzumotzen. Dann kann daraus ja mal noch etwas anständiges werden. ![]()
Benenne Sie einfach von Irgendwas.exe in Irgendwas.txt um und schon hast du es.
So, die neueste Version ist Online.
@Marsi: Danke für die Hinweise. Ich habe jetzt alles geändert. Und das mit Sleep wusste ich gar nicht. Tja, man lernt nie aus.
@xXxProGamerxXx: So, eine Superwaffe gibts jezt auch. Hoffentlich gefällt sie dir ![]()
Ja genau. Das ist der Zweck eines Compilers. (Bei AutoIt passiert ja eigentlich nichts anderes wenn du eine .exe erstellst) Sonst wärs ja völlig unsinnig wenn man nur mit Assembler arbeiten könnte.
Also ich habe auch ein Board mit dem genau gleichen PIC (zufälle gibts...) und da musst du definitiv nicht alles in Assambler schreiben. (Guckst du Hier mit "HI-TECH C Lite Compiler for PIC10/12/16 MCUs"). Vor USB kann ich dich nur warnen wenn du kein USB-Modul hast. Da wirst du verrückt.
In dem PIC den du hast hast du auch ein EUSART-Modul (RS232) und da müsstest du eigentlich nur noch eine Buchse an die Richtigen Pins anschliesssen (siehe Datenblatt). Um das Modul dann zu verwenden musst du dir dann auch wieder das Datenblatt anschauen. Aber zu dem Thema gibt es sicher auch viel im Internet. Wenn du willst kann ich auch schauen ob ich noch was dazu von meinem Board finde.
Von bascom hab ich jetzt keine Ahnung, da kann ich dir leider keinen Tipp geben.
Also die Meinung deines Kollegen, dass AVRs einfacher sind als PICs teile ich nicht, aber das ist meine Meinung
.
Wie gesagt, mit der schon genannten UDF kannst du ja dinge über RS232 senden. Jetzt musst du einfach an deinen Controller eine RS232-Buchse anschliessen. Vorzugsweise nimmst du dazu auch einen Controller mit integriertem RS232-Modul. Um mit dem PC und somit auch mit AutoIt zu kommunizieren musst du noch ein Programm schreiben, welches die Befehle, welche von AutoIt kommen auch umsetzten.
Das ganze ist nicht gerade mit wenig Aufwand verbunden wenn du von null beginnst, aber mit entsprechender Hardware sollte es eigentlich nicht so ein grosses Problem darstellen.
Gruss Shadowigor
Erstmal danke für die vielen Rückmeldungen.
@Marsi: Stimmt. Hab ich vergessen. Mache ich noch.
@xXxProGamerxXx und chesstiger: Gute Idee. Das werde ich sicher auch noch machen. Das dauert aber wohl noch ein wenig...
Ich hab jetzt mal eine neue Version hochgeladen (siehe Post #1).
PS: Kann mir jemand sagen weshalb er erst so nach dem 3. Leertastendruck beginnt umzuschalten? Das versteh ich irgendwie nicht ganz.
Danke vielmals.
L3viathan: Also den Punktestand zeigt es ja schon an (ganz unten in der mitte. ist vielleicht ein wenig klein). Das mit der Höhe und Breite lässt sich machen.
Hat sonst noch jemand Verbesserungsvorschläge?
Hallo zusammen
Ich habe mal ein kleine Spiel gemacht um mich ein wenig mit GDI+ zu beschäftigen. Es ist eigentlich selbsterklärend. Steuern kann man mit WASD oder den Pfeiltasten.
Ich hoffe es gefällt euch.
Anleitung:
WASD, Pfeiltasten oder Linke Maustaste: Bewegen
Maus: Blickrichtung ändern
Leertaste: Superwaffe
Esc: Beenden
Enter: Zwischen mit und ohne Rand wechseln/Neustart wenn man verloren hat
Alt: Pause
Änderungen:
Version 1.5
- Das Raumschiff wird erst langsamer bevor es stillsteht
- Superwaffe wird jetzt mit der Leertaste gezündet
- Wenn man die linke Maustaste drückt, fliegt das Raumschiff jetzt in Blickrichtung
- Diverse Bugfixes
Version 1.4
- Wenn man verliert, kann man es mit Enter noch mal versuchen
- Man hat 3 Leben
- Das Raumschiff bewegt sich jetzt selber (Noch im Teststadium)
- Einige Bugfixes
Version 1.3
- Es können PowerUps eingesammelt werden (kleine, Dunkelgrüne Rechtecke). Dadurch wird man für kurze Zeit unverwundbar.
- Verbesserte Kollisionserkennung
- Diverse Bugfixes
Version 1.2
- Superwaffe kann mit Enter gezündet werden
- Statusbalken für die Superwaffe am unteren Rand (Gelb = Noch nicht einsatzfähig, Violett = Einsatzfähig)
- Diverse Bugfixes
Version 1.1
- Pause mit Alt möglich
- Mit der Leertaste kann zwischen Popup-Fenster und Grössenveränderbarem Fenster gewechselt werden.
- Einige Bugfixes
Code:
#region Includes
#include <GDIPlus.au3>
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#endregion Includes
#region Options
_GDIPlus_Startup()
OnAutoItExitRegister("_exit")
Opt("MustDeclareVars", 1)
#endregion Options
;--- Changeable Constants ---------------------------------------------------------------------
Global Const $PlayerRadius = 40
Global Const $nPlayerSpeed = 2
Global Const $nPlayerSmoothing = 20
Global Const $nPlayerSmoothingSpeed = 1
Global Const $nInvincibleTime = 50
Global Const $SHOOTING_SPEED = 2
Global Const $nSpeedEnemys = 5
Global Const $nSpeeedNewEnemy = 15
Global Const $nEnemyMaxSize = 200
Global Const $nEnemyMinSize = 90
Global Const $nEnemyDestroySize = 50
Global Const $nEnemySmallingSpeed = 30
Global Const $nPowerUpPlayerRadius = 60
Global Const $nPowerUpRadius = 30
Global Const $nPowerUpMinTime = 400
Global Const $nPowerUpMaxTime = 800
Global Const $nPowerUpDuration = 200
;----------------------------------------------------------------------------------------------
#region Global Variabels
Global Const $pi = 3.14159265358979
Global Const $HalfPi = $pi / 2
Global Const $Cos08 = Cos(0.8), $Sin08 = Sin(0.8), $Cosn08 = Cos(-0.8), $Sinn08 = Sin(-0.8)
Global Const $MAX_ENEMYS = 40, $MAX_SHOTS = 40
Global Const $nEnemyX = 0, $nEnemyY = 1, $nEnemySize = 2, $nEnemyDir = 3
Global Const $nShotXFront = 0, $nShotYFront = 1, $nShotXBack = 2, $nShotYBack = 3
Global $hGraphic, $hBrushPlayer, $hBrushEnemy, $hPen, $xPlayer, $yPlayer, $rotationPlayer, $xGUI, $yGUI, $hBitmap, $hBuffer
Global $nPlayerFrontX, $nPlayerFrontY, $nPlayerBack1X, $nPlayerBack1Y, $nPlayerBack2X, $nPlayerBack2Y, $hBrushWhite, $hLayoutOver
Global $hFontFamily, $hFontPoints, $hLayoutPoints, $hFontOver, $nPoints, $hPenMenu, $hBrushSuper1, $hBrushSuper2
Global $fWeaponShooting, $nWeaponRadius, $xWeapon, $yWeapon, $hBrushPowerUp, $hBrushPowerUpPlayer, $fPowerUp
Global $fPowerUpReady, $nPowerUpTimer, $xPowerUp, $yPowerUp, $nPowerUpActiveTime, $nLives, $fWeaponReady
Global $fWeaponReloading, $nLine, $nNewEnemy, $nlSpeedNewEnemys, $nNewShot, $nSmooth
Global $aShots[$MAX_SHOTS][4] ; [x1][y1][x2][y2]
Global $aEnemys[$MAX_ENEMYS][4] ; [x][y][Size][Direction]
Global $afCollided[$MAX_ENEMYS]
Global $anPointsPowerUp[5][2]
Global $widhtGUI = 800
Global $heightGUI = 800
Global $hDLL = DllOpen("Kernel32.dll")
#endregion Global Variables
#region Variable Initialisations
$xGUI = (@DesktopWidth - $widhtGUI) / 2
$yGUI = (@DesktopHeight - $heightGUI) / 2
_InitVars()
#endregion Variable Initialisations
#region GUI
Local $GUI_Border = False
Local $hGUI = GUICreate("PolyShoot", $widhtGUI, $heightGUI, $xGUI, $yGUI, $WS_POPUP)
GUISetBkColor(0x000000, $hGUI)
#endregion GUI
#region GDI+
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBrushPlayer = _GDIPlus_BrushCreateSolid(0xFF00FF00) ; Grün
$hBrushEnemy = _GDIPlus_BrushCreateSolid(0xFFFF0000) ; Rot
$hBrushWhite = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) ; Weiss
$hBrushSuper1 = _GDIPlus_BrushCreateSolid(0xFFFFFF00) ; Gelb
$hBrushSuper2 = _GDIPlus_BrushCreateSolid(0xFF551A8B) ; Violett
$hBrushPowerUpPlayer = _GDIPlus_BrushCreateSolid(0x7FFFFF00) ; Blasses Gelb
$hBrushPowerUp = _GDIPlus_BrushCreateSolid(0xFF006400) ; Dunkelgrün
$hPen = _GDIPlus_PenCreate(0xFF0000FF, 5) ; Blau
$hPenMenu = _GDIPlus_PenCreate(0xFFFFFFFF, 3) ; Weiss
$hLayoutOver = _GDIPlus_RectFCreate(($widhtGUI / 2) - 280, ($heightGUI / 2) - 70, 800, 100)
$hLayoutPoints = _GDIPlus_RectFCreate(($widhtGUI / 2) - 50, $heightGUI - 80, 200, 50)
$hFontFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFontOver = _GDIPlus_FontCreate($hFontFamily, 60)
$hFontPoints = _GDIPlus_FontCreate($hFontFamily, 10)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($widhtGUI, $heightGUI, $hGraphic)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
_GDIPlus_GraphicsFillRect($hBuffer, ($widhtGUI / 2) + 50, $heightGUI - 60, ($widhtGUI / 2) + 100, $heightGUI - 30, $hBrushSuper2)
[/autoit] [autoit][/autoit] [autoit]#endregion GDI+
[/autoit] [autoit][/autoit] [autoit]GUISetState(@SW_SHOW, $hGUI)
[/autoit] [autoit][/autoit] [autoit]#region Main Loop
While 1
_LoopDelay()
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_RESIZED
_Resized()
EndSwitch
_SpecialKeys()
_UpdatePlayer()
If _IsPressed("01") Then _Move($nPlayerSpeed, $nPlayerFrontX, $nPlayerFrontY)
_UpdateShots()
_PowerUp()
_UpdateEnemys()
_SuperWeapon()
_CheckCollisions()
_DrawPoints()
_UpdateScreen()
WEnd
#endregion Main Loop
#region Functions
[/autoit] [autoit][/autoit] [autoit]Func _LoopDelay()
Local Static $nTimer = 0
If $nTimer = 0 Then
$nTimer = TimerInit()
Return
EndIf
While TimerDiff($nTimer) < 50
Sleep(1)
WEnd
$nTimer = TimerInit()
EndFunc
Func _SpecialKeys()
If _IsPressed("0D") Then
If $GUI_Border Then
GUISetStyle($WS_POPUP)
Else
GUISetStyle($WS_OVERLAPPEDWINDOW)
EndIf
$GUI_Border = Not $GUI_Border
While _IsPressed("0D")
Sleep(10)
WEnd
EndIf
If _IsPressed("12") Then
While _IsPressed("12")
Sleep(10)
WEnd
_GDIPlus_GraphicsDrawStringEx($hGraphic, " Paused", $hFontOver, $hLayoutOver, Default, $hBrushWhite)
While Not _IsPressed("12")
Sleep(10)
WEnd
While _IsPressed("12")
Sleep(10)
WEnd
EndIf
EndFunc
Func _UpdatePlayer()
Dim $posMouse, $aPolygon[4][2]
Local $tmpRotation, $xTmp, $yTmp, $fLeft, $fRight, $fUp, $fDown
Local Static $fLeftTmp, $fRightTmp, $fUpTmp, $fDownTmp, $fMouseDown = False, $nMouseXTmp, $nMouseYTmp
If Not _IsPressed("01") Then
$fUp = _IsPressed("57") Or _IsPressed("26")
$fDown = _IsPressed("53") Or _IsPressed("28")
$fRight = _IsPressed("44") Or _IsPressed("27")
$fLeft = _IsPressed("41") Or _IsPressed("25")
_MovePlayer($nPlayerSpeed, $fLeft, $fRight, $fUp, $fDown)
If $fUp Or $fDown Or $fRight Or $fLeft Then
$nSmooth = $nPlayerSmoothing
$fLeftTmp = $fLeft
$fRightTmp = $fRight
$fUpTmp = $fUp
$fDownTmp = $fDown
$fMouseDown = False
ElseIf $nSmooth > $nPlayerSmoothingSpeed Then
If $fMouseDown Then
_Move($nSmooth / 10, $nMouseXTmp, $nMouseYTmp)
Else
_MovePlayer($nSmooth / 10, $fLeftTmp, $fRightTmp, $fUpTmp, $fDownTmp)
EndIf
$nSmooth -= $nPlayerSmoothingSpeed
Else
$fMouseDown = False
EndIf
Else
$nSmooth = $nPlayerSmoothing
$fMouseDown = True
$nMouseXTmp = $nPlayerFrontX
$nMouseYTmp = $nPlayerFrontY
EndIf
Do
$posMouse = GUIGetCursorInfo()
Sleep(10)
Until IsArray($posMouse)
$rotationPlayer = ATan(($posMouse[0] - $xPlayer) / ($yPlayer - $posMouse[1]))
If $posMouse[1] > $yPlayer Then $rotationPlayer *= -1
$tmpRotation = $rotationPlayer
If $tmpRotation < 0 Then $tmpRotation *= -1
$nPlayerFrontX = $PlayerRadius * Sin($tmpRotation)
$tmpRotation = $HalfPi - $tmpRotation
$nPlayerFrontY = $nPlayerFrontX * Tan($tmpRotation)
If $posMouse[1] > $yPlayer Then
$nPlayerFrontY = $yPlayer + $nPlayerFrontY
Else
$nPlayerFrontY = $yPlayer - $nPlayerFrontY
EndIf
If $posMouse[0] < $xPlayer Then
$nPlayerFrontX = $xPlayer - $nPlayerFrontX
Else
$nPlayerFrontX = $xPlayer + $nPlayerFrontX
EndIf
$yTmp = ($yPlayer - $nPlayerFrontY) / 1.5
$xTmp = ($xPlayer - $nPlayerFrontX) / 1.5
$nPlayerBack1X = $xTmp * $Cos08 - $yTmp * $Sin08 + $xPlayer
$nPlayerBack1Y = $xTmp * $Sin08 + $yTmp * $Cos08 + $yPlayer
$nPlayerBack2X = $xTmp * $Cosn08 - $yTmp * $Sinn08 + $xPlayer
$nPlayerBack2Y = $xTmp * $Sinn08 + $yTmp * $Cosn08 + $yPlayer
$aPolygon[0][0] = 3
$aPolygon[1][0] = $nPlayerFrontX
$aPolygon[1][1] = $nPlayerFrontY
$aPolygon[2][0] = $nPlayerBack1X
$aPolygon[2][1] = $nPlayerBack1Y
$aPolygon[3][0] = $nPlayerBack2X
$aPolygon[3][1] = $nPlayerBack2Y
_GDIPlus_GraphicsClear($hBuffer, 0xFF000000)
_GDIPlus_GraphicsFillPolygon($hBuffer, $aPolygon, $hBrushPlayer)
EndFunc
Func _MovePlayer($nSpeed, $fLeft, $fRight, $fUp, $fDown)
If $fUp Then
$yPlayer -= 3 * $nSpeed
If $fRight Then
$xPlayer += 3 * $nSpeed
ElseIf $fLeft Then
$xPlayer -= 3 * $nSpeed
Else
$yPlayer -= $nSpeed
EndIf
ElseIf $fDown Then
$yPlayer += 3 * $nSpeed
If $fRight Then
$xPlayer += 3 * $nSpeed
ElseIf $fLeft Then
$xPlayer -= 3 * $nSpeed
Else
$yPlayer += $nSpeed
EndIf
ElseIf $fLeft Then
$xPlayer -= 4 * $nSpeed
ElseIf $fRight Then
$xPlayer += 4 * $nSpeed
EndIf
EndFunc
Func _Move($nValue, ByRef $x, ByRef $y)
$x -= ($xPlayer - $x) * $nValue / 10
$xPlayer -= ($xPlayer - $x) * $nValue / 10
$y -= ($yPlayer - $y) * $nValue / 10
$yPlayer -= ($yPlayer - $y) * $nValue / 10
EndFunc
Func _UpdateShots()
Local $xTmp, $yTmp, $k
If Mod($nNewEnemy, $SHOOTING_SPEED) = 0 Then
$k = $nNewShot / $SHOOTING_SPEED
$aShots[$k][$nShotXFront] = $nPlayerFrontX
$aShots[$k][$nShotYFront] = $nPlayerFrontY
$aShots[$k][$nShotXBack] = $xPlayer - (($xPlayer - $nPlayerFrontX) * 1.2)
$aShots[$k][$nShotYBack] = $yPlayer - (($yPlayer - $nPlayerFrontY) * 1.2)
If $k > ($MAX_SHOTS - 2) Then $nNewShot = 0
EndIf
For $j = 0 To $MAX_SHOTS - 1
$xTmp = $aShots[$j][$nShotXFront]
$yTmp = $aShots[$j][$nShotYFront]
$aShots[$j][$nShotXFront] = $aShots[$j][$nShotXBack] - ($xTmp - $aShots[$j][$nShotXBack])
$aShots[$j][$nShotYFront] = $aShots[$j][$nShotYBack] - ($yTmp - $aShots[$j][$nShotYBack])
$aShots[$j][$nShotXBack] = $aShots[$j][$nShotXFront] - ($aShots[$j][$nShotXBack] - $aShots[$j][$nShotXFront])
$aShots[$j][$nShotYBack] = $aShots[$j][$nShotYFront] - ($aShots[$j][$nShotYBack] - $aShots[$j][$nShotYFront])
_GDIPlus_GraphicsDrawLine($hBuffer, $aShots[$j][$nShotXFront], $aShots[$j][$nShotYFront], $aShots[$j][$nShotXBack], $aShots[$j][$nShotYBack], $hPen)
Next
$nNewShot += 1
EndFunc
Func _SuperWeapon()
If _IsPressed("20") And $fWeaponReady Then
$fWeaponReady = False
$fWeaponShooting = True
$fWeaponReloading = True
$xWeapon = $xPlayer
$yWeapon = $yPlayer
EndIf
If $fWeaponShooting Then
_GDIPlus_GraphicsDrawArc($hBuffer, $xWeapon - $nWeaponRadius, $yWeapon - $nWeaponRadius, $nWeaponRadius * 2, $nWeaponRadius * 2, 0, 360, $hPen)
$nWeaponRadius += 10
If $nWeaponRadius > ($widhtGUI * 3) And $nWeaponRadius > ($heightGUI * 4) Then
$fWeaponShooting = False
$nWeaponRadius = 0
_ClearCollisionArray()
EndIf
EndIf
If $fWeaponReloading Then
_GDIPlus_GraphicsFillRect($hBuffer, ($widhtGUI / 2) + 100, $heightGUI - 80, $nLine, 20, $hBrushSuper1)
$nLine += 0.1
If $nLine > 50 Then
$fWeaponReady = True
$fWeaponReloading = False
$nLine = 0
EndIf
Else
_GDIPlus_GraphicsFillRect($hBuffer, ($widhtGUI / 2) + 100, $heightGUI - 80, 50, 20, $hBrushSuper2)
EndIf
EndFunc
Func _PowerUp()
If $nPowerUpTimer < 1 And Not $fPowerUpReady And Not $fPowerUp Then
$fPowerUpReady = True
$xPowerUp = Random($nPowerUpRadius, $widhtGUI - $nPowerUpRadius, 1)
$yPowerUp = Random($nPowerUpRadius, $heightGUI - $nPowerUpRadius, 1)
$anPointsPowerUp[1][0] = $xPowerUp - $nPowerUpRadius
$anPointsPowerUp[1][1] = $yPowerUp
$anPointsPowerUp[2][0] = $xPowerUp
$anPointsPowerUp[2][1] = $yPowerUp - $nPowerUpRadius
$anPointsPowerUp[3][0] = $xPowerUp + $nPowerUpRadius
$anPointsPowerUp[3][1] = $yPowerUp
$anPointsPowerUp[4][0] = $xPowerUp
$anPointsPowerUp[4][1] = $yPowerUp + $nPowerUpRadius
_GDIPlus_BrushSetSolidColor($hBrushPowerUpPlayer, 0x7FFFFF00)
ElseIf $fPowerUpReady Then
_GDIPlus_GraphicsFillPolygon($hBuffer, $anPointsPowerUp, $hBrushPowerUp)
ElseIf Not $fPowerUp Then
$nPowerUpTimer -= 1
EndIf
If $fPowerUp Then
If $nPowerUpActiveTime = 10 Or $nPowerUpActiveTime = 20 Or $nPowerUpActiveTime = 30 Then _GDIPlus_BrushSetSolidColor($hBrushPowerUpPlayer, 0x7FFFFF00)
If $nPowerUpActiveTime = 5 Or $nPowerUpActiveTime = 15 Or $nPowerUpActiveTime = 25 Or $nPowerUpActiveTime = 35 Then _GDIPlus_BrushSetSolidColor($hBrushPowerUpPlayer, 0x00FFFF00)
_GDIPlus_GraphicsFillEllipse($hBuffer, $xPlayer - $nPowerUpPlayerRadius, $yPlayer - $nPowerUpPlayerRadius, $nPowerUpPlayerRadius * 2, $nPowerUpPlayerRadius * 2, $hBrushPowerUpPlayer)
$nPowerUpActiveTime -= 1
If $nPowerUpActiveTime < 1 Then
$fPowerUp = False
$nPowerUpTimer = Random($nPowerUpMinTime, $nPowerUpMaxTime, 1)
EndIf
EndIf
EndFunc
Func _UpdateEnemys()
Local $j
If Mod($nNewEnemy + 1, $nlSpeedNewEnemys) = 0 Then
$j = Round($nNewEnemy / $nlSpeedNewEnemys)
$aEnemys[$j][$nEnemySize] = Random($nEnemyMinSize, $nEnemyMaxSize, 1)
$aEnemys[$j][$nEnemyDir] = Random(0, 3, 1) ; 0 = Left, 1 = Top, 2 = Right, 3 = Down
Switch $aEnemys[$j][$nEnemyDir]
Case 0
$aEnemys[$j][$nEnemyX] = - $aEnemys[$j][$nEnemySize]
$aEnemys[$j][$nEnemyY] = Random(0, $heightGUI - $aEnemys[$j][$nEnemySize], 1)
Case 1
$aEnemys[$j][$nEnemyX] = Random(0, $widhtGUI - $aEnemys[$j][$nEnemySize], 1)
$aEnemys[$j][$nEnemyY] = - $aEnemys[$j][$nEnemySize]
Case 2
$aEnemys[$j][$nEnemyX] = $widhtGUI + $aEnemys[$j][$nEnemySize]
$aEnemys[$j][$nEnemyY] = Random(0, $heightGUI - $aEnemys[$j][$nEnemySize], 1)
Case 3
$aEnemys[$j][$nEnemyX] = Random(0, $widhtGUI - $aEnemys[$j][$nEnemySize], 1)
$aEnemys[$j][$nEnemyY] = $heightGUI + $aEnemys[$j][$nEnemySize]
EndSwitch
If $j > $MAX_ENEMYS - 2 Then
$nNewEnemy = 0
$nlSpeedNewEnemys -= 2
EndIf
EndIf
For $j = 0 To $MAX_ENEMYS - 1
Switch $aEnemys[$j][$nEnemyDir]
Case 0
$aEnemys[$j][$nEnemyX] += $nSpeedEnemys
Case 1
$aEnemys[$j][$nEnemyY] += $nSpeedEnemys
Case 2
$aEnemys[$j][$nEnemyX] -= $nSpeedEnemys
Case 3
$aEnemys[$j][$nEnemyY] -= $nSpeedEnemys
EndSwitch
_GDIPlus_GraphicsFillRect($hBuffer, $aEnemys[$j][$nEnemyX], $aEnemys[$j][$nEnemyY], $aEnemys[$j][$nEnemySize], $aEnemys[$j][$nEnemySize], $hBrushEnemy)
Next
$nNewEnemy += 1
EndFunc
Func _CheckCollisions()
For $i = 0 To $MAX_ENEMYS - 1
For $j = 0 To $MAX_SHOTS - 1
If ($aShots[$j][$nShotXFront] > $aEnemys[$i][$nEnemyX]) And ($aShots[$j][$nShotXFront] < ($aEnemys[$i][$nEnemyX] + $aEnemys[$i][$nEnemySize])) And ($aShots[$j][$nShotYFront] > $aEnemys[$i][$nEnemyY]) And ($aShots[$j][$nShotYFront] < ($aEnemys[$i][$nEnemyY] + $aEnemys[$i][$nEnemySize])) Then
$aShots[$j][$nShotXFront] = 0
$aShots[$j][$nShotYFront] = 0
$aShots[$j][$nShotXBack] = -1
$aShots[$j][$nShotYBack] = -1
_DamageEnemy($i)
EndIf
Next
If _LineEnemyIntersects($nPlayerFrontX, $nPlayerFrontY, $nPlayerBack1X, $nPlayerBack1Y, $i) _
Or _LineEnemyIntersects($nPlayerBack1X, $nPlayerBack1Y, $nPlayerBack2X, $nPlayerBack2Y, $i) _
Or _LineEnemyIntersects($nPlayerBack2X, $nPlayerBack2Y, $nPlayerFrontX, $nPlayerFrontY, $i) Then
$nLives -= 1
If $nLives = 0 Then
_GDIPlus_GraphicsDrawStringEx($hBuffer, "Game Over", $hFontOver, $hLayoutOver, Default, $hBrushWhite)
_DrawPoints()
_UpdateScreen()
_InitVars()
While Not _IsPressed("0D")
Sleep(10)
If _IsPressed("1B") Then Exit
WEnd
While _IsPressed("0D")
Sleep(10)
WEnd
Else
_DamageEnemy($i)
$fPowerUp = True
$nPowerUpActiveTime = $nInvincibleTime
_GDIPlus_BrushSetSolidColor($hBrushPowerUpPlayer, 0x7FFFFF00)
EndIf
EndIf
If $fWeaponShooting And Not $afCollided[$i] Then
If _ArcEnemyIntersects($i, $xWeapon, $yWeapon, $nWeaponRadius) Then
_DamageEnemy($i)
$afCollided[$i] = True
EndIf
EndIf
If $fPowerUpReady Then
If (Sqrt(($xPlayer - $xPowerUp) ^ 2 + ($yPlayer - $yPowerUp) ^ 2) < $nPowerUpRadius) Then
$fPowerUp = True
$fPowerUpReady = False
$nPowerUpActiveTime = $nPowerUpDuration
EndIf
EndIf
If $fPowerUp Then
If _ArcEnemyIntersects($i, $xPlayer, $yPlayer, $nPowerUpPlayerRadius) Then
_DamageEnemy($i)
EndIf
EndIf
Next
EndFunc
Func _DrawPoints()
If $nLives > 2 Then _GDIPlus_GraphicsFillEllipse($hBuffer, ($widhtGUI / 2) - 250, $heightGUI - 90, 30, 40, $hBrushWhite)
If $nLives > 1 Then _GDIPlus_GraphicsFillEllipse($hBuffer, ($widhtGUI / 2) - 200, $heightGUI - 90, 30, 40, $hBrushWhite)
If $nLives > 0 Then _GDIPlus_GraphicsFillEllipse($hBuffer, ($widhtGUI / 2) - 150, $heightGUI - 90, 30, 40, $hBrushWhite)
_GDIPlus_GraphicsDrawStringEx($hBuffer, "Punkte: " & $nPoints, $hFontPoints, $hLayoutPoints, Default, $hBrushWhite)
EndFunc
Func _UpdateScreen()
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
EndFunc
Func _exit()
_GDIPlus_BrushDispose($hBrushPlayer)
_GDIPlus_BrushDispose($hBrushEnemy)
_GDIPlus_BrushDispose($hBrushWhite)
_GDIPlus_BrushDispose($hBrushSuper1)
_GDIPlus_BrushDispose($hBrushSuper2)
_GDIPlus_BrushDispose($hBrushPowerUpPlayer)
_GDIPlus_BrushDispose($hBrushPowerUp)
_GDIPlus_PenDispose($hPen)
_GDIPlus_PenDispose($hPenMenu)
_GDIPlus_FontFamilyDispose($hFontFamily)
_GDIPlus_FontDispose($hFontOver)
_GDIPlus_FontDispose($hFontPoints)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_Shutdown()
EndFunc
Func _Resized()
Local $nGUI_Pos = WinGetPos("PolyShoot")
$widhtGUI = $nGUI_Pos[2]
$heightGUI = $nGUI_Pos[3]
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hBuffer)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($widhtGUI, $heightGUI, $hGraphic)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hLayoutOver = _GDIPlus_RectFCreate(($widhtGUI / 2) - 280, ($heightGUI / 2) - 70, 800, 100)
$hLayoutPoints = _GDIPlus_RectFCreate(($widhtGUI / 2) - 50, $heightGUI - 80, 200, 50)
EndFunc
Func _DamageEnemy($nEnemy)
If $aEnemys[$nEnemy][$nEnemySize] < $nEnemyDestroySize Then
$aEnemys[$nEnemy][$nEnemySize] = 0
Else
$aEnemys[$nEnemy][$nEnemySize] -= $nEnemySmallingSpeed
$aEnemys[$nEnemy][$nEnemyX] += $nEnemySmallingSpeed / 2
$aEnemys[$nEnemy][$nEnemyY] += $nEnemySmallingSpeed / 2
EndIf
$nPoints += 100
EndFunc
Func _LineEnemyIntersects($x0, $y0, $x1, $y1, $i)
Local $m, $c, $topoverlap, $botoverlap, $top_intersection, $bottom_intersection, $toptrianglepoint, $bottomtrianglepoint, $l, $r, $t, $b
$l = $aEnemys[$i][$nEnemyX]
$r = $aEnemys[$i][$nEnemyX] + $aEnemys[$i][$nEnemySize]
$t = $aEnemys[$i][$nEnemyY]
$b = $aEnemys[$i][$nEnemyY] + $aEnemys[$i][$nEnemySize]
$m = ($y1 - $y0) / ($x1 - $x0)
$c = $y0 - ($m * $x0)
if ($m > 0) Then
$top_intersection = ($m * $l + $c)
$bottom_intersection = ($m * $r + $c)
else
$top_intersection = ($m * $r + $c)
$bottom_intersection = ($m * $l + $c)
EndIf
if ($y0 < $y1) Then
$toptrianglepoint = $y0
$bottomtrianglepoint = $y1
else
$toptrianglepoint = $y1
$bottomtrianglepoint = $y0
EndIf
If $top_intersection > $toptrianglepoint Then
$topoverlap = $top_intersection
Else
$topoverlap = $toptrianglepoint
EndIf
If $bottom_intersection < $bottomtrianglepoint Then
$botoverlap = $bottom_intersection
Else
$botoverlap = $bottomtrianglepoint
EndIf
return($topoverlap < $botoverlap) And (Not (($botoverlap < $t) Or ($topoverlap > $b)))
EndFunc
Func _ArcEnemyIntersects($nEnemy, $nArcX, $nArcY, $nArcRadius)
Return(Sqrt(($nArcX - $aEnemys[$nEnemy][$nEnemyX]) ^ 2 + ($nArcY - $aEnemys[$nEnemy][$nEnemyY]) ^ 2) < $nArcRadius) _
Or (Sqrt(($nArcX - $aEnemys[$nEnemy][$nEnemyX] - $aEnemys[$nEnemy][$nEnemySize]) ^ 2 + ($nArcY - $aEnemys[$nEnemy][$nEnemyY]) ^ 2) < $nArcRadius) _
Or (Sqrt(($nArcX - $aEnemys[$nEnemy][$nEnemyX]) ^ 2 + ($nArcY - $aEnemys[$nEnemy][$nEnemyY] - $aEnemys[$nEnemy][$nEnemySize]) ^ 2) < $nArcRadius) _
Or (Sqrt(($nArcX - $aEnemys[$nEnemy][$nEnemyX] - $aEnemys[$nEnemy][$nEnemySize]) ^ 2 + ($nArcY - $aEnemys[$nEnemy][$nEnemyY] - $aEnemys[$nEnemy][$nEnemySize]) ^ 2) < $nArcRadius) _
Or ((($nArcX + $nArcRadius) > $aEnemys[$nEnemy][$nEnemyX]) And (($nArcX + $nArcRadius) < $aEnemys[$nEnemy][$nEnemyX] + $aEnemys[$nEnemy][$nEnemySize]) _
And ($nArcY > $aEnemys[$nEnemy][$nEnemyY]) And ($nArcY < ($aEnemys[$nEnemy][$nEnemyY] + $aEnemys[$nEnemy][$nEnemySize]))) _
Or ((($nArcY + $nArcRadius) > $aEnemys[$nEnemy][$nEnemyY]) And (($nArcY + $nArcRadius) < $aEnemys[$nEnemy][$nEnemyY] + $aEnemys[$nEnemy][$nEnemySize]) _
And ($nArcX > $aEnemys[$nEnemy][$nEnemyX]) And ($nArcX < ($aEnemys[$nEnemy][$nEnemyX] + $aEnemys[$nEnemy][$nEnemySize]))) _
Or ((($nArcX - $nArcRadius) > $aEnemys[$nEnemy][$nEnemyX]) And (($nArcX - $nArcRadius) < $aEnemys[$nEnemy][$nEnemyX] + $aEnemys[$nEnemy][$nEnemySize]) _
And ($nArcY > $aEnemys[$nEnemy][$nEnemyY]) And ($nArcY < ($aEnemys[$nEnemy][$nEnemyY] + $aEnemys[$nEnemy][$nEnemySize]))) _
Or ((($nArcY - $nArcRadius) > $aEnemys[$nEnemy][$nEnemyY]) And (($nArcY - $nArcRadius) < $aEnemys[$nEnemy][$nEnemyY] + $aEnemys[$nEnemy][$nEnemySize]) _
And ($nArcX > $aEnemys[$nEnemy][$nEnemyX]) And ($nArcX < ($aEnemys[$nEnemy][$nEnemyX] + $aEnemys[$nEnemy][$nEnemySize])))
EndFunc
Func _InitVars()
$xPlayer = 400
$yPlayer = 400
$rotationPlayer = 0
$nPoints = 0
$nLives = 3
$anPointsPowerUp[0][0] = 4
$nPowerUpTimer = Random($nPowerUpMinTime, $nPowerUpMaxTime, 1)
$fWeaponReady = True
$fWeaponReloading = False
$fWeaponShooting = False
$nWeaponRadius = 0
$nLine = 0
$nNewEnemy = 0
$nlSpeedNewEnemys = $nSpeeedNewEnemy
$nNewShot = 0
$xWeapon = 0
$yWeapon = 0
$fPowerUp = False
$fPowerUpReady = False
$nPowerUpActiveTime = $nPowerUpDuration
$nSmooth = 0
_GDIPlus_BrushSetSolidColor($hBrushPowerUpPlayer, 0x7FFFFF00)
For $i = 0 To $MAX_ENEMYS - 1
$afCollided[$i] = False
$aEnemys[$i][$nEnemyX] = 0
$aEnemys[$i][$nEnemyY] = 0
$aEnemys[$i][$nEnemySize] = 0
Next
For $i = 0 To $MAX_SHOTS - 1
$aShots[$i][$nShotXFront] = 0
$aShots[$i][$nShotYFront] = 0
$aShots[$i][$nShotXBack] = 0
$aShots[$i][$nShotYBack] = 0
Next
EndFunc
Func _ClearCollisionArray()
For $i = 0 To $MAX_ENEMYS - 1
$afCollided[$i] = False
Next
EndFunc
#endregion Functions
[/autoit]
Gruss Shadowigor
Du kannst ihn z.B. mittels einer seriellen Schnittstelle ansteuern. Dafür gibt es auch schon eine UDF. Siehe z.B. Hier.
Gruss Shadowigor
ICH würde es so machen:
For $i = 4294967295 To 16777215 Step -16777216
_GDIPlus_BrushSetSolidColor($hBrush, BitAND(0xFF00FF00, $i))
; Hier Zeichnest du das Rechteck
Sleep(1)
Next
Falls dich die Zahlen verwirren, eigentlich sollte es so sein:
For $i = 0xFFFFFFFF To 0x00FFFFFF Step -0x01000000
Leider akzeptiert AutoIt aber heine Hex-Zahlen in For-Schleifen, wie ich gerade feststellen musste. Wenns dir zu langsam ist nimmst du für den Step einfach die Dezimalen Werte von 0x02000000 oder 0x03000000.
Gruss Shadowigor