def create_touch_buttons(self, button_width): ## Create rectangles that will detect direction self.left = pg.image.load("img/left.png").convert_alpha() self.left = pg.transform.scale(self.left, (button_width, button_width)) self.right = pg.image.load("img/right.png").convert_alpha() self.right = pg.transform.scale(self.right, (button_width, button_width)) self.power = pg.image.load("img/power.png").convert_alpha() self.power = pg.transform.scale(self.power, (button_width, button_width)) self.shot = pg.image.load("img/shot.png").convert_alpha() self.shot = pg.transform.scale(self.shot, (button_width, button_width)) self.left_rect = pg.Rect(0, self.size[1] - button_width, button_width, button_width) self.right_rect = pg.Rect(button_width, self.size[1] - button_width, button_width, button_width) self.shot_rect = pg.Rect(self.size[0] - button_width, self.size[1] - button_width, button_width, button_width) self.power_rect = pg.Rect(self.size[0] - button_width * 2, self.size[1] - button_width, button_width, button_width)
def __init__(self, x, y, size, win): self.width = size/2 self.win = win self.gap = pygame.Rect(x+self.width, y, self.width, size) self.upper_pipe = pygame.Rect(x, 0, self.width, y) self.lower_pipe = pygame.Rect(x, y+size, self.width, win.get_height()-y+size) self.movement_speed = 13.5 self.passed = False
def kill(self): current_center = self.coordinates.center # Change animation to DEAD self.rect = pygame.Rect((self.coordinates.x, self.coordinates.y), ENEMY_CONFIG['ENEMIES']['DEAD']['SIZE']) # Center image self.coordinates.center = current_center # Delete enemy from physical map self.rect = pygame.Rect((self.coordinates.x, self.coordinates.y), (0, 0))
def __init__(self, x, y, width, height, color, on_click, args=None): self.width = width self.height = height self.color = color self.args = args self.on_click = on_click self.rect = pygame.Rect(x, y, width, height)
def __init__(self, x, y, s, color, health): self.s = s self.color = color self.rect = pygame.Rect(x, y, s, s) self.health = health self.inithealth = health self.font = pygame.font.SysFont("DejaVuSans", self.s * 0.2)
def __init__(self, size, offset, border=1, border_color='#FFFFFF', color='#111111', protected=False): super().__init__() self.protected = protected self.is_active = False self.text = '' self.font = pygame.font.Font('./fonts/space_invaders.ttf', 24) self.text_label = self.font.render(self.text, 1, (255, 255, 255)) self.border = border self.bottom_image = pygame.Surface(size) self.bottom_image.fill(pygame.Color(border_color)) width, height = size self.top_image = pygame.Surface( (width - 2 * border, height - 2 * border)) self.top_image.fill(pygame.Color(color)) self.rect = pygame.Rect(*offset, *size)
def __init__(self, image_path, position, visible): """Initialise les attributs visuels et d'observation""" pygame.sprite.DirtySprite.__init__(self) Observer.__init__(self) # monochromatic surface instead of images may be allowed later self.image = load_image(image_path) self.rect = pygame.Rect(position, self.image.get_size()) # self.mask = pygame.mask.from_surface(self.image) # currently not used, good thing because pygame_sdl2 does not support it yet self.visible = visible # TODO: should affect detection self.subject_list = []
def __init__(self, size, offset, color=None): super().__init__() self.health = None # If color exists - create Surface if color is not None: self.image = pygame.Surface(size) self.image.fill(pygame.Color(color)) else: self.image = None self.rect = pygame.Rect(*offset, *size)
def __init__(self, i, j): self.i = i self.j = j self._name = '–' self._neighbors = 0 self._mine = False # cell is mine :- boolean self._state = False # cell is revealed :- boolean self.flagged = False # cell is flagged self.xPos = PADDING + (SEPARATION + TILE_DIMENSION) * i self.yPos = PADDING + (SEPARATION + TILE_DIMENSION) * j self.rect = pygame_sdl2.Rect(self.xPos, self.yPos, TILE_DIMENSION, TILE_DIMENSION) self.font = pygame_sdl2.font.SysFont("Arial", 20)
def __init__(self, win, x, y, width, height, color): self.x, self.y = x, y self.win = win self.width = width self.height = height self.color = color self.rect = pygame.Rect(x, y, width, height) self.facing = "D" self.speed = 30 self.isShooting = False self.moveU = False self.moveD = False self.moveL = False self.moveR = False
def load_sprites(self): # Snake self.snake_sprites = pygame.sprite.RenderPlain((self.snake)) # Pellets, boosters self.pellet_sprites = pygame.sprite.Group() self.booster_sprites = pygame.sprite.Group() for i in range(len(self.grid)): for j in range(len(self.grid[i])): r = pygame.Rect(j * GRID_SPACING, i * GRID_SPACING, GRID_SPACING, GRID_SPACING) if self.grid[i][j] == 'P': self.pellet_sprites.add(Pellet(r)) elif self.grid[i][j] == 'B': self.booster_sprites.add(Booster(r))
def __init__(self, x, y, s, vel, facing, dmg): self.s = s self.vel = vel self.dmg = dmg self.rect = pygame.Rect(x, y, s, s) self.color = (0, 0, 0) moveX, moveY = 0, 0 if facing == "U": self.moveX = 0 self.moveY = -1 if facing == "D": self.moveX = 0 self.moveY = 1 if facing == "L": self.moveX = -1 self.moveY = 0 if facing == "R": self.moveX = 1 self.moveY = 0
import pygame_sdl2 as pygame from random import randint pygame.init() winx, winy = 1080, 1920 win = pygame.display.set_mode((winx, winy)) font = pygame.font.SysFont("DejaVuSans", 128) font2 = pygame.font.SysFont("DejaVuSans", 64) bird = pygame.Rect(winx/4, winy/2, 128, 128) clock = pygame.time.Clock() WHITE = (255,255,255) GREEN = (0,200,0) text = font.render("Clicc to start", 0, WHITE) started = False hit = False velocity = 7.5 jump_count = 10 jump = False score = 0 class pipe(object): def __init__(self, x, y, size, win): self.width = size/2 self.win = win self.gap = pygame.Rect(x+self.width, y, self.width, size) self.upper_pipe = pygame.Rect(x, 0, self.width, y) self.lower_pipe = pygame.Rect(x, y+size, self.width, win.get_height()-y+size) self.movement_speed = 13.5 self.passed = False