Making a Game WITHOUT an Engine?!
45sThe hook challenges the norm of using engines, sparking curiosity about how it's possible.
▶ Play Clip"The title promises a game without a game engine, and the video delivers exactly that, though the process is longer than necessary due to debugging."
The video demonstrates how to create a simple 2D game using Python and Pygame, without relying on a traditional game engine. The creator walks through setting up the environment, writing the code, and debugging issues, emphasizing the importance of understanding code even when using AI assistance.
The creator starts by explaining the goal: to create a game using Python and Pygame, without a game engine. They mention their preference for moving away from Windows to Linux but proceed with Windows for this tutorial.
The creator installs Python 3 and pip, then uses a virtual environment to install Pygame. They verify the installation by checking the pip version (24.0) and running a Pygame test.
The creator creates a main.py file in the project directory, which will contain the game code. They explain that this file initiates the application.
The creator imports Pygame and system libraries. They explain the concept of frameworks and packages, using the analogy of building a base and adding features for specific tasks like game development.
The creator defines a function called 'load_assets' and explains Python's syntax, noting the use of indentation instead of curly braces. They also define window width and height as constants.
The creator creates the game window using pygame.display.set_mode, sets the caption to 'My First Python Game', and creates a clock object to control the frame rate.
The creator defines the player as a 50x50 square with a starting position. They explain the game loop, event handling, and keyboard input for movement, noting the use of arrow keys.
The creator adds boundary checks to keep the player inside the window. They explain the rendering process, including filling the screen with a color and drawing the player as a yellow rectangle.
The creator limits the game to 60 frames per second using the clock. They discuss the importance of frame rate for consistent physics and mention the game loop's exit conditions.
The creator encounters an error message and consults ChatGPT, which suggests it might be a text editor issue. They run the game and successfully move the square, then change the speed to 20 to demonstrate the effect.
The creator realizes the error was due to a VS Code extension issue, not the environment. After fixing the extension, the game runs successfully. They emphasize that AI tools like ChatGPT require understanding to avoid garbage code.
The creator reflects on the process, noting it took over an hour of debugging. They highlight the achievement of building a game from scratch without a game engine and encourage viewers to learn Python gaming.
The video successfully demonstrates how to create a basic 2D game using Python and Pygame, emphasizing the importance of understanding code and debugging. It serves as a beginner-friendly introduction to game development without a game engine.
What library is used to create games in Python?
Pygame
02:04
What is the purpose of a virtual environment?
To isolate project dependencies and avoid conflicts.
01:49
What does pygame.display.set_mode() do?
Creates the game window with specified dimensions.
05:20
Why is frame rate important in games?
It affects physics consistency; different frame rates can cause physics to behave differently.
06:02
What is the difference between a variable and a constant?
Constants cannot be changed, while variables can.
05:08
How do you handle keyboard input in Pygame?
Using pygame.key.get_pressed() to get the state of all keys.
07:55
What does pygame.draw.rect() do?
Draws a rectangle on the screen.
09:50
What is the purpose of the clock object?
To control the frame rate of the game.
05:47
What does the 'while running' loop do?
Keeps the game running until the player quits.
07:26
What is the RGB color model?
Red, Green, Blue - used to define colors in Pygame.
09:50
Pygame Installation
Shows the exact command to install Pygame, a key step for any Python game developer.
02:04Python Syntax Explanation
Explains Python's use of indentation instead of curly braces, helpful for beginners.
04:28Frame Rate and Physics
Highlights the importance of frame rate for consistent game physics, a critical concept in game development.
06:02AI as a Tool
Emphasizes that AI tools like ChatGPT require understanding to avoid generating garbage code.
12:50Building from Scratch
Demonstrates that a game can be built without a game engine, encouraging DIY development.
14:30[00:03] I have to watch myself when I do this cuz I'm sitting in underwear. [laughter] starts getting naughty. So today we're going to learn how to uh create a game this down cuz this is immediately after the previous video, but I am using
[00:18] Windows, which is something that I I'm actually trying to actively get away do a transition for the past little while where I'm trying not to use these sort of products that are being monopolized by these big IT companies
[00:31] where they just start like injecting ads into our computer that we don't want. trying to get away from Windows 11 and I want to get into Linux. Totally off track here for a second, but basically we're trying to set up Python. So it
[00:47] recommends the Windows terminal which started this whole thing. So, uh, Windows Terminal supported by Microsoft can run PowerShell. I do have can run PowerShell. I do have PowerShell. I do also have WSL.
[01:00] Oh, it even says here, old cmd.exe still works but outdated. Okay, you know, works but outdated. Okay, you know, we're going to use then. So, Python 3 we're going to use then. So, Python 3 version. Yes, that. Okay, that did not
[01:12] work. And again, we're going to take a screenshot cuz this is obviously not working. So, just going to send that. Is it messing me up that I'm using uh it messing me up that I'm using uh Ubuntu instead or WSL? I can try again.
[01:25] Ubuntu instead or WSL? I can try again. Oh, and it's doing it. Okay. Did I Did I Yeah. Okay, it is installing pip. So, now we need to verify that it works. I always love seeing this when I use the terminal. It just looks awesome when
[01:37] it's compiling [music] and installing and doing different things. I look like a hacker. [laughter] Okay, so it's done. Uh, so we can check for the version. So basically we have pip 24.0.
[01:49] pip 24.0. Do this use a virtual environment. and then we're going to go and create a virtual environment. And now we can upgrade. So we're going to do that. Boom. And it's going to work exactly
[02:04] like we expected it to. going to install Pygame uh which I'm guessing is a framework in order to uh either like a a package or framework or something in order to start making games. Okay, so it says hello from Pygame community.
[02:19] Awesome. So right now we we have a directory but I I don't actually have a game. So no, yeah, you do not have a game yet. You just have a project folder and a virtual environment. So inside the project folder, we're going to create a
[02:34] file called main.py. Pi, we can just uh go in here. Which which side? This side. Oh my god, it's so tiny. Zoom in. Uh so this is our virtual environment. So what this is our virtual environment. So what I want to do is I want to create a file
[02:49] which should be inside this directory here called main.py. And the main.py file I believe is the file that we need to initiate our application, which in a game. Okay, we're just going to copy the code here and we're just going to
[03:04] take it step by step inside of here. If I wrap it down. So, we import the Pygame library so we can create a window and handle input. And we do that by simply importing Pygame, which we did just install. You have to see like C and
[03:19] Python and all these programming languages. You have to see them as like you have this base thing and if you want to do something else with it, let's say you want to build a mobile game or you want to build not a mobile game, a
[03:32] mobile app or you want to build a Windowsbased game that you can you know play on Windows or you want to build a website you know then you have to figure out what framework and packages are used in order to build those things and you
[03:46] import them into your applications. So in this case, we want to build a game using Python. So we're importing Pygame. Uh we can also import system. So we cleanly exit the program when the windows is when the window is closed.
[04:01] That's good. We need that as well. I'm noticing Python has some uh like the way like uh syntax, it doesn't close off with a semicolon. Like it just like minimizes how much you actually need to write in order to get things working.
[04:16] Like there's not all this junk. Uh, I know that's something that some programmers they hate seeing when it comes to Python, but I actually think it looks uh, it looks good. It looks clean. And basically, if you're writing a
[04:28] function, you would say something like is it define defaf? It's is it just deaf? Yeah, deaf. Okay, so basically load assets, right? So you just basically this is a function called load assets and you don't write curly
[04:41] brackets. to just indent out basically and that's going to tell it okay so that's for this particular function we initialize all imported pygame modules initialize all imported pygame modules so graphics sound input etc okay so we
[04:55] say pygameinit so we initialize it now we do also need to define the window width and the window height these are just variables anything in front of it we just write the name of it actually these are
[05:08] constants so they don't change these are these cannot be changed I guess if we have to be able to resize the window, it has to be a variable, not a constant, I'm guessing. But basically, we then go in and say we create the window using
[05:20] width and height defined above. So we say that the screen variable is going to say that the screen variable is going to be equal to py.d display set mode which basically goes in and grabs these parameters in order to create a window
[05:34] and then we set that window equal to screen. So inside the display the window that we [music] create we want to set a caption called my first Python game. Then we want to create a clock object to control how fast the game runs. So
[05:47] frames per second. This is I believe inside Unity we have in C something called update and fixed [music] update. Update is just like the frame rate and fixed update is for physics. Because if you put everything inside update, which
[06:02] means that if you have a really, let's say you have a bad computer that can only run a game with like 20 frames per second, then you have a supercomputer that can run a game at 140 frames per second, then all of a sudden the physics
[06:15] in the game gets out of whack cuz it's unoptimized for like the different frame rates cuz they change. So frame rate is very important. Uh, and I'm guessing this is just update inside Uni or like inside C. It's not fixed update, it's
[06:31] update. So just updates per frame. Uh, which can be a little bit troublesome if which can be a little bit troublesome if we are trying to make physics, but we'll just go with it for now. It can always like let's see player setup. Define the
[06:44] size of the player, which is going to be a square. So width and height. Uh, so we have a player size and then we have a starting position. So X and Y coordinates cuz this is a 2D game. Play a size 50. Oh, so both the width and
[06:57] height. So if I wanted size to be like the height, then we could say size Y, then size X, you know, to to have different sizes. But let's just go with a square cuz that is what it's trying to to give us here. So for each frame when
[07:11] it five pixels. [music] And this is where the issue comes in. if frame rate is different on different machines. This variable keeps the game running until the player quits. Okay, so this basically variable is a boolean.
[07:26] It's a true and false statement. It says okay, so if this one is true, then while this is true, so while it's running then do these things. So in this case here, loop through all events. So keyboard, mouse, window, and close. Basically just
[07:40] going through if we have any sort of inputs is the mouse moving and are we closing the window then I guess yeah it's going to set it to false so it's going to quit the game so keys equal to pygamekey get pressed so any sort of
[07:55] keyboard click I do is going to get recorded into this variable and then we're going to check what this variable is so if I click on J it's going to be registered as J inside keys and then it's going to go down and check. Okay.
[08:11] it's going to go down and check. Okay. Does this keys variable actually uh fit So, my keyboard does left and right and up and down, right? So, if it's left, then we move the player left by simply minusing the player's position on the
[08:25] minusing the player's position on the x-axis with the speed we defined. Uh, register my up and down, left and right, just like, which I hate, by the way, cuz I always use WD like any other video game does. But for some reason, whenever
[08:39] there's a tutorial on how to make a game, they used the arrow keys. And that's kind of like, you know, a '9s sort of game thing. Like, we don't do that today, unless you're making a a two-player game where one person can use
[08:53] one and one can use the other. Uh, keep the player inside the window boundaries. So, basically, if the player gets outside the boundary, then then stop outside the boundary, then then stop activating the uh the movement script. I
[09:05] for fun at my work. Uh just a fun fact cuz I was bored one Friday. Um I built a browser cuz they blocked off all sorts of websites and I I you know if I wanted JavaScript. I built this game where you
[09:20] each other and you had to like paint as many tiles as possible. In that game you can move outside the boundary which is kind of fun to see. Okay. So drawing what is it called inside Unity? um rendering. Yeah, render right when you
[09:35] render the different uh objects. So, fill the entire screen with a dot taking the screen and we say do fill which is a function that goes in and fills. And then we say we want to have this particular color. So, this is RGB.
[09:50] This is red, green, blue, right? Draw the player as a yellow square on the screen. So, pygame.draw.rect which is basically draw this rectangle. draw on the screen and then we want to have these colors here or this color and
[10:04] have these colors here or this color and then we want pygame rectangle which is then we want pygame rectangle which is so pygame.rect. So we're basically oh it's because I saw it here. I was like h I saw it somewhere. Uh so we want to
[10:17] draw a rectangle and it's going to be based on the player x the player y and the player size. So in that location with that particular size which was 50 I believe it says here literal 50. Okay. So limit the game to 60. Okay. So this
[10:31] about game speed. But what if you have a device that cannot push 60 frames pers? I mean you have to have a pretty old computer for this symbol game. But there has to be some sort of solution there to avoid insane physics inside the game.
[10:45] What does flip do? It doesn't say. And then we have the exit. So pygame.quit and then cis.exit. exit. One thing that I'm interested in here is, okay, so it's going to draw my character, but if I then move my character, is it going to
[10:59] is it moving the rectangle or is it going to redraw it? Cuz then the there. I guess it's creating an object and not as much drawing in the square. Like if that's built into Pygame and that's how the the engine works or like
[11:14] the the frameworks, then that is probably fine. It is giving me an error message though. Let me uh let me send this to chat dbt. Okay. Well, according to uh according to it, it's it's going to
[11:28] work. So, maybe it's just because my uh text editor is not updated for Python. So, let's uh let's actually run it, I think. Is it uh is it going to give me an error message now because I'm not writing Python 3? No, I guess not.
[11:50] outside the boundary. That's awesome. So, okay. So, if we close this down and go in and we change the speed cuz let's uh let's do that. Let's uh have it be 20. We go in. Oh my god, [laughter]
[12:04] that's so cool. I mean, you know, for the for people who, you know, want to make a game game, this is probably not too impressive, but I want you to stop and think for a second. This is built from scratch. And I know chat dbt has
[12:19] kind of like fed it to me, but people widely misunderstand using chat dbt cuz if you ask it for code, you need to be able to read the code and understand what it does before you start using it. You don't just copy paste and then just
[12:35] don't even bother understanding the code cuz chat GPT will create garbage code often. For now, I think this is fine. Let me see what it says about the error messages cuz it is probably a VS Code thing. Okay, I think I might be over
[12:50] complicating things because I'm using Ubuntu and I have to set up the virtual environment and I don't know. I'm I probably still need to do that, but it probably still need to do that, but it it clearly does not know that I have
[13:02] Pygame installed. Okay, so we're going to go back out again. I'm going to restart and we're just going to delete everything and I'm going to go with Windows PowerShell. So now we need to do
[13:14] everything from scratch. Okay, so basically we need to go and redownload Python for Windows. [laughter] This is so dumb. And it should hopefully this time work without throwing error messages. Copy. There we go. Good. And
[13:32] it still gives me the error messages. Oh, that's so annoying. [laughter] Oh, that's so annoying. [laughter] Python type checking mode overrides. Okay, so right now I'm not getting any sort of error messages. I just had to go
[13:48] in and change my extension. So I could have made this using Ubuntu or WSL in Windows we're going to stick to PowerShell for now. But it was just an
[14:00] extension issue. This is one of the things I I said, you know, like AI is good, but it's just a tool. It's not going to replace anything cuz you need to know how to use it. In this case here, it let me in wild circles. I
[14:14] basically installed everything twice and everything came down to an extension everything came down to an extension error. So, it's working now. And if I actually run this, you can see that we do have a game running
[14:30] that can do something. Either way, this is the beginning. We set up a square that can move. And my recording here is one hour and 17 minutes long [laughter]
[14:44] to to get this working. This was basically just debugging for like an hour in order to get this working. Like just like my editor not giving error messages. First step in learning Python, at least Python gaming. What do you guys
[14:57] think? I think this is kind of awesome to see like an actual game being built, but it's not being built by some company owned, you know, application like Linux. owned, you know, application like Linux. So, not not Linux, um, uh, Unity or
[15:12] Unreal Engine. With that said, I hope you enjoyed and I'll see you guys next you enjoyed and I'll see you guys next time.
⚡ Saved you 0h 15m reading this? Transcribe any YouTube video for free — no signup needed.