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

Username:   Password: 
 RegisterRegister   
 I am working on a simple platforming project. need some advice.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
poww10s




PostPosted: Fri Mar 21, 2014 7:45 pm   Post subject: I am working on a simple platforming project. need some advice.

What is it you are trying to achieve?
Create a successful platforming project.


What is the problem you are having?ef
Got the general concept down earlier in my programming class (GR10), But I cannot figure out why the player (Blue Circle) is stopping in the ground (Bottom of Screen). I am doing it the same as I did before but this is a smaller circle 16 pixel instead of 50.


Describe what you have tried to solve this problem
I have tried changing how far away the ball should stop at, (doesn't change.) and I had a temporary solution of setting it to stay at y 16 (radius of the ball), but this is not suitable for what I am doing.


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

Turing:


View.Set ("offscreenonly")

proc collision (cx1,cy1,cx2,cy2 : int)

end collision

var x, y, y2 : int
var xspeed, yspeed : int := 0
var gravity : int := 1
var player : boolean := false
var chars : array char of boolean

% Create Player, then cause them to fall down to bottom of screen. Plus Jumping stuff.
x := 16
y := maxy - 16
y2 := 10
loop
    Input.KeyDown (chars)
    drawfillbox (200, y2, 100, 0, red)
    % Draw Oval (Player)
    drawfilloval (x, y, 16, 16, red)
    % Physics!
    if gravity not= 0
            then
        yspeed := yspeed + gravity
    else
        yspeed := -yspeed
    end if
    y := y - yspeed
    % Stop
    if y < 16 or y < y2 - 16
            then
        yspeed := 0 - gravity
    end if
    % Movement
    if chars (KEY_LEFT_ARROW) then
        xspeed := xspeed - 1
    elsif chars (KEY_RIGHT_ARROW) then
        xspeed := xspeed + 1
    else
        xspeed := 0
    end if
    x := x + xspeed
    % Jumping
    if chars ('w') and y < 32 then
        yspeed := yspeed - 6
    end if
    Time.Delay (45)
    View.Update
    cls
end loop
%Daniel


Please specify what version of Turing you are using
Turing v4.1
Sponsor
Sponsor
Sponsor
sponsor
tiedye1




PostPosted: Fri Mar 21, 2014 9:54 pm   Post subject: Re: I am working on a simple platforming project. need some advice.

This statement in your loop essentially says if your player is below y = 16, then stop moving down.

Turing:

    if y < 16 or y < y2 - 16
            then
        yspeed := 0 - gravity
    end if


The y < y2 - 16 is actually doing nothing since y2 is always 10, 10-16 = -6 and if y < -6 is true, then y < 16 is also true, so its redundant and can be reduced to.

Turing:

    if y < 16 then
        yspeed := 0 - gravity
    end if


I'm don't exactly understand the effect you are trying to achieve, could you restate what you want it to do?
poww10s




PostPosted: Sat Mar 22, 2014 12:25 pm   Post subject: Re: I am working on a simple platforming project. need some advice.

Oh yeah. I actually removed that part. it didn't really do anything at the time.


Basically what is happening, is instead of it stopping like my previous program. This time for some reason it keeps moving for a while and stops further down. this causes it to look like it's clipping through the bottom of the screen, instead of stopping right at the bottom of the screen. I don't have this problem with moving on the x axis, only on the y.
tiedye1




PostPosted: Sat Mar 22, 2014 1:12 pm   Post subject: RE:I am working on a simple platforming project. need some advice.

The reason its stopping below the screen is that each frame, it may move many pixels down, and your code just stops it when its below a certain point. (notice how the faster its moving down the farther down it can get stuck) You have to set y to 16 when it goes below 16 if you want to keep it from appearing below 16.

Turing:

if y < 16 then
    yspeed := - gravity
    y := 16
end if
poww10s




PostPosted: Sat Mar 22, 2014 1:36 pm   Post subject: RE:I am working on a simple platforming project. need some advice.

That's the only way then? Thanks for helping out.

Also, with a module, does it have to all be procedures? Could I write the jumping and collision all in a module then load it via the main program?
tiedye1




PostPosted: Sat Mar 22, 2014 4:51 pm   Post subject: Re: I am working on a simple platforming project. need some advice.

There are always other ways to do things, that's just a simple way.

A module can contain most anything, variables, types, procedures, etc. So you could put any part of your program in a module if you want. Read the turing documentation on modules, it describes how to use modules fairly well. http://compsci.ca/holtsoft/doc/module.html
poww10s




PostPosted: Sat Mar 22, 2014 5:36 pm   Post subject: RE:I am working on a simple platforming project. need some advice.

Ok thanks. One last thing, is there a way to stop mouse input? I've got a loop set up to gather input from mouse clicks, then add the coordinates to an array, and the array is flexible to allow for the user to input the upper limit. however, if you click anywhere before you enter the limit, then enter the limit, it sets those clicks as data in the array. can I stop this? or at least the mouse input.
poww10s




PostPosted: Sat Mar 22, 2014 5:49 pm   Post subject: RE:I am working on a simple platforming project. need some advice.

Also, can I save files, with the File location being "\\Saves\\Levels\\" and having it save local to the file running? so if this was running, and it saved, it would save to the folders in the same directory, not in the C:\ directory.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sat Mar 22, 2014 7:37 pm   Post subject: RE:I am working on a simple platforming project. need some advice.

Quote:
is there a way to stop mouse input?


Absolutely. Under what conditions do you want to store mouse coordinates? If those conditions aren't met, don't store them. If you only want Y values greater than 0, check for that before you store them. If you don't want to record clicks before the limit is set, just get the limit before you start checking the mouse state.

As for saving, why not experiment. Save a file within Turing and see where it ends up.
poww10s




PostPosted: Sat Mar 22, 2014 8:02 pm   Post subject: RE:I am working on a simple platforming project. need some advice.

I've done that, however for some reason it must also be running the loop at the same time. anyway to stop this? if commands for loops don't work to stop them.
Also, how do I write arrays to a file, they keep repeating the same number over and over.
poww10s




PostPosted: Sat Mar 22, 2014 11:37 pm   Post subject: Re: I am working on a simple platforming project. need some advice.

EDIT: If anyone read this specific post, nevermind I have figured it out.
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: