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

Username:   Password: 
 RegisterRegister   
 Simple Mouse.Where Program Help
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
V1RU5




PostPosted: Tue Jun 08, 2010 11:27 pm   Post subject: Re: RE:Simple Mouse.Where Program Help

Cezna @ Tue Jun 08, 2010 10:54 am wrote:
You need to subtract a constant gravity value (probably something like .7 or .8) from the y velocity every cycle of the main loop.
Then you can tell it not to enact gravity if the ball is on top of something such as the ground or an object.


SO basically I make gravity a constant variable and make it equal to 0.7 which means it is a real number? If that is correct, then I am not able to subtract gravity form y because y is an int and gravity is a real number so it does not let me do that. What am I to do in order for this to work?
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Wed Jun 09, 2010 7:40 am   Post subject: RE:Simple Mouse.Where Program Help

Well you could just make y a real number. Or just subtract by 1 every frame instead. Keep in mind that gravity will combat your up movement. If you do this though, your guy's just gonna fly up in so long as you hold the mouse down instead of jump.

If you want it to be more "jumpy". When you jump, it's more of an arc, the speed of which you jump from the ground is really fast, but as you get higher, gravity takes hold until you hit a point where your floating, before gravity slowly makes you speed faster and faster towards the ground. So the speed that which you travel changes from positive, to 0, to negative as you fall. We can represent this as another variable. (Velocity is just a physic-y word for speed with direction.)

code:
x, y
xVelocity, yVelocity = 0

for every frame:
        if jump then yVelocity = jumpStartingSpeed
        yVelocity -= Gravity

        x += xVelocity
        y += yVelocity


For this purpose, you don't really need xVelocity, but it's better to stay consistent with variables of the same ... genre (in this case, coordinates for a blob). Also, your gonna want a variable to single when you can jump and can't, otherwise you can jump in the air or hold down the jump button and fly up.
V1RU5




PostPosted: Wed Jun 09, 2010 8:23 am   Post subject: RE:Simple Mouse.Where Program Help

So here is what I did

Turing:

var xPos : int
var yPos : int
var button : int
var x : int := 50
var y : int := 50
var gravity : int := 1
var xVelocity, yVelocity : int := 0
const tennisBall := Pic.FileNew ("tennis ball.bmp")

View.Set ("offscreenonly")     % part of the common anti-flicker fix
loop
    % update ball position here
    Mouse.Where (xPos, yPos, button)

    if button = 1 then
        if y > yPos then
            y -= 2
        elsif y < yPos then
            y += 2
        end if
        if x > xPos then
            x -= 2
        elsif x < xPos then
            x += 2
        end if
       
        yVelocity := 2
        yVelocity -= gravity
        x += xVelocity
        y += yVelocity
    end if

    if y > 0 then
    y -= 0
    end if
    % draw ball here
    %Pic.Draw (tennisBall, x, y, picMerge)
    Draw.FillOval (x, y, 10, 10, blue)

    % update screen, then clear it for the next frame
    View.Update ()
    Draw.Cls ()
end loop


Okay I did not notice but I am having the problem again that it goes up on the y-axis and then right or left on the x-axis but it does not go diagonally. I do not know how to fix this. Does "if jump" refer to "if button = 1"? Also, I guess the jumpStartingSpeed is 2.
Zren




PostPosted: Wed Jun 09, 2010 9:40 am   Post subject: RE:Simple Mouse.Where Program Help

Your code is going diagonally. It's just going diagonally really fast after the last mods you made, then moving the rest of the way horizontally. Your only moving in 8-degrees of movement (similar to zelda on the gameboy movement).

Can I ask you a question, how do you control jumping? Do you run horizontally then jump when you click above the character? Do you plan to have you press a button on the keyboard?
V1RU5




PostPosted: Wed Jun 09, 2010 5:58 pm   Post subject: Re: RE:Simple Mouse.Where Program Help

Zren @ Wed Jun 09, 2010 9:40 am wrote:
Your code is going diagonally. It's just going diagonally really fast after the last mods you made, then moving the rest of the way horizontally. Your only moving in 8-degrees of movement (similar to zelda on the gameboy movement).

Can I ask you a question, how do you control jumping? Do you run horizontally then jump when you click above the character? Do you plan to have you press a button on the keyboard?


NVM i fixed this now it works, thanks to everyone who helped. I might have more questions later then I will ask but thanks for now Smile
Cezna




PostPosted: Wed Jun 09, 2010 6:24 pm   Post subject: RE:Simple Mouse.Where Program Help

You need to have the x and y co-ordinates of the object as real numbers, and instead of putting:
Turing:

drawfilloval (x, y, radius, radius, colour)


you should have

Turing:

drawfilloval (round (x), round (y), radius, radius, colour)


Having real co-ordiantes, even though they are being rounded before being used for the drawing, will allow for smoother movement.

With real co-ordinates:
Let's say that y velocity is -2.4, and y is 10.
First time around, y would become 7.6, which would be drawn at 8.
Second time around, y would still be 7.6, so y now becomes 5.2, which is drawn at 5.

With integer co-ordinates:
Let's say that y velocity is -2, and y is 10.
First time around, y would become 8, which would be drawn at 8.
Second time around, y be 8, so y now becomes 6, which is drawn at 6.

You can see how this would limit the possible speeds you can move at.
Using real co-ordinates for moving objects, and rounding them to draw is thus far superior to using integer co-ordinates, since normally the animations would be going to fast that you won't notice the difference between rounding real co-ordinates and actually drawing at real co-ordinates (which is impossible in Turing, I just mean to say it creates the same effect as drawing at real co-ordinates would when run fast enough).
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 2 of 2  [ 21 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: