Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Uncle Worm
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mr. T




PostPosted: Sun Mar 27, 2005 9:51 pm   Post subject: Uncle Worm

Three Problems:
1. flickering..(where should i put the View.Updates)
2. food gets deleted after 1 second (i know that this problem can be fixed by taking out the cls, but then my snake just keeps on growing)
3. when you hit the wall...the deathRing procedure should start...but instead, for some reason it jumps to the next level segment
----------------------------------
suggestions/solutions are greatly appreciated
----------------------------------

code:

%variable declaration
View.Set ("graphics:500;400,title:Uncle Worm           Score: 0,nocursor")
var foodx, foody, foodSize : int %food variables
var makeFood : boolean := true %when food boolean is true, food is drawn
var boxx : int := 0 %variable for box surrounding the screen
var boxy : int := 0 %variable for box surrounding the screen
var countdown : int := 5
var snakesize : int := 5
var move, move2, move3, move4 := false
var key : array char of boolean
var ring : int := 0
var answer : string
move3 := true %starting direction of snake
var newMaxX : int := 500 %innitial screen dimensions (x co-ords)
var newMaxY : int := 400 %innitial screen dimensions (y co-ords)
var levelUpX : int := 50 %decrease in screen dimensions (x co-ords) upon completion of level
var levelUpY : int := 40 %decrease in screen dimensions (y co-ords) upon completion of level
var scoreLevel : int := 50
var score : int := 0 %score
var exitFont : int
exitFont := Font.New ("arial:14")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
type snakeDat :
    record
        x : int
        y : int
    end record

var snake : flexible array 1 .. 2 of snakeDat


snake (1).x := maxx div 2
snake (1).y := maxy div 2
snake (2).x := (maxx div 2) - 10
snake (2).y := maxy div 2
%%%%%%%%%
% START %
%%%%%%%%%
colour (0)
colourback (7)
cls




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%gives time for user to get ready
loop
    locate (12, 25) %locates the count down test
    put "Starting in...", countdown  %starts the countdown
    delay (300) %delay between each consecutive decreasing number
    countdown := countdown - 1 %decreasing increments
    cls %erases the countdown text when countdown reaches 0
    exit when countdown = 0 %game begins when countdown hits 0
end loop


%creates food in random locations
procedure food
    if makeFood then %makeFood:=true
        randint (foodx, 1, newMaxX - 10) %random food location (but not in the walls)
        randint (foody, 1, newMaxY - 10) %random food location (but not in the walls)
        randint (foodSize, 2, 10) %random food size
        drawfilloval (foodx, foody, foodSize, foodSize, 2) %draws the food
    end if
end food

%point of contact upon death
procedure ringEnd
    loop
        drawoval (snake (1).x, snake (1).y, snakesize + ring, snakesize + ring, ring)  %ring expands around the ball at the point of collision
        ring += 2 %increments of the rings
        delay (10) %delay between each ring increment
        exit when ring = 100 %game ends when ring incremeent hits 100
    end loop
end ringEnd


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




%draws food
food


%snake movement
loop

    drawbox (boxx, newMaxY - 1, newMaxX - 1, boxy, 14)
    drawfilloval (snake (1).x, snake (1).y, snakesize, snakesize, 12)
        if move then
        snake (1).y += 10
    elsif move2 then
        snake (1).y -= 10
    elsif move3 then
        snake (1).x += 10
    elsif move4 then
        snake (1).x -= 10
    end if
   
    for decreasing i : upper (snake) .. 2 %set each of the snake's sections to equal the one before it
            snake (i) := snake (i - 1)
        end for
       
        delay (100)
       
    Input.KeyDown (key)
    if key (KEY_UP_ARROW) and move2 = false then %Two Conditions: 1. up arrow is pressed 2. move2 = false
        move2 := false
        move3 := false
        move4 := false
        move := true
    elsif key (KEY_DOWN_ARROW) and move = false then  %Two Conditions: 1. down arrow is pressed 2. move = false
        move := false
        move3 := false
        move4 := false
        move2 := true
    elsif key (KEY_RIGHT_ARROW) and move4 = false then %Two Conditions: 1. right arrow is pressed 2. move4 = false
        move := false
        move2 := false
        move4 := false
        move3 := true
    elsif key (KEY_LEFT_ARROW) and move3 = false then   %Two Conditions: 1. left arrow is pressed 2. move3 = false
        move := false
        move2 := false
        move3 := false
        move4 := true
    end if
