This is because we’ve shifted control of the Player’s position to the self.pos variable. Notice that we’ve removed the center parameter. The first parameters represents acceleration/velocity along the X axis and the second is for the Y axis. There is horizontal acceleration and also vertical acceleration.
Remember, velocity and acceleration are vector quantities. If you’re good with maths and physics, you’ll understand this quickly.Ĭreating two dimensional vectors allows us to keep things simpler. If you go back and look at the start where we initialized it, you’ll see that it’s creating vectors. vec is simply used to create variables with two dimensions. This is because we haven’t drawn any of the objects we created above to the display screen. We have no images to show our progress so far, because the screen still shows the same black screen as before. It starts with basic concepts of programming, and is carefully designed to define all terms when they are first used and to develop each new concept in a logical progression. This is the second edition of Think Python, which uses Python 3. These names are completely arbitrary of course, and you can change them to whatever you want. Think Python is an introduction to Python programming for beginners. Remember, top left hand corner is the origin point with the co-ordinates (0, 0).įinally, we create two objects, PT1 (stands for platform 1) and P1 (stands for Player 1). The center = (10, 420) and center = (WIDTH/2, HEIGHT - 10) parameters we passed are used to define the starting position of the objects when they are drawn to screen. Finally, we create a rect object from the surface object using the get_rect() method on the surface object.
Built on top of the highly portable SDL (Simple DirectMedia Layer) development library, pygame can run across many platforms and operating systems. We give each of them a color using the fill() function (RGB format). The pygame library is an open-source module for the Python programming language specifically intended to help you make games and other multimedia applications. We create surface objects for each class with a fixed size. Most of this should only require basic Pygame knowledge. Self.rect = _rect(center = (WIDTH/2, HEIGHT - 10))