เกมส์ยิงไอคอนที่หล่น เป็นโค้ดเริ่มต้นสำหรับการทำนะครับ
- ขยับยานไปซ้ายขวา ใช้ปุ่มลูกศร
- ยิงปืนกดปุ่ม สเปชบาร์ ยิงได้พร้อมกัน 5 นัด หลังจากลูกปืนหายไปแล้ว(ในจอมีไม่ครบ 5 นัด) จึงจะยิงต่อได้
- ขยับยานไปซ้ายขวา ใช้ปุ่มลูกศร
- ยิงปืนกดปุ่ม สเปชบาร์ ยิงได้พร้อมกัน 5 นัด หลังจากลูกปืนหายไปแล้ว(ในจอมีไม่ครบ 5 นัด) จึงจะยิงต่อได้
- Code:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
Global $speed = 10, $Label2, $shipmove = 0
Global $s = False, $shot_left[5], $shot_right[5], $numbicon[20]
Global $shottime = TimerInit()
Global $LRshot = 1, $checkshotL, $checkshotR
Global $icontime = TimerInit()
$Form1 = GUICreate(" ", 400, 436, 629, 72)
GUISetBkColor(0x000000)
$ship = GUICtrlCreateGraphic(222, 390, 42, 36)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xFFFFFF)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 14, 8, 12, 25)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x0000FF)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 6, 25, 30, 7)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 1, 10, 39, 11)
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 29, 0, -18, 18)
$Label1 = GUICtrlCreateLabel("", 320, 8, 75, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)
While 1
If GUIGetMsg() = -3 Then Exit
$position = ControlGetPos($Form1, "", $ship)
GUICtrlSetData($Label1, $position[0] & "x" & $position[1])
Sleep(20)
If _IsPressed("25") Then $shipmove = 1 ;กดปุ่มลูกศรซ้าย
If _IsPressed("20") Then $shipmove = 2 ;กดปุ่มสเปชบาร์
If _IsPressed("27") Then $shipmove = 3 ;กดปุ่มลูกศรขวา
animation()
createicon()
WEnd
Func createicon()
If TimerDiff($icontime) > Random(1000, 2000, 1) Then
For $i = 0 To 19
If Not IsNumber($numbicon[$i]) Then
$numbicon[$i] = GUICtrlCreateIcon("shell32.dll", Random(1, 20, 1), Random(0, 400 - 32, 1), 0)
$icontime = TimerInit()
ExitLoop
EndIf
Next
EndIf
EndFunc ;==>createicon
Func iconmove()
For $i = 0 To 19
$positionicon = ControlGetPos($Form1, "", $numbicon[$i])
If IsArray($positionicon) Then
If $positionicon[1] < 400 Then
If checkshot($numbicon[$i]) <> 1 Then
GUICtrlSetPos($numbicon[$i], $positionicon[0], $positionicon[1] + 2)
Else
GUICtrlDelete($numbicon[$i])
$numbicon[$i] = ""
EndIf
Else
GUICtrlDelete($numbicon[$i])
$numbicon[$i] = ""
EndIf
EndIf
Next
EndFunc ;==>iconmove
Func checkshot($numb)
$checkcollision = ControlGetPos($Form1, "", $numb)
$XHicon = $checkcollision[0] + $checkcollision[2] ;แกน X และกว้าง
$YWicon = $checkcollision[1] + $checkcollision[3];แกน Y และความสูง
For $a = 0 To 4
$check1 = ControlGetPos($Form1, "", $shot_left[$a])
$XHcheck1 = $check1[0] + $check1[2];แกน X และความกว้าง
$YWcheck1 = $check1[1] + $check1[3] ;แกน Y และความสูง
If BitAND($check1[0] < $XHicon, $XHcheck1 > $checkcollision[0], $YWcheck1 > $checkcollision[1], $check1[1] < $YWicon) Then
Return 1
EndIf
$check1 = ControlGetPos($Form1, "", $shot_right[$a])
$XHcheck1 = $check1[0] + $check1[2];แกน X และความกว้าง
$YWcheck1 = $check1[1] + $check1[3] ;แกน Y และความสูง
If BitAND($check1[0] < $XHicon, $XHcheck1 > $checkcollision[0], $YWcheck1 > $checkcollision[1], $check1[1] < $YWicon) Then
Return 1
EndIf
;แกน X ของลูกปืน ต้องน้อยกว่า แกน X และความสูงของไอคอน
;แกน X และความกว้าง ของลูกปืน ต้องมากกว่า แกน X ของไอคอน
;แกน Y และความสูง ของลูกปืน ต้องมากกว่า แกน Y ของไอคอน
;แกน Y ของลูกปืน ต้องน้อยกว่า แกน Y และความสูงของไอคอน
Next
EndFunc ;==>checkshot
Func shotmove()
For $i = 0 To 4
$positionshot = ControlGetPos($Form1, "", $shot_left[$i])
If IsArray($positionshot) Then
If $positionshot[1] > 1 Then
GUICtrlSetPos($shot_left[$i], $positionshot[0], $positionshot[1] - 2)
Else
GUICtrlDelete($shot_left[$i])
$shot_left[$i] = ""
EndIf
EndIf
Next
For $i = 0 To 4
$positionshot = ControlGetPos($Form1, "", $shot_right[$i])
If IsArray($positionshot) Then
If $positionshot[1] > 1 Then
GUICtrlSetPos($shot_right[$i], $positionshot[0], $positionshot[1] - 2)
Else
GUICtrlDelete($shot_right[$i])
$shot_right[$i] = ""
EndIf
EndIf
Next
EndFunc ;==>shotmove
Func animation()
iconmove()
If $s = True Then shotmove()
Switch $shipmove
Case 1 ;ซ้าย
If $position[0] > 2 Then GUICtrlSetPos($ship, $position[0] - $speed, $position[1])
$shipmove = 0
Case 2 ;ยิง
If TimerDiff($shottime) > 100 Then
$s = True
For $i = 0 To 4
If $LRshot = 1 Then
If Not IsNumber($shot_left[$i]) Then
$shot_left[$i] = GUICtrlCreateLabel("", $position[0] + 4, $position[1] - 1, 2, 6)
GUICtrlSetBkColor($shot_left[$i], 0xFFFFFF)
$shipmove = 0
$shottime = TimerInit()
$LRshot = 0
ExitLoop
Else
$shipmove = 0
EndIf
Else
If Not IsNumber($shot_right[$i]) Then
$shot_right[$i] = GUICtrlCreateLabel("", $position[0] + 36, $position[1] - 1, 2, 6)
GUICtrlSetBkColor($shot_right[$i], 0xFFFFFF)
$shipmove = 0
$shottime = TimerInit()
$LRshot = 1
ExitLoop
Else
$shipmove = 0
EndIf
EndIf
Next
EndIf
Case 3 ;ขวา
If $position[0] < 352 Then GUICtrlSetPos($ship, $position[0] + $speed, $position[1])
$shipmove = 0
EndSwitch
EndFunc ;==>animation
แก้ไขล่าสุดโดย POS เมื่อ 30/07/11, 07:48 am, ทั้งหมด 1 ครั้ง