From: parking_turkeys Date: Wed, 15 Jul 2026 00:08:41 +0000 (-0400) Subject: finished the second part of the yap X-Git-Url: http://git.p-t.hackclub.app/?a=commitdiff_plain;h=ccd857fde54757d815f244d408a58c554857114d;p=website-v3%2F.git finished the second part of the yap --- diff --git a/pages/2026-07-14_raylib_platformer.html b/pages/2026-07-14_raylib_platformer.html index 290daca..af10e47 100644 --- a/pages/2026-07-14_raylib_platformer.html +++ b/pages/2026-07-14_raylib_platformer.html @@ -32,3 +32,18 @@

After this, the program sets the variable direction to 1 for right, -1 for left, or 0 for neither. It does this by looking at what keys are pressed. Then, player.velocity.x is set to SPEED * direction, and that's the end of the function. (It returns 1 in case I want to add errors later.)

physics()

+

The physics() function does multiple things, but its main thing is that it runs the move_player() function in the same file. This is the function that translates the velocity of the player into its new x/y coordinates.

+

First, it figures out how far the player actually has to move. This is done by literally just delta*velocity for both x/y. Then this is rounded away from 0, so that the player never moves 0 pixels.

+

The way the function actually moves the player while making sure that they don't just go into a platform is simple. The program moves them in smaller steps; if the player has collided into a platform, they then are rewinded one step. After this, the program just moves them one pixel in both x/y until they collide with a wall so that it doesn't end with them 1 pixel above the ground and unable to jump.

+

The amount of steps and how large they are is done so that neither x nor y is less than 1 pixel. This is done with a bunch of if statements.

+

    +
  1. If both the x distance and the y distance are 0, there are... 0 steps and all steps are 0 pixels, because uh. they don't have to be moved at all.
  2. +
  3. If only x is 0, the amount of steps is |y| (since negative steps wouldn't work), and each step for y is distance.y/steps_phys (steps physics, idk why i think i was worried steps would conflict with something). This is so that if distance.y is negative, stepy is still negative.
  4. +
  5. If only y is 0, it's the same thing, but with x instead of y. so steps_phys = abs(distance.x); stepx = distance.x/steps_phys;
  6. +
  7. If neither is 0, but the absolute value of x is greater than that of y, steps_phys becomes the absolute value of distance.y. This is so that stepy isn't less than 1/-1. Then, stepy becomes distance.y/steps_phys, so -1 if distance.y is negative, or 1 if it's positive. stepx becomes ceil(distance.x/steps_phys, or literally just the amount needed to accomplish the distance within the steps given.
  8. +
  9. If the absolute value of y is greater, it's literally the same as the last one, just swap "x" and "y".
  10. +
+

After figuring out the steps and how large they are, there is a for loop that loops for each step and adds stepx to position.x and stepy to position.y. After that, it checks if the player is in the ground. If this is true, it subtracts stepx from position.x and stepy from position.y, and enters another loop.

+

This second loop uses the same variable (i) as the first one, so it only continues for as many loops as the first one had left. It literally just adds or subtracts 1 (based on whether stepx or stepy was positive or negative) from position.x and position.y until the player goes into a wall, where it then moves back 1 in both directions. The idea of this loop is so that the player doesn't end up just floating a couple pixels off of any platform. Then, the function is ended.

+

The rest of physics() is very simple. All it does is check if the player is off the right side of the screen. If so, it changes to the next level, sets frozen to 1 in order to allow dialogue to play, and moves the player up to the top left of the screen. Also, it breaks the game somehow. When I added the frozen=1it started closing the window on reaching it. This doesn't happen when main() does this, so I have no idea why it happens here. (that's also partially why I'm writing this, I hope i can figure it out...)

+

Drawing on the screen