Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

pygame

  1. menator01

    Python Pygame pong - part 1 (Getting pygame window up and running)

    In this tutorial we will build a simple pong game with python and pygame. The final result should be simular to the below image Pygame can be installed using pip install pygame or python3 -m pip install pygame Create a python file called pong.py in the text editor of choice. I prefer vscode...
  2. menator01

    Python Pygame pong - part 2 (The paddle)

    In part 2 we will: create the paddle class create allsprites group create the paddle movement import pygame # Create empty list and sprite group players = [] allsprites = pygame.sprite.Group() class Player(pygame.sprite.Sprite): ''' Player class will define our player and player...
  3. menator01

    Python Pygame pong part 3 - (The Ball)

    In part 3 we will be creating the ball class Give the ball a size Give the ball a color Give the ball a random velocity and direction when colliding with the paddles or wall class Ball(pygame.sprite.Sprite): ''' The Ball class creates the ball for our pong table. ''' def...
  4. menator01

    Python Pygame pong part 4 - Scoreboard

    In part 4 we will create a scoreboard placed at the top of the pong table In the while loop add # Draw the scoreboard to screen board = pygame.Surface([window[0], 40]) board.fill((60,60,60)) screen.blit(board, (0,0)) # Add a font font = pygame.font.Font(None, 24)...
  5. menator01

    Python Pygame pong part 5 - (Start Page)

    In the 5th and final part of the tutorial we will create a start page for our pong game. The start page will present some text an image and instructions on how to start the game. # Class creates a start/title page class Page: def title(self): ''' title method creates a start page...
  6. menator01

    Python Simple pygame dodge car game - Introduction

    In this tutorial, we will make a simple pygame dodge car game. Requirements: python 3.12 Note: python 3.10 and 3.11 will probably work. pygame 2.5.2 Images I used images from opengameart specific images are pixel-race-car-pack Editor of choice. I use vscode The game should look something like...
  7. menator01

    Python Simple pygame dodge car game - pygame window

    The directory structure I'm using: car media images cars car.py car being the main folder, media to hold all the media types folders, images, and then the folder holding car images car.py should be something like: # Do the imports import pygame import os ''' Get the path of the...
  8. menator01

    Python Simple pygame dodge car game - The Road

    In this tutorial we will be creating the road. Although there are several ways of doing this, I created three functions. One function for the blacktop part, one for the 2 yellow lines, and one for the white dotted line # define a function to draw the yellow lines def line(surf, x): line =...
  9. menator01

    Python Simple pygame dodge car game - Player and Mobs

    In this tutorial we will be creating a classes for the player and mob cars In the cars images I downloaded, I took and edited the images with gimp as the has space around them that was causing the mob cars to hit the player car at a distance. I just used crop to shrink/remove the spaces. I've...
  10. menator01

    Python Simple pygame dodge car game - sprite collisions

    In this part of the tutorial we will be adding sprite collision detection In the game loop, I put it right under the update and draw ''' Mob has moved off the screen kill the sprite. Create a new mob. ''' if mob.rect.top > 720: # Screen height mob.kill()...
  11. menator01

    Python Simple pygame dodge car game - Scoring and start page

    In this final part of the tutorial we will implement a scoring system and start page Scoring: Create a function for displaying text Player class add attribute for keeping the score total Blit the score to the screen function for displaying text def score(score): # Create a font and size...
  12. User8574

    Python How do I remove the background of an image (Pygame)

    I tried using Gimp to make an alpha channel, I tried using convert_alpha(); how do I remove the background of an image on pygame?
  13. User8574

    Python Pygame: screen.fill and screen.blit not working, please help!

    # Modules import pygame, sys # Init / Clock pygame.init() clock = pygame.time.Clock() # Display Setup screen_width = 1920 screen_height = 1080 screen = pygame.display.set_mode((screen_width,screen_height)) pygame.display.set_caption("Coin Collector") # Objects coin =...
  14. User8574

    Python I make a global variable and then it says it isn't defined, wtf? (Python / Pygame)

    def ball_animation(): global player_score player_score = 0 player_score_surf = font.render(str(player_score), False, (10,10,10)) Apparently player score is not defined. Please help! I tried taking it out of the function above it and it still doesn't work.
  15. User8574

    Python 'Function needs at least three arguments' Pygame screen.blit error

    screen.blit(player_score_surf, (200,200)) I get an error that screen.blit requires three arguments. I tried adding centre as the third as the point of which is at 200,200, but that still doesn't work. How do I fix it?
  16. Wolfmann Games

    Python How to continue sound in Pygame?

    I have a sound that I wish to play. My code; [...] if var_camera_flip == 1: if var_camera != 4: pygame.mixer.Channel(2).play(pygame.mixer.Sound(r'audio\camera\camera motor.mp3'), -1) else: pygame.mixer.Channel(2).stop()...
Back
Top Bottom