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

Username:   Password: 
 RegisterRegister   
 Making a Border in turing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
orbez




PostPosted: Sat Dec 07, 2013 7:35 pm   Post subject: Making a Border in turing

What is it you are trying to achieve?
I am attempting to make a game kinda like pac man. In this game a yellow dot can not leave the screen.


What is the problem you are having?
I made a border but you can still exit the screen by spamming/holding an arrow key down, is there a way to change that?


Describe what you have tried to solve this problem
I have tried bouncing the dot back by making the delta x and/or delta y the opposite but since then I have
been specific introductions that the dot much stop at the border.
I also expanded the border but all that does is just delay the out come.
(only included part of my program as it is somewhat long)


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:

 %Border
    if X <= (R1 + 1) or X >= maxx - (R1 + 1) then
        DX := 0
    end if
    if Y <= (R1 + 1) or Y >= maxy - (R1 + 1) then
        DY := 0
    end if
%Movement/speed
    if hasch then
        getch (key)
        if ord (key) = 205 then
            DX := speed
            DY := 0
        elsif ord (key) = 203 then
            DX := -speed
            DY := 0
        elsif ord (key) = 200 then
            DX := 0
            DY := speed
        elsif ord (key) = 208 then
            DX := 0
            DY := -speed
        end if
    end if




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




PostPosted: Sat Dec 07, 2013 7:39 pm   Post subject: RE:Making a Border in turing

If pac-man ever crosses the border, simply teleport him back to the correct side of it. If the left border is x = 0, then 'if (pacmanX <0) then packmanX := 0'. Tweak to suit your own game.
orbez




PostPosted: Sat Dec 07, 2013 7:52 pm   Post subject: Re: Making a Border in turing

I have never thought about it that way, thanks man.
Zren




PostPosted: Sat Dec 07, 2013 8:01 pm   Post subject: RE:Making a Border in turing

Don't move Pacman until you are sure the destination is in bounds.

Eg:

Turing:

type Vector2D :
    record
        x, y : real
    end record

var pacman :
    record
        position : Vector2D
        velocity : Vector2D
    end record


var destination : Vector2D
desination.x := pacman.position.x + pacman.velocity.x
desination.y := pacman.position.y + pacman.velocity.y

% Collision Detection: Walls
if ... then % If destination is in bounds
     % Move pacman to the destination
    pacman.position := destination
end if


This way, he's never out of bounds to begin with. Unless of course the walls move and the bounds change from one iteration to the next.
Zren




PostPosted: Sun Dec 08, 2013 2:25 pm   Post subject: RE:Making a Border in turing

Version without records/types in case they threw you for a loop.

Turing:

var pacmanX, pacmanY, pacmanVelX, pacmanVelY : int

loop
    %%% Input
    % ...

    %%% Logic
    var pacmanDestinationX, pacmanDestinationY : int
    pacmanDestinationX := pacmanX + pacmanVelX
    pacmanDestinationY := ...

    if 0 <= pacmanDestinationX and pacmanDestinationX <= maxx and ... then
        % Move pacman
        pacmanX := pacmanDestinationX
    else
        % Don't move pacman. As he would move into a wall.
        % You will most likely have a space between pacman and
        % the wall in this case. Insectoid's method to move
        % pacmanX to be just touching the left wall (pacmanX=0)
        % if pacmanX is past the wall (pacmanX < 0), is the
        % easiest way to deal with this.
    end if

    %%% Draw Frame
    % ...

end loop





More on records/types:

There's the Turing Documention on those keywords: record, type

There's also this tutorial Records Part I Declaration and other Introductory Concepts which is part of the greater tutorial called The Turing Walkthrough.
orbez




PostPosted: Sun Dec 08, 2013 3:44 pm   Post subject: Re: Making a Border in turing

Yeah, this is allot better, I came up with something similar but your code is much smaller and simpler, thanks.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: