Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Problems with jumping in my platform game.
Author Message
GlobeTrotter

Posted: Sat Jun 12, 2004 11:10 pm   Post subject: Problems with jumping in my platform game.

This is my mario-style game.
Why is it that:
A) When you hold up and down at the same time you sort of fly.
B) When you jump from high enough and hold up, you double jump in mid-air sometimes.

Any help would be appreciated.

 code: setscreen ("offscreenonly") var x, vx, y, vy, grav := 0.0 var chars : array char of boolean var xsize, ysize := 10 var jump := true var cheats : string x := xsize + 20 y := ysize + 100 vx := 0 grav := 0.3 loop     delay (20)     cls     Input.KeyDown (chars)     if chars (KEY_CTRL) then         get cheats         if cheats = "nogravity" and grav ~= 0.07 then             grav := 0.07         else             grav := 0.3         end if     end if     if chars (KEY_UP_ARROW) and not jump then         vy := 5         jump := true     elsif chars (KEY_UP_ARROW) and chars (KEY_DOWN_ARROW) then         ysize := 7     elsif chars (KEY_DOWN_ARROW) and jump then         vy := -5         ysize := 8     elsif chars (KEY_DOWN_ARROW) and not jump then         ysize := 5     else         ysize := 10     end if     if chars (KEY_LEFT_ARROW) then         vx := -3     elsif chars (KEY_RIGHT_ARROW) then         vx := 3     else         vx := 0     end if     if jump then         y += vy         vy -= grav     else         vy := 0     end if     ysize += round (vy / 2)     x += vx     drawfillbox (0, 0, maxx, 100, 7)     drawfillbox (80, 120, 150, 140, 7)     drawfillbox (10, 160, 50, 180, 7)     drawfillbox (400, 190, 110, 200, 7)     drawfillbox (350, 110, 390, 122, 7)     drawfillbox (0, 0, 20, maxy, 7)     drawfillbox (maxx, 0, maxx - 20, maxy, 7)     for i : 0 .. 5         drawfilloval (round (x), round (y), xsize - i, ysize - i, RGB.AddColor (i / 5, i / 5, 0))     end for     drawfilloval (round (x) - 3 + round (vx), round (y) + 3 + round (vy), 2, 2, 7)     drawfilloval (round (x) + 3 + round (vx), round (y) + 3 + round (vy), 2, 2, 7)     drawdot (round (x) - 3 + round (vx), round (y) + 3 + round (vy), 0)     drawdot (round (x) + 3 + round (vx), round (y) + 3 + round (vy), 0)     drawline (round (x) - 2 + round (vx), round (y) - 3 + round (vy), round (x) + 2 + round (vx), round (y) - 3 + round (vy), 7)     if whatdotcolor (round (x), round (y) + ysize + 1) ~= 0 then         y -= 1     end if     if y - ysize <= 100 or whatdotcolor (round (x), round (y) - ysize - 1) ~= 0 then         jump := false     elsif whatdotcolor (round (x), round (y) - ysize - 1) = 0 then         jump := true     end if     if whatdotcolor (round (x), round (y) + ysize + 1) ~= 0 then         vy := -0.5     elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) ~= 0 then         y += 1     end if     if chars (KEY_LEFT_ARROW) and whatdotcolor (round (x) - xsize - 1, round (y)) ~= 0 then         x -= vx     end if     if chars (KEY_RIGHT_ARROW) and whatdotcolor (round (x) + xsize + 1, round (y)) ~= 0 then         x -= vx     end if     View.Update end loop

Cervantes

Posted: Sun Jun 13, 2004 8:23 am   Post subject: (No subject)

oh my, I love your character! You are truly an artist!!
but, unfortunately, in your attempt to give him a mouth, you created the problem that led you here.
When your character jumps and you hit down, he looks down. ie, his eyes and mouth move under his body kinda. nice looking, but it screws things up. because then when the program asks,
 code: if y - ysize <= 100 or whatdotcolor (round (x), round (y) - ysize - 1) ~= 0 then

the whatdotcolour says is checking right where that pesky mouth is and it says "no, it's not = 0" and it therefore goes into that if statement, and does this:
 code: jump := false

Now that jump is false, both of these conditions:
 code: if chars (KEY_UP_ARROW) and not jump then

can be satisfied, since jump was made false.

your second problem is the same. after a while, his mouth and eyes aim downwards if he's in the air long enough. hitting down just accelerates how long it takes before his eyes and eyebrow are underneath him.

So, basically, he's jumping off of his own mouth.
to fix it, comment out this line
 code: drawline (round (x) - 2 + round (vx), round (y) - 3 + round (vy), round (x) + 2 + round (vx), round (y) - 3 + round (vy), 7)

