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

Username:   Password: 
 RegisterRegister   
 Maze Game
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Smarteez




PostPosted: Wed Nov 29, 2006 5:51 pm   Post subject: Maze Game

Ok, I have a problem here. I have created the first level of my game and then as I go to run it, I try to move the object and it won't move, I don't know if it is because it can't run so much code or if I have done something wrong. Here is the code and could somebody please help me out with it.
code:
setscreen ("graphics:800;600")
setscreen ("offscreenonly")
setscreen ("nocursor")
var chars : array char of boolean
var y1, x1, y2, x2, c2 : int
var star : string
var box1_x1, box1_y1, box1_x2, box1_y2 : int
var box2_x1, box2_y1, box2_x2, box2_y2 : int
var box3_x1, box3_y1, box3_x2, box3_y2 : int
var box4_x1, box4_y1, box4_x2, box4_y2 : int
var box5_x1, box5_y1, box5_x2, box5_y2 : int
var box6_x1, box6_y1, box6_x2, box6_y2 : int
var box7_x1, box7_y1, box7_x2, box7_y2 : int
var box8_x1, box8_y1, box8_x2, box8_y2 : int
var box9_x1, box9_y1, box9_x2, box9_y2 : int
var box10_x1, box10_y1, box10_x2, box10_y2 : int
var box11_x1, box11_y1, box11_x2, box11_y2 : int
var box12_x1, box12_y1, box12_x2, box12_y2 : int
var box13_x1, box13_y1, box13_x2, box13_y2 : int
var box14_x1, box14_y1, box14_x2, box14_y2 : int
% This shows the line values, showing where the lines will end up
box1_x1 := 30
box1_y1 := 0
box1_x2 := 30
box1_y2 := 250
box2_x1 := 0
box2_y1 := 0
box2_x2 := 0
box2_y2 := 280
box3_x1 := 0
box3_y1 := 280
box3_x2 := 60
box3_y2 := 280
box4_x1 := 60
box4_y1 := 280
box4_x2 := 60
box4_y2 := 150
box5_x1 := 30
box5_y1 := 120
box5_x2 := 90
box5_y2 := 120
box6_x1 := 90
box6_y1 := 120
box6_x2 := 90
box6_y2 := 250
box7_x1 := 60
box7_y1 := 280
box7_x2 := 500
box7_y2 := 280
box8_x1 := 90
box8_y1 := 250
box8_x2 := 530
box8_y2 := 250
box9_x1 := 530
box9_y1 := 250
box9_x2 := 530
box9_y2 := 500
box10_x1 := 500
box10_y1 := 280
box10_x2 := 500
box10_y2 := 470
box11_x1 := 530
box11_y1 := 500
box11_x2 := 480
box11_y2 := 500
box12_x1 := 500
box12_y1 := 470
box12_x2 := 450
box12_y2 := 470
box13_x1 := 450
box13_y1 := 470
box13_x2 := 450
box13_y2 := 600
box14_x1 := 480
box14_y1 := 500
box14_x2 := 480
box14_y2 := 600
c2 := 16
% Procedure
procedure getKey
    var ch : string (1)
    getch (ch)
end getKey
% Level 1 Maze Layout
cls
drawfillbox (box1_x1, box1_y1, box1_x2, box1_y2, c2)
drawfillbox (box2_x1, box2_y1, box2_x2, box2_y2, c2)
drawfillbox (box3_x1, box3_y1, box3_x2, box3_y2, c2)
drawfillbox (box4_x1, box4_y1, box4_x2, box4_y2, c2)
drawfillbox (box5_x1, box5_y1, box5_x2, box5_y2, c2)
drawfillbox (box6_x1, box6_y1, box6_x2, box6_y2, c2)
drawfillbox (box7_x1, box7_y1, box7_x2, box7_y2, c2)
drawfillbox (box8_x1, box8_y1, box8_x2, box8_y2, c2)
drawfillbox (box9_x1, box9_y1, box9_x2, box9_y2, c2)
drawfillbox (box10_x1, box10_y1, box10_x2, box10_y2, c2)
drawfillbox (box11_x1, box11_y1, box11_x2, box11_y2, c2)
drawfillbox (box12_x1, box12_y1, box12_x2, box12_y2, c2)
drawfillbox (box13_x1, box13_y1, box13_x2, box13_y2, c2)
drawfillbox (box14_x1, box14_y1, box14_x2, box14_y2, c2)
% Starting Position of square
y1 := 4
x1 := 4
y2 := 24
x2 := 24
drawfillbox (x1, y1, x2, y2, 1)
getKey
% use loop for movement
loop
    % Level 1 Maze Layout
    cls
    drawfillbox (box1_x1, box1_y1, box1_x2, box1_y2, c2)
    drawfillbox (box2_x1, box2_y1, box2_x2, box2_y2, c2)
    drawfillbox (box3_x1, box3_y1, box3_x2, box3_y2, c2)
    drawfillbox (box4_x1, box4_y1, box4_x2, box4_y2, c2)
    drawfillbox (box5_x1, box5_y1, box5_x2, box5_y2, c2)
    drawfillbox (box6_x1, box6_y1, box6_x2, box6_y2, c2)
    drawfillbox (box7_x1, box7_y1, box7_x2, box7_y2, c2)
    drawfillbox (box8_x1, box8_y1, box8_x2, box8_y2, c2)
    drawfillbox (box9_x1, box9_y1, box9_x2, box9_y2, c2)
    drawfillbox (box10_x1, box10_y1, box10_x2, box10_y2, c2)
    drawfillbox (box11_x1, box11_y1, box11_x2, box11_y2, c2)
    drawfillbox (box12_x1, box12_y1, box12_x2, box12_y2, c2)
    drawfillbox (box13_x1, box13_y1, box13_x2, box13_y2, c2)
    drawfillbox (box14_x1, box14_y1, box14_x2, box14_y2, c2)
    Input.KeyDown (chars)
    % Check for collision between object and Maze wall
    if x2 > box1_x1 and x1 < box1_x2 and x2 > box1_y1 and y2 < box1_y2 then
        put "Game Over"
    elsif x2 > box2_x1 and x1 < box2_x2 and x2 > box2_y1 and y2 < box2_y2 then
        put "Game Over"
    elsif x2 > box3_x1 and x1 < box3_x2 and x2 > box3_y1 and y2 < box3_y2 then
        put "Game Over"
    elsif x2 > box4_x1 and x1 < box4_x2 and x2 > box4_y1 and y2 < box4_y2 then
        put "Game Over"
    elsif x2 > box5_x1 and x1 < box5_x2 and x2 > box5_y1 and y2 < box5_y2 then
        put "Game Over"
    elsif x2 > box6_x1 and x1 < box6_x2 and x2 > box6_y1 and y2 < box6_y2 then
        put "Game Over"
    elsif x2 > box7_x1 and x1 < box7_x2 and x2 > box7_y1 and y2 < box7_y2 then
        put "Game Over"
    elsif x2 > box8_x1 and x1 < box8_x2 and x2 > box8_y1 and y2 < box8_y2 then
        put "Game Over"
    elsif x2 > box9_x1 and x1 < box9_x2 and x2 > box9_y1 and y2 < box9_y2 then
        put "Game Over"
    elsif x2 > box10_x1 and x1 < box10_x2 and x2 > box10_y1 and y2 < box10_y2 then
        put "Game Over"
    elsif x2 > box11_x1 and x1 < box11_x2 and x2 > box11_y1 and y2 < box11_y2 then
        put "Game Over"
    elsif x2 > box12_x1 and x1 < box12_x2 and x2 > box12_y1 and y2 < box12_y2 then
        put "Game Over"
    elsif x2 > box13_x1 and x1 < box13_x2 and x2 > box13_y1 and y2 < box13_y2 then
        put "Game Over"
    elsif x2 > box14_x1 and x1 < box14_x2 and x2 > box14_y1 and y2 < box14_y2 then
        put "Game Over"
        % Movement of the square
        if chars (KEY_UP_ARROW) then
            y1 := y1 + 1
            y2 := y2 + 1
            drawfillbox (x1, y1, x2, y2, 1)
        elsif chars (KEY_DOWN_ARROW) then
            y1 := y1 - 1
            y2 := y2 - 1
            drawfillbox (x1, y1, x2, y2, 1)
        elsif chars (KEY_LEFT_ARROW) then
            x1 := x1 - 1
            x2 := x2 - 1
            drawfillbox (x1, y1, x2, y2, 1)
        elsif chars (KEY_RIGHT_ARROW) then
            x1 := x1 + 1
            x2 := x2 + 1
            drawfillbox (x1, y1, x2, y2, 1)
        end if
        View.Update
        getKey
        cls
    end if
end loop



If someone could please help me out as soon as possible it would be greatly appreciated, and please don't just steel the code for your own benefit, I have been working on this for a while and don't want someone just to steal it and take credit for something they didn't do.

Thank-You,

Smarteez
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Wed Nov 29, 2006 6:24 pm   Post subject: (No subject)

When you were coding this, were you frustrated at how many variables you had to make? There's a better way. Learn to use arrays.

Your code fails because you mismatched an end if. See the end if that comes after the View.Update and cls stuff? It should be moved up. Right now you're only checking for input if that last elsif statement is true, which is silly.

Also, you should be using either Input.KeyDown or getch. Not both. In this case, you should be using Input.KeyDown.

Hope that helps
PiGuy




PostPosted: Wed Nov 29, 2006 6:31 pm   Post subject: Re: Maze Game

Sorry about repeating what Cervantes said 5 mintues ago... I was typing this out when Cervantes posted a reply.

You put your movement code within a 'game over' check:
code:

        elsif x2 > box14_x1 and x1 < box14_x2 and x2 > box14_y1 and y2 < box14_y2 then
            put "Game Over"
            % Movement of the square
            if chars (KEY_UP_ARROW) then
                   y1 := y1 + 1
                   y2 := y2 + 1
                   drawfillbox (x1, y1, x2, y2, 1)
            elsif chars (KEY_DOWN_ARROW) then
                   y1 := y1 - 1
                   y2 := y2 - 1
                   drawfillbox (x1, y1, x2, y2, 1)
            elsif chars (KEY_LEFT_ARROW) then
                   x1 := x1 - 1
                   x2 := x2 - 1
                   drawfillbox (x1, y1, x2, y2, 1)
            elsif chars (KEY_RIGHT_ARROW) then
                   x1 := x1 + 1
                   x2 := x2 + 1
                   drawfillbox (x1, y1, x2, y2, 1)
            end if
            View.Update
            getKey
            cls
        end if


This caused the program to completely overlook the movement of the person's square unless that condition is true, in which case the game is over anyway.

You have to bring the code outside that check, and the easiest way to do this is simply to add an 'else'. Therefore, it should look something like this:
code:

        elsif x2 > box14_x1 and x1 < box14_x2 and x2 > box14_y1 and y2 < box14_y2 then
            put "Game Over"
        else   %the thing that was previously missing
            % Movement of the square
            if chars (KEY_UP_ARROW) then
                y1 := y1 + 1
                y2 := y2 + 1
                drawfillbox (x1, y1, x2, y2, 1)
            elsif chars (KEY_DOWN_ARROW) then
                y1 := y1 - 1
                y2 := y2 - 1
                drawfillbox (x1, y1, x2, y2, 1)
            elsif chars (KEY_LEFT_ARROW) then
                x1 := x1 - 1
                x2 := x2 - 1
                drawfillbox (x1, y1, x2, y2, 1)
            elsif chars (KEY_RIGHT_ARROW) then
                x1 := x1 + 1
                x2 := x2 + 1
                drawfillbox (x1, y1, x2, y2, 1)
            end if
            View.Update
            getKey
            cls
         end if
Smarteez




PostPosted: Wed Nov 29, 2006 6:43 pm   Post subject: (No subject)

Ok, I fixed those things but now, It says game over but the thing keeps moving.
PiGuy




PostPosted: Wed Nov 29, 2006 6:57 pm   Post subject: (No subject)

Exit the loop as soon as one of your 'game over' conditions is true.

This means that every 'game over' in your loop will be followed by an 'exit.'
Smarteez




PostPosted: Wed Nov 29, 2006 7:03 pm   Post subject: (No subject)

Ok, I tried this but some of the lines don't seem to do anything so I can still go through some for some reason... Could someone please edit this for me? I would greatly appreciate it...
code:
setscreen ("graphics:800;600")
setscreen ("offscreenonly")
setscreen ("nocursor")
var chars : array char of boolean
var y1, x1, y2, x2, c2 : int
var star : string
var box1_x1, box1_y1, box1_x2, box1_y2 : int
var box2_x1, box2_y1, box2_x2, box2_y2 : int
var box3_x1, box3_y1, box3_x2, box3_y2 : int
var box4_x1, box4_y1, box4_x2, box4_y2 : int
var box5_x1, box5_y1, box5_x2, box5_y2 : int
var box6_x1, box6_y1, box6_x2, box6_y2 : int
var box7_x1, box7_y1, box7_x2, box7_y2 : int
var box8_x1, box8_y1, box8_x2, box8_y2 : int
var box9_x1, box9_y1, box9_x2, box9_y2 : int
var box10_x1, box10_y1, box10_x2, box10_y2 : int
var box11_x1, box11_y1, box11_x2, box11_y2 : int
var box12_x1, box12_y1, box12_x2, box12_y2 : int
var box13_x1, box13_y1, box13_x2, box13_y2 : int
var box14_x1, box14_y1, box14_x2, box14_y2 : int
% This shows the line values, showing where the lines will end up
box1_x1 := 30
box1_y1 := 0
box1_x2 := 30
box1_y2 := 250
box2_x1 := 0
box2_y1 := 0
box2_x2 := 0
box2_y2 := 280
box3_x1 := 0
box3_y1 := 280
box3_x2 := 60
box3_y2 := 280
box4_x1 := 60
box4_y1 := 280
box4_x2 := 60
box4_y2 := 150
box5_x1 := 30
box5_y1 := 120
box5_x2 := 90
box5_y2 := 120
box6_x1 := 90
box6_y1 := 120
box6_x2 := 90
box6_y2 := 250
box7_x1 := 60
box7_y1 := 280
box7_x2 := 500
box7_y2 := 280
box8_x1 := 90
box8_y1 := 250
box8_x2 := 530
box8_y2 := 250
box9_x1 := 530
box9_y1 := 250
box9_x2 := 530
box9_y2 := 500
box10_x1 := 500
box10_y1 := 280
box10_x2 := 500
box10_y2 := 470
box11_x1 := 530
box11_y1 := 500
box11_x2 := 480
box11_y2 := 500
box12_x1 := 500
box12_y1 := 470
box12_x2 := 450
box12_y2 := 470
box13_x1 := 450
box13_y1 := 470
box13_x2 := 450
box13_y2 := 600
box14_x1 := 480
box14_y1 := 500
box14_x2 := 480
box14_y2 := 600
c2 := 16
% Procedure
procedure getKey
    var ch : string (1)
    getch (ch)