cls
   for i : 1 .. upper (snake) %redraw snake
            Draw.FillOval (snake (i).x, snake (i).y, 5,  5, 12)
           
        end for
       
       
   

    %wall collision detection
    if snake (1).x = 4 or snake (1).x = maxx - 4 or snake (1).y = 4 or snake (1).y = maxy - 4 then   %collision detection to detect whether the ball has hit the walls
        View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score) + "             You Lose!") %if balls hits the wall, you lose!
        ringEnd %fancy death
        exit %game ends
    end if
   
 
   
 %food collision detection
    if score < scoreLevel   %additional check to make sure the level isnt completed
        and whatdotcolour (foodx + foodSize, foody + foodSize) = 12 or whatdotcolour (foodx - foodSize, foody - foodSize) = 12
                then
                new snake, upper (snake)+1
            score += 10 %when food collision detected points are added to score
            View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score)) %if food eaten, score added to total at the top of the screen
            snake (upper (snake)) := snake (upper (snake) - 1) %set new element's coordinates
            drawfilloval (foodx, foody, foodSize, foodSize, 7)  %so that no chunk of food is left behind
            food %continue to make food if its still the same level
            exit when whatdotcolour (foodx, foody) = 7 %make sure food is not drawn on the snake
            for i : 1 .. upper (snake) %redraw snake
            Draw.FillOval (snake (i).x, snake (i).y, 5,  5, 12)
        end for
                end if
       
 



    %NEXT LEVEL
    if score >= scoreLevel %ready to enter next level
        /*then drawfillbox ((maxx div 2) - 10, maxy, (maxx div 2) + 10, maxy - 5, 0)*/
            then
        Font.Draw ("EXIT", (maxx div 2) - 25, maxy - 20, exitFont, 0)    %level's exit point
        makeFood := false   %once exit appears, no more food is drawn
    end if

   
    if whatdotcolour (snake (1).x + snakesize, snake (1).y + snakesize) = 0 %if the snake reaches the exit (detects the WHITE(whatdotcolour) exit point)
            then
        cls      %clears the screen for the scoring updates

        %scoring system (after each completed level)
        put "Your score is: ", score %score with out additional time bonus
        var bonus : int := 60000 div 1000 %1 min to get bonus (bonus = 60000 milliseconds = 60 seconds =1 min)
        var timeBonus : int := bonus - Time.Elapsed div 1000 %1 min timer (Time.Elapsed = 1000 milliseconds = 1 min)
        put "Your time bonus is: ", timeBonus %time bonus
        score := score + timeBonus %updated score = score as of to that point + time bonus
        put "Your overall score is: ", score %score as of to that point + time bonus
        put "[press enter to continue to next round]" %gives the user time to read the score
        Input.Pause %waits for a button to be pressed before entering the next level
              /*getch (ch)
         if ch =(KEY_ENTER)
         then*/

        %variable reset
        newMaxX := newMaxX - levelUpX %updated screen dimensions = screen dimensions - 50
        newMaxY := newMaxY - levelUpY %updated screen dimensions = screen dimensions - 40
        View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score)) %displaying new screen dimensions and score
        new snake, 2 %set snake's length to 2
        snake (1).x := newMaxX div 2 %new x co-ords for the start of a new level
        snake (1).y := newMaxY div 2 %new y co-ords for the start of a new level
        colour (0) %reset the colour of any writing
        colourback (7) %reset the colour of the background
        cls %paints the background specified colour
        makeFood := true %makign it possible to draw food
        food %start redrawing food
          scoreLevel := score + 50 %next level will be completed after an additional 50 points

       
    end if



end loop

View.Update
Sponsor
Sponsor
Sponsor
sponsor
ssr




PostPosted: Sun Mar 27, 2005 11:09 pm   Post subject: (No subject)

I didnt fully read ur code
but I think View.Update is suppose to be right before cls
also I think a View.UpdatArea can solve the food problem
I donno we ll c
Mr. T




PostPosted: Sun Mar 27, 2005 11:22 pm   Post subject: (No subject)

nope, no luck
Naveg




PostPosted: Sun Mar 27, 2005 11:28 pm   Post subject: (No subject)

that cls is definitely a problem, try taking it out and finding another way to make the snake move on. A tracer maybe?
Mr. T




PostPosted: Sun Mar 27, 2005 11:31 pm   Post subject: (No subject)

elaborate.
Naveg




PostPosted: Sun Mar 27, 2005 11:32 pm   Post subject: (No subject)

make a circle the colour of the background follow the snake
Mr. T




PostPosted: Sun Mar 27, 2005 11:37 pm   Post subject: (No subject)

can u show me how i would do that, in my code.
RaPsCaLLioN




PostPosted: Sun Mar 27, 2005 11:56 pm   Post subject: (No subject)

Add..
code:
drawfilloval (foodx, foody, foodSize, foodSize, 2)


..just underneath line 133. Right where ur drawing the snake.

And don't randomly generate food size either.. hard to find where it lies on the grid. Set foodSize to '2' when u declare the variable.
As for flickering, I didn't see any. I think my computer's too fast.
Sponsor
Sponsor
Sponsor
sponsor
Mr. T




PostPosted: Sun Mar 27, 2005 11:59 pm   Post subject: (No subject)

thnx. that solves the food issue.
but i still have the problem where when u hit the wal...it should jump to the ringEnd procedure...but for some reason instead it goes to the next level segment.

(it still flickers for me)
RaPsCaLLioN




PostPosted: Mon Mar 28, 2005 12:08 am   Post subject: (No subject)

code:
    if snake (1).x <= 4 or snake (1).x >= maxx - 4 or snake (1).y <= 4 or snake (1).y >= maxy - 4 then   %collision detection to detect whether the ball has hit the walls
        View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score) + "             You Lose!") %if balls hits the wall, you lose!
        ringEnd  %fay death
        exit %game ends
    end if


You need to put in those < and > signs in there. Just incase the snake jumps over the 4.
Mr. T




PostPosted: Mon Mar 28, 2005 12:17 am   Post subject: (No subject)

your on a role lol.
im still having few other little bugs.
but i wanna take a stab at them by myself.
if i need anymore help, ill ask.
thnx Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: