Computer Science Canada collision detection and movement questions |
Author: | alexcaz [ Mon Jan 22, 2007 8:37 pm ] |
Post subject: | collision detection and movement questions |
Here is my Code, sorry about the loading screen, its not mine i'll get it changed as soon as i can. import GUI Music.PlayFileLoop ("H:/Game/maintheme.mp3") const screenWidth : int := Config.Display (cdScreenWidth) const screenHeight : int := Config.Display (cdScreenHeight) var windowID : int := 0 var helpg := Pic.FileNew ("controls.jpg") var helpg2 := Pic.FileNew ("keyboard.jpg") var backg := Pic.FileNew ("Beach.jpg") var mblt1 := Pic.FileNew ("H:/Game/mblt1.jpg") var mblt2 := Pic.FileNew ("H:/Game/mblt2.jpg") var mblt3 := Pic.FileNew ("H:/Game/mblt3.jpg") var beach := Pic.FileNew ("beach3large.jpg") var ammo := Pic.FileNew ("ammo.jpg") var shield := Pic.FileNew ("health.jpg") var gun2 := Pic.FileNew ("machinegun.jpg") var gun := Pic.FileNew ("mgun.jpg") var soldi : array 0 .. 25 of int soldi (0) := Pic.FileNew ("soldierss.jpg") var x1, y1, button1 : int := 0 var x2, y2 : int := 0 var x4, y4, x3, y3, button2 : int proc cross drawoval (325, 300, 8, 8, brightgreen) drawline (317, 300, 334, 300, brightgreen) drawline (325, 292, 325, 308, brightgreen) drawdot (325, 300, brightred) end cross proc backgrounds Pic.SetTransparentColor (gun, 0) x1 := x1 - 1500 y1 := y1 - 800 Pic.Draw (shield, 20, 500, picMerge) Pic.Draw (ammo, 20, 20, picMerge) cross View.Update end backgrounds var ht : int := 75 procedure mblts loop delay (100) Pic.Draw (mblt1, 650, ht, picMerge) delay (300) Pic.Draw (mblt2, 685, ht + 25, picMerge) delay (300) Pic.Draw (mblt3, 620, ht - 5, picMerge) View.Update delay (150) exit end loop end mblts proc maingame View.Set ("graphics:max;max,position:center;center,offscreenonly,noecho") loop View.Update Mouse.Where (x4, y4, button2) x3 := x4 y3 := y4 loop View.Update Pic.Draw (beach, -x3 - 300, -y3 - 180, picCopy) Pic.Draw (gun, 350, -50, picMerge) exit end loop View.Update Mouse.Where (x1, y1, button1) x2 := x2 + 0 y2 := y2 - 1 backgrounds Pic.Draw (soldi (0), x1 - 1500, y1 - 800, 3) if button1 = 1 then loop delay (100) Pic.Draw (mblt1, 700, 85, 2) View.Update delay (100) Pic.Draw (mblt2, 735, 110, 2) View.Update delay (100) Pic.Draw (mblt3, 780, 105, 2) View.Update delay (75) delay (10) View.Update exit end loop else delay (20) View.Update end if end loop end maingame var x, y, button : int windowID := Window.Open ("title:Window #" + intstr (0) + ",graphics:" + intstr (150) + ";" + intstr (100) + ",position:" + intstr (50) + ";" + intstr (50)) setscreen ("graphics:640;480,offscreenonly,position:center;center") loop var quitButton : int := GUI.CreateButton (530, 450, 0, "EXIT GAME", GUI.Quit) Pic.Draw (backg, 0, 0, 0) View.Update loop Mouse.Where (x, y, button) if button = 1 and x >= 288 and x <= 353 and y >= 21 and y <= 45 then cls var zz : int := 1 for i : 1 .. 100 delay (50) Draw.FillBox (100, 15, 100 + zz, 25, 54) Draw.Box (100, 15, 200, 25, 1) zz := zz + 1 locate (23, 13) View.Update put "Loading... ", zz, "%" .. end for locate (23, 13) put "Done Loading! " .. View.Update delay (500) colorback (white) delay (300) Music.PlayFileStop cls Pic.Draw (beach, 750, 630, 0) loop Mouse.Where (x1, y1, button1) maingame View.Update delay (20) end loop exit elsif button = 1 and x >= 424 and x <= 483 and y >= 22 and y <= 43 then Pic.Draw (helpg, 0, 0, 0) View.Update loop loop Mouse.Where (x, y, button) if button = 1 and x >= 458 and y >= 55 and x <= 516 and y <= 76 then Pic.Draw (helpg2, 0, 0, 0) View.Update loop Mouse.Where (x, y, button) if button = 1 and x >= 106 and y >= 55 and y <= 77 and x <= 163 then Pic.Draw (helpg, 0, 0, 0) View.Update exit end if end loop elsif button = 1 and x >= 548 and x <= 605 and y >= 455 and y <= 480 then exit elsif button = 1 and x >= 106 and y >= 55 and y <= 77 and x <= 163 then Pic.Draw (backg, 0, 0, 0) View.Update exit end if exit when button = 1 and x >= 106 and y >= 55 and y <= 77 and x <= 163 end loop Pic.Draw (backg, 0, 0, 0) exit end loop View.Update elsif button = 1 and x >= 548 and x <= 605 and y >= 455 and y <= 480 then exit end if end loop exit end loop loop exit when GUI.ProcessEvent end loop if windowID not= 0 then GUI.CloseWindow (windowID) end if GUI.CloseWindow (windowID) Yes i know its a really cheap way of doing 3d, but.. would anyone explain to me how to do the collision detection if i was to have soldiers popping out and you have to shoot them?? especially how you get your crosshair to be exactly under your mouse but still be like in the middle,and when you move your mouse to the sides the background follows. plz help me people. the files and the pictues are attached[/list] |
Author: | Ultrahex [ Tue Jan 23, 2007 4:56 pm ] |
Post subject: | Re: collision detection and movement questions |
basically you would have to check whether or not the unit is under the crosshair(either within a square of the screen or square of area. and you cannot control the mouse cursor position in windows with turing without some massive programming job; maybe so then... i really wouldn't recommend it. |
Author: | alexcaz [ Tue Jan 23, 2007 5:26 pm ] |
Post subject: | Re: collision detection and movement questions |
umm would you be able to explain the "major programming"???, or an alternative? and can anyone explain the detection program?? and if anyone does have a solution can you please reply asap?? i need like tomorrow |