Player Class - Code

From RoboWiki
Revision as of 21:00, 22 May 2024 by Robot (talk | contribs) (Created page with "Return back to project page: Game Controller - Jakub Vojtek Python code for the Color Sorter project: <syntaxhighlight lang=...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Return back to project page: Game Controller - Jakub Vojtek

Python code for the Color Sorter project:

 

import pygame

class Player:
    def __init__(self, x, y, width, height, speed):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.speed = speed
        self.image = pygame.image.load("pictures/jet.png").convert_alpha()
        self.image = pygame.transform.rotate(self.image, 90)  # Rotate the image 90 degrees left
        self.image = pygame.transform.scale(self.image, (width, height))  # Resize the image

    def move_left(self):
        self.x -= self.speed

    def move_right(self):
        self.x += self.speed