Computer Science Canada How can I make The character eat an object |
Author: | turing1094 [ Thu Jun 10, 2010 3:29 pm ] | ||
Post subject: | How can I make The character eat an object | ||
What is it you are trying to achieve? I want to get the star to eat the dots that pop up randomly. As the star eats the dots the score should go up by 20 points What is the problem you are having? I cant get the star to eat dots that pop up randomly Describe what you have tried to solve this problem Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) % These are some variables that need to be declared to make the game work correctly var chars : array char of boolean var x1 : int := 1 % This is the position of the object (x1) var x2 : int := x1 + 10 % This is the position of the object (x2) var y1 : int := 1 % This is the position of the object (y1) var y2 : int := y1 + 10 % This variable represents the position of the object (y2) var xv : real := 0 % This variable is the speed for the objects var yv : real := 0 % This variable is the y value speed var g : real := 1 % This is the gravity var ground : boolean := true % This variable checks to see if the object is on the ground var count : int := 0 var speed : int var level : int % This step is the variable for picking your difficulty var foodx : int := 325 var foody : int := 205 var delayinterval : int put "What difficulty would you like to play on" get level if level = 1 then % This will put you in level 1 if you choose delayinterval := 20 % This step is the the speed of the star(character) will be moving at elsif level = 2 then % This will put you in level 2 if you choose it delayinterval := 10 % This step will set the speed of the star(character) a little faster elsif level = 3 then % This will put you in level 3 if you choose delayinterval := 5 % This will set the star to move very fast. This is the hardest difficulty. end if setscreen ("graphics:650;650,offscreenonly") var font19 := Font.New ("Algerian:20") % This step sets the font for the text var text19 := "Please Help" % This step enters text into the menu var width19 := Font.Width (text19, font19) % This step sets the width var font := Font.New ("Wide Latin:30") % This step sets the font for the text var text := "Food Frenzy!!!" % This step enters the text into the menu var width := Font.Width (text, font) var font2 := Font.New ("Algerian:30") % This step sets the font for the text var text2 := "CLICK TO CONTINUE!" % This step enters text into the menu var width2 := Font.Width (text2, font2) var x, y, button : int drawfillbox (0, 0, maxx, maxy div 2, 42) % This is needed to display all the text for the menu Font.Draw (text, round (maxx / 2 - width / 2), maxy div 2, font, red) Font.Draw (text2, round (maxx / 4 - width2 / 4), maxy div 4, font2, red) Font.Draw (text19, round (maxx / 6 - width19 / 6), maxy div 6, font19, red) % This step lets the mouse be active in the menu loop Mouse.Where (x, y, button) if button = 1 then delay (200) cls exit when button = 1 end if end loop loop Input.KeyDown (chars) % This gives a value to the game of the keys being pressed if chars (KEY_UP_ARROW) and y2 < maxy and ground = true then % These two lines are saying if the Up Arrow is pressed and the player is not touching the ground then make the star jump yv += 12 end if if chars (KEY_LEFT_ARROW) and x1 > 0 then % These two lines are saying if the left arrow is pressed then substract 1 from the xSpeed causing the object to move left xv -= 1 elsif chars (KEY_RIGHT_ARROW) and x2 < maxx then % These two lines are saying if the right arrow is pressed then, add to the xSpeed casuing the player to move right xv += 1 elsif chars (KEY_ESC) then % This step will end the program exit end if if y1 > 0 then % These two lines are syaing if the player is not touching the ground then subtract the speed until the player moves down yv -= g % The next three lines make sure that the box does not go below the screen elsif y1 < 0 then yv := 0 y1 := 0 end if % The next three lines slow down the box when moving if xv > 0 then xv -= 0.5 elsif xv < 0 then % The next five lines makes sure the box does not go off the left side of the screen and if it does moves it to the edge and stop it xv += 0.5 end if if x1 < 0 then x1 := 0 xv := 0 % The next 5 lines do the same thing as the left side but for the right elsif x2 > maxx then x1 := maxx - 10 xv := 0 % Stop the player end if % This again does the same thing but for the top of the screen if y2 > maxy then y1 := maxy - 10 yv := 0 % Stop the player end if % The next few lines allow the player to jump if y1 = 0 then ground := true % Allows the jump else ground := false % Player cannot junp end if % The next steps creat movement and the size of the player x1 += round (xv) y1 += round (yv) x2 := x1 + 20 y2 := y1 + 20 drawfilloval (foodx, foody, 5, 5, brightred) if whatdotcolor (foodx, foody) not= brightred then count := count + 1 randint (foodx, 1, maxx) randint (foody, 1, maxy) end if % The next two lines make the player Draw.FillStar (x1, y1, x2, y2, black) Draw.Star (x1 - 1, y1 - 1, x2 + 1, y2 + 1, grey) locate (1, 1) View.Update % Brings the player to the screen delay (delayinterval) cls %erases everything on the screen end loop
Please specify what version of Turing you are using <Answer Here> |
Author: | Unnamed.t [ Thu Jun 10, 2010 3:36 pm ] |
Post subject: | Re: How can I make The character eat an object |
I think what you can use is the Math.Distance command. Look into it on the Turing Reference (F10) Math.Distance. |
Author: | musicman [ Thu Jun 10, 2010 4:52 pm ] | ||
Post subject: | Re: How can I make The character eat an object | ||
or you can use the whatdotcolour command and then erase whatever it is that you are trying to have your character eat. heres the code for the whatdotcolour command:
ps. please use syntax tags: <syntax="turing"]<CODE GOES HERE>[/syntax]> |
Author: | Tony [ Fri Jun 11, 2010 12:11 pm ] |
Post subject: | RE:How can I make The character eat an object |
But if the character overlaps the object it is trying to eat, then you can no longer check for that colour. You are just checking if there is anything blue at a fixed point ahead -- Math.Distance does just this. |
Author: | Cezna [ Fri Jun 11, 2010 3:02 pm ] |
Post subject: | RE:How can I make The character eat an object |
Math.Distance will also help in moving you're character towards the dots, and possibly doing something like accelerating towards it. whatdotcolour will not tell you much, as you will have to check the colour of every dot within a certain radius of the star, whereas using Math.Distance will allow you to move towards a dot with assigned co-ordinates. Also, Math.Distance will allow you to have dots of all different colours, whereas whatdotcolour will restrict your use of colours for the dots and the star and the background, and anything else you include in the program. |