]> _ Git - website-v3/.git/commitdiff
start work on overly detailedly detailing how my little platformer game works in...
authorparking_turkeys <roya1060wien@gmail.com>
Tue, 14 Jul 2026 23:34:49 +0000 (19:34 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Tue, 14 Jul 2026 23:34:49 +0000 (19:34 -0400)
pages/2026-07-14_raylib_platformer.html [new file with mode: 0644]

diff --git a/pages/2026-07-14_raylib_platformer.html b/pages/2026-07-14_raylib_platformer.html
new file mode 100644 (file)
index 0000000..290daca
--- /dev/null
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML>
+<HTML>
+       <HEAD>
+               <TITLE>notes on the platformer i'm making</TITLE>
+               <META NAME="viewport" CONTENT="width=device-width, initial-width=1">
+               <LINK REL="stylesheet" HREF="../style.css">
+       </HEAD>
+       <BODY>
+               <H1>Platformer I'm making in raylib</H1>
+               <P>[<A HREF="../tags.programming.html">programming</A>:gamedev, <A HREF="../tags.programming.html">programming</A>:C]; Last updated 2026-07-14</P>
+               <BR>
+               <P>So recently I learned about this game engine-type thing, <A HREF="https://raylib.com">raylib</A>. It's pretty cool; it basically gives you a lot of the most basic things for games and stuff, like ... drawing a rectangle or image on the screen, and checking whether two rectangles overlap.</P>
+               <P>After getting bored with another game (in Godot), I decided to try making something in it. Turns out it's like really hard. So here are my notes on how I structured my program, mainly because I'm trying to fix a bug and I'm hoping this will help.</P>
+               <H2>The main loop</H2>
+               <P>Ok so in main.c there's a loop that loops while <CODE>(!WindowShouldClose())</CODE>. <CODE>WindowShouldClose()</CODE> is true when Escape or the Close button on the window is pressed. This loop then has two parts — the part that gets everything ready for drawing on the screen, and the part that ... draws on the screen. This is the basic setup in all of the raylib examples.</P>
+               <P> First, the loop checks if <CODE>frozen</CODE> is true (or well 1). This is true when dialogue is going on. Dialogue is all shown during the drawing part for the level, so when frozen is true it just stops any of the other stuff from being updated. (in the function <CODE>variables()</CODE>)</P>
+               <P>If <CODE>frozen</CODE> is false (or 0), the like moving around stuff happens. This happens in the function <CODE>variables()</CODE>, which calls two functions — <CODE>spieler_bewegen()</CODE> (move player[m. technicially]) in <CODE>player.c</CODE>, and <CODE>physics()</CODE> in <CODE>physics.c</CODE>.</P>
+               <H2>Moving the player</H2>
+               <P>The two functions work together to move the player — <CODE>spielerbewegen()</CODE> calculates the <CODE>velocity</CODE> (in both x and y directions) of the player based on where they are and what inputs the user inputs. Then, <CODE>physics()</CODE>sets the <CODE>x</CODE> and <CODE>y</CODE> of the player based on this.</P>
+               <P>As to the player themselves, they are a <CODE>struct</CODE> with a <CODE>Rectangle</CODE> (raylib type) named <CODE>rect</CODE> defining where they are, and a <CODE>Vector2</CODE> (also raylib type iirc??) named <CODE>velocity</CODE> defining how they will move in pixels per second.</P>
+               <P>A lot of the structure of this is just taken from some godot code I had because it seemed like it worked.</P>
+               <H3><CODE lang="de">spielerbewegen()</CODE></H3>
+               <P>First, <CODE>spielerbewegen</CODE> sets a file-wide variable to the frametime/delta. This is for animation purposes.</P>
+               <P>The next part checks whether the player is on the floor, using a function defined in <CODE>level.c</CODE>. If they are <i>not</i>, the constant <CODE>GRAVITY</CODE> defined in <CODE>game.h</CODE> is added to their y velocity. Otherwise, their y velocity is reset to 0.</P>
+               <P>The next if/else checks whether the player should jump. If <CODE>inputs[2]</CODE> is pressed down, and <CODE>on_floor</CODE> returns 1, they jump and their y velocity is changed to the constant <CODE>JUMPVELOCITY</CODE>.</P>
+               <DETAILS>
+                       <SUMMARY>how <CODE>on_floor()</CODE> works!</SUMMARY>
+                       <P>First, I had to decide how I would define "on the floor". I decided that the best choice would be if the player is right on top of a platform but not colliding with it.</P>
+                       <P>Each level is made up of an array of platforms (a <CODE>struct</CODE> with a <CODE>Rectangle</CODE> named <CODE>rect</CODE> and a <CODE>Color</CODE> named <CODE>colour</CODE>), so this function loops through them and checks each seperately.</P>
+                       <P>This is checked in two parts. First, the y-value is checked. If the player is on the floor, the y-value of the bottom of their rectangle should be equal to the y-value of the top of the platform. The x/y coordinates in raylib are of the upper left corner, so this is <CODE>if ((rect-&gt;y + rect-&gt;h) == (check&gt;y))</CODE>.</P>
+                       <P>After that, the x-values are checked. I decided the easiest way to do this would be to use the built-in function in raylib to check if two rectangles are overlapping, and then just make the rectangles have the same y and height. So, this basically tests if two lines are overlapping. If they are, then the x and y both match up, and the function returns 1. Otherwise, it keeps looping. If it reaches the end of the array and none of them match, then the player is not on the floor, and it returns 0.</P>
+               </DETAILS>
+               <P>After this, the program sets the variable <CODE>direction</CODE> to 1 for right, -1 for left, or 0 for neither. It does this by looking at what keys are pressed. Then, <CODE>player.velocity.x</CODE> is set to <CODE>SPEED * direction</CODE>, and that's the end of the function. (It returns 1 in case I want to add errors later.)</P>
+               <H3><CODE>physics()</CODE></H3>