
-----------------------------------
Ellerton
Wed Jan 23, 2013 5:03 pm

snake game counter help
-----------------------------------
What is it you are trying to achieve?



What is the problem you are having?



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)








Please specify what version of Turing you are using


-----------------------------------
Ellerton
Wed Jan 23, 2013 5:05 pm

RE:snake game counter help
-----------------------------------
cant get snake game counter to work

% Music
process DoMusic
    loop
        Music.PlayFile ("Halo Theme Song Dubstep.mp3")
        Music.PlayFile ("Super Mario DUBSTEP REMIX _HEAVY DROP_.mp3")
        Music.PlayFile ("Mortal Dubstep (Mortal Kombat Dubstep).mp3")
        Music.PlayFile ("legend of zelda dubstep.mp3")
    end loop
end DoMusic
fork DoMusic

% Main Game Starts Here


% Title Screen
procedure drawSnakeTitle (var x, y : int)
    var clr : int
    var clr2 : int
    var titleFont := Font.New ("Algerian:30:bold")
    loop
        randint (clr, 0, 111)
        exit when clr not= 7 or not (clr >= 16 and clr = 125 and x < 500 then
            x := 505
        end if
    end if
    if x = 50 then
        y := y + 10
    end if
    if x = 585 then
        y := y - 10
    end if
    if y = 70 and x > 565 then
        x := x + 10
    end if
    if x >= maxx then
        x := 0
    end if
    Mouse.Where (mousex, mousey, button)
    if (mousex > 200 and mousex < 444 and mousey > 120 and mousey < 160 and button = 1) then
        exit
    elsif (mousex > 200 and mousex < 340 and mousey > 65 and mousey < 105 and button = 1) then
        quit 
    end if
end loop
cls

% Game Background
drawfillbox (maxx, maxy, 0, 0, white)
colorback (white)
color (black)

% Snake Movement and Food
var counter : int
counter := 0
var score : int
var add : boolean := false
var losingFont := Font.New ("Algerian:30:bold")
var food1, food2 : int
var xdirec : int
var ydirec : int
xdirec := 10
ydirec := 0
var move : array char of boolean
var segments : int := 3
var snakex : array 1 .. 1000 of int
var snakey : array 1 .. 1000 of int
snakex (1) := 75
snakey (1) := 75
snakex (2) := 65
snakey (2) := 75
snakex (3) := 55
snakey (3) := 75
randint (food1, 0, maxx div 10 - 1)
food1 := food1 * 10 + 5
randint (food2, 0, maxy div 10 - 1)
food2 := food2 * 10 + 5
drawfilloval (food1, food2, 4, 4, green)

% Main Game Loop
setscreen ("offscreenonly")

loop
    drawfilloval (food1, food2, 4, 4, black)
    if whatdotcolour (snakex (1), snakey (1)) = black then
        delay (5)
        randint (food1, 0, maxx div 10 - 1)
        food1 := food1 * 10 + 5
        randint (food2, 0, maxy div 10 - 1)
        food2 := food2 * 10 + 5
        % Snake Growth
        segments := segments + 1
    end if

    Input.KeyDown (move)
    View.Update
    delay (80)

    if (move ('d') or move (KEY_RIGHT_ARROW)) and xdirec not= -10 then
        xdirec := 10
        ydirec := 0
    elsif (move ('a') or move (KEY_LEFT_ARROW)) and xdirec not= 10 then
        xdirec := -10
        ydirec := 0
    elsif (move ('w') or move (KEY_UP_ARROW)) and ydirec not= -10 then
        ydirec := +10
        xdirec := 0
    elsif (move ('s') or move (KEY_DOWN_ARROW)) and ydirec not= 10 then
        ydirec := -10
        xdirec := 0
    end if
    % Moves body
    for decreasing i : segments .. 2
        snakex (i) := snakex (i - 1)
        snakey (i) := snakey (i - 1)
    end for
    % New head position
    snakex (1) := snakex (1) + xdirec
    snakey (1) := snakey (1) + ydirec
    % Head Collision Detection
    if whatdotcolour (snakex (1), snakey (1)) = blue then
        cls
        colorback (black)
        Font.Draw ("Game Over", 245, 285, losingFont, blue)
        exit
    end if
    cls
    for decreasing i : segments .. 1
        drawfilloval (snakex (i), snakey (i), 5, 5, blue)
    end for
    % Colision detection
    if snakex (1) >= maxx or snakex (1) = maxy or snakey (1) = 16 and clr = 125 and x < 500 then
            x := 505
        end if
    end if
    if x = 50 then
        y := y + 10
    end if
    if x = 585 then
        y := y - 10
    end if
    if y = 70 and x > 565 then
        x := x + 10
    end if
    if x >= maxx then
        x := 0
    end if
    Mouse.Where (mousex, mousey, button)
    if (mousex > 200 and mousex < 444 and mousey > 120 and mousey < 160 and button = 1) then
        exit
    elsif (mousex > 200 and mousex < 340 and mousey > 65 and mousey < 105 and button = 1) then
        quit
    end if
end loop
cls


% Game Background
drawfillbox (maxx, maxy, 0, 0, white)
colorback (white)
color (black)


% Snake Movement and Food
var counter : int
counter := 0
var losingFont := Font.New ("Algerian:30:bold")
var food1, food2 : int
var xdirec : int
var ydirec : int
xdirec := 10
ydirec := 0
var move : array char of boolean
var segments : int := 3
var snakex : array 1 .. 1000 of int
var snakey : array 1 .. 1000 of int
snakex (1) := 75
snakey (1) := 75
snakex (2) := 65
snakey (2) := 75
snakex (3) := 55
snakey (3) := 75
randint (food1, 0, maxx div 10 - 1)
food1 := food1 * 10 + 5
randint (food2, 0, maxy div 10 - 1)
food2 := food2 * 10 + 5


% Instruction screen
var press : array char of boolean
View.Update
put " +---------------+"
put " |  How To Play  |"
put " +---------------+"
put ""
put ""
put " Movement: "
put ""
put " Use the W,A,S,D keys or Arrow keys to move."
put ""
put ""
put " Do not hit the walls or the black line."
put " If you do any of those then you will lose."
put " Do not Hit your own tail."
put ""
put ""
put "Press 'C' to continue"
loop
    Input.KeyDown (press)
    if (press ('c')) then
        cls
        exit
    end if
end loop


% Main Game Loop
setscreen ("offscreenonly")

loop
    counter := counter + 1

   
    drawline (0, maxy - 20, maxx, maxy - 20, black)
    put counter, "" ..
    drawfilloval (food1, food2, 4, 4, black)
    if whatdotcolour (snakex (1), snakey (1)) = black then
        delay (5)
        randint (food1, 0, maxx div 10 - 1)
        food1 := food1 * 10 + 5
        randint (food2, 0, maxy div 10 - 1 - 20)
        food2 := food2 * 10 + 5
        % Snake Growth
        segments := segments + 1
    end if

    Input.KeyDown (move)
    View.Update
    delay (80) 

    if (move ('d') or move (KEY_RIGHT_ARROW)) and xdirec not= -10 then
        xdirec := 10
        ydirec := 0
    elsif (move ('a') or move (KEY_LEFT_ARROW)) and xdirec not= 10 then
        xdirec := -10
        ydirec := 0
    elsif (move ('w') or move (KEY_UP_ARROW)) and ydirec not= -10 then
        ydirec := +10
        xdirec := 0
    elsif (move ('s') or move (KEY_DOWN_ARROW)) and ydirec not= 10 then
        ydirec := -10
        xdirec := 0
    end if
    % Moves body
    for decreasing i : segments .. 2
        snakex (i) := snakex (i - 1)
        snakey (i) := snakey (i - 1)
    end for
    % New head position
    snakex (1) := snakex (1) + xdirec
    snakey (1) := snakey (1) + ydirec
    % Head Collision Detection
    if whatdotcolour (snakex (1), snakey (1)) = blue then
        colorback (black)
        cls
        Font.Draw ("Game Over", 245, 285, losingFont, white)
        View.Update
        delay (50)
        exit
    end if
    cls
    for decreasing i : segments .. 1
        drawfilloval (snakex (i), snakey (i), 5, 5, blue)
    end for
    % Colision detection
    if snakex (1) >= maxx or snakex (1) = maxy - 20 or snakey (1) 