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

Username:   Password: 
 RegisterRegister   
 Need help creating boundaries for a maze game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MI




PostPosted: Wed Mar 27, 2013 2:30 am   Post subject: Need help creating boundaries for a maze game

I am trying to make a maze game using Turing. I REALLY need help making the maze walls. I want my character to move through the maze and not be able to walk right through the maze walls. How do I create boundaries?

Any help is appreciated:)


Describe what you have tried to solve this problem
I tried looking at forums and Turing game examples but it's really difficult to understand.
I am kinda new to this program.

Please specify what version of Turing you are using
Turing 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Nathan4102




PostPosted: Wed Mar 27, 2013 7:47 am   Post subject: RE:Need help creating boundaries for a maze game

Hmm, You could draw your lines using the turing graphics functions, and then create an imaginary boundary one pixel away from that line. Then every time you try to move, turing will check if we are standing on one of these imaginary boundaries. If we are, don't move? If you need explanation, I could probably code a small example.
Raknarg




PostPosted: Wed Mar 27, 2013 1:10 pm   Post subject: RE:Need help creating boundaries for a maze game

Turing:

var x, y : int

if x > maxx then
    x := maxx
elsif x < 0 then
    x := 0
end if

if y > maxy then
    y := maxy
elsif y < 0 then
    y := 0
end if


Think about it. If you're past a bound, basically set the thing behind or on the bound. Now x and y won't escape the screen.
MI




PostPosted: Wed Mar 27, 2013 9:19 pm   Post subject: Re: RE:Need help creating boundaries for a maze game

Raknarg @ Wed Mar 27, 2013 1:10 pm wrote:
Turing:

var x, y : int

if x > maxx then
    x := maxx
elsif x < 0 then
    x := 0
end if

if y > maxy then
    y := maxy
elsif y < 0 then
    y := 0
end if


I am not getting how exactly to add it to my code. Suppose I want (just for an example) a character to go through a maze and I don't want it to be able to pass a maze wall:

var x, y : int
x := 100
y := 100

var chars : array char of boolean
loop

Input.KeyDown (chars)

if chars (KEY_UP_ARROW) then
y := y + 5
elsif chars (KEY_RIGHT_ARROW) then
x := x + 5

elsif chars (KEY_LEFT_ARROW) then
x := x - 5

elsif chars (KEY_DOWN_ARROW) then
y := y - 5
end if

drawfilloval (x, y, 10,10, blue)
delay (10)
cls
drawline (0,50,500,50,black)
end loop

In this above code, how can I make the circle not be able to go past the line? I know you already gave me the idea but I just don't know how to add it to this. Please help! Thank you so much Smile Oh and if possible, do you know how to make the flashing stop?
MI




PostPosted: Wed Mar 27, 2013 9:23 pm   Post subject: Re: RE:Need help creating boundaries for a maze game

Nathan4102 @ Wed Mar 27, 2013 7:47 am wrote:
Hmm, You could draw your lines using the turing graphics functions, and then create an imaginary boundary one pixel away from that line. Then every time you try to move, turing will check if we are standing on one of these imaginary boundaries. If we are, don't move? If you need explanation, I could probably code a small example.


Here's my example of a code (a moving circle as a character and a line as a maze wall):

Turing:

var x, y : int
x := 100
y := 100

var chars : array char of boolean
loop

    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        y := y + 5
   elsif chars (KEY_RIGHT_ARROW) then
        x := x + 5
   
    elsif chars (KEY_LEFT_ARROW) then
        x := x - 5
   
    elsif chars (KEY_DOWN_ARROW) then
        y := y - 5
    end if
   
    drawfilloval (x, y, 10,10, blue)
    delay (10)
    cls
drawline (0,50,500,50,black)
end loop


How would I add boundaries to the line so that the circle can't go past the line and instead, collide with it?
Dragon20942




PostPosted: Fri Mar 29, 2013 4:01 pm   Post subject: RE:Need help creating boundaries for a maze game

It will be an if statement.

Pseudocode:

if the character's position is beyond the boundary
reverse the action that caused it to happen
end if
Cancer Sol




PostPosted: Fri Mar 29, 2013 4:14 pm   Post subject: Re: Need help creating boundaries for a maze game

Quote:
If you're past a bound, basically set the thing behind or on the bound.

Omg, that's so smart Smile
I never thought of that before Razz
Zren




PostPosted: Fri Mar 29, 2013 6:12 pm   Post subject: RE:Need help creating boundaries for a maze game

Instead of moving the variable back (to most likely a constant location), don't move it at all in the first place. Use a temporary variable to calculate it's destination. Then, if that destination is valid, assign the value.
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Sat Mar 30, 2013 8:41 pm   Post subject: RE:Need help creating boundaries for a maze game

That's how they do vector collision, right?
MI




PostPosted: Tue Apr 02, 2013 4:12 pm   Post subject: RE:Need help creating boundaries for a maze game

Thank you guys!!! I think I got it Very Happy
basi




PostPosted: Thu Mar 28, 2019 10:39 am   Post subject: Re: RE:Need help creating boundaries for a maze game

MI @ Wed Mar 27, 2013 9:19 pm wrote:
Raknarg @ Wed Mar 27, 2013 1:10 pm wrote:
Turing:

var x, y : int

if x > maxx then
    x := maxx
elsif x < 0 then
    x := 0
end if

if y > maxy then
    y := maxy
elsif y < 0 then
    y := 0
end if


I am not getting how exactly to add it to my code. Suppose I want (just for an example) a character to go through a maze and I don't want it to be able to pass a maze wall:

var x, y : int
x := 100
y := 100

var chars : array char of boolean
loop

Input.KeyDown (chars)

if chars (KEY_UP_ARROW) then
y := y + 5
elsif chars (KEY_RIGHT_ARROW) then
x := x + 5

elsif chars (KEY_LEFT_ARROW) then
x := x - 5

elsif chars (KEY_DOWN_ARROW) then
y := y - 5
end if

drawfilloval (x, y, 10,10, blue)
delay (10)
cls
drawline (0,50,500,50,black)
end loop

In this above code, how can I make the circle not be able to go past the line? I know you already gave me the idea but I just don't know how to add it to this. Please help! Thank you so much Smile Oh and if possible, do you know how to make the flashing stop?



you can stop the flasing by doing this
View.Set ("graphics:350;400,offscreenonly")
its what i did, it should work to stop the flickering 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: