Computer Science Canada reset |
Author: | yodu123 [ Fri Jun 05, 2009 11:10 pm ] |
Post subject: | reset |
i want to have a reset button but i don`t know how to do it this is my code drawfillbox (0, 0, 700, 700, 255) colorback (255) color (85) locatexy (100, 200) put "LEVEL ONE" locatexy (250, 200) put "LEVEL TWO" locatexy (400, 200) put "LEVEL THREE" locatexy (70, 20) put "HELP" locatexy (490, 20) put "HIGH SCORE" var done : boolean := false var x, y, z : int := 0 var level1, level2, level3 : boolean := false function ptinrect (h, v, x1, v1, x2, v2 : int) : boolean result (h > x1) and (h < x2) and (v > v1) and (v < v2) end ptinrect drawbox (80, 180, 200, 210, 85) drawbox (230, 180, 350, 210, 85) drawbox (380, 180, 500, 210, 85) drawbox (50, 10, 110, 40, 85) drawbox (480, 10, 570, 40, 85) loop buttonwait ("down", x, y, z, z) if ptinrect (x, y, 80, 180, 200, 210) then level1 := true exit end if if ptinrect (x, y, 230, 180, 350, 210) then level2 := true exit end if if ptinrect (x, y, 380, 180, 500, 210) then level3 := true exit end if end loop var carname : string var time1 : int var xPos : real var yPos : real var velocity : real := 0 var turnVelocity : real := 0 var angle : real := 0 var collcol1, collcol2, collcol3 : int var backname : string if level1 = true then include "level 1.t" drawfillbox (400, 25, 430, 150, 75) end if if level2 = true then include "level 2.t" end if if level3 = true then angle := 45 include "level 3.t" end if var car := Pic.FileNew (carname) var carXMid : int := Pic.Width (car) div 2 var carYMid : int := Pic.Height (car) div 2 var back := Pic.FileNew (backname) proc updateVelocities var keys : array char of boolean Input.KeyDown (keys) if keys (chr (32)) then locatexy (200, 100) put "pause" Input.Pause end if if keys (KEY_UP_ARROW) then velocity += 0.03 end if if keys (KEY_DOWN_ARROW) then velocity -= 0.03 end if if keys (KEY_LEFT_ARROW) then turnVelocity += 0.1 Input.Flush end if if keys (KEY_RIGHT_ARROW) then turnVelocity -= 0.1 Input.Flush end if end updateVelocities proc updatePositions angle := (angle + turnVelocity) mod 360 xPos += cosd (angle) * velocity yPos += sind (angle) * velocity velocity *= 0.99 turnVelocity *= .99 end updatePositions proc drawBackground drawfillbox (0, 0, 750, 650, 255) Pic.Draw (back, 10, 10, picCopy) end drawBackground proc drawCar var rotatedCarPic : int := Pic.Rotate (car, round (angle), carXMid, carYMid) if whatdotcolor (round (xPos) - carXMid + 25, round (yPos) - carYMid + 15) = collcol1 then Music.PlayFile ("car sound 2.wav") velocity := 0 turnVelocity := 0 end if if whatdotcolor (round (xPos) - carXMid + 25, round (yPos) - carYMid + 15) = collcol2 then Music.PlayFile ("car sound 2.wav") velocity := 0 turnVelocity := 0 end if if whatdotcolor (round (xPos) - carXMid + 25, round (yPos) - carYMid + 15) = collcol3 then Music.PlayFile ("car sound 2.wav") velocity := 0 turnVelocity := 0 end if if whatdotcolor (round (xPos) - carXMid + 55, round (yPos) - carYMid + 40) = collcol1 then Music.PlayFile ("car sound 2.wav") velocity := 0 turnVelocity := 0 end if if whatdotcolor (round (xPos) - carXMid + 55, round (yPos) - carYMid + 40) = collcol2 then Music.PlayFile ("car sound 2.wav") velocity := 0 turnVelocity := 0 end if if whatdotcolor (round (xPos) - carXMid + 55, round (yPos) - carYMid + 40) = collcol3 then Music.PlayFile ("car sound 2.wav") velocity := 0 turnVelocity := 0 end if Pic.Draw (rotatedCarPic, round (xPos) - carXMid, round (yPos) - carYMid, picMerge) drawfilloval (round (xPos) - carXMid + 25, round (yPos) - carYMid + 15, 2, 2, 0) drawfilloval (round (xPos) - carXMid + 55, round (yPos) - carYMid + 40, 2, 2, 0) Pic.Free (rotatedCarPic) end drawCar proc drawInfo put "X position: ", xPos : 0 : 2, " px" put "time: ", time1 div 1000 : 0 : 2, " sec" put "Y position: ", yPos : 0 : 2, " px" put "Speed: ", velocity * 10 : 0 : 2, " px/s" put "Angle: ", angle : 0 : 2, "?" put "Turning velocity: ", turnVelocity * 20 : 0 : 2, "?/s" end drawInfo loop time1 := Time.Elapsed updateVelocities updatePositions drawBackground drawInfo drawCar View.Update Draw.Cls end loop |
Author: | Kharybdis [ Sat Jun 06, 2009 9:31 am ] |
Post subject: | RE:reset |
Can you put your level files in a zip folder? I cannot run your program as those files are not included. Thanks. However, just looking into your code, anytime the reset button is clicked, assign all of your car positions to the initial value. If you don't have an initial value, just make one up. I think that's what you mean by having a reset button.. but... I can help you more if you include the level files. |
Author: | tjmoore1993 [ Sat Jun 06, 2009 11:40 am ] |
Post subject: | RE:reset |
What Kharybdis stated was reseting the values to initial point which means starting value. If you have a constant point of lets say 0? Then your better off defining it as a constant then continuing from there. Good luck. |