LimeSeed Posted June 12, 2008 Share Posted June 12, 2008 is there any way to detect if 2 pics (made with guictrlcreatepic) in a gui collide? I am trying to make it so that the ball bounces off the black slime at the bottom. you will need the files at the bottom to run it. expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.0 Author: Isaac Flaum #ce ---------------------------------------------------------------------------- #include<guiconstants.au3> #include <Misc.au3> #NoTrayIcon $slimevolleyball = guicreate("Slime Volleyball by 2o2", 745, 345) GUISetBkColor(0x0000FF) $1 = 1 $l = 120 $q = 230 $w = 80 $e = 42.5 $j = 0 $k = 145 $v = 90 $z = 25 $Dll = DllOpen("user32.dll") $slime1 = @scriptDir & "\Slime1.bmp" $floor = @scriptDIr & "\floor.bmp" $ball = @scriptDir & "\ball.bmp" guisetstate(@SW_SHOW) _slime() _floor() _ball() while $1 = 1 $msg = guigetmsg() Select Case ($msg = -3) $1 = 2 EndSelect If _IsPressed("27", $DLL) Then $l = $l + 3 guictrlsetpos($slimeg1, $l, $q, $w, $e) EndIf If _IsPressed("26", $DLL) Then $q = $q - 3 $j = $j + 1 guictrlsetpos($slimeg1, $l, $q, $w, $e) elseif $j > 10 Then $q = 230 guictrlsetpos($slimeg1, $l, $q, $w, $e) EndIf If _IsPressed("25", $DLL) Then $l = $l - 3 guictrlsetpos($slimeg1, $l, $q, $w, $e) EndIf WEnd func _Slime() if fileexists($slime1) Then global $slimeg1 = guictrlcreatepic($slime1, $l, $q, $w, $e) Else msgbox(0, "Slime Volleyball by 2o2", "Error, missing image") $1 = 2 EndIf EndFunc func _floor() if fileexists($floor) Then $floorg = guictrlcreatepic($floor, 0, 272.5, 745, 80) Else msgbox(0, "Slime Volleyball by 2o2", "Error, missing image") $1 = 2 EndIf EndFunc func _ball() if fileexists($ball) then Global $ballg = guictrlcreatepic($ball, 145, 90, 25, 25) Else msgbox(0, "Slime Volleyball by 2o2", "Error, missing image") EndIf EndFuncSlime1.bmpfloor.bmp global $warming = true Link to comment Share on other sites More sharing options...
smashly Posted June 12, 2008 Share Posted June 12, 2008 (edited) Hi,and ball.bmp is ?Since your wanting the ball to collide with a curve in a square picture, I hope your mathematically adept. Because it really doesn't look that easy to some1 who's not.. (Me..lol)I gather thats why the last time you posted about the slime game no one responded.I saw your other slime game post not long after I had written a ball, brick and paddle game with autoit. ($hit A Brick)I had a look at writing the slime game using GDI+ in autoit, but it was to much calculation commitment for me on the collision detection of a large moving curve (the slime) and a ball.Best of luckCheers Edited June 12, 2008 by smashly Link to comment Share on other sites More sharing options...
LimeSeed Posted August 8, 2008 Author Share Posted August 8, 2008 yea thanks! im only 15 and just finished geometry, so i have a little understanding aka like the Pythagorean theorm and distance formula, but not stuff like calculus and precalc. Maybe ill wait a couple of years before writing this one it is also hard to bounce the ball correctly off of a semicircular object (the slime!) Thanks! -isaac global $warming = true Link to comment Share on other sites More sharing options...
Vindicator209 Posted August 8, 2008 Share Posted August 8, 2008 (edited) Try either of these two, they might help you, you'll have to dig around though:Physix (examples, this might serve your purpose better)http://www.autoitscript.com/forum/index.ph...3&hl=PhysixPhactor (this is a game made with Physix, to show you how it can be used)http://www.autoitscript.com/forum/index.ph...&hl=PhactorYou don't need that much math knowledge, I did these with basic pre-algebra knowledgeI can't help you with an Actual curved object, but using the scripts above, you can do the collisions using multiple square objectsto (easily) create "curves" without mapping out the entire image, you can create "blocks" you can't see, that follow the curve of the line, this way it makes it much, much easier.heres what I mean: Edited August 8, 2008 by VindicatorOmega [center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center] Link to comment Share on other sites More sharing options...
LimeSeed Posted August 8, 2008 Author Share Posted August 8, 2008 i gocha! thanks! global $warming = true Link to comment Share on other sites More sharing options...
LimeSeed Posted August 8, 2008 Author Share Posted August 8, 2008 just wondering if it would be any easier if i used guictrlcreategraphic and then set it to a 180 degree pie radius? global $warming = true Link to comment Share on other sites More sharing options...
LimeSeed Posted August 8, 2008 Author Share Posted August 8, 2008 wouldnt that make it easier since there is no external image needed? global $warming = true Link to comment Share on other sites More sharing options...
Vindicator209 Posted August 8, 2008 Share Posted August 8, 2008 sure, you can use whatever you want, as long as it's still a control [center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center] Link to comment Share on other sites More sharing options...
Adam1213 Posted November 19, 2008 Share Posted November 19, 2008 (edited) just wondering if it would be any easier if i used guictrlcreategraphic and then set it to a 180 degree pie radius? You can detect the collision by measuring the distance between the two circles using the coordinates of the centres using distance=sqrt( (x2-x1)^2 + (y2-y1)^2) If the distance is equal to (or less than) the sum of the radius of both circles than a collision has occurred. - In your case one of the objects is a semicircle (so you don't have the bottom of this circle). So if the vertical coordinate of the circle [y1] is less than that of the semicircle [y2] then you should use distance_x=abs(x2-x1) - in a collision this will be equal to (or less than) the sum of the radii of both circles distance_y=y2-y1 - in a collision this will be equal to (or less than) the radius of the circle [no need for the absolute value because this method is only used when the conditions are met (the circle is below the semicircle, y1<y2)] For a collision both the horizontal and vertical conditions must be satisfied (If you are using a coordinate system where the y values get smaller as you go up you need to change the calculations and conditions around [or just swap y1 for y2]. Your current code that you have posted Slime Volleyball, Slime Volleyball with collision detection! does not appear to handle the part where the ball is below the slime that well. However it can handle when the ball is above the slime (with a few issues) Edited November 19, 2008 by Adam1213 IRC Client - 75 pages 3728 lines. Blob crumbler (game)Backup (drag to backup + cmd line)RS232 Link to comment Share on other sites More sharing options...
LimeSeed Posted November 20, 2008 Author Share Posted November 20, 2008 You can detect the collision by measuring the distance between the two circles using the coordinates of the centres using distance=sqrt( (x2-x1)^2 + (y2-y1)^2) If the distance is equal to (or less than) the sum of the radius of both circles than a collision has occurred. - In your case one of the objects is a semicircle (so you don't have the bottom of this circle). So if the vertical coordinate of the circle [y1] is less than that of the semicircle [y2] then you should use distance_x=abs(x2-x1) - in a collision this will be equal to (or less than) the sum of the radii of both circles distance_y=y2-y1 - in a collision this will be equal to (or less than) the radius of the circle [no need for the absolute value because this method is only used when the conditions are met (the circle is below the semicircle, y1<y2)] For a collision both the horizontal and vertical conditions must be satisfied (If you are using a coordinate system where the y values get smaller as you go up you need to change the calculations and conditions around [or just swap y1 for y2]. Your current code that you have posted Slime Volleyball, Slime Volleyball with collision detection! does not appear to handle the part where the ball is below the slime that well. However it can handle when the ball is above the slime (with a few issues)lol yea! im trying to make it better, and making some progress though! global $warming = true Link to comment Share on other sites More sharing options...
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