Computer Science Canada

Need help with game

Author:  hojo12345 [ Mon Dec 19, 2011 1:26 pm ]
Post subject:  Need help with game

What is it you are trying to achieve?
Hi ill get right to the point. I'm am trying to recreate frostbite for my class. I can't figure out how to make the guy jump like the guy in this video
http://www.youtube.com/watch?v=iajqWQjchjY&safety_mode=true&persist_safety_mode=1&safe=active

What is the problem you are having?
I can't figure out how to make the guy jump right


Describe what you have tried to solve this problem
i have tried different codes all have ended in disaster


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

Turing:


var PicFaceLeft, PicFaceRight : int

var x, y : int
x := 100
y := 100
var direction : int := 0
var chars : array char of boolean
View.Set ("offscreenonly")
PicFaceLeft := Pic.FileNew ("Person 1.jpg")
PicFaceRight := Pic.FileNew ("Person 2.jpg")

Pic.Draw (PicFaceRight, x, y, picMerge)
View.Update
loop
    drawfillbox (0, 0, 640, 400, 255)


    Pic.Draw (PicFaceRight, x, y, picMerge)

    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        y := y + 5

    elsif chars (KEY_RIGHT_ARROW) then
        x := x + 5
        direction := 1
        Pic.Draw (PicFaceRight, x, y, picMerge)

    elsif chars (KEY_LEFT_ARROW) then
        Pic.Draw (PicFaceLeft, x, y, picMerge)
        x := x - 5
        direction := 2
    elsif chars (KEY_DOWN_ARROW) then
        y := y + 12

        if direction = 1 then
            x := x + 50
            Pic.Draw (PicFaceRight, x, y, picMerge)
        elsif direction = 2 then
            x := x - 50
            Pic.Draw (PicFaceLeft, x, y, picMerge)
        end if
        View.Update
        delay (100)
        y := y - 35
        if direction = 1 then

            Pic.Draw (PicFaceRight, x, y, picMerge)
        elsif direction = 2 then

            Pic.Draw (PicFaceLeft, x, y, picMerge)
        end if

    end if
    View.Update

    delay (10)


end loop



Please specify what version of Turing you are using
i am using turing 4.0.4c

Author:  chipanpriest [ Mon Dec 19, 2011 1:32 pm ]
Post subject:  Re: Need help with game

hojo12345 @ Mon Dec 19, 2011 1:26 pm wrote:

Turing:

    elsif chars (KEY_RIGHT_ARROW) then
        x := x + 5
        direction := 1
        Pic.Draw (PicFaceRight, x, y, picMerge)

    elsif chars (KEY_LEFT_ARROW) then
        Pic.Draw (PicFaceLeft, x, y, picMerge)
        x := x - 5
        direction := 2


^This is what you have


This is what you need
Turing:

    elsif chars (KEY_RIGHT_ARROW) then
        Pic.Draw (PicFaceRight, x, y, picMerge)
        x := x + 5
        direction := 1

    elsif chars (KEY_LEFT_ARROW) then
        Pic.Draw (PicFaceLeft, x, y, picMerge)
        x := x - 5
        direction := 2

Author:  hojo12345 [ Mon Dec 19, 2011 1:40 pm ]
Post subject:  Re: Need help with game

thanks i didn't know how t fix that but i need help on how to get the movement right

Author:  chipanpriest [ Mon Dec 19, 2011 1:48 pm ]
Post subject:  RE:Need help with game

Whats wrong with the movement?

Author:  hojo12345 [ Mon Dec 19, 2011 1:57 pm ]
Post subject:  Re: Need help with game

i want the image to move like on the video

Author:  chipanpriest [ Mon Dec 19, 2011 1:58 pm ]
Post subject:  RE:Need help with game

aha i cant see the video cause im at school :p

Author:  hojo12345 [ Mon Dec 19, 2011 2:02 pm ]
Post subject:  Re: Need help with game

you can't use Youtube at school i can

Author:  chipanpriest [ Mon Dec 19, 2011 2:06 pm ]
Post subject:  RE:Need help with game

lol no :/ it sucks, i know

Author:  hojo12345 [ Mon Dec 19, 2011 2:13 pm ]
Post subject:  Re: Need help with game

have you ever trying HTTPS

Author:  Dreadnought [ Mon Dec 19, 2011 3:32 pm ]
Post subject:  Re: Need help with game

I'm not sure if this will fix your problem, but its the first thing that caught my eye.

You have something like this
Turing:
if condition1 then

elsif condition2 then

elsif condition3 then

end if

When condition1 is true do condition2 and condition3 matter?
If this was intended then I apologize for bringing this up.

Author:  hojo12345 [ Mon Dec 19, 2011 3:53 pm ]
Post subject:  Re: Need help with game

it's there to change my picture when i hit the left and right keys

Author:  Dreadnought [ Mon Dec 19, 2011 7:08 pm ]
Post subject:  Re: Need help with game

Yes, but your code wont change the picture while jumping. And you can only jump straight up (no sideways motion while jumping). And since your asking how to "jump right"...

Author:  Velocity [ Mon Dec 19, 2011 7:46 pm ]
Post subject:  RE:Need help with game

to jump right you want something like this
if KeyDown (RIGHT_ARROW_KEY) and keyDown ("Your jump key") then
x += 5 % how long you want to jump on the x scale
y += 5 % how high you want to jump on the y scale
x := x %make a new x coord for the previous command
y := y %make a new y coord for the previous command
end if

think about this in depth and you should get a solution in place.

RE : You must program the jump using a more enhanced program and implement the function use an open command.
if you dont want to do that then you can just make a key command for jump like i showed above without the "and" statement and then just press the right or left arrow key while you fall from your jump
or you can make seperate keys for jumping left and jump right and jumping up, and keys for just moving left, and right.

Author:  hojo12345 [ Tue Dec 20, 2011 7:40 am ]
Post subject:  Re: Need help with game

i meant jump correctly i wanted to know if there is a way i can get an image or shape to be able to jump like the guy in the video i posted above

Author:  tg851 [ Wed Dec 21, 2011 11:15 am ]
Post subject:  RE:Need help with game

i think he means the way the character itself moves when it jumps,arching over on the jump

Author:  Raknarg [ Thu Dec 22, 2011 6:29 pm ]
Post subject:  RE:Need help with game

With some effort, it will work. I'll make a small program to show you:

Turing:

setscreen ("offscreenonly")
var y, x, vy : real := 0
var key : array char of boolean
var jumping : boolean := false

const gravity := 0.1
const speed := 2

loop
    Input.KeyDown (key)

    if key (KEY_UP_ARROW) and jumping = false then
        vy := 6
        jumping := true
    end if
    if not key (KEY_UP_ARROW) and jumping = true and vy > 0.5 then
        vy := 0.5
    end if
   
    if key (KEY_RIGHT_ARROW) then
        x += speed
    elsif key (KEY_LEFT_ARROW) then
        x -= speed
    end if

    if y < 5 then
        y := 5
        vy := 0
        jumping := false
    end if

    y += vy

    if jumping = true then
        vy -= gravity
    end if
   
    Draw.FillOval (round (x), round (y), 3, 3, brightblue)
    View.Update
    delay (5)
    cls

end loop


I'll explain this briefly. You have your x and y, obviously. The vy is also called "the change in y". You don't want to change y by a constant amount, because it isnt realistic; therefore, we need a changing number. This will suffice. The last important one is the jumping variable, which we use to detect if a character is in the air.

First, we check to see if the player has pressed the up button. If the player hasnt already jumped, then the character will begin to "jump", or we set the vy variable. The part next to it isnt nesessary. All it does it see if the player has let go while the character is jumping. If they have, it stops going up and goes down. This only happens, however, when the character's vy is greater than 0.5. After this, the function will be counterproductive.

"if y < 5 then..."
I set 5 to be the ground. When he goes below the ground, I say he's not longer jumping and set vy to 0. Lastly, I add vy to y and if the player is jumping, I take gravity away from vy. Thats basically it.


: