def draw_text(surface, text, size, pos): # font = pg.font.Font(FONT_NAME, size) font = pg.font.Font(None, size) text_surface = font.render(text, True, rgb('white')) text_rect = text_surface.get_rect() x, y = pos text_rect.midtop = (x, y) surface.blit(text_surface, text_rect)
def __init__(self, game, x, y): pg.sprite.Sprite.__init__(self) self.image = game.laser_img self.image.set_colorkey(rgb('black')) self.rect = self.image.get_rect() self.rect.bottom = y self.rect.centerx = x self.speedy = -10
def __init__(self, game, center): pg.sprite.Sprite.__init__(self) self.game = game self.type = random.choice(['shield', 'bolt_silver', 'bolt_gold']) self.image = self.game.powerups_img[self.type] self.image.set_colorkey(rgb('black')) self.rect = self.image.get_rect() self.rect.center = center self.speedy = 10
def __init__(self, number): self.stars = [] # create about 20% of tiny stars, 30% medium # and keep the rest bigger for n in range(int(number * 0.2)): x = random.randrange(0, WIDTH) y = random.randrange(0, HEIGHT) self.stars.append([x, y, rgb('grey')]) for n in range(int(number * 0.3)): x = random.randrange(0, WIDTH) y = random.randrange(0, HEIGHT) self.stars.append([x, y, rgb('lightgrey')]) for n in range(int(number * 0.5)): x = random.randrange(0, WIDTH) y = random.randrange(0, HEIGHT) self.stars.append([x, y, rgb('white')]) random.shuffle(self.stars)
def __init__(self, game): self.game = game pg.sprite.Sprite.__init__(self) self.image_original = random.choice(self.game.meteors_img) self.image_original.set_colorkey(rgb('black')) self.image = self.image_original.copy() self.rect = self.image.get_rect() self.radius = int(self.rect.width * 0.85 / 2) # pg.draw.circle(self.image, rgb('red'), self.rect.center, self.radius) self.rect.x = random.randrange(WIDTH - self.rect.width) self.rect.y = random.randrange(-100, -40) self.speedy = random.randrange(1, 8) self.speedx = random.randrange(-3, 3) self.rot = 0 self.rot_speed = random.randrange(-8, 8) self.last_update = pg.time.get_ticks()
def __init__(self, game): pg.sprite.Sprite.__init__(self) self.game = game self.image = pg.transform.scale(game.player_img, (50, 38)) self.image.set_colorkey(rgb('black')) self.rect = self.image.get_rect() self.radius = 20 # pg.draw.circle(self.image, rgb('red'), self.rect.center, self.radius) self.shield = SHIELD_MAX self.shot_delay = SHOTDELAY_INIT self.last_shot_time = pg.time.get_ticks() self.hidden = False self.hide_timer = pg.time.get_ticks() self.lives = LIVES self.power_level = POWER_LEVEL_INIT self.power_timer = pg.time.get_ticks() # speed and position self.rect.bottom = HEIGHT self.rect.centerx = WIDTH / 2 self.position = vec(WIDTH / 2, HEIGHT) self.acceleration = vec(0, 0) self.velocity = vec(0, 0)
def build_background(self): r, g, b, a = rgb('white') + (255, ) l = layer.ColorLayer(r, g, b, a, self.width, self.height) return l
def rgba(name, alpha=255): return rgb(name) + (alpha,)