Before we being creating the paddle we need to initialise pygame by making one call which is pygame.init(). This will attempt to initialise all the pygame modules for you that you will be using. Personally I like to put this code after all my functions because it works better to have your functions right underneath your variables. (We will be doing the functions in a later blog).
Before we started creating the paddle we need to set up the pygame window that the game will run in. This is done by using the pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)), these are the variables that we set up in the last post, and this should be saved in a variable called windowSurface. Next we are going to add a tittle to the top of the window. This is done by adding the line of code pygame.display.set_caption("GAME"). Where I have put the word "GAME" is where you can call it whatever you want.
Now that we have the window set up, we can begin creating the player's paddle. We can do this by calling the Rect method and saving this information in a variable called player. The parameters you put in this method relate to where you want to put it on the screen(x-axis and y-axis) and the length and width you want to set the paddle to. Once you have this done you need to add it to the window by adding in pygame.draw.rect(windowSurface, BLACK, player). This draws the player object onto the window in the colour that I have saved in the BLACK variable.
In the next blog post I will show you how to move the block using users' input.
No comments:
Post a Comment