ChatDev/WareHouse/RunningGame_THUNLP_20231023211843/sprites.py
2023-10-26 15:59:16 +08:00

26 lines
814 B
Python

'''
This file defines the Block and Obstacle classes.
'''
import pygame
class Block(pygame.sprite.Sprite):
def __init__(self, x, y, size):
super().__init__()
self.image = pygame.Surface((size, size))
self.image.fill((0, 0, 0))
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.speed_y = 0
def update(self, gravity):
self.speed_y += gravity
self.rect.y += self.speed_y
class Obstacle(pygame.sprite.Sprite):
def __init__(self, x, y, width, height):
super().__init__()
self.image = pygame.Surface((width, height))
self.image.fill((0, 0, 0))
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
def update(self, speed):
self.rect.x -= speed