now he has no eyebrows, and his eyes aren't a problem because no part of them is exactly in the centre of his body (when using whatdotcolour, you check at x, the exact middle of his body. the eyes are on either side). I guess the easiest way to fix this is chaning the colours around a bit. Make his mouth a dark brown or something and incorporate that into the whatdotcolour collision.

now its time for my question(s):
in an if statement when you're comparing two things, what does ~= do? I guess its like not but im not sure. I'm ~ sure?
and what's with the ~ before chars in this if statement:
 code: elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) ~= 0 then

Cheers
SuperGenius

Posted: Sun Jun 13, 2004 9:10 am   Post subject: (No subject)

I like the complex animation of the character, in only a few lines. good job on that.
mynameisbob

Posted: Sun Jun 13, 2004 10:02 am   Post subject: (No subject)

Cervantes

Posted: Sun Jun 13, 2004 12:44 pm   Post subject: (No subject)

erg, i tihnk that you will have to do the same thing with the eyes, because if you are moving left or right one part of the eyes will have the same x value as the centre of the character..
in other words, you can do the double jump if you are moving left or right.
GlobeTrotter

Posted: Sun Jun 13, 2004 1:25 pm   Post subject: (No subject)

Thanks. I figured it out from there. I simply changed all ~= 0 to = 7 basically. Then I changed the color of my mouth and eyes so that they are different from the bricks. As for ~=, it is the same as not =.
Here is an updated example.

SuperGenius

Posted: Sun Jun 13, 2004 2:43 pm   Post subject: (No subject)

Wow i like what you did with it.
GlobeTrotter

Posted: Sun Jun 13, 2004 9:20 pm   Post subject: (No subject)

I added another level, and I have another question.
How would it be possible to stop my guy from bouncing? I may keep him bouncing since he is a ball, but for gameplay's sake, I'd like to see how the game plays without the bouncing. I didn't program the bounce intentionally, so I don't know how to stop it. Help please.

mynameisbob

Posted: Sun Jun 13, 2004 10:32 pm   Post subject: (No subject)

they both look like the same level...
i think ive found a bug in ur game. Usually when the player falls from a high place he dies, but if you hold down while falling he doesnt die.
GlobeTrotter

Posted: Sun Jun 13, 2004 11:11 pm   Post subject: (No subject)

I will try and fix the bug. It is caused by: When the player hits down and he's in mid-air it sets his vertical velocity to a certain amount (less than the max speed before he is killed). The only thing I can think of is so that when you press down in mod-air, you can can only press it once per jump.

As for them both being the same level, you have to beat the first level to get to the second.
Cervantes

Posted: Mon Jun 14, 2004 8:25 am   Post subject: (No subject)

this game has lots of potential! keep working on it.

to stop him from bouncing, try commenting out these lines:
 code: elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then             y += 2

hope that helps
beard0

Posted: Mon Jun 14, 2004 10:19 am   Post subject: (No subject)

Great game! I was messing around with your latest version, and found one little bug: When I was falling quickly, I was able to fall through some of a smaller piece of "ground" I'd suggest that you put your whatdotcolor testing in a for loop to check all the pixels between the bottom of your character, and the pixel at which his bottom would next be at the current velocity. But other than that, it looks pretty good to me.
GlobeTrotter

Posted: Mon Jun 14, 2004 3:12 pm   Post subject: (No subject)

Cervantes wrote:
this game has lots of potential! keep working on it.

to stop him from bouncing, try commenting out these lines:
 code: elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then             y += 2

hope that helps

That doesn't really help, since that is what I use so that when his downward velocity is greater than 1 and he hits the brick in the middle of it, he moves to the top of it. When I uncommented that, and jumped from a relatively high height he went right to the middle of the brick and got stuck.
beard0

Posted: Tue Jun 15, 2004 9:39 am   Post subject: (No subject)

GlobeTrotter:
Try re-commenting that section, and applying my for loop whatdotcolor testing, so that as he falls, you can stop him from getting to the middle of the ground that way. (if there's ground somwhere within the space between him and where he should be in the next frame, just set his y value to be on the ground.
Once you have this all set up, you'll have to make a level editor !

Good Luck!
GlobeTrotter

Posted: Thu Jun 17, 2004 6:44 pm   Post subject: (No subject)

I managed to stop the bounce. I also added some other features:
-cooler background
-coins
-no longer go through blocks

Here it is. You need to kill all the people to progress to the next level. Try and collect coins too.

 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 2  [ 26 Posts ]
Goto page 1, 2  Next
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: