![]() As you can see we insert the SPACE variable to load our space image, the process is the same we get the “path” with the OS, of course, it’s in the same folder than our spaceship image. Now it is time to place the background that we downloaded, for this we repeat the process of inserting the spaceship. We can also do other fun things like rotate the spaceship for example. The result is incredible! now we have our little spaceship. Take our SPACESHIP image do “transform” and “scale” in this case to 65 and 50. In order to fix the size we are going to scale the image. We also see that our ship is too big so we proceed to scale it now. You can see we have our spaceship on a black background which is the default light background so we can actually assign whatever background color we want but in this case it won’t be necessary. Something important to understand is that pygame’s coordinate system starts from the top left, this will be our (0,0), so if I put x = 300, my image will move 300 to the right from the top left and if I put y = 100, my image will be positioned 100 down from the top left corner. What we are going to do is place our spaceship in the window, for this we use “blit”. Now we are going to create a function to draw on the window. Create a variable to load the image called “SPACESHIP” and write the path to find the image “os.path.join(‘Images’, ‘space.png’)”. We import OS which means “Operating System” this helps us to load the images from the directory where we put them. In this case we open the window until the exit event occurs.Īfter running the code the windows appear according to the defined size. Then we define a window and give it the WIDTH and HEIGHTĪfter that, we create a main function and inside it we create a loop to open the window and execute some actions. ![]() ![]() We import pygame and then define some constant variables WIDTH, HEIGHT and assign them some values. Now it’s time to put all these images into our game, to do this we’re going to create a python file named “game” This is important for loading the images in our code. Give the folder a name in this case named it “Images”. Save the images to a folder and place it in the “Game” file directory. Again we can choose from a variety of great backgrounds for our games. Now if you go to freepik you are going to find some great backgrounds in this case we are looking for space backgrounds so in the search bar we type “space backgrounds”. Now you have a lot of fun arcade icons for your game. ![]() Getting some Images and Iconsįirst of all I’m going to show you how to get some arcade icons for free, just go to flaticon and in the search bar type “arcade”. There are other platforms like Unity that are easier to use. To make complex 3D games you can use Panda 3D with Python but as I said it is very complex. Pygame is used more for learning, it’s a great tool that can make very complex games with python logic, but it’s all text based and can only make 2D games. Pygame is recommended to create games very easily. The first release was in October 2000 and the stable release in 2021. It includes graphics and sound libraries for the Python programming languages. Pygame is a Python module that helps us create games.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |