Example #1
0
 def init(self):
     self.pygame.init()
     self.size = (self.width, self.height)
     self.screen = pygame.display.set_mode(self.size)
     self.clock = self.pygame.time.Clock()
     self.time_step = 0
     # TODO: init sprite, tile,...
     self.my_mario = mario.Mario(self)
     self.mariosprite = pygame.sprite.RenderPlain(self.my_mario)
Example #2
0
def main():


    wn = turtle.Screen()
    wn.register_shape("mario.gif")
    wn.register_shape("khaled.gif")
    alex = mario.Mario(wn)
    salem = Obstacle(wn, mario)

    example = ThreadingExample(alex, salem, wn)
    time.sleep(1)
    earth = World(wn, alex, salem)
    earth.run()

    wn.mainloop()
Example #3
0
    def init_map(self, map_file, new_pos, first_time):
        self.tilemap = tmx.load(map_file, self.screen.get_size())

        if first_time:
            # condition for first attempt
            self.sprites = tmx.SpriteLayer()
            start_cell = self.tilemap.layers['triggers'].find('player')[0]
            self.my_mario = mario.Mario((start_cell.px, start_cell.py),
                                        self.sprites)
        else:
            start_cell = self.tilemap.layers['triggers'].find(new_pos)[0]
        self.my_mario.rect.topleft = (start_cell.px, start_cell.py)

        self.coinboxs = tmx.SpriteLayer()
        for _coinbox in self.tilemap.layers['triggers'].find('coinbox'):
            box_type = getattr(coinbox,
                               _coinbox.properties.get("type", "SECRET"))
            prize = None
            if _coinbox.properties.get("item"):
                prize = getattr(powerup, _coinbox.properties.get("item"))
            count = _coinbox.properties.get("count", 1)
            coinbox.CoinBox(self, (_coinbox.px, _coinbox.py), box_type, prize,
                            count, self.coinboxs)

        self.bricks = tmx.SpriteLayer()
        for _brick in self.tilemap.layers['triggers'].find('brick'):
            brick.Brick(self, (_brick.px, _brick.py), self.bricks)

        self.coins = tmx.SpriteLayer()
        for _coin in self.tilemap.layers['triggers'].find('coin'):
            coin.Coin((_coin.px, _coin.py), self.coins)

        self.enemies = tmx.SpriteLayer()
        for _turtle in self.tilemap.layers['triggers'].find('turtle'):
            turtle.Turtle((_turtle.px, _turtle.py), self.enemies)
        for _flower in self.tilemap.layers['triggers'].find('flower'):
            color = getattr(flower,
                            _flower.properties.get("color", "GREEN_FLOWER"))
            flower.Flower((_flower.px, _flower.py), color, self.enemies)

        self.powerups = tmx.SpriteLayer()
        # layer order: background, midground + sprites, foreground
        self.insert_layer(self.powerups, "powerups", 1)
        self.insert_layer(self.coins, "coins", 2)
        self.insert_layer(self.coinboxs, "coinboxs", 3)
        self.insert_layer(self.bricks, "bricks", 4)
        self.insert_layer(self.enemies, "enemies", 5)
        self.insert_layer(self.sprites, "sprites", 6)
Example #4
0
def run_game():
    pygame.init()
    config.screen = pygame.display.set_mode(
        (config.SCREEN_SIZE.x, config.SCREEN_SIZE.y))
    pygame.display.set_caption(config.CAPTION)

    config.clock = pygame.time.Clock()
    config.camera = camera.Camera(Vector2(), config.SCREEN_SIZE.x,
                                  config.SCREEN_SIZE.y)
    config.mario = mario.Mario(config.MARIO_START_POSITION, 36, 48,
                               Vector2(0, 0))
    level = level_1_1  #从第一关开始
    config.static_colliders = level.static_colliders
    config.dynamic_colliders = level.dynamic_colliders

    while True:
        config.delta_time = config.clock.tick(60)  #设置帧率
        gf.check_keyboard(level)  #键盘响应
        gf.update_time()  #刷新时间相关
        gf.update_screen()  #刷新屏幕
        pygame.display.update()
Example #5
0
import pygame
import mario
import world

screen = pygame.display.set_mode((336, 432))
pygame.display.set_caption("Mario Mayhem")
clock = pygame.time.Clock()

world = world.World()
mario = mario.Mario((250, 355), world)

running = True

while running:
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			running = False
	
	mario.handle_event(event)
	mario.handle_animation()
			
	screen.fill(pygame.Color('black'))	
	screen.blit(world.image, world.rect)
	screen.blit(mario.image, mario.rect, mario.area)

	pygame.display.flip()		
	clock.tick(15)
def main():
    '''This main function initializes the pygame screen, creates the level object and mario object and draws them on the screen in a while loop at 60 frames per second'''

    pygame.init()

    prevu = 0
    size = [SCREENWIDTH, SCREENHEIGHT]
    screen = pygame.display.set_mode(size)
    restartCount = 0
    pygame.display.set_caption("Big Papa and Fofo!")

    winningCoverCount = 0
    player = mario.Mario()

    lives = 3

    life = Level(player, lives)

    currentLevel = Level(player, lives)
    currentLevel.sound.play()
    activeSpriteList = pygame.sprite.Group()
    player.level = currentLevel

    player.rect.x = 340
    player.rect.y = SCREENHEIGHT - player.rect.height - 20
    activeSpriteList.add(player)

    done = False

    clock = pygame.time.Clock()

    while not done:

        if player.rect.y > SCREENHEIGHT and lives > 1:
            if restartCount > 90:
                lives = lives - 1
                player = mario.Mario()
                currentLevel = Level(player, lives)

                activeSpriteList = pygame.sprite.Group()
                player.level = currentLevel

                player.rect.x = 340
                player.rect.y = SCREENHEIGHT - player.rect.height - 20
                activeSpriteList.add(player)
                restartCount = 0

                currentLevel.sound.play()

            else:
                restartCount += 1

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    player.goLeft()
                if event.key == pygame.K_RIGHT:
                    player.goRight()

                if event.key == pygame.K_UP:
                    player.jump()

                if event.key == pygame.K_SPACE:
                    print(player.rect.x + prevu)
                    prevu = player.rect.x

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT and player.changeX < 0:

                    player.stop()

                if event.key == pygame.K_RIGHT and player.changeX > 0:

                    player.stop()

        currentLevel.movingEnemies()

        activeSpriteList.update()

        currentLevel.update()

        if player.rect.x > SCREENWIDTH - 40:

            currentLevel.shiftingWorld(-SCREENWIDTH)
            player.rect.x = 20

        if player.rect.left < 20:

            currentLevel.shiftingWorld(SCREENWIDTH)
            player.rect.x = 620

        currentLevel.draw(screen)
        if player.bowserDies == False:
            activeSpriteList.draw(screen)

        else:
            if winningCoverCount == 125:
                'DO NOTHING'

            else:
                activeSpriteList.draw(screen)
                winningCoverCount += 1

        clock.tick(60)

        pygame.display.flip()

    pygame.quit()