Kreatorul Posted October 16, 2006 Posted October 16, 2006 (edited) Hi I am trying to make a game but i can't get the colision detector to work. Here is what i have so far and how i tried to do it and it's not working #include <GuiConstants.au3> #Include <Misc.au3> GUICreate("Game", 500, 500) ;Vars: $can=GuiCtrlCreateButton("Lada", 270, 450, 80, 50) $pica=GuiCtrlCreateButton("Cade", 450, 20) $pica2=GuiCtrlCreateButton("Cade alta", 350, 10) GuiSetState() While 1 $posc=ControlGetPos("Game", "", $can) $posp=ControlGetPos("Game", "", $pica) $msg=GuiGetMsg() If $msg=$Gui_event_close Then Exit If _Ispressed("27") Then GuiCtrlSetPos($can, $posc[0]+2, $posc[1]) If _Ispressed("25") Then GuiCtrlSetPos($can, $posc[0]-2, $posc[1]) GuiCtrlSetPos($pica, $posp[0], $posp[1]+1) If $posp[1]=500 Then GuiCtrlSetPos($pica, random(0, 470), 0) EndIf If $posp[0] + $posp[1] = $posc[0] + $posc[1] Then GuiCtrlSetPos($pica, random(0, 470), 0) GuiCtrlCreateLabel("You Scored", 90, 10) EndIf Wend Edit: There was a bad EndIf i putted there...but it's still not working too good. Suggestions to improve it? Edited October 16, 2006 by Kreatorul
cppman Posted October 16, 2006 Posted October 16, 2006 Try this... This is the collision detection I used for my pacman game: expandcollapse popup#include <GuiConstants.au3> #Include <Misc.au3> $window = GUICreate("Game", 500, 500) ;Vars: $can=GuiCtrlCreateButton("Lada", 270, 450, 80, 50) $pica=GuiCtrlCreateButton("Cade", 450, 20) $pica2=GuiCtrlCreateButton("Cade alta", 350, 10) GuiSetState() While 1 $posc=ControlGetPos("Game", "", $can) $posp=ControlGetPos("Game", "", $pica) $msg=GuiGetMsg() If $msg=$Gui_event_close Then Exit If _Ispressed("27") Then GuiCtrlSetPos($can, $posc[0]+2, $posc[1]) If _Ispressed("25") Then GuiCtrlSetPos($can, $posc[0]-2, $posc[1]) GuiCtrlSetPos($pica, $posp[0], $posp[1]+1) If $posp[1]=500 Then GuiCtrlSetPos($pica, random(0, 470), 0) EndIf if (Intersection($window, $can, $pica)) Then GuiCtrlSetPos($pica, random(0, 470), 0) GuiCtrlCreateLabel("You Scored", 90, 10) EndIf Wend Func Intersection($hWnd, $nControl1, $nControl2) ;True if they have intersected in any way. $rect1 = ControlGetPos($hWnd, "", $nControl1) $rect2 = ControlGetPos($hWnd, "", $nControl2) if ((($rect1[0] < ($rect2[0]+$rect2[2])) and ($rect2[0] < ($rect1[0]+$rect1[2])) and ($rect1[1] < ($rect2[1] + $rect2[3])))) Then Return ($rect2[1] < ($rect1[1]+$rect1[3])) Else Return False EndIf EndFunc the Function: Intersection($hWnd, $control1, $control2) returns true if $control1 has collided with $control2 or vice versa ;D Miva OS Project
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now