Computer Science Canada my friends snake- sort of :P |
Author: | Wajih [ Sun Jan 30, 2011 8:05 pm ] |
Post subject: | my friends snake- sort of :P |
this is my friends richards program. it is snake but with a twist! [/b]This is not mine, and i am not taking credit for it! %Author: Richard Nguyen %Date: Jan 7, 2010 %File: Snake.beta %Version: 1.0 %Description: This is a fun version of the classic game, SNAKE! setscreen ("graphics:max;max,nobuttonbar") var snakex : int := 10 var snakey : int := 10 var snakex2 : int := 20 var snakey2 : int := 20 var direction : int := 5 var boundx : int := 0 var boundy : int := 0 var boundx2 : int := maxx var boundy2 : int := maxy var fruitx : int := Rand.Int (8, maxx - 8) var fruity : int := Rand.Int (8, maxy - 8) const fruitsize : int := 7 var rockx : int := Rand.Int (11, maxx - 11) var rocky : int := Rand.Int (11, maxy - 11) var rockx2 : int := Rand.Int (11, maxx - 11) var rocky2 : int := Rand.Int (11, maxy - 11) var rockx3 : int := Rand.Int (11, maxx - 11) var rocky3 : int := Rand.Int (11, maxy - 11) var rockx4 : int := Rand.Int (11, maxx - 11) var rocky4 : int := Rand.Int (11, maxy - 11) var rockx5 : int := Rand.Int (11, maxx - 11) var rocky5 : int := Rand.Int (11, maxy - 11) var rockx6 : int := Rand.Int (11, maxx - 11) var rocky6 : int := Rand.Int (11, maxy - 11) var rockx7 : int := Rand.Int (11, maxx - 11) var rocky7 : int := Rand.Int (11, maxy - 11) var rockx8 : int := Rand.Int (11, maxx - 11) var rocky8 : int := Rand.Int (11, maxy - 11) var rockx9 : int := Rand.Int (11, maxx - 11) var rocky9 : int := Rand.Int (11, maxy - 11) var rockx10 : int := Rand.Int (11, maxx - 11) var rocky10 : int := Rand.Int (11, maxy - 11) var rockx11 : int := Rand.Int (11, maxx - 11) var rocky11 : int := Rand.Int (11, maxy - 11) var rockx12 : int := Rand.Int (11, maxx - 11) var rocky12 : int := Rand.Int (11, maxy - 11) var rockx13 : int := Rand.Int (11, maxx - 11) var rocky13 : int := Rand.Int (11, maxy - 11) var rockx14 : int := Rand.Int (11, maxx - 11) var rocky14 : int := Rand.Int (11, maxy - 11) var rockx15 : int := Rand.Int (11, maxx - 11) var rocky15 : int := Rand.Int (11, maxy - 11) const rocksize : int := 10 var score : int := 0 var gameover : int := 0 locate (19, 54) put "INSTRUCTIONS XD" .. locate (20, 33) put "The object of this game is to eat as many fruits as you can" .. locate (21, 32) put "The red circles are fruits, the light-green circles are rocks" .. locate (22, 42) put "Press the right or up arrow key to begin" .. loop %Creates the first fruit drawfilloval (fruitx, fruity, fruitsize, fruitsize, brightred) %Creates the score indicator locate (1, 118) Text.Color (white) put "Score: ", score .. %Waits for key input var ch : char if hasch then %Creates the black background colorback (black) %Creates the snake drawfillbox (snakex, snakey, snakex2, snakey2, white) ch := getchar %These are the controls for the snake (arrow keys) %Up key if ord (ch) = 200 then direction := 1 end if %Down key if ord (ch) = 208 then direction := 2 end if %Right key if ord (ch) = 205 then direction := 3 end if %Left key if ord (ch) = 203 then direction := 4 end if end if %Controls the snake with the arrow keys if (direction = 1) then drawfillbox (snakex, snakey, snakex2, snakey2, white) delay (10) snakey := snakey + 5 snakey2 := snakey2 + 5 cls elsif (direction = 2) then drawfillbox (snakex, snakey, snakex2, snakey2, white) delay (10) snakey := snakey - 5 snakey2 := snakey2 - 5 cls elsif (direction = 3) then drawfillbox (snakex, snakey, snakex2, snakey2, white) delay (10) snakex := snakex + 5 snakex2 := snakex2 + 5 cls elsif (direction) = 4 then drawfillbox (snakex, snakey, snakex2, snakey2, white) delay (10) snakex := snakex - 5 snakex2 := snakex2 - 5 cls end if %Creates Boundaries drawbox (boundx, boundy, boundx2, boundy2, black) if snakex < boundx then direction := 0 gameover := 1 elsif snakex2 > boundx2 then direction := 0 gameover := 1 elsif snakey < boundy then direction := 0 gameover := 1 elsif snakey2 > boundy2 then direction := 0 gameover := 1 end if %When the snake eats the fruit, the fruit will relocate itself if (fruitx > snakex - fruitsize) and (fruitx < snakex2 + fruitsize) and (fruity > snakey - fruitsize) and (fruity < snakey2 + fruitsize) then fruitx := Rand.Int (8, maxx - 8) fruity := Rand.Int (8, maxy - 8) score := score + 1 end if %Randomly draws rocks when the player gets one more point if score >= 1 then drawfilloval (rockx, rocky, rocksize, rocksize, brown) end if if score >= 2 then drawfilloval (rockx2, rocky2, rocksize, rocksize, brown) end if if score >= 3 then drawfilloval (rockx3, rocky3, rocksize, rocksize, brown) end if if score >= 4 then drawfilloval (rockx4, rocky4, rocksize, rocksize, brown) end if if score >= 5 then drawfilloval (rockx5, rocky5, rocksize, rocksize, brown) end if if score >= 6 then drawfilloval (rockx6, rocky6, rocksize, rocksize, brown) end if if score >= 7 then drawfilloval (rockx7, rocky7, rocksize, rocksize, brown) end if if score >= 8 then drawfilloval (rockx8, rocky8, rocksize, rocksize, brown) end if if score >= 9 then drawfilloval (rockx9, rocky9, rocksize, rocksize, brown) end if if score >= 10 then drawfilloval (rockx10, rocky10, rocksize, rocksize, brown) end if if score >= 11 then drawfilloval (rockx11, rocky11, rocksize, rocksize, brown) end if if score >= 12 then drawfilloval (rockx12, rocky12, rocksize, rocksize, brown) end if if score >= 13 then drawfilloval (rockx13, rocky13, rocksize, rocksize, brown) end if if score >= 14 then drawfilloval (rockx14, rocky14, rocksize, rocksize, brown) end if if score >= 15 then drawfilloval (rockx15, rocky15, rocksize, rocksize, brown) end if %When the snake eats a rock, it will send out 2 commands %One will end the game, the other displays game over messages if (rockx > snakex - rocksize) and (rockx < snakex2 + rocksize) and (rocky > snakey - rocksize) and (rocky < snakey2 + rocksize) then direction := 0 gameover := 1 elsif (rockx2 > snakex - rocksize) and (rockx2 < snakex2 + rocksize) and (rocky2 > snakey - rocksize) and (rocky2 < snakey2 + rocksize) and (score >= 2) then direction := 0 gameover := 1 elsif (rockx3 > snakex - rocksize) and (rockx3 < snakex2 + rocksize) and (rocky3 > snakey - rocksize) and (rocky3 < snakey2 + rocksize) and (score >= 3) then direction := 0 gameover := 1 elsif (rockx4 > snakex - rocksize) and (rockx4 < snakex2 + rocksize) and (rocky4 > snakey - rocksize) and (rocky4 < snakey2 + rocksize) and (score >= 4) then direction := 0 gameover := 1 elsif (rockx5 > snakex - rocksize) and (rockx5 < snakex2 + rocksize) and (rocky5 > snakey - rocksize) and (rocky5 < snakey2 + rocksize) and (score >= 5) then direction := 0 gameover := 1 elsif (rockx6 > snakex - rocksize) and (rockx6 < snakex2 + rocksize) and (rocky6 > snakey - rocksize) and (rocky6 < snakey2 + rocksize) and (score >= 6) then direction := 0 gameover := 1 elsif (rockx7 > snakex - rocksize) and (rockx7 < snakex2 + rocksize) and (rocky7 > snakey - rocksize) and (rocky7 < snakey2 + rocksize) and (score >= 7) then direction := 0 gameover := 1 elsif (rockx8 > snakex - rocksize) and (rockx8 < snakex2 + rocksize) and (rocky8 > snakey - rocksize) and (rocky8 < snakey2 + rocksize) and (score >= 8) then direction := 0 gameover := 1 elsif (rockx9 > snakex - rocksize) and (rockx9 < snakex2 + rocksize) and (rocky9 > snakey - rocksize) and (rocky9 < snakey2 + rocksize) and (score >= 9) then direction := 0 gameover := 1 elsif (rockx10 > snakex - rocksize) and (rockx10 < snakex2 + rocksize) and (rocky10 > snakey - rocksize) and (rocky10 < snakey2 + rocksize) and (score >= 10) then direction := 0 gameover := 1 elsif (rockx11 > snakex - rocksize) and (rockx11 < snakex2 + rocksize) and (rocky11 > snakey - rocksize) and (rocky11 < snakey2 + rocksize) and (score >= 11) then direction := 0 gameover := 1 elsif (rockx12 > snakex - rocksize) and (rockx12 < snakex2 + rocksize) and (rocky12 > snakey - rocksize) and (rocky12 < snakey2 + rocksize) and (score >= 12) then direction := 0 gameover := 1 elsif (rockx13 > snakex - rocksize) and (rockx13 < snakex2 + rocksize) and (rocky13 > snakey - rocksize) and (rocky13 < snakey2 + rocksize) and (score >= 13) then direction := 0 gameover := 1 elsif (rockx14 > snakex - rocksize) and (rockx14 < snakex2 + rocksize) and (rocky14 > snakey - rocksize) and (rocky14 < snakey2 + rocksize) and (score >= 14) then direction := 0 gameover := 1 elsif (rockx15 > snakex - rocksize) and (rockx15 < snakex2 + rocksize) and (rocky15 > snakey - rocksize) and (rocky15 < snakey2 + rocksize) and (score >= 15) then direction := 0 gameover := 1 end if %If the snake hits a wall or eats a rock, gameover will = 1 %When gameover = 1 then the 2 messages will appear if gameover = 1 then Text.Color (white) locate (20, 42) put "Game Over" locate (21, 42) put "Your score was ", score locate (22, 42) put "If you want to try again," locate (23, 42) put "Close the window and run the program again" end if %When the snake eats a rock or hits a wall, the direction variable will = 0 %When direction=0, the whole program stops exit when direction = 0 end loop he told me to submit it |
Author: | Wajih [ Sun Jan 30, 2011 8:07 pm ] |
Post subject: | RE:my friends snake- sort of :P |
There are 2 glitches so far : The flickr : you cannot fix it because out teacher said it's a bug in turing and sometimes the fruit will sometimes relocate itself in a rock. -_- |
Author: | DemonWasp [ Sun Jan 30, 2011 8:27 pm ] |
Post subject: | RE:my friends snake- sort of :P |
You can fix flickering trivially in Turing. Either look up View.Update() or search the Turing Help forum here for "flicker", because this is a problem that gets asked about here approximately 3 times a week. You could even look at the Turing Walkthrough under the Turing Tutorials section and find the bit about "eliminating flicker". It's not a bug in Turing, it's a bug in this program. |
Author: | Wajih [ Sun Jan 30, 2011 8:33 pm ] |
Post subject: | RE:my friends snake- sort of :P |
no see, he tried that view.update, view.set offscreenonly just about evrywhere, and it flickered more, so he just took it out. |
Author: | DemonWasp [ Mon Jan 31, 2011 1:25 am ] |
Post subject: | RE:my friends snake- sort of :P |
Then clearly he was doing it wrong. Have him go read the tutorials: it is possible to animate anything without flicker in Turing*. * This doesn't mean that some things won't render slowly/infrequently, it just means it won't flicker. |
Author: | Raknarg [ Wed Feb 16, 2011 10:00 pm ] |
Post subject: | Re: my friends snake- sort of :P |
So the issue here i think for the flicker is your coding. You have to use setscreen ( "offscreenonly" ) and then View.Update. Just in case, if you use View.Update after a cls and a draw statement, you'll have a similar problem. Just use it after you draw the snake and stuff. |
Author: | mirhagk [ Thu Feb 17, 2011 8:53 am ] |
Post subject: | RE:my friends snake- sort of :P |
Here's a secret, struture your loop like this loop logic for controlling things, etc all non drawing updates draw everything ALL AT ONCE View.Update Time.DelaySinceLast() like a regular delay but it delays since the last call to delay (ie if you set the time.delaysincelast to 10, and your loop took 3 milli seconds, it waits 7) then cls end loop |
Author: | Offroadrider [ Fri Apr 01, 2011 4:10 pm ] |
Post subject: | Re: my friends snake- sort of :P |
I think I know how to fix the flickering. write View.Set ("offscreenonly") after your drawfill.... then write View.Update after your drawfill.... Hope this helps! |
Author: | Raknarg [ Fri Apr 01, 2011 4:29 pm ] |
Post subject: | RE:my friends snake- sort of :P |
Thanks for the input, but for future reference, try not to necropost |