示例#1
0
    def __init__(self, screen, maze, img, behavior):
        super(Ghost, self).__init__()
        self.screen = screen
        self.sz = 34
        self.spritesheet = SpriteSheet('images/' + img + '.png')
        self.behavior = behavior
        self.images = []
        for i in range(8):
            self.images.append(self.spritesheet.get_image(i * 16, 0, 16, 16))
            self.images[i] = pygame.transform.scale(self.images[i],
                                                    (self.sz, self.sz))
        self.image = self.images[0]
        self.rect = self.images[0].get_rect()
        self.center = float(self.rect.centerx)
        # Move to start position
        self.reset()

        self.walls = maze.bricks

        self.speed = 1
        self.moveLeft = False
        self.moveRight = False
        self.moveUp = False
        self.moveDown = False

        self.path = []
        # self.genPath(behavior)
        self.curPath = 1

        self.last = pygame.time.get_ticks()
        self.animIter = 0
示例#2
0
class Dead_duck:
    def __init__(self,x,y):
        self.deadDuck = SpriteSheet("dead_duck.png")
        self.frames = []
        self.image = self.deadDuck.get_image(85,0,40,70)
        self.frames.append(self.image)
        self.image = self.deadDuck.get_image(125,0,40,70)
        self.frames.append(self.image)
        self.image = self.deadDuck.get_image(165, 0, 40, 70)
        self.frames.append(self.image)
        self.image = self.deadDuck.get_image(0,0,70,70)
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
        self.change = 8
    def fall(self):
        self.rect.y += self.change
        pos = self.rect.x
        frame = (pos // 30) % len(self.frames)
        if self.rect.y > 400:
            self.change = 0
            dog = pygame.image.load("dog.png").convert_alpha()
            screen.blit(dog,(self.rect.x,self.rect.y))
        self.image = self.frames[frame]
    def draw(self):
        screen.blit(self.image,(self.rect.x,self.rect.y))
示例#3
0
    def __init__(self, screen: pygame.Surface):
        global current_game
        current_game = self
        self.screen = screen

        spritesheet = SpriteSheet('./assets/sprites.png')
        self.life_image = pygame.transform.scale(
            spritesheet.image_at((423, 345, 16, 8), color_key=-1), (64, 32))
        self.checkpoint_image = pygame.transform.scale(
            spritesheet.image_at((389, 335, 8, 8), color_key=-1), (32, 32))

        self.simplex = OpenSimplex()
        self.font = pygame.font.Font('freesansbold.ttf', 24)
        self.next_hole = self.screen.get_width(
        ) + random.random() * HOLE_SPACE_VAR
        self.holes = []
        self.checkpoint = 0
        self.checkpoint_score = 0
        self.lives = 3
        self.score = 0
        self.highest_score = 0

        self.terrain = Terrain(screen, MARTIAN_BROWN, self.terrain_point)
        self.all_sprites = pygame.sprite.Group()

        self.player = Player(START_LOCATION, 0)
        self.all_sprites.add(self.player)
示例#4
0
 def load_images(self, path, rect: Tuple[int, int, int, int],
                 size: Tuple[int, int]):
     img = SpriteSheet(path)
     self.images = [
         self.transform_sprite(i)
         for i in img.images_with_fixed_size(rect, size)
     ]
示例#5
0
    def __init__(self, dimensions, time):
        addr = os.getcwd()
        self.time = time
        self.lastFrameTime = self.time.time()
        self.dimensions = dimensions
        # resource addresses
        self.clouds = simplegui.load_image("file:///" + addr +
                                           "/images/background_clouds.png")
        self.sun = simplegui.load_image("file:///" + addr + "/images/sun.png")
        self.water_world = simplegui.load_image(
            "file:///" + addr +
            "/images/underwater-seamless-landscape-cartoon-background-vector-7524975.png"
        )

        # establish background elements as spritesheet objects with their spritesheet image
        self.bubbles = SS("file:///" + addr + "/images/Bubble1.png", (6, 5),
                          time=1250,
                          scale=0.22,
                          timehand=self.time)
        self.carol = SS("file:///" + addr + "/images/carol.png", (5, 1),
                        time=800,
                        scale=0.22,
                        timehand=self.time)
        self.perl = SS("file:///" + addr + "/images/pearl.png", (3, 3),
                       time=3000,
                       scale=0.22,
                       looping=False,
                       timehand=self.time)
        self.bWaveParts = []
        self.mWaveParts = []
        self.sWaveParts = []
        self.pollycount = 35
        t = threading.Thread(target=self.update, args=())
        t.start()
示例#6
0
class PowerUp(Sprite):
    """ Represents a powerup"""
    def __init__(self, P_TYPE, screen, x, y):
        """ Init attributes"""
        super().__init__()

        # Attributes
        self.P_TYPE = P_TYPE
        self.sheet = settings.power_up_sheet
        self.sheet_cols = settings.power_up_sheet_cols
        self.sheet_rows = settings.power_up_sheet_rows
        self.spritesheet = SpriteSheet(self.sheet, self.sheet_cols,
                                       self.sheet_rows)
        self.image = self.spritesheet.get_image(int(self.P_TYPE), colorkey=-1)
        self.x = x
        self.y = y
        self.width = self.image.get_width()
        self.height = self.image.get_height()
        self.rect = pygame.Rect(x, y, self.width, self.height)
        self.screen = screen
        self.spin_degrees = 1 * settings.power_up_spin_factor

    def draw(self):
        """ Draws powerup to screen"""
        self.spritesheet.draw(self.screen, int(self.P_TYPE), self.rect.x,
                              self.rect.y)

    def update(self):
        """ Updates movement of powerup"""
        self.rect.y += settings.power_up_speed_factor
示例#7
0
    def __init__(self):
        """ Constructor function """

        # Call the parent's constructor
        pygame.sprite.Sprite.__init__(self)

        sprite_sheet = SpriteSheet("mario.png")

        # Load all the right facing images into a list
        image = sprite_sheet.get_image(0, 0, constants.BLOCK_SIZE,
                                       2 * constants.BLOCK_SIZE)
        self.standing = image

        image = sprite_sheet.get_image(5 * constants.BLOCK_SIZE, 0,
                                       constants.BLOCK_SIZE,
                                       2 * constants.BLOCK_SIZE)
        self.jumping = image

        for i in xrange(1, 4):
            image = sprite_sheet.get_image(i * constants.BLOCK_SIZE, 0,
                                           constants.BLOCK_SIZE,
                                           2 * constants.BLOCK_SIZE)
            self.walking_frames.append(image)

        self.walking_frames.append(self.walking_frames[1])

        # Set the image the player starts with
        self.image = self.standing

        # Set a referance to the image rect.
        self.rect = self.image.get_rect()
        self.rect.y = constants.BLOCK_SIZE * (constants.BLOCK_HEIGHT - 3.5)
        self.rect.x = constants.BLOCK_SIZE * (constants.BLOCK_WIDTH / 2.0 - .5)
示例#8
0
class Fireball(sf.Drawable, Collideable):
    def __init__(self, x, y, world):
        Collideable.__init__(self, x, y, 100, 100, False)
        self._sprite = SpriteSheet(Res.fireball)
        self._sprite.init(10, 10, 0.1)
        self._sprite.position = sf.Vector2(x, y)
        self.world = world
        self.dead = False
        
    def draw(self, target, render_states):
        target.draw(self._sprite, render_states)
    
    def update(self, dt):
        self._sprite.update(dt)
        
        self.position.y += FIREBALL_MOVE_SPEED*dt 

        # Update player sprite position
        self._sprite.position = self.position
        
    def on_collision_begin(self, other, side):
        if self.dead:
            return False
        self.world.create_explosion(self.position.x, self.position.y)
        self.dead = True
        if hasattr(other, "health"):
            other.health -= 1
        return False
    
    def on_collision_end(self, other):
        pass
示例#9
0
    def __init__(self):
        # kutsutaan parenttia
        super().__init__()

        #luodaan hahmo
        self.walking_frames_r = []
        sprite_sheet = SpriteSheet("fatherlonglegssprite.png")
        image = sprite_sheet.get_image(12, 12, 80, 40)
        self.walking_frames_r.append(image)
        image2 = sprite_sheet.get_image(110, 12, 80, 55)
        self.walking_frames_r.append(image2)
        image3 = sprite_sheet.get_image(220, 12, 72, 55)
        self.walking_frames_r.append(image3)

        self.image = self.walking_frames_r[0]

        #luodaan referenssi
        self.rect = self.image.get_rect()

        # luodaan nopeudet
        self.change_x = 0
        self.change_y = 0

        #
        self.level = None
示例#10
0
文件: gui.py 项目: MrKren/TTA
    def __init__(self):

        super().__init__()

        self.sheet = SpriteSheet("GUI.png")
        self.image = self.sheet.get_image(0, 0, 196, 278)
        self.rect = self.image.get_rect()
示例#11
0
 def __init__(self, x, y, right):
     pygame.sprite.Sprite.__init__(self)
     self.frame = 0
     self.right = right
     if self.right:
         self.dx = 10
     else:
         self.dx = -10
     sheet = SpriteSheet('data\sprites\player1.bmp')
     self.spLaserLoc = [{
         "x": 464,
         "y": 83,
         "wid": 24,
         "hei": 24,
         "flip": False
     }, {
         "x": 493,
         "y": 83,
         "wid": 24,
         "hei": 24,
         "flip": False
     }]
     self.spLaser = sheet.getSet(self.spLaserLoc)
     self.image = self.spLaser[0]
     self.rect = self.image.get_rect()
     self.rect.x = x
     self.rect.y = y
    def __init__(self):
        """
        Constructor
        """
        super().__init__()

#------ Attributes
        # Speed of the player
        self.change_x = 0
        self.change_y = 0

        #This list holds images for our player
        self.walking_frames_l = []
        self.walking_frames_r = []

        #Direction of walking
        self.direction = "R"

        sprite_sheet = SpriteSheet("walk_sheet2.png")
        #Load all the left facing images into a list
        self.walking_frames_l = sprite_sheet.load_strip([0, 0, 50, 62], 4, constants.WHITE)

        #Load all the left facing images then flip them right
        for image in self.walking_frames_l:
            image = pygame.transform.flip(image, True, False)
            self.walking_frames_r.append(image)
        
        #Set the image tge player starts with
        self.image = self.walking_frames_r[0]

        #Set a reference to the image rect
        self.rect = self.image.get_rect()
示例#13
0
    def __init__(self, ai_settings, screen):
        """Initialize the alien, and set its starting position."""
        super(Bunker, self).__init__()
        self.screen = screen
        self.ai_settings = ai_settings

        # Load the alien image, and set its rect attribute.
        self.bunker_frames = []

        bunker_sprite = SpriteSheet("images/SpriteSheet.png")

        image = bunker_sprite.get_image(0, 346, 96, 64)
        self.bunker_frames.append(image)
        image = bunker_sprite.get_image(0, 346, 96, 64)
        self.bunker_frames.append(image)

        self.image = self.bunker_frames[0]

        self.rect = self.image.get_rect()

        # Start each new alien near the top left of the screen.
        self.rect.x = self.rect.width
        self.rect.y = self.rect.height

        # Store the alien's exact position.
        self.x = float(self.rect.x)
示例#14
0
    def __init__(self, ai_settings, screen):
        """Initialize the alien, and set its starting position."""
        super(Alien2, self).__init__()
        self.screen = screen
        self.ai_settings = ai_settings

        # Load the alien image, and set its rect attribute.
        self.alien2_frames = []

        alien2_sprite = SpriteSheet("images/SpriteSheet.png")

        for num_pics1 in range(24):
            image = alien2_sprite.get_image(32, 0, 32, 32)
            self.alien2_frames.append(image)
        for num_pics2 in range(24):
            image = alien2_sprite.get_image(32, 32, 32, 32)
            self.alien2_frames.append(image)

        self.image = self.alien2_frames[0]

        self.rect = self.image.get_rect()

        # Start each new alien near the top left of the screen.
        self.rect.x = self.rect.width
        self.rect.y = self.rect.height

        # Store the alien's exact position.
        self.x = float(self.rect.x)

        self.index = 0
示例#15
0
    def __init__(self):
        # self.PlayerSprite = SpriteSheet('https://gyazo.com/616943d4546f31d854a59cc4b2b0b461', (3, 4))
        self.PlayerSprite_up = SpriteSheet(
            "https://raw.githubusercontent.com/CalhamZeKoala/GameImg/master/player%20sprites/player_up.png",
            (4, 1), 10)
        self.PlayerSprite_right = SpriteSheet(
            "https://raw.githubusercontent.com/CalhamZeKoala/GameImg/master/player%20sprites/player_right.png",
            (4, 1), 10)
        self.PlayerSprite_down = SpriteSheet(
            "https://raw.githubusercontent.com/CalhamZeKoala/GameImg/master/player%20sprites/player_down.png",
            (4, 1), 10)
        self.PlayerSprite_left = SpriteSheet(
            "https://raw.githubusercontent.com/CalhamZeKoala/GameImg/master/player%20sprites/player_left.png",
            (4, 1), 10)
        self.PlayerSprite_current = self.PlayerSprite_up
        self.vel = Vector(3, 0)
        self.pos = Vector(CANVAS_DIMS[0] / 2, 2 * CANVAS_DIMS[1] / 3.)
        self.radius = max(self.PlayerSprite_current.frameHeight,
                          self.PlayerSprite_current.frameWidth) / 2

        self.health = Health()
        self.healthSprite = HealthSpriteSheet(self.health)
        self.cooldown_max = 30
        self.cooldown = self.cooldown_max
        self.border = 1
示例#16
0
    def __init__(self, screen, x, y, indices=()):
        """ Setting up attributes"""
        # Call parent constructor
        super(Explosion, self).__init__()

        # Screen attribute
        self.screen = screen

        # Spritesheet containing explosion animation
        self.sprite_sheet = SpriteSheet(settings.explosion_sheet,
                                        settings.explosion_cols,
                                        settings.explosion_rows)

        # Animation length in milliseconds
        self.time_length = settings.explosion_anim_length

        # Animation instance
        self.animation = Animation(self.sprite_sheet,
                                   settings.explosion_anim_length, indices)

        # Prints animation debug info to terminal.
        self.animation.debug_mode = False

        # Is animation finished?
        self.finished = False

        # Start with first image in animation list
        self.image = self.animation.images[0]

        # Location rect for explosion
        self.rect = pygame.Rect(x, y, self.image.get_width(),
                                self.image.get_height())
示例#17
0
    def __init__(self):
        """ Constructor function """

        # Call the parent's constructor
        pygame.sprite.Sprite.__init__(self)

        sprite_sheet = SpriteSheet("mario.png")

        # Load all the right facing images into a list
        image = sprite_sheet.get_image(0, 0, constants.BLOCK_SIZE, 2 * constants.BLOCK_SIZE)
        self.standing = image

        image = sprite_sheet.get_image(5 * constants.BLOCK_SIZE, 0, constants.BLOCK_SIZE, 2 * constants.BLOCK_SIZE)
        self.jumping = image
        
        for i in xrange(1, 4):
            image = sprite_sheet.get_image(i * constants.BLOCK_SIZE, 0, constants.BLOCK_SIZE, 2 * constants.BLOCK_SIZE)
            self.walking_frames.append(image)
            
        self.walking_frames.append(self.walking_frames[1])
        
        # Set the image the player starts with
        self.image = self.standing

        # Set a referance to the image rect.
        self.rect = self.image.get_rect()
        self.rect.y = constants.BLOCK_SIZE * (constants.BLOCK_HEIGHT - 3.5)
        self.rect.x = constants.BLOCK_SIZE * (constants.BLOCK_WIDTH / 2.0 - .5)
示例#18
0
 def __init__(self, sprite_sheet_data):
     pygame.sprite.Sprite.__init__(self)
     sprite_sheet = SpriteSheet("resources/menu_items.png")  # To be created
     self.image = sprite_sheet.get_image(sprite_sheet_data[0],
                                         sprite_sheet_data[1],
                                         sprite_sheet_data[2],
                                         sprite_sheet_data[3])  # x, y, height, width of menu item
     self.rect = self.image.get_rect()
示例#19
0
 def __init__(self):
     current_path = os.path.dirname(__file__)
     self._image_path = os.path.join(current_path, 'images')
     self._sprite_sheet = SpriteSheet(os.path.join(self._image_path,
                                                   "sprites.png"),
                                      color_key=-1)
     self._ship = self._sprite_sheet.image_at((66, 14, 35, 32))
     self._ship_rect = self._ship.get_rect()
示例#20
0
	def __init__(self,dimensions):
		self.lastFrameTime = time.time()
		self.dimensions = dimensions
		self.clouds = simplegui.load_image("https://raw.githubusercontent.com/CougarTasker/twenty-four/master/proto/images/background_clouds.png")
		self.sun = simplegui.load_image("https://raw.githubusercontent.com/CougarTasker/twenty-four/master/proto/images/sun.png")
		self.water_world = simplegui.load_image("https://raw.githubusercontent.com/CougarTasker/twenty-four/master/proto/images/underwater-seamless-landscape-cartoon-background-vector-7524975.png")
		self.bubbles = SS("https://raw.githubusercontent.com/CougarTasker/twenty-four/master/proto/images/Bubble1.png",(6,5),time=1250,scale=0.22)
		self.carol = SS("https://raw.githubusercontent.com/CougarTasker/twenty-four/master/proto/images/carol.png",(5,1),time=800,scale=0.22)
		self.perl = SS("https://raw.githubusercontent.com/CougarTasker/twenty-four/master/proto/images/pearl.png",(3,3),time=3000,scale=0.22,looping=False)
示例#21
0
 def __init__(self, sheet_path, frame_change, rects, sprite_id):
     super(AnimatedSprite, self).__init__()
     sheet = SpriteSheet(sheet_path)
     self.surfs = sheet.images_at(rects, graphics.TRANSPARENT)
     self.walk_count = 0
     self.frame_change = frame_change
     self.frame_count = 0
     self.sprite_id = sprite_id
     self.sprite_count = len(self.surfs)
示例#22
0
    def __init__(self, x_pos, y_pos, sheet_data, sheetname):
        super().__init__()
        items_sheet = SpriteSheet(sheetname)
        self.image = items_sheet.get_image(sheet_data[0], sheet_data[1],
                                           sheet_data[2], sheet_data[3])

        self.rect = self.image.get_rect()
        self.rect.x = x_pos
        self.rect.y = y_pos
示例#23
0
def load_spritesheet_from_image(imagepath):
    print("load_spritesheet_from_image()")
    spritesheet = SpriteSheet(imagepath)
    images = []
    images.append(spritesheet.get_image(0, 0, 32, 32).convert())
    images.append(spritesheet.get_image(32, 0, 32, 32).convert())
    images.append(spritesheet.get_image(64, 0, 32, 32).convert())
    images.append(spritesheet.get_image(96, 0, 32, 32).convert())
    return images
示例#24
0
文件: banana.py 项目: 450W16/MODACT
	def __init__(self, width, height, x, y, owner=None):
		Projectile.__init__(self, 25, 25, x, y)
		self.owner = owner
		self.speed = 5
		
		# initialize sprite lists
		ss = SpriteSheet(path.join(get_art_dir(), 'Monkey', 'Banana_spritesheet.png'), 8)
		self.sprites_throw_right = ss.get_sprites(size=(25, 25))
		self.sprites_throw_left = [pygame.transform.flip(s, True, False) for s in self.sprites_throw_right]
示例#25
0
文件: spider.py 项目: 450W16/MODACT
	def __init__(self, width, height, x, y):
		Enemy.__init__(self, width, 20, x, y)
		self.dir = 'D'
		self.speed = 1
		
		# initialize sprite lists
		ss = SpriteSheet(path.join(get_art_dir(), 'Spider', 'Spider_spritesheet.png'), 4)
		self.sprites_walk_left = ss.get_sprites(size=(30, 20))
		self.sprites_walk_right = [pygame.transform.flip(s, True, False) for s in self.sprites_walk_left]
		self.image = self.sprites_walk_left[0]
    def loadSprites(self):
        #TODO: Am I exporting this image with transparency already in? Why does "False" have no back-fill.
        #and True have no back-fill but also no shadow?
        spritesheet = SpriteSheet("torch_sheet_1_Large.bmp", use_transparency = False)

        self.sprites[0] = spritesheet.getSprite(0, self.facing.value - 1)
        self.sprites[1] = spritesheet.getSprite(1, self.facing.value - 1)
        self.sprites[2] = spritesheet.getSprite(2, self.facing.value - 1)

        self.image = self.sprites[self.anim_frame]
示例#27
0
 def __init__(self, screen):
     sprite_sheet = SpriteSheet("Images/enemies.png")
     self.under_piranha = []
     imagePop = pygame.transform.scale(
         sprite_sheet.get_image(390, 60, 19, 25), (32, 32))
     self.under_piranha.append(imagePop)
     imagePop = pygame.transform.scale(
         sprite_sheet.get_image(420, 60, 19, 25), (32, 32))
     self.under_piranha.append(imagePop)
     super().__init__(screen=screen, pop_list=self.under_piranha)
示例#28
0
 def animate(self):
     self.acc.x += self.game.ACC
     self.num_anim = 4
     image_path = os.path.join('bin', 'resources', 'creatures',
                               f'mom_walking_transparent.png')
     self.player_ss = SpriteSheet(image_path)
     rect = (0, 0, 130, 150)
     self.player_frames = self.player_ss.load_strip(rect, self.num_anim)
     self.image = self.player_frames[int(self.creature_state)]
     self.rect = self.surf.get_rect()
示例#29
0
    def __init__(self, screen):
        """Initialize the main character"""
        self.screen = screen
        self.image = pygame.image.load('sprites/chronotrigger2.png')
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()

        self.rect.centerx = self.screen_rect.centerx
        self.rect.centery = self.screen_rect.centery

        self.sprite_sheet = SpriteSheet("sprites/chronotrigger2.png", 4, 4)
示例#30
0
    def __init__(self, x, y, platformSprites):
        Enemy.__init__(self, x, y, platformSprites)
        self.spMoveLeft = []
        self.spMoveRight = []

        self.spMoveLeftLoc = [{
            'x': 0,
            'y': 0,
            'wid': 31,
            'hei': 45,
            'flip': False
        }, {
            'x': 33,
            'y': 0,
            'wid': 30,
            'hei': 45,
            'flip': False
        }, {
            'x': 64,
            'y': 0,
            'wid': 31,
            'hei': 45,
            'flip': False
        }]

        self.spMoveRightLoc = [{
            'x': 0,
            'y': 0,
            'wid': 31,
            'hei': 45,
            'flip': True
        }, {
            'x': 33,
            'y': 0,
            'wid': 30,
            'hei': 45,
            'flip': True
        }, {
            'x': 64,
            'y': 0,
            'wid': 31,
            'hei': 45,
            'flip': True
        }]

        sheet = SpriteSheet('data\sprites\zombie.gif')
        self.spMoveLeft = sheet.getSet(self.spMoveLeftLoc)
        self.spMoveRight = sheet.getSet(self.spMoveRightLoc)

        self.image = self.spMoveLeft[0]
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
示例#31
0
 def animate(self):
     self.num_anim = 10
     image_path = os.path.join('bin', 'resources', 'creatures',
                               f'stork_flying_right.png')
     self.player_ss = SpriteSheet(image_path)
     rect = (0, 0, 200, 180)
     self.player_frames = self.player_ss.load_strip(rect,
                                                    self.num_anim,
                                                    colorkey=(255, 255,
                                                              255))
     self.image = self.player_frames[int(
         self.creature_state)]  # Updates rect
示例#32
0
 def load_images(self):
     img_x = 0
     img_y = 0
     bullet_sheet = SpriteSheet("assets/fire_spritesheet.png")
     for i in range(2):
         for j in range(10):
             self.images.append(bullet_sheet.get_image(
                 img_x, img_y, 16, 16))
         img_x += 16
     for i in range(20):
         self.images[i] = pygame.transform.smoothscale(
             self.images[i], (8, 8))
示例#33
0
    def __init__(self, max_hp, cur_hp, hb_img, img_dim):
        pygame.sprite.Sprite.__init__(self)
        self.max_hp = max_hp
        self.cur_hp = cur_hp
        self.images = []
        self.barcount = 15

        sp = SpriteSheet(hb_img)
        for i in range(self.barcount):
            self.images.append(sp.image_at((0, -img_dim[1] * (self.barcount - i - 1), img_dim[0], img_dim[1]), -1))

        self.image, self.rect = self.images[self.hp_to_bar_value(self.cur_hp)]
示例#34
0
文件: coin.py 项目: aoneill01/pymario
    def __init__(self):
        # Call the parent's constructor
        pygame.sprite.Sprite.__init__(self)

        sprite_sheet = SpriteSheet("coin.png")
        
        for i in xrange(0, 5):
            self.images.append(sprite_sheet.get_image(i * constants.BLOCK_SIZE, 0, constants.BLOCK_SIZE, constants.BLOCK_SIZE))

        self.image = self.images[0]
	self.rect = self.image.get_rect()
	self.rect.x = constants.BLOCK_SIZE * (constants.BLOCK_WIDTH / 2.0 - .5)
示例#35
0
class Player1():
    """Represents main character"""
    def __init__(self, screen):
        """Initialize the main character"""
        # initialize screen attribute
        self.screen = screen

        # load spritesheet
        self.sprite_sheet = SpriteSheet("sprites/rocket_ship4x2.png", 4, 2)
        self.width = self.sprite_sheet.cellWidth
        self.height = self.sprite_sheet.cellHeight

        # initialize player start coordinates
        self.x = screen.get_rect().width / 2
        self.y = screen.get_rect().height / 2

        # screen rect
        self.screen_rect = screen.get_rect()
        self.screen_width = self.screen_rect.width
        self.screen_height = self.screen_rect.height

        # keeps track of the need to move
        self.moving_right = False
        self.moving_left = False
        self.moving_up = False
        self.moving_down = False

    def getRect(self):
        """return a current rect for player object"""
        return pygame.Rect(self.x - self.width / 2, self.y - self.height / 2,
                           self.width, self.height)

    def blit(self, handle):
        """Draws character"""
        self.sprite_sheet.draw(self.screen, 0, int(self.x), int(self.y),
                               int(handle))

    def update(self):
        """updates player coordinates when moving"""
        rect = self.getRect()

        if self.moving_right:
            if rect.right < self.screen_width:
                self.x += 1
        if self.moving_left:
            if rect.left > 0:
                self.x -= 1
        if self.moving_up:
            if rect.top > 0:
                self.y -= 1
        if self.moving_down:
            if rect.bottom < self.screen_height:
                self.y += 1
示例#36
0
class Explosion(Sprite):
    """ Represents an explosion and runs explosion animation"""
    def __init__(self, screen, x, y, indices=()):
        """ Setting up attributes"""
        # Call parent constructor
        super(Explosion, self).__init__()

        # Screen attribute
        self.screen = screen

        # Spritesheet containing explosion animation
        self.sprite_sheet = SpriteSheet(settings.explosion_sheet,
                                        settings.explosion_cols,
                                        settings.explosion_rows)

        # Animation length in milliseconds
        self.time_length = settings.explosion_anim_length

        # Animation instance
        self.animation = Animation(self.sprite_sheet,
                                   settings.explosion_anim_length, indices)

        # Prints animation debug info to terminal.
        self.animation.debug_mode = False

        # Is animation finished?
        self.finished = False

        # Start with first image in animation list
        self.image = self.animation.images[0]

        # Location rect for explosion
        self.rect = pygame.Rect(x, y, self.image.get_width(),
                                self.image.get_height())

    def draw(self):
        """ Starts and draws explosion """
        # Start animation
        self.animation.run()

        # Draw explosion if there are frames left
        if self.animation.current_frame < self.animation.num_frames:
            self.sprite_sheet.draw(self.screen,
                                   self.animation.current_frame - 1,
                                   self.rect.x, self.rect.y)

    def update(self):
        """ Updates image to draw from animation"""
        self.image = self.animation.images[self.animation.current_frame - 1]

        # Update finished flag
        self.finished = self.animation.anim_finished
示例#37
0
 def __init__(self, x, y, right):
     pygame.sprite.Sprite.__init__(self)
     self.right = right
     if self.right:
         self.dx = 10
     else:
         self.dx = -10
     sheet = SpriteSheet('data\sprites\skeleton.png')
     self.spArrow = sheet.getSprite(260, 23, 43, 8, not right)
     self.image = self.spArrow
     self.rect = self.image.get_rect()
     self.rect.x = x
     self.rect.y = y
示例#38
0
    def __init__(self, center=None):
        pygame.sprite.Sprite.__init__(self)
        img = SpriteSheet(os.path.join(env.img_folder, 'flower.png'))
        self.image = pygame.transform.scale(img.image_at(
            (5 * 32, 0, 32, 32)), (self.width, self.height)).convert_alpha()
        self.rect = self.image.get_rect()

        if center is None:
            center = (random.randint(self.width // 2,
                                     env.WIDTH - self.width // 2),
                      random.randint(self.height // 2,
                                     env.HEIGHT - self.height // 2))
        self.rect.center = center
示例#39
0
    def __init__(self, is_next, is_top):
        # Call the parent's constructor
        pygame.sprite.Sprite.__init__(self)
        self.is_next = is_next
        self.is_top = is_top

        sprite_sheet = SpriteSheet("question-sprite.png")
        
        for i in xrange(0, 6):
            self.images.append(sprite_sheet.get_image(i * constants.BLOCK_SIZE, 0, constants.BLOCK_SIZE, constants.BLOCK_SIZE))

        self.image = self.images[0]
	self.rect = self.image.get_rect()
示例#40
0
文件: wolf.py 项目: 450W16/MODACT
    def __init__(self, width, height, x, y):
        Enemy.__init__(self, 80, 41, x, y)
        self.dir = "R"
        self.speed = 2

        # initialize sprite lists
        ss = SpriteSheet(path.join(get_art_dir(), "Wolf", "Wolf_spritesheet.png"), 6)
        self.sprites_walk_left = ss.get_sprites(size=(80, 41))
        self.sprites_walk_right = [pygame.transform.flip(s, True, False) for s in self.sprites_walk_left]

        self.image = self.sprites_walk_right[0]
        self.rect = self.image.get_rect()
        self.rect.x = width
        self.rect.y = height
示例#41
0
    def __init__(self, sprite_sheet_data):
        """ Platform constructor. Assumes constructed with user passing in
            an array of 5 numbers like what's defined at the top of this
            code. """
        pygame.sprite.Sprite.__init__(self)

        sprite_sheet = SpriteSheet("resources/tiles_spritesheet.png")
        # Grab the image for this platform
        self.image = sprite_sheet.get_image(sprite_sheet_data[0],
                                            sprite_sheet_data[1],
                                            sprite_sheet_data[2],
                                            sprite_sheet_data[3])

        self.rect = self.image.get_rect()
示例#42
0
    def loadSprites(self):
        spritesheet = SpriteSheet("letters_large.bmp", spritewidth = 32) 

        #Get a set of number sprites #TODO: Move this to a separate class?
        for i in range(0, 10):
            self.number_sprites.append(spritesheet.getSprite(i, 3))

        #Draw the part of the image that won't ever change
        crab_sprite = spritesheet.getSprite(0, 2)
        x_sprite = spritesheet.getSprite(23, 1)
        label_sprite = pygame.Surface((32 + 32, 64)) 
        label_sprite.blit(crab_sprite, (0,0))
        label_sprite.blit(x_sprite, (crab_sprite.get_width()+1, 0))
        self.image.blit(label_sprite, (0,0))
示例#43
0
文件: biggie.py 项目: 450W16/MODACT
	def __init__(self, x, y):
		Player.__init__(self, x, y)

		# initialize list for walking sprites
		ss = SpriteSheet(path.join(get_art_dir(), 'Biggie', 'Biggie_spritesheet.png'), 10)
		self.sprites_walk_right = ss.get_sprites(size=(96, 96))
		self.sprites_walk_left = [pygame.transform.flip(s, True, False) for s in self.sprites_walk_right]
		ss = SpriteSheet(path.join(get_art_dir(), 'Biggie', 'Bridge.png'), 8)
		self.sprites_bridge = ss.get_sprites(size=(256, 32))
		ss = SpriteSheet(path.join(get_art_dir(), 'Biggie', 'Ladder.png'), 8)
		self.sprites_ladder = ss.get_sprites(size=(32, 256))
		ss = SpriteSheet(path.join(get_art_dir(), 'Biggie', 'Umbrella.png'), 8)
		self.sprites_wall = ss.get_sprites(size=(200, 83))
		
		self.heading = Directions.Left
		self.image = self.sprites_walk_left[0]
		self.rect = self.image.get_rect()
		self.rect.x = x
		self.rect.y = y
		self.rect.width = BIGGIE_WIDTH
		self.rect.height = BIGGIE_HEIGHT
		self.image = pygame.transform.scale(self.image, self.rect.size)
		ladder = Ladder()
		self.abilities[ladder.getKey()] = ladder
		bridge = Bridge()
		self.abilities[bridge.getKey()] = bridge
		wall = Wall()
		self.abilities[wall.getKey()] = wall
		self.status = Transformed.Default

		self.wallUnlocked = False
示例#44
0
文件: crab.py 项目: 450W16/MODACT
	def __init__(self, width, height, x, y):
		Enemy.__init__(self, 55, 25, x, y)
		self.dir = 'L'
		self.speed = 1
		self.radius = 100
		self.dist = 0

		self.spawn = [x,y] 
		
		# initialize sprite lists
		ss = SpriteSheet(path.join(get_art_dir(), 'Crab', 'Crab_spritesheet.png'), 4)
		self.sprites_walk_right = ss.get_sprites(size=(55, 25))
		self.sprites_walk_left = [pygame.transform.flip(s, True, False) for s in self.sprites_walk_right]
		self.image = self.sprites_walk_right[0]
示例#45
0
文件: monkey.py 项目: 450W16/MODACT
	def __init__(self, width, height, x, y):
		Enemy.__init__(self, 45, 45, x, y)
		self.dir = 'R'
		self.speed = 2

		# initialize sprite lists
		ss = SpriteSheet(path.join(get_art_dir(), 'Monkey', 'Monkey_spritesheet.png'), 7)
		self.sprites_walk_left = ss.get_sprites(size=(45, 45))
		self.sprites_walk_right = [pygame.transform.flip(s, True, False) for s in self.sprites_walk_left]
		self.image = self.sprites_walk_right[0]

		self.aggroRange = 200

		self.cooldown = 2000
		self.last = pygame.time.get_ticks()
示例#46
0
 def __init__(self, x, y, world):
     Collideable.__init__(self, x, y, 100, 100, False)
     self._sprite = SpriteSheet(Res.fireball)
     self._sprite.init(10, 10, 0.1)
     self._sprite.position = sf.Vector2(x, y)
     self.world = world
     self.dead = False
示例#47
0
 def __init__(self, sprite_sheet_data=None):
     pygame.sprite.Sprite.__init__(self)
     self.sprite_sheet = SpriteSheet("resources/hud_spritesheet.png")
     if sprite_sheet_data:
         self.image = self.sprite_sheet.get_image(sprite_sheet_data[0],
                                                  sprite_sheet_data[1],
                                                  sprite_sheet_data[2],
                                                  sprite_sheet_data[3])
         self.rect = self.image.get_rect()
示例#48
0
文件: tracy.py 项目: 450W16/MODACT
	def __init__(self, x, y):
		Player.__init__(self, x, y)
		
		# initialize lists for walking sprites
		ss = SpriteSheet(path.join(get_art_dir(), 'Tracy', 'Tracy_spritesheet.png'), 8)
		self.sprites_walk_left = ss.get_sprites(size=(32, 64))
		self.sprites_walk_right = [pygame.transform.flip(s, True, False) for s in self.sprites_walk_left]
		ss = SpriteSheet(path.join(get_art_dir(), 'Tracy', 'Tracy_climb_spritesheet.png'), 8)
		self.sprites_climb = ss.get_sprites(size=(46, 64))
		
		self.image = self.sprites_walk_right[0]
		self.rect = self.image.get_rect()
		self.rect.x = x
		self.rect.y = y
		climbUp = ClimbUp()
		self.abilities[climbUp.getKey()] = climbUp
		climbDown = ClimbDown()
		self.abilities[climbDown.getKey()] = climbDown
		self.climbing = False
示例#49
0
 def __init__(self, x, y, world):
     Collideable.__init__(self, x, y, 128, 64, True)
     self._sprite = SpriteSheet(Res.ufo)
     self._sprite.init(7, 7, 0.1)
     self._sprite.set_frame_loop(0, 5)
     self._sprite.position = sf.Vector2(x, y)
     self.world = world
     self.time = 3
     self.timer = 0
     self.shoot_time = 1
     self.shoot_timer = 0
     self.direction = 1
示例#50
0
 def create_explosion(self, x, y):
     explosion = SpriteSheet(Res.explosion)
     explosion.init(16, 4, 0.1)
     explosion.position = sf.Vector2(x, y)
     explosion.set_frame_loop(0, 9, False)
     self.explosions.append(explosion)
     Res.explosion_sound.loop = False
     Res.explosion_sound.volume = 10.0
     #Res.explosion_sound.position = (x, y, 0)
     Res.explosion_sound.play()
class SpriteManager(object):
    """ A basic manager for adding sprites to the game."""
    def __init__(self, sheet_json_file):
        self.sheet = SpriteSheet(sheet_json_file)
        self.groups = {}
        for g in ['background', 'friendly', 'enemy', 'particle', 'ui']:
            self.groups[g] = pygame.sprite.RenderUpdates()
        self.screen = pygame.display.get_surface()
        
    def add_star(self):
        star_speed = uniform(0.1, 0.5)
        star_x_location = randint(0,self.screen.get_width())
        star_surface = self.sheet.new_surface('star_y_1')
        new_star = StarSprite(star_surface, star_x_location, star_speed)
        self.groups['background'].add(new_star)
        return new_star
                
    def add_ship(self):
        ship_surface = self.sheet.new_surface('ship')
        new_ship = ShipSprite(ship_surface, 
            self.screen.get_width()/2, 
            self.screen.get_height()-40)
        self.groups['friendly'].add(new_ship)
        return new_ship
    
    def add_bullet(self, bullet_x, bullet_y):
        bullet_surface = self.sheet.new_surface('bullet')
        new_bullet = BulletSprite(bullet_surface, 
                                          bullet_x, bullet_y, -0.8)
        self.groups['friendly'].add(new_bullet)
        return new_bullet
                
    def add_random_enemy(self):
        enemy_speed = uniform(0.2, 0.5)
        enemy_x_location = randint(0, self.screen.get_width())
        if randint(1,2) == 1:
            enemy_surface = self.sheet.new_surface('enemy_1')
            new_enemy = EnemySprite(enemy_surface, enemy_x_location, enemy_speed)
        else:
            enemy_surface = self.sheet.new_surface('enemy_2')
            new_enemy = PingPongEnemySprite(enemy_surface, enemy_x_location, 
                                            enemy_speed, self.screen.get_width())
        self.groups['enemy'].add(new_enemy)
        return new_enemy
            
    def add_explosion(self, start_x, start_y):
        explode_image = 'explode_{}'.format(randint(1,2))
        explode_surface = self.sheet.new_surface(explode_image)
        new_explode = ExplodeSprite(explode_surface, start_x, start_y)
        self.groups['particle'].add(new_explode)
        return new_explode
示例#52
0
    def __init__(self, x, y):
        Collideable.__init__(self, x, y, 24, 44)
        self._sprite = SpriteSheet(Res.blue_peewee)
        self._sprite.init(36, 6, 0.1)
        self._sprite.set_frame_loop(0, 5)
        self._sprite.position = sf.Vector2(x, y)
        self.current_checkpoint = sf.Vector2(x, y)
        
        self.health = 5
        
        # Controls
        self._move_left = False
        self._move_right = False
        self._on_ground = False

        # Direction -- for animating stuff
        self._direction = DIR_RIGHT
        
        self._vertical_velocity = 0
示例#53
0
class Enemy(pygame.sprite.Sprite):
    """Enemy"""

    def __init__(self, sprite_sheet_data=None):
        """ Enemy constructor. Assumes constructed with user passing in
            an array of 4 numbers like what's defined at the top of this
            code. """
        pygame.sprite.Sprite.__init__(self)

        self.sprite_sheet = SpriteSheet("resources/enemies_spritesheet.png")
        # Grab the image for this platform
        if sprite_sheet_data:
            self.image = self.sprite_sheet.get_image(sprite_sheet_data[0],
                                                     sprite_sheet_data[1],
                                                     sprite_sheet_data[2],
                                                     sprite_sheet_data[3])
            self.rect = self.image.get_rect()

        self.level = None
示例#54
0
class UFO(sf.Drawable, Collideable):
    def __init__(self, x, y, world):
        Collideable.__init__(self, x, y, 128, 64, True)
        self._sprite = SpriteSheet(Res.ufo)
        self._sprite.init(7, 7, 0.1)
        self._sprite.set_frame_loop(0, 5)
        self._sprite.position = sf.Vector2(x, y)
        self.world = world
        self.time = 3
        self.timer = 0
        self.shoot_time = 1
        self.shoot_timer = 0
        self.direction = 1
        
    def draw(self, target, render_states):
        target.draw(self._sprite, render_states)
    
    def update(self, dt):
        self._sprite.update(dt)
        
        self.timer += dt
        if self.timer >= self.time:
            # Switch directions
            self.direction *= -1
            # Reset the timer
            self.timer=0
        
        self.shoot_timer += dt
        if self.shoot_timer >= self.shoot_time:
            # Reset the timer
            self.shoot_timer=0
            self.world.create_fireball(self.position.x, self.position.y+70)

        self.position = self.position + sf.Vector2(75*dt, 0)*self.direction
            
        # Update player sprite position
        self._sprite.position = self.position
        
    def on_collision_begin(self, other, side):
        return False

    def on_collision_end(self, other):
        pass
 def loadSprites(self):
     
     spritesheet = SpriteSheet("Cricketbigsheet_reduced.bmp", border = 4)
     
     self.sprites["not_walking"] = {}
     self.sprites["not_walking"][Character.Direction.UP] = spritesheet.getSprite(0, 2)
     self.sprites["not_walking"][Character.Direction.RIGHT] = spritesheet.getSprite(0, 1)
     self.sprites["not_walking"][Character.Direction.DOWN] = spritesheet.getSprite(0, 0)
     self.sprites["not_walking"][Character.Direction.LEFT] = spritesheet.getSprite(0, 3)
             
     self.sprites["not_walking"]["holding"] = {}
     self.sprites["not_walking"]["holding"][Character.Direction.UP] = spritesheet.getSprite(3, 4)
     self.sprites["not_walking"]["holding"][Character.Direction.RIGHT] = spritesheet.getSprite(1, 4)
     self.sprites["not_walking"]["holding"][Character.Direction.DOWN] = spritesheet.getSprite(0, 4)
     self.sprites["not_walking"]["holding"][Character.Direction.LEFT] = spritesheet.getSprite(2, 4)
     
     self.sprites["not_walking"]["swinging"] = {}
     self.sprites["not_walking"]["swinging"][Character.Direction.UP] = spritesheet.getSprite(3, 5)
     self.sprites["not_walking"]["swinging"][Character.Direction.RIGHT] = spritesheet.getSprite(1, 5)
     self.sprites["not_walking"]["swinging"][Character.Direction.DOWN] = spritesheet.getSprite(0, 5)
     self.sprites["not_walking"]["swinging"][Character.Direction.LEFT] = spritesheet.getSprite(2, 5)
     
     self.sprites["walking"] = {}
     self.sprites["walking"][Character.Direction.UP] = Animation([
                                               (spritesheet.getSprite(0, 2), 128), 
                                               (spritesheet.getSprite(2, 2), 128), 
                                               (spritesheet.getSprite(0, 2), 128),
                                               (spritesheet.getSprite(1, 2), 128)])
     self.sprites["walking"][Character.Direction.RIGHT] = Animation([
                                               (spritesheet.getSprite(0, 1), 128), 
                                               (spritesheet.getSprite(2, 1), 128), 
                                               (spritesheet.getSprite(0, 1), 128),
                                               (spritesheet.getSprite(1, 1), 128)])
     self.sprites["walking"][Character.Direction.DOWN] = Animation([
                                               (spritesheet.getSprite(0, 0), 128), 
                                               (spritesheet.getSprite(2, 0), 128), 
                                               (spritesheet.getSprite(0, 0), 128),
                                               (spritesheet.getSprite(1, 0), 128)])
     self.sprites["walking"][Character.Direction.LEFT] = Animation([
                                               (spritesheet.getSprite(0, 3), 128), 
                                               (spritesheet.getSprite(2, 3), 128), 
                                               (spritesheet.getSprite(0, 3), 128),
                                               (spritesheet.getSprite(1, 3), 128)])
     
     self.sprites["walking"]["holding"] = {}
     self.sprites["walking"]["holding"][Character.Direction.UP] = Animation([(spritesheet.getSprite(4, 2), 128), 
                                               (spritesheet.getSprite(6, 2), 128), 
                                               (spritesheet.getSprite(4, 2), 128),
                                               (spritesheet.getSprite(5, 2), 128)])
     self.sprites["walking"]["holding"][Character.Direction.RIGHT] = Animation([(spritesheet.getSprite(4, 1), 128), 
                                               (spritesheet.getSprite(6, 1), 128), 
                                               (spritesheet.getSprite(4, 1), 128),
                                               (spritesheet.getSprite(5, 1), 128)])
     self.sprites["walking"]["holding"][Character.Direction.DOWN] = Animation([(spritesheet.getSprite(4, 0), 128), 
                                               (spritesheet.getSprite(6, 0), 128), 
                                               (spritesheet.getSprite(4, 0), 128),
                                               (spritesheet.getSprite(5, 0), 128)])
     self.sprites["walking"]["holding"][Character.Direction.LEFT] = Animation([(spritesheet.getSprite(4, 3), 128), 
                                               (spritesheet.getSprite(6, 3), 128), 
                                               (spritesheet.getSprite(4, 3), 128),
                                               (spritesheet.getSprite(5, 3), 128)])
 def __init__(self, sheet_json_file):
     self.sheet = SpriteSheet(sheet_json_file)
     self.groups = {}
     for g in ['background', 'friendly', 'enemy', 'particle', 'ui']:
         self.groups[g] = pygame.sprite.RenderUpdates()
     self.screen = pygame.display.get_surface()
示例#57
0
class Player(sf.Drawable, Collideable, KeyHandler):
    def __init__(self, x, y):
        Collideable.__init__(self, x, y, 24, 44)
        self._sprite = SpriteSheet(Res.blue_peewee)
        self._sprite.init(36, 6, 0.1)
        self._sprite.set_frame_loop(0, 5)
        self._sprite.position = sf.Vector2(x, y)
        self.current_checkpoint = sf.Vector2(x, y)
        
        self.health = 5
        
        # Controls
        self._move_left = False
        self._move_right = False
        self._on_ground = False

        # Direction -- for animating stuff
        self._direction = DIR_RIGHT
        
        self._vertical_velocity = 0
    
    def draw(self, target, render_states):
        target.draw(self._sprite, render_states)
    
    def update(self, dt):
        self._sprite.update(dt)

        ### TUTORIAL 1:
        # Uncomment the following 4 lines
        if self._move_left:
            self.position.x -= PLAYER_MOVE_SPEED*dt
        elif self._move_right:
            self.position.x += PLAYER_MOVE_SPEED*dt
        
        # Apply Vertical velocity
        self.position.y += self._vertical_velocity*dt

        if not self._on_ground:
            # Apply gravity
            self._vertical_velocity += 1000*dt

            # Animations when player is off ground
            if self._vertical_velocity <= 0: # Going up
                if self._direction == DIR_LEFT:
                    self._sprite.set_frame_loop(33, 33)
                elif self._direction == DIR_RIGHT:
                    self._sprite.set_frame_loop(30, 30)
            elif self._vertical_velocity > 0: # Going down
                if self._direction == DIR_LEFT:
                    self._sprite.set_frame_loop(33, 35, False)
                elif self._direction == DIR_RIGHT:
                    self._sprite.set_frame_loop(30, 32, False)
        else: # On ground
            if self._move_left:
                self._sprite.set_frame_loop(12, 17)
            elif self._move_right:
                self._sprite.set_frame_loop(18, 23)
            else: # Not moving
                if self._direction == DIR_LEFT:
                    self._sprite.set_frame_loop(1, 1)
                elif self._direction == DIR_RIGHT:
                    self._sprite.set_frame_loop(6, 6)

        # Update player sprite position
        self._sprite.position = self.position-sf.Vector2(23, 10)
    
    def on_key_pressed(self, key_code):
        if key_code == sf.Keyboard.A and not self._move_right:
            self._move_left = True
            self._direction = DIR_LEFT
        elif key_code == sf.Keyboard.D and not self._move_left:
            self._move_right = True
            self._direction = DIR_RIGHT
        elif key_code == sf.Keyboard.SPACE and self._on_ground:
            self._vertical_velocity = -PLAYER_JUMP_VELOCITY
    
    def on_key_released(self, key_code):
        if key_code == sf.Keyboard.A:
            self._move_left = False
        elif key_code == sf.Keyboard.D:
            self._move_right = False
    
    def on_collision_begin(self, other, side):       
        if other.stationary:
            if side == physics.side_down or side == physics.side_up:
                self._vertical_velocity = 0
            if side == physics.side_down:
                self._on_ground = True
        return True
    
    def on_collision_end(self, other):
        self._on_ground = False
示例#58
0
    def __init__(self, x, y):
        """ Constructor function """

        # Call the parent's constructor
        super().__init__()

        self.health = 10
        self.direction = "R"
        self.win = pygame.image.load("Assets/Pictures/bowser_win.png").convert_alpha()

        # get images for right idle
        for number in range(0, 7):
            bowser_r_idle_sheet = SpriteSheet('Assets/Pictures/bowser_idle_r.png')
            image = bowser_r_idle_sheet.get_image(number * self.idle_width, 0, self.idle_width, self.idle_length)
            self.idle_frames_r.append(image)
            self.idle_frames_l.append(pygame.transform.flip(image, True, False))

        # get images for right/left walking
        for row in range(0, 3):
            for column in range(0, 6):
                bowser_r_walking_sheet = SpriteSheet('Assets/Pictures/bowser_walking_r.png')
                if row != 2:
                    image = bowser_r_walking_sheet.get_image(
                        column * self.walking_width, row * self.walking_length, self.walking_width, self.walking_length
                    )
                    self.walking_frames_r.append(image)
                    self.walking_frames_l.append(pygame.transform.flip(image, True, False))
                else:
                    if column < 4:
                        image = bowser_r_walking_sheet.get_image(
                            column * self.walking_width, row * self.walking_length, self.walking_width, self.walking_length
                        )
                        self.walking_frames_r.append(image)
                        self.walking_frames_l.append(pygame.transform.flip(image, True, False))

        # get images for right/left facing punching
        for row in range(0, 5):
            for column in range(0, 6):
                bowser_r_punching_sheet = SpriteSheet('Assets/Pictures/bowser_punching_r.png')
                if row != 4:
                    image = bowser_r_punching_sheet.get_image(
                        column * self.punching_width, row * self.punching_length, self.punching_width, self.punching_length
                    )
                    self.punching_frames_r.append(image)
                    self.punching_frames_l.append(pygame.transform.flip(image, True, False))
                else:
                    if column < 4:
                        image = bowser_r_punching_sheet.get_image(
                            column * self.punching_width, row * self.punching_length, self.punching_width, self.punching_length
                        )
                        self.punching_frames_r.append(image)
                        self.punching_frames_l.append(pygame.transform.flip(image, True, False))

        # get images for right/left facing dying
        for row in range(0, 3):
            for column in range(0, 6):
                bowser_r_dying_sheet = SpriteSheet('Assets/Pictures/bowser_death_r.png')
                if row != 2:
                    image = bowser_r_dying_sheet.get_image(
                        column * self.death_width, row * self.death_length, self.death_width, self.death_length
                    )
                    self.dying_frames_r.append(image)
                    self.dying_frames_l.append(pygame.transform.flip(image, True, False))
                else:
                    if column < 1:
                        image = bowser_r_dying_sheet.get_image(
                            column * self.death_width, row * self.death_length, self.death_width, self.death_length
                        )
                        self.dying_frames_r.append(image)
                        self.dying_frames_l.append(pygame.transform.flip(image, True, False))

        # Set the image the player starts with
        self.image = self.idle_frames_r[0]

        # Set a referance to the image rect.
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
        self.rect.width -= 15
        self.rect.height -= 10
        print(self.rect)

from random import randint

import pygame
from pygame.locals import *

from spritesheet import SpriteSheet


pygame.init()
screen = pygame.display.set_mode((500, 600))

sprite_sheet = SpriteSheet('assets/shooter_sheet.sheet')
star_surface = sprite_sheet.new_surface('star_y_1')
ship_surface = sprite_sheet.new_surface('ship')
bullet_surface = sprite_sheet.new_surface('bullet')
enemy_surface = sprite_sheet.new_surface('enemy_1')

class Star(pygame.sprite.Sprite):
    def __init__(self, surface, speed, start_x):
        pygame.sprite.Sprite.__init__(self)
        self.image = surface
        self.rect = self.image.get_rect()
        self.last_time = pygame.time.get_ticks()
        self.y = 0
        self.rect.x = start_x
        self.speed = speed
        
    def update(self):
        if self.rect.y >= 600:

from random import randint

import pygame
from pygame.locals import *

from spritesheet import SpriteSheet


pygame.init()
screen = pygame.display.set_mode((500, 600))

sprite_sheet = SpriteSheet('assets/shooter_sheet.sheet')
star_surface = sprite_sheet.new_surface('star_y_1')

class Star(pygame.sprite.Sprite):
    def __init__(self, surface, speed, start_x):
        pygame.sprite.Sprite.__init__(self)
        self.image = surface
        self.rect = self.image.get_rect()
        self.last_time = pygame.time.get_ticks()
        self.y = 0
        self.rect.x = start_x
        self.speed = speed
        
    def update(self):
        if self.rect.y >= 600:
            self.kill()
            return
        current_time = pygame.time.get_ticks()