end getKey
% Level 1 Maze Layout
cls
drawfillbox (box1_x1, box1_y1, box1_x2, box1_y2, c2)
drawfillbox (box2_x1, box2_y1, box2_x2, box2_y2, c2)
drawfillbox (box3_x1, box3_y1, box3_x2, box3_y2, c2)
drawfillbox (box4_x1, box4_y1, box4_x2, box4_y2, c2)
drawfillbox (box5_x1, box5_y1, box5_x2, box5_y2, c2)
drawfillbox (box6_x1, box6_y1, box6_x2, box6_y2, c2)
drawfillbox (box7_x1, box7_y1, box7_x2, box7_y2, c2)
drawfillbox (box8_x1, box8_y1, box8_x2, box8_y2, c2)
drawfillbox (box9_x1, box9_y1, box9_x2, box9_y2, c2)
drawfillbox (box10_x1, box10_y1, box10_x2, box10_y2, c2)
drawfillbox (box11_x1, box11_y1, box11_x2, box11_y2, c2)
drawfillbox (box12_x1, box12_y1, box12_x2, box12_y2, c2)
drawfillbox (box13_x1, box13_y1, box13_x2, box13_y2, c2)
drawfillbox (box14_x1, box14_y1, box14_x2, box14_y2, c2)
% Starting Position of square
y1 := 4
x1 := 4
y2 := 24
x2 := 24
drawfillbox (x1, y1, x2, y2, 1)
getKey
loop
    % Level 1 Maze Layout
    cls
    drawfillbox (box1_x1, box1_y1, box1_x2, box1_y2, c2)
    drawfillbox (box2_x1, box2_y1, box2_x2, box2_y2, c2)
    drawfillbox (box3_x1, box3_y1, box3_x2, box3_y2, c2)
    drawfillbox (box4_x1, box4_y1, box4_x2, box4_y2, c2)
    drawfillbox (box5_x1, box5_y1, box5_x2, box5_y2, c2)
    drawfillbox (box6_x1, box6_y1, box6_x2, box6_y2, c2)
    drawfillbox (box7_x1, box7_y1, box7_x2, box7_y2, c2)
    drawfillbox (box8_x1, box8_y1, box8_x2, box8_y2, c2)
    drawfillbox (box9_x1, box9_y1, box9_x2, box9_y2, c2)
    drawfillbox (box10_x1, box10_y1, box10_x2, box10_y2, c2)
    drawfillbox (box11_x1, box11_y1, box11_x2, box11_y2, c2)
    drawfillbox (box12_x1, box12_y1, box12_x2, box12_y2, c2)
    drawfillbox (box13_x1, box13_y1, box13_x2, box13_y2, c2)
    drawfillbox (box14_x1, box14_y1, box14_x2, box14_y2, c2)
    Input.KeyDown (chars)
    % Check for collision between object and Maze wall
    if x2 > box1_x1 and x1 < box1_x2 and x2 > box1_y1 and y2 < box1_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box2_x1 and x1 < box2_x2 and x2 > box2_y1 and y2 < box2_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box3_x1 and x1 < box3_x2 and x2 > box3_y1 and y2 < box3_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box4_x1 and x1 < box4_x2 and x2 > box4_y1 and y2 < box4_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box5_x1 and x1 < box5_x2 and x2 > box5_y1 and y2 < box5_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box6_x1 and x1 < box6_x2 and x2 > box6_y1 and y2 < box6_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box7_x1 and x1 < box7_x2 and x2 > box7_y1 and y2 < box7_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box8_x1 and x1 < box8_x2 and x2 > box8_y1 and y2 < box8_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box9_x1 and x1 < box9_x2 and x2 > box9_y1 and y2 < box9_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box10_x1 and x1 < box10_x2 and x2 > box10_y1 and y2 < box10_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box11_x1 and x1 < box11_x2 and x2 > box11_y1 and y2 < box11_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box12_x1 and x1 < box12_x2 and x2 > box12_y1 and y2 < box12_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box13_x1 and x1 < box13_x2 and x2 > box13_y1 and y2 < box13_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box14_x1 and x1 < box14_x2 and x2 > box14_y1 and y2 < box14_y2 then
        put "Game Over"
        quit
    else
    end if
    % Movement of the square
    if chars (KEY_UP_ARROW) then
        y1 := y1 + 1
        y2 := y2 + 1
        drawfillbox (x1, y1, x2, y2, 1)
    elsif chars (KEY_DOWN_ARROW) then
        y1 := y1 - 1
        y2 := y2 - 1
        drawfillbox (x1, y1, x2, y2, 1)
    elsif chars (KEY_LEFT_ARROW) then
        x1 := x1 - 1
        x2 := x2 - 1
        drawfillbox (x1, y1, x2, y2, 1)
    elsif chars (KEY_RIGHT_ARROW) then
        x1 := x1 + 1
        x2 := x2 + 1
        drawfillbox (x1, y1, x2, y2, 1)
    end if
    View.Update
    getKey
    cls
end loop


Clayton




PostPosted: Wed Nov 29, 2006 7:15 pm   Post subject: (No subject)

code like this breaks my heart:

code:

% Check for collision between object and Maze wall
    if x2 > box1_x1 and x1 < box1_x2 and x2 > box1_y1 and y2 < box1_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box2_x1 and x1 < box2_x2 and x2 > box2_y1 and y2 < box2_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box3_x1 and x1 < box3_x2 and x2 > box3_y1 and y2 < box3_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box4_x1 and x1 < box4_x2 and x2 > box4_y1 and y2 < box4_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box5_x1 and x1 < box5_x2 and x2 > box5_y1 and y2 < box5_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box6_x1 and x1 < box6_x2 and x2 > box6_y1 and y2 < box6_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box7_x1 and x1 < box7_x2 and x2 > box7_y1 and y2 < box7_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box8_x1 and x1 < box8_x2 and x2 > box8_y1 and y2 < box8_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box9_x1 and x1 < box9_x2 and x2 > box9_y1 and y2 < box9_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box10_x1 and x1 < box10_x2 and x2 > box10_y1 and y2 < box10_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box11_x1 and x1 < box11_x2 and x2 > box11_y1 and y2 < box11_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box12_x1 and x1 < box12_x2 and x2 > box12_y1 and y2 < box12_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box13_x1 and x1 < box13_x2 and x2 > box13_y1 and y2 < box13_y2 then
        put "Game Over"
        quit
        end if
    if x2 > box14_x1 and x1 < box14_x2 and x2 > box14_y1 and y2 < box14_y2 then
        put "Game Over"
        quit
    else
    end if


this can be made so much easier if you simply go through the Turing Walkthrough and look at the tutorials on arrays (as Cervantes mentioned) and, if you're ambitious, records. With this, the following code could be shortened to:

code:

type Box :
    record
        x1, x2, y1, y2 : int
    end record

var box : array 1 .. 14 of Box

%all the other code up to that Game Over check
...
%Game over check
for i : 1 .. upper(box)
    if x2 > box(i).x1 and box(i).x2 < x1 and y2 > box(i).y1 and box(i).y2 < y1 then
        put "Game Over"
        quit %I wouldn't suggest using quit, look up other ways to exit
    end if
end for


So much shorter, and only requires a little work on your part to understand whats going on there.
Smarteez




PostPosted: Wed Nov 29, 2006 7:20 pm   Post subject: (No subject)

I don't understand that which is above
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Wed Nov 29, 2006 7:32 pm   Post subject: (No subject)

So go click on the link I provided to the Turing Walkthrough (there it is again) and read through the tutorials that I said you needed to look through to understand the code that I posted (namely the tutorials on arrays and records)
Smarteez




PostPosted: Wed Nov 29, 2006 8:09 pm   Post subject: (No subject)

Ok, so I read the manuels, tried it out and I ended up with over 21 errors...
code:
setscreen ("graphics:800;600")
setscreen ("offscreenonly")
setscreen ("nocursor")
type Box :
    record
        x1, x2, y1, y2 : int
    end record

var box : array 1 .. 14 of Box

box(1) := 30, 0, 30, 250
box(2) := 0, 0, 0, 280
box(3) := 0, 280, 0, 280
box(4) := 60, 280, 60, 150
box(5) := 30, 120, 90, 120
box(6) := 90, 120, 90, 250
box(7) := 60, 280, 500, 280
box(8) := 90, 250, 530, 250
box(9) := 530, 250, 530, 500
box(10) := 500, 280, 500, 470
box(11) := 530, 500, 480, 500
box(12) := 500, 470, 450, 470
box(13) := 450, 470, 450, 600
box(14) := 480, 500, 480, 600

% Procedure
procedure getKey
    var ch : string (1)
    getch (ch)
end getKey

% Starting Position of square
y1 := 4
x1 := 4
y2 := 24
x2 := 24
drawfillbox (x1, y1, x2, y2, 1)
getKey



loop
    % Level 1 Maze Layout
    cls
    drawfillbox (box(1),14)
    drawfillbox (box(2),14)
    drawfillbox (box(3),14)
    drawfillbox (box(4),14)
    drawfillbox (box(5),14)
    drawfillbox (box(6),14)
    drawfillbox (box(7),14)
    drawfillbox (box(8),14)
    drawfillbox (box(9),14)
    drawfillbox (box(10),14)
    drawfillbox (box(11),14)
    drawfillbox (box(12),14)
    drawfillbox (box(13),14)
    drawfillbox (box(14),14)
    Input.KeyDown (chars)
    ...
%Game over check
for i : 1 .. upper(box)
    if x2 > box(i).x1 and box(i).x2 < x1 and y2 > box(i).y1 and box(i).y2 < y1 then
        put "Game Over"
        exit
    end if
end for
    % Movement of the square
    if chars (KEY_UP_ARROW) then
        y1 := y1 + 3
        y2 := y2 + 3
        drawfillbox (x1, y1, x2, y2, 1)
    elsif chars (KEY_DOWN_ARROW) then
        y1 := y1 - 3
        y2 := y2 - 3
        drawfillbox (x1, y1, x2, y2, 1)
    elsif chars (KEY_LEFT_ARROW) then
        x1 := x1 - 3
        x2 := x2 - 3
        drawfillbox (x1, y1, x2, y2, 1)
    elsif chars (KEY_RIGHT_ARROW) then
        x1 := x1 + 3
        x2 := x2 + 3
        drawfillbox (x1, y1, x2, y2, 1)
    end if
    View.Update
    getKey
    cls
end loop
Clayton




PostPosted: Wed Nov 29, 2006 8:40 pm   Post subject: (No subject)

okay, read through that again carefully, giving box(1) 30, 0, 30, 250 doesn't work, Turing doesn't know which value goes to where, so insted, you have to tell it which value of Box you want it to inhabit, ie:

code:

box(1).x1 := 30
box(1).x2 := 0
box(1).y1 := 30
box(1).y2 := 250
%etc..


The same holds true when you draw your box, instead of giving it box(1), you have to tell it which elements of box(1) you want/need it to use, ie:

code:

Draw.FillBox (box(1).x1, box(1).y1, box(1).x2, box(1).y2, 14)


Take your time reading through the tutorials, otherwise you will just get yourself confused.
uberwalla




PostPosted: Wed Nov 29, 2006 8:50 pm   Post subject: (No subject)

ok i know this is kind of different from editing your code but why have that if u hit a wall then u lose and it quits? why not just make the walls impassable and instead of ending on collision just have a timer and give ther people a certain time limit to get to the end.
PiGuy




PostPosted: Wed Nov 29, 2006 8:50 pm   Post subject: (No subject)

Also, you didn't declare your x1, y1, x2, y2 variables for the user-
controlled box.

Finally, just a little correction to the 'game over' conditions:
code:
if x2 > box(i).x1 and x1 < box(i).x2 and y2 > box(i).y1 and y1 < box(i).y2 then


By the way, an efficient solution, Freakman Smile
Clayton




PostPosted: Wed Nov 29, 2006 9:14 pm   Post subject: (No subject)

actually, its not all that efficient in terms of computing power, however it does save you a whackload of time when it comes to typing it up Very Happy I'm sure there are more efficient ways of doing it.
Smarteez




PostPosted: Wed Nov 29, 2006 10:10 pm   Post subject: (No subject)

Which other way is there to exit without quiting the window so it just says try again or something like that...
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 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: