Exemplo n.º 1
0
Arquivo: cuts.py Projeto: int-0/aftris
def ShowLogo(screen):
    clock = pygame.time.Clock()
    logo_frame = [
        resources.load_image('int0_sketch.png'),
        resources.load_image('int0_pencil.png'),
        resources.load_image('int0_ink.png'),
        resources.load_image('int0_final.png')
    ]
    white = pygame.Surface(logo_frame[0].get_size())
    white.fill((255, 255, 255, 255))

    black = pygame.Surface(screen.get_size())
    black = black.convert_alpha()
    black.set_alpha(255)
    black.fill((0, 0, 0, 0))

    screen.fill((0, 0, 0))
    pygame.display.flip()
    for w in range(256):
        screen.fill((w, w, w))
        pygame.display.flip()

    FadeTo(screen, white, logo_frame[0])
    for frm in range(len(logo_frame) -1):
        FadeTo(screen, logo_frame[frm], logo_frame[frm + 1])

    time.sleep(1.0)

    for w in range(256):
        black.fill((0, 0, 0, w))
        screen.blit(black, (0, 0))
        pygame.display.flip()
Exemplo n.º 2
0
 def __init__(self, bounds, level, facing):
     if facing == "right":
         self.proj = load_image("treatright.png")
     if facing == "left":
         self.proj = load_image("treatleft.png")
     self.proj.set_colorkey((255,255,255))
     Projectile.__init__(self, bounds, level, facing)
Exemplo n.º 3
0
    def __init__(me, game):
        me.stats = Stats()
        me.nextShape = None
        me.rows, me.cols = 22, 10
        me.c = Canvas(me.rows, me.cols, me.genShape())
        me.wmarg = game.w * 25 / 100
        me.hmarg = game.h * 8 / 100
        me.bpx = min((game.w - 2 * me.wmarg) / me.cols, (game.h - 2 * me.hmarg) / me.rows)  # block size

        # top left coordinate of the game canvas.
        me.xs = me.wmarg + (game.w - 2 * me.wmarg) * 35 / 100
        me.ys = me.hmarg + me.hmarg / 3

        # resources
        me.bg = load_image(resources.ingame_background, (game.w, game.h))
        me.cbg = load_image(resources.canvas_background, (me.bpx, me.bpx))
        me.blockimgs = [
            load_image(resources.b_blue, (me.bpx, me.bpx)),
            load_image(resources.b_teal, (me.bpx, me.bpx)),
            load_image(resources.b_yellow, (me.bpx, me.bpx)),
            load_image(resources.b_brown, (me.bpx, me.bpx)),
            load_image(resources.b_red, (me.bpx, me.bpx)),
            load_image(resources.b_green, (me.bpx, me.bpx)),
            load_image(resources.b_orange, (me.bpx, me.bpx)),
        ]

        me.delay = 250
        me.lastUpdate = pygame.time.get_ticks()
Exemplo n.º 4
0
 def draw(self, screen, player):
     bounds = screen.get_rect()
     if self.type == "jungle":
         self.bg = load_image("junglebg1.png")
     elif self.type == "cliff":
         self.bg = load_image("cliffbg.png")
     elif self.type == "lab":
         self.bg = load_image("labbg.png")
     rect = self.bg.get_rect()
     rect.center = bounds.centerx, bounds.centery
     screen.blit(self.bg, rect)
Exemplo n.º 5
0
def render_bezel(label, power_off=False):
    """Render the bezel and label text."""
    if power_off:
        bezel = load_image('media/bezel_off.png')
    else:
        bezel = load_image('media/bezel.png')
    text = load_font('media/fonts/METRO-DF.TTF', 19).render(
        label, True, (60, 60, 60))

    # Copy the bezel surface so we don't overwrite the stored cached surface in
    # the media manager.
    surf = bezel.copy()
    surf.blit(text, text_align(text, (725, 570), Align.CENTER))

    return surf
Exemplo n.º 6
0
	def initialize(self):
		if self.nframes is 1:
			if self.imagename is not None:
				self.images = load_image(self.imagename)
			else:
				self.images = None
		else:
			self.images = []
			for i in range(self.nframes):
				# Loads files in the pattern "character/animation_xxx.png", where xxx is a 3-digit number, with the first number being 001.
				name = self.imagename + "_%.3d.png" 
				tmpimage = load_image(name % (i+1))
				colorkey = tmpimage.get_at((1,1))
				tmpimage.set_colorkey(colorkey)
				self.images.append(tmpimage)
Exemplo n.º 7
0
    def __init__(self, x, y):
        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = resources.load_image("gold.png", -1)
        self.rect.move_ip(x, y)

        self.add(data.gold)
        self.add(data.entities)
Exemplo n.º 8
0
    def __init__(self, turn, **kwargs):
        super().__init__(resources.load_image('WindowBorder.png'), (70, 70),
                         layout_height=gui.LayoutParams.FILL_PARENT,
                         layout_width=270,
                         layout_gravity=gui.Gravity.RIGHT,
                         gravity=Gravity.TOPLEFT,
                         padding=30,
                         **kwargs)

        font = f.MEDIEVAL18
        self.endturn_btn = gui.Button(_("End Turn"),
                                      font,
                                      layout_gravity=Gravity.BOTTOMRIGHT,
                                      callback=lambda *_: turn.end_turn())
        self.turn_label = gui.Label(_("{team} turn"), font)
        self.terrain_label = gui.Label(
            f'Terrain: {{0}}\n{_("Def")}: {{1}}\n{_("Avoid")}: {{2}}\n{_("Allowed")}: {{3}}',
            font)
        self.unit_label = gui.Label(
            'Unit: {0}\nHealth: {1}\nCan move on: {2}\nWeapon: {3}', font)
        self.coord_label = gui.Label('X: {0} Y: {1}',
                                     font,
                                     layout_gravity=Gravity.BOTTOM)
        self.clock = gui.Clock(font, layout_gravity=Gravity.BOTTOM)

        self.add_children(self.turn_label, self.terrain_label, self.unit_label,
                          self.coord_label, self.clock)

        if isinstance(turn, game.PlayerTurn):
            self.add_child(self.endturn_btn)
Exemplo n.º 9
0
 def __init__(self, loc):
     Sprite.__init__(self)
     self.door = load_image("labdoor.png")
     self.door.set_colorkey((255,255,255))
     self.image = self.door
     self.rect = self.image.get_rect()
     self.rect.bottomleft = loc
Exemplo n.º 10
0
    def __init__(self, x, y):
        pygame.sprite.Sprite.__init__(self)
        #self.image = pygame.image.load
        self.image, self.rect = resources.load_image("wall.png")
        self.rect.move_ip(x,y)

        self.add(config.walls)
Exemplo n.º 11
0
 def __init__(self, x, y):
     pygame.sprite.Sprite.__init__(self)
     self.image, self.rect = resources.load_image("gold.png",-1)
     self.rect.move_ip(x,y)
     
     self.add(data.gold)
     self.add(data.entities)
Exemplo n.º 12
0
    def __init__(self,
                 diameter=32,
                 left=20,
                 top=20,
                 imagefile='crystal.png',
                 number='x',
                 # None or milliseconds until crystal disappears on its own:
                 lifetime_millis_max=None,
                 play_buzzer_on_negative_score=True):
        # todo: options for start/fadeout/end times
        # todo: option for scoring-number
        VirtualGameSprite.__init__(self)  # call Sprite initializer
        self.gamediameter = diameter
        self.gamerect = pygame.Rect(left, top, diameter, diameter)
        self.update_rect()
        self.image = load_image(
            imagefile,
            (self.rect.width, self.rect.height),
            convert_alpha=True)
        self.number = number
        self.visible = 0
        self.active = False
        self.pickup_sound = load_sound('ring_inventory.wav')
        self.pickup_sound_negative = load_sound('prompt_error.wav')
        self.flashing = False
        self.flashing_counter = 0

        # max time this crystal remains active
        self.lifetime_millis_max = lifetime_millis_max
        # current elapsed millis this crystal has been active
        self.lifetime_millis_elapsed = 0

        self.play_buzzer_on_negative_score = play_buzzer_on_negative_score
Exemplo n.º 13
0
    def __init__(self, diameter=200, dx=4, dy=10, left=20, top=20, area=None):
        VirtualGameSprite.__init__(self)  # call Sprite intializer
        self.gamediameter = diameter
        self.gamerect = pygame.Rect(left, top, diameter, diameter)
        self.update_rect()
        self.image = load_image(
            'asteroid.png',
            (self.rect.width, self.rect.height),
            convert_alpha=True)

        if area:
            self.GAME_PLAY_AREA = area
        else:
            self.GAME_PLAY_AREA = virtualdisplay.GAME_PLAY_AREA
        # rect uses integer positions but I need to handle fractional pixel/frame speeds.
        # store float x/y positions here:
        self.gametopfloat = float(top)
        self.gameleftfloat = float(left)
        self.dx = dx
        self.dy = dy
        self.speedfactor = 1.0
        self.gamediameternew_start_diameter = diameter
        self.gamediameternew_end_diameter = diameter
        self.gamediameternew_transition_duration_millis = 0
        self.gamediameternew_transition_remaining_millis = 0
        self.dxnew = self.dx
        self.dynew = self.dy
Exemplo n.º 14
0
 def __init__(
         self,
         lifetime_millis_elapsed=0,
         w=virtualdisplay.screenplayarea.width,
         h=virtualdisplay.screenplayarea.height,
         visible=0,
         **kwargs_extra):
     # if kwargs_extra: print 'extra arguments:', kwargs_extra
     VirtualGameSprite.__init__(self)  # call Sprite initializer
     self.gamediameter = w
     left, top = [0, 0]
     self.gamerect_visible = pygame.Rect(left, top, w, h)
     self.gamerect_hidden = pygame.Rect(-9999, -9999, w, h)
     self.gamerect = self.gamerect_hidden
     self.update_rect()
     if not image or image == 'none':
         image = 'transparent.png'
     self.image = load_image(image,
                             (virtualdisplay.screenplayarea.width,
                              virtualdisplay.screenplayarea.height),
                             convert_alpha=False)
     self.elapsed = lifetime_millis_elapsed
     self.flashing_counter = 0
     self.visible = visible
     self.counter = 0
Exemplo n.º 15
0
	def __init__(self, dungeon, name, pos):
		self.dungeon = dungeon
		self.name = name
		self.pos = pos
		self.data = data.database(dungeonmap.entityfolder, self.name)
		self.selected = False
		self.selectionimage, rect = resources.load_image("gui", "selection.png") #@UnusedVariable
		self.refresh()
Exemplo n.º 16
0
def setup():
    """Perform initial setup."""
    pygame.init()
    pygame.display.set_mode([800, 600], pygame.DOUBLEBUF | pygame.HWSURFACE,
                            24)
    pygame.display.set_icon(load_image("media/icon.png"))
    pygame.display.set_caption(constants.GAMENAME)
    mouse.current.set_cursor(mouse.Cursor.ARROW)
    random.seed()
Exemplo n.º 17
0
 def load_tiles(self, name):
     #load the tileset
     level, level_rect = resources.load_image(name)
     image_width = level.get_width()
     self.tiles = []
     #cut each tile from the tileset and append to an array for later use
     for i in range(0, image_width / self.tile_size):
         rect = (i * self.tile_size, 0, self.tile_size, self.tile_size)
         self.tiles.append(level.subsurface(rect))
Exemplo n.º 18
0
 def load_tiles(self, name):
     #load the tileset
     level, level_rect = resources.load_image(name)
     image_width = level.get_width()
     self.tiles = []
     #cut each tile from the tileset and append to an array for later use
     for i in range (0, image_width / self.tile_size):
         rect = (i * self.tile_size, 0, self.tile_size, self.tile_size)
         self.tiles.append(level.subsurface(rect))
Exemplo n.º 19
0
    def __init__(self, x, y):
        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = resources.load_image("player.png",-1)
        self.rect.move_ip(x,y)
        self.add(config.entities)
        self.direction = direction.NONE
        self.SPEED = 2

        self.add(config.entities)
        config.player = self
Exemplo n.º 20
0
 def __init__(me, game, resume = 0):
     me.bg = load_image(resources.menu_background, (game.w, game.h))
     me.entries = [
         'New Game',
         'Options',
         'Exit'
     ]
     if resume:
         me.entries.insert(0, 'Resume')
     me.selected = 0
Exemplo n.º 21
0
 def __init__(self, diameter=32, left=20, top=20):
     VirtualGameSprite.__init__(self)  # call Sprite initializer
     self.gamediameter = diameter
     self.gamerect = pygame.Rect(left, top, diameter, diameter)
     self.update_rect()
     self.image = load_image(
         'crystal.png',
         (self.rect.width, self.rect.height),
         convert_alpha=True)
     self.pickup_sound = load_sound('ring_inventory.wav')
Exemplo n.º 22
0
Arquivo: piece.py Projeto: namdre/ORTC
 def move_to(self, gridpos): 
     # promotion
     if self.piece == PAWN and (gridpos.y == 0 or gridpos.y == GRIDDIM.y - 1):
         self.piece = self.promotion
         self.image, self.rect = load_image(piece_image(self.piece, self.color), -1)
     # update 
     self.delay = DELAY
     self.gridpos = gridpos
     self.rect.center = gridpos * FIELDSIZE + 0.5 * FIELDSIZE
     self.attackpos = None
Exemplo n.º 23
0
    def __init__(self):
        play_song(self.song)

        self.state = "menu"
        self.bg = load_image("menu.png")
        self.spawn = (0, 160)
        self.newlvlnum = 0
        self.inst = False
        self.done = False
        self.mute = False
Exemplo n.º 24
0
 def __init__(self, game_bounds=virtualdisplay.GAME_PLAY_AREA):
     VirtualGameSprite.__init__(self)  # call Sprite initializer
     # find screen diameter
     self.gamediameter = 32
     self.gamerect = pygame.Rect(0, 0, self.gamediameter, self.gamediameter)
     self.game_bounds = game_bounds
     self.update_rect()
     self.image = load_image(
         'cursor.png',
         (self.rect.width, self.rect.height),
         convert_alpha=True)
Exemplo n.º 25
0
    def __init__(self, x, y):
        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = resources.load_image("monster.png", -1)
        self.rect.move_ip(x,y)

        self.add(config.entities)
        self.add(config.monsters)

        self.SPEED = 3
        self.SENSES = 100
        self.timetochangedirection = config.gamespeed * 10
        self.timeleft = self.timetochangedirection
Exemplo n.º 26
0
 def __init__(self, type, grid_position):
     pygame.sprite.Sprite.__init__(self)
     if not type in saved_images:
         image = load_image(type + ".png")
         if image.get_size() != Tile.SIZE:
             print("Cannot load tile:", type)
             raise SystemExit
         saved_images[type] = image
     self.image = saved_images[type]
     self.rect = self.image.get_rect()
     self.rect.x = grid_position[0] * Tile.SIZE[0]
     self.rect.y = grid_position[1] * Tile.SIZE[1]
Exemplo n.º 27
0
 def __init__(self):
     super().__init__(allowed_events=[pl.MOUSEMOTION, pl.MOUSEBUTTONDOWN, pl.KEYDOWN],
                      bg_color=c.BLACK, bg_image=resources.load_image('Ice Emblem.png'),
                      layout_width=FILL, layout_height=FILL,
                      spacing=50)
     self.click_to_start = gui.Label(_("Click to Start"), f.MAIN_MENU, padding=10,
                                     txt_color=c.ICE, layout_gravity=gui.Gravity.BOTTOM, die_when_done=False)
     self.hmenu = gui.HorizontalMenu([(_("License"), self.show_license), (_("Settings"), self.settings_menu)],
                                     f.SMALL, die_when_done=False, layout_gravity=gui.Gravity.BOTTOMRIGHT)
     self.add_children(self.click_to_start, self.hmenu)
     self.bind_keys((pl.K_RETURN, pl.K_SPACE), self.show_map_menu)
     self.bind_click((1,), self.show_map_menu, self.hmenu.rect, False)
Exemplo n.º 28
0
 def test():
     import resources
     import room
     import fonts as f
     import logging
     logging.basicConfig(level=logging.DEBUG)
     nine = NinePatch(resources.load_image('WindowBorder.png'), (70, 70),
                      wait=False,
                      padding=100,
                      layout_gravity=gui.Gravity.FILL)
     nine.add_child(gui.Label("test", f.MAIN))
     nine.add_child(gui.Clock(f.MAIN))
     room.run_room(nine)
Exemplo n.º 29
0
    def update(self, millis):
        """Update the position and direction of the Asteroid to move, and bounce"""

        # handle size transition:
        if (self.gamediameternew_transition_remaining_millis > 0):
            self.gamediameternew_transition_remaining_millis -= millis
            if (self.gamediameternew_transition_remaining_millis < 0):
                self.gamediameternew_transition_remaining_millis = 0

            # Transition diameter
            newdiameter = int(round(
                map_range(self.gamediameternew_transition_remaining_millis,
                          self.gamediameternew_transition_duration_millis,
                          0,
                          self.gamediameternew_start_diameter,
                          self.gamediameternew_end_diameter)))

            center = self.gamerect.center
            if (newdiameter != self.gamediameter):
                self.gamediameter = newdiameter
                self.gamerect.size = (newdiameter, newdiameter)
                self.gamerect.center = center
                self.update_rect()
                # resample image
                # TODO: is this too slow?
                # Yep, until the images are cached this is super slow
                self.image = load_image(
                    'asteroid.png',
                    (self.rect.width, self.rect.height),
                    convert_alpha=True)

        # when bouncing, change from expected X or Y speed towards
        # new speed by at most +/-4px/frame
        adjusted_abs_dx = clamp_range(abs(self.dxnew), max(abs(self.dx) - 4, 1), abs(self.dx) + 4)
        adjusted_abs_dy = clamp_range(abs(self.dynew), max(abs(self.dy) - 4, 1), abs(self.dy) + 4)

        # bounce by setting sign of x or y speed if off of corresponding side of screen
        if self.gamerect.left < self.GAME_PLAY_AREA.left:
            self.dx = adjusted_abs_dx
        if self.gamerect.right > self.GAME_PLAY_AREA.right:
            self.dx = -adjusted_abs_dx
        if self.gamerect.top < self.GAME_PLAY_AREA.top:
            self.dy = adjusted_abs_dy
        if self.gamerect.bottom > self.GAME_PLAY_AREA.bottom:
            self.dy = -adjusted_abs_dy

        self.gameleftfloat += self.dx * self.speedfactor
        self.gametopfloat += self.dy * self.speedfactor
        self.gamerect.left = self.gameleftfloat
        self.gamerect.top = self.gametopfloat
        self.update_rect()
Exemplo n.º 30
0
Arquivo: piece.py Projeto: namdre/ORTC
 def __init__(self, surf, piece, color, gridpos):
     pygame.sprite.Sprite.__init__(self) #call Sprite initializer
     self.surf = surf
     self.piece = piece
     self.color = color
     self.image, self.rect = load_image(piece_image(piece, color), -1)
     self.move_to(gridpos)
     self.delay = 0
     self.hitpoints = MAXHP[piece]
     self.maxhp = MAXHP[piece]
     self.promotion = None # promotion goal if eligible
     self.attackpos = None
     # cyclical attack frame counter for drawing
     self.attack_time = 0 
Exemplo n.º 31
0
def splash():
	clock = pygame.time.Clock()
	time = pygame.time.get_ticks()
	background = load_image("hacksplash.png")
	while True:
		if skipsplash():
			return
		if time+5000 <= pygame.time.get_ticks() or stop_splash:
			#Stop showing after 5 seconds
			return
		screen.blit(background, (0,0))
		pygame.display.update()
		pygame.display.flip()
		clock.tick(FPS/2)
Exemplo n.º 32
0
    def draw_titles(self, screen, dt):
        bounds = screen.get_rect()
        pygame.font.init()
        pixfont = "./data/fonts/pixelated.ttf"
        font = pygame.font.Font(pixfont, 40)
        if self.inst == False:
            self.newgame = font.render(("NEW GAME"), True, self.fg_color)
            self.newgamerect = self.newgame.get_rect()
            self.newgamerect.center = bounds.centerx - 210, bounds.centery - 30
            screen.blit(self.newgame, self.newgamerect)

            self.contgame = font.render(("CONTINUE GAME"), True, self.fg_color)
            self.contgamerect = self.contgame.get_rect()
            self.contgamerect.center = bounds.centerx - 210, bounds.centery + 30
            screen.blit(self.contgame, self.contgamerect)

            self.instructions = font.render(("INSTRUCTIONS"), True, self.fg_color)
            self.instrect = self.instructions.get_rect()
            self.instrect.center = bounds.centerx - 210, bounds.centery + 90
            screen.blit(self.instructions, self.instrect)

            font = pygame.font.Font(pixfont, 20)
            self.quit = font.render(("EXIT GAME"), True, self.fg_color)
            self.quitrect = self.quit.get_rect()
            self.quitrect.center = bounds.centerx - 210, bounds.centery + 145
            screen.blit(self.quit, self.quitrect)

        if self.inst == True:
            self.bg = load_image("instructions.png")
            if self.blinker(dt/2) > 50:
                font = pygame.font.Font(pixfont, 18)
                self.cont = font.render("PRESS X TO RETURN TO MENU", True, self.fg_color)
                rect = self.cont.get_rect()
                rect.center = bounds.centerx + 270, bounds.centery - 150
                screen.blit(self.cont, rect)
        elif self.inst == False:
            self.bg = load_image("menu.png")
Exemplo n.º 33
0
def mainloop():
	clock = pygame.time.Clock()
	background = load_image("background.jpg") 
	render = pygame.sprite.RenderPlain()
	render.add(hero)
	render.add(g_slope)
	while True:
		playerinput()
		hero.sprite.isCollidingWith(pygame.sprite.spritecollide(hero.sprite, solid_obstacles, False), groups)
		hero.update(clock.get_time())
		screen.blit(background, (0,0))
		render.draw(screen)
		pygame.display.update()
		pygame.display.flip()
		clock.tick(FPS)
Exemplo n.º 34
0
 def __init__(self):
     pygame.sprite.Sprite.__init__(self)
     self.image, self.rect = resources.load_image("player.png")
     #player position relative to screen
     self.position = [0, 0]
     #player position relative to map
     self.location = [128, 128]
     self.state = "idle"
     self.movement_cooldown = 0.0
     self.movement_limit = 0.16
     self.movement_points = [0, 0, 0, 0] #up, right, down, left
     self.directions_blocked = {}
     self.health = 100.0
     self.mana = 0.0
     self.inventory = []
Exemplo n.º 35
0
 def __init__(self):
     pygame.sprite.Sprite.__init__(self)
     self.image, self.rect = resources.load_image("player.png")
     #player position relative to screen
     self.position = [0, 0]
     #player position relative to map
     self.location = [128, 128]
     self.state = "idle"
     self.movement_cooldown = 0.0
     self.movement_limit = 0.16
     self.movement_points = [0, 0, 0, 0]  #up, right, down, left
     self.directions_blocked = {}
     self.health = 100.0
     self.mana = 0.0
     self.inventory = []
Exemplo n.º 36
0
    def _pick_images(self):
        """Pick the images to present, and generate buttons from them."""
        # Pick 3 images from the user's images, and a 4th from the remaining
        # images, shuffle together to form the final list of images.
        user_imgs = random.sample(self._user_info, 3)
        other_img = random.sample(
            set(Categories).difference(self._user_info), 1)
        choices = user_imgs + other_img
        random.shuffle(choices)

        # Build the buttons
        self._buttons = []
        for i, c in enumerate(choices):
            self._buttons.append([
                load_image(c.value), ImagePassword._BUTTON_COORDS[i], c, False
            ])
Exemplo n.º 37
0
    def __init__(self, diameter=32, left=80, top=80):
        BasePowerup.__init__(self, diameter=diameter, left=left, top=top, maxduration=5.0)
        self.type = 'shield'
        self.gamerect = pygame.Rect(left, top, diameter, diameter)
        self.update_rect()
        self.image = load_image(
            'shield.png',
            (self.rect.width, self.rect.height),
            convert_alpha=True)
        self.image = pygame.transform.smoothscale(
            self.image, (self.rect.width, self.rect.height))

        self.sound_begin = load_sound('shield start.wav')
        self.sound_end = load_sound('shield end.wav')
        # these let me start the ending sound to end overlapping when the effect ends:
        self.sound_end_duration = self.sound_end.get_length() - 1.0
        self.sound_end_started = False
Exemplo n.º 38
0
    def __init__(self, diameter=32, left=100, top=100):
        BasePowerup.__init__(self, diameter=diameter, left=left, top=top, maxduration=5.0)
        self.type = 'slow'
        self.gamerect = pygame.Rect(left, top, diameter, diameter)
        self.update_rect()
        self.image = load_image(
            'clock.png',
            (self.rect.width, self.rect.height),
            convert_alpha=True)

        self.sound_begin = load_sound('slow start.wav')
        self.sound_end = load_sound('slow end.wav')
        # these let me start the ending sound to end overlapping when the effect ends:
        self.sound_end_duration = self.sound_end.get_length() - 0.5
        self.sound_end_started = False

        self.speedfactor = 0.25
Exemplo n.º 39
0
def initialize() -> None:
    """
    Must be called first to initialize pygame and this module.
    """
    global window, clock, FPS_FONT
    if pygame.get_init():
        return

    pygame.init()
    pygame.display.set_icon(resources.load_image('icon.png'))
    version = utils.get_version()

    window = pygame.display.set_mode(resolution, mode)
    pygame.display.set_caption("Ice Emblem " + version)
    pygame.key.set_repeat(200, 50)
    clock = pygame.time.Clock()

    FPS_FONT = pygame.font.SysFont("Liberation Sans", 12)
Exemplo n.º 40
0
 def copy_from(self, asteroid):
     self.gamediameter = asteroid.gamediameter
     self.gamerect = asteroid.gamerect.copy()
     self.update_rect()
     self.image = load_image(
         'asteroid.png',
         (self.rect.width, self.rect.height),
         convert_alpha=True)
     self.GAME_PLAY_AREA = asteroid.GAME_PLAY_AREA
     self.gametopfloat = asteroid.gametopfloat
     self.gameleftfloat = asteroid.gameleftfloat
     self.dx = asteroid.dx
     self.dy = asteroid.dy
     self.gamediameternew_start_diameter = asteroid.gamediameter
     self.gamediameternew_end_diameter = asteroid.gamediameter
     self.gamediameternew_transition_duration_millis = 0
     self.gamediameternew_transition_remaining_millis = 0
     self.dxnew = self.dx
     self.dynew = self.dy
Exemplo n.º 41
0
    def __init__(self, image, dimensions, colorkey=-1):

        #load the image
        if type(image) is str:
            image = load_image(image)
#examines the pixel at (0,0), so we can set that to the transparent color
        if colorkey == -1:
            colorkey = image.get_at((0,0))  
        if colorkey:
            image.set_colorkey(colorkey)

        cols, rows = dimensions
        w = self.width = 1.0 * image.get_width() / cols
        h = self.height = 1.0 * image.get_height() / rows
        
        #build the images
        self._images = []
        for y in range(rows):
            row = []
            for x in range(cols):
                row.append(image.subsurface((x*w, y*h, w, h)))
            self._images.append(row)
Exemplo n.º 42
0
    def __init__(self, x, y):
        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = resources.load_image("gold.png")
        self.rect.move_ip(x,y)

        self.add(config.gold)
Exemplo n.º 43
0
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.

import pygame
import resources


class Player(pygame.sprite.Sprite):
    def __init__(self, (x, y), speed, collide_lambda, fps=10):
        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = resources.load_image(
            "../assets/images/player/front1.bmp", -1)
        self.rect.move_ip(x, y)
        self.speed = speed
        self.walls = []
        self.obstacles = []
        self.collide_obstacle = collide_lambda
        self._start = pygame.time.get_ticks()
        self._delay = 1000 / fps
        self._last_update = 0
        self._frame = 0
        self.anim_paused = True
        self.forward_images = []
        self.backward_images = []
        self.left_images = []
        self.right_images = []
        self.forward_images.append(
Exemplo n.º 44
0
 def __init__(self, x, y, z=100):
     self.image = resources.load_image('logo.png')
     super(LogoView, self).__init__(x,y,self.image.get_width(), self.image.get_height(), z)
Exemplo n.º 45
0
 def __init__(self):
     super().__init__(resources.load_image('GNU GPL.jpg'), layout_gravity=gui.Gravity.FILL, 
                      allowed_events=[pl.MOUSEBUTTONDOWN, pl.KEYDOWN], die_when_done=True)
Exemplo n.º 46
0
 def __init__(self, x, y, name, obs_type):
     pygame.sprite.Sprite.__init__(self)
     self.image, self.rect = resources.load_image("../assets/images/objs/" + name + ".bmp", -1)
     self.rect.move_ip(x, y)
     self.obs_type = obs_type
     self.name = name
Exemplo n.º 47
0
import pygame
import resources, model, mapping

size = width, height = 800, 600
tilesize = 32  #quadratic
screen = pygame.display.set_mode(size)
gamespeed = 30
clock = None

entities = pygame.sprite.RenderUpdates()
walls = pygame.sprite.Group()
monsters = pygame.sprite.Group()
gold = pygame.sprite.Group()
player = None

background, background_rect = resources.load_image("background2.png")
level = resources.load_map("map0.txt")
mapping.process_level()
Exemplo n.º 48
0
    def __init__(
            self,
            diameter=64,
            position_list=[[20, 20]],
            sound='tone440.wav',
            image='triangle.png',
            input_key='K_1',
            showtimes_millis=[],
            showtimes_trigger_counts=[],
            timeout_millis=5000,
            stay_visible=False,
            score_pass=None,
            score_fail=None,
            score_miss=None,
            fail_on_wrong_key=False,
            pass_fail_sounds=False,
            **kwargs_extra):
        # if kwargs_extra: print 'extra arguments:', kwargs_extra
        VirtualGameSprite.__init__(self)  # call Sprite initializer
        self.gamediameter = diameter
        self.position_list = position_list
        self.position_index = -1
        left, top = self.position_list[self.position_index]
        self.gamerect_visible = pygame.Rect(left, top, diameter, diameter)
        self.gamerect_hidden = pygame.Rect(-9999, -9999, diameter, diameter)
        self.gamerect = self.gamerect_hidden
        self.update_rect()

        if not image or image == 'none':
            image = 'transparent.png'
        self.image = load_image(
            image,
            (self.rect.width, self.rect.height),
            convert_alpha=True)
        self.image_name = image

        if sound and sound != 'none':
            self.prompt_sound = load_sound(sound, mixing_group='reaction')
            self.sound_name = sound
        else:
            self.prompt_sound = NoneSound()
            self.sound_name = 'none'

        if pass_fail_sounds:
            self.pass_sound = load_sound('prompt_correct.wav', mixing_group='reaction')
            self.fail_sound = load_sound('prompt_error.wav', mixing_group='reaction')
        else:
            self.pass_sound = NoneSound()
            self.fail_sound = NoneSound()

        self.showtimes_millis = showtimes_millis
        # todo: implement trigger showing
        self.showtimes_trigger_counts = showtimes_trigger_counts
        if isinstance(timeout_millis, str) or isinstance(timeout_millis, str):
            timeout_millis = None
        self.timeout_millis = timeout_millis
        self.stay_visible = stay_visible
        self.score_pass = score_pass
        self.score_fail = score_fail
        self.score_miss = score_miss
        self.fail_on_wrong_key = fail_on_wrong_key
        self.active = False
        self.visible = False
        self.total_elapsed = 0
        self.showtime_last = 0  # millis when shown
        self.step_trigger_count_last = 0
        if input_key.startswith('K_MOUSE'):
            mousebutton_index = 0
            if input_key == 'K_MOUSE1':
                mousebutton_index = 0  # left mouse
            elif input_key == 'K_MOUSE2':
                mousebutton_index = 1  # middle mouse
            elif input_key == 'K_MOUSE3':
                mousebutton_index = 2  # right mouse
            else:
                raise QuitGame('mouse button for input_key for reaction prompt of %s is not recognized' % input_key)
                raise QuitGame()

            self.dismiss_test = lambda evt: evt.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[
                mousebutton_index]
        else:
            # input_key should correspond to actual key
            pygame_key_constant = getattr(pygame, input_key, None)
            if not pygame_key_constant:
                print('input_key of "%s" not found. Please use one of the following' % input_key)
                print(', '.join(['"' + s + '"' for s in list(CODE_BY_PYGAME_CONSTANT.keys())] + ['K_MOUSE1', 'K_MOUSE2',
                                                                                                 'K_MOUSE3']))
                raise QuitGame('input_key of "%s" not found. ' % input_key)
            self.dismiss_test = lambda evt: evt.type == pygame.KEYDOWN and evt.key == pygame_key_constant
Exemplo n.º 49
0
 def __init__(self):
     self.state = "last"
     self.spawn = (20, 200)
     self.bg = load_image("ending.png")
Exemplo n.º 50
0
 def __init__(me, game, stats):
     me.stats = stats
     me.bg = load_image(resources.score_background, (game.w, game.h))
Exemplo n.º 51
0
 def __init__(self):
     self.state = 3
     self.spawn = (20, 200)
     self.bg = load_image("almost.png")
Exemplo n.º 52
0
	def refresh(self):
		self.image, self.rect = resources.load_image(self.imagefolder, self.imagename)
		if self.size != None:
			self.image = pygame.transform.scale(self.image, (int(self.size[0]), int(self.size[1])))
			self.rect.width = int(self.size[0])
			self.rect.height = int(self.size[1])
Exemplo n.º 53
0
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.

import pygame
import resources

class Player(pygame.sprite.Sprite):
    def __init__(self, (x, y), speed, collide_lambda, fps=10):
        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = resources.load_image("../assets/images/player/front1.bmp", -1)
        self.rect.move_ip(x, y)
        self.speed = speed
        self.walls = []
        self.obstacles = []
        self.collide_obstacle = collide_lambda
        self._start = pygame.time.get_ticks()
        self._delay = 1000 / fps
        self._last_update = 0
        self._frame = 0
        self.anim_paused = True
        self.forward_images = []
        self.backward_images = []
        self.left_images = []
        self.right_images = []
        self.forward_images.append(resources.load_image_no_rect("../assets/images/player/front1.bmp", -1))
Exemplo n.º 54
0
    screen = pygame.display.set_mode((1024, 768), HWSURFACE|DOUBLEBUF)
    tileset = Tileset("../assets/maps/Level1.tmx")
    walls = []
    obstacles = []
    player = Player((32, 32), 1, lambda o: collide_obstacle(o))
    clock = pygame.time.Clock()
    
    

    allsprites = pygame.sprite.RenderPlain(obstacles)
    allsprites.add(player)
    font = pygame.font.Font(None,36)
    
    init()

    start_bg, start_rect = resources.load_image("../assets/images/bg/start.bmp")
    win_bg, win_rect = resources.load_image("../assets/images/bg/win.bmp")
    lose_bg, lose_rect = resources.load_image("../assets/images/bg/lose.bmp")
    desc_bg = pygame.Surface((1024, 768)).convert()
    desc_bg.fill((255, 255, 255))
    
    pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER)
    hurt_sound = pygame.mixer.Sound("../assets/sound/hurt.wav")
    pickup_sound = pygame.mixer.Sound("../assets/sound/pickup.wav")
    
    while 1:
        clock.tick(60)
        
        for e in pygame.event.get():
            if e.type == QUIT:
                sys.exit()