示例#1
0
    def __init__(self, width, height):
        Level.__init__(self, width, height)
        ##initialize blocks##
        boxtop = Terrain(20, -19, 40, 2, 0, 0,100, self, 0.5)
        boxleft= Terrain(-1,-5,2,30,0,0,100,self,0.5)
        boxbottom= Terrain(27.0,9.0,54.0,2.0,0.0,0.0,100,self,0.5)
        boxright= Terrain(55,-5,2,30,0,0,100,self,0.5)

        goal= Goal(53,5,1,5,0,0,100,self,0.5)
        
        
        b =   Block(2, 2,  4, 1, 0, 0,  1, self, 0.5)
        c =  Player(7, 5,  1, 2, 0, 0,  1, self, 0.5)
        d =   Block(4, 2, 4, 1, 0, 5,  2, self, 0.5)  
        a =   GoalBlock(4, 5, 2, 2, 0, 5,  2, self, 0.5) 
        m = Trampoline(30, -4, 2, 1, 0, 0, 1, self, 0.5)
        e = Spike(30.0, 7.5, 41.0, 1.0, 0.0, 0.0, 100, self, 0.1)
        f = Spike(29.0, 6.5, 1.0, 1.0, 0.0, 0.0, 100, self, 0.1)
        self.add_elem(c)
        self.add_elem(m)
        self.add_elem(b)
        self.add_elem(a)
        self.add_elem(d)
        self.add_elem(e)
        self.add_elem(f)
        self.add_elem(boxtop)
        self.add_elem(boxright)
        self.add_elem(boxbottom)
        self.add_elem(boxleft)
        self.add_elem(goal)
示例#2
0
    def createSpikes(self):
        """
        Function for creation of sprites
        """

        spikes = self.level()

        if self.rightlimit:
            while not self.createRightlimit:
                self.Spike_x = 25
                for spike in range(0, int(spikes)):
                    self.Spike_y = random.randint(80, 450)
                    self.Right_or_Left = True
                    self.spikeMain = Spike(self.Spike_x, self.Spike_y,
                                           self.Right_or_Left)
                    self.spikeList.append(self.spikeMain)
                    self.Spike_List_y.append(self.Spike_y)
                self.createRightlimit = True
                self.createLeftlimit = False

        elif self.leftlimit:
            while not self.createLeftlimit:
                self.Spike_x = 270
                for spike in range(0, int(spikes)):
                    self.Spike_y = random.randint(80, 450)
                    self.Right_or_Left = False
                    self.spikeMain = Spike(self.Spike_x, self.Spike_y,
                                           self.Right_or_Left)
                    self.spikeList.append(self.spikeMain)
                    self.Spike_List_y.append(self.Spike_y)
                self.createLeftlimit = True
                self.createRightlimit = False
def playbackRedrawAll(canvas, data):
    canvas.create_image(data.width/2,data.height/2,image=data.playBGImage)
    drawSnowflakes(canvas,data)
    Drop.draw(canvas,data)
    Brick.draw(canvas,data)
    Target.draw(canvas,data)
    Scroll.draw(canvas,data)
    drawScore(canvas,data)
    drawLevel(canvas,data)
    Spike.draw(canvas,data)
    Bomb.draw(canvas,data)
    WormholeA.draw(canvas,data)
    WormholeB.draw(canvas,data)
    Trap.draw(canvas,data)
    drawPlaybackTable(canvas,data)
示例#4
0
 def _emplace_cust(self, x, y, ident):
     new_element = None
     if ident == 'spike':
         new_element = Spike(self.ids[ident], x, y)
     elif ident == 'food':
         new_element = Food(self.ids[ident], x, y)
     if not new_element:
         return False
     self.lists[ident].append(new_element)
     self.ids[ident] += 1
     self.counts[ident] += 1
     return True
    def shoot(self, other):
        x = self.rect.center[0] - other.rect.center[0]
        y = self.rect.center[1] - other.rect.center[1]

        if math.fabs(x) > math.fabs(y):
            if x > 0:
                direction = "right"
            else:
                direction = "left"
        else:
            if y > 0:
                direction = "down"
            else:
                direction = "up"
        return Spike(self, direction)
示例#6
0
    def loadLevel(self):
        levelFile = open(self.fileName, "r")
        jsonString = levelFile.read()
        parsedJson = json.loads(jsonString)

        player = None
        for instance in parsedJson["Level"]:
            for item in instance:
                if item == "Name" and instance[item] == "Player":
                    y = instance["Y"]
                    x = instance["X"]
                    angle = instance["Angle"]
                    player = Player(self.world, x, y, cursor=self.cursor)
                    player.rotation = angle
                    player.stableRotation = angle
                    self.world.addEntity(player)
        for instance in parsedJson["Level"]:
            for item in instance:
                if item == "Room":
                    self.world.roomHeight = instance[item]["Height"]
                    self.world.roomWidth = instance[item]["Width"]
                    
                if item == "Name":
                    y = instance["Y"]
                    x = instance["X"]
                    angle = instance["Angle"]
                    if instance[item] == "Satellite Platform":
                        imageIndex = instance["Image Index"]
                        
                        platform = Platform(self.world, x, y, player=player)
                        platform.frame = imageIndex
                        self.levelObjects.append(platform)
                        
                    elif instance[item] == "Spikes":
                        imageIndex = instance["Image Index"]
                        
                        sprite = None
                        if imageIndex == 0:
                            sprite = self.world.assetLoader.smallSpikes
                        elif imageIndex == 2:
                            sprite = self.world.assetLoader.bigSpikes
                        spike = Spike(self.world, x, y, sprite=sprite, player=player)
                        self.levelObjects.append(spike)
                        
                    elif instance[item] == "Checkpoint":
                        
                        checkpoint = Checkpoint(self.world, x, y, player=player)
                        self.levelObjects.append(checkpoint)
                        
                    elif instance[item] == "Pull Orb":
                        
                        pass
                        pullOrb = PullOrb(self.world, x, y, player=player, cursor=self.cursor)
                        self.levelObjects.append(pullOrb)
                              
                    elif instance[item] == "Attract Tether":
                        
                        pass
                        pullOrbTether = PullOrbTether(self.world, x, y, player=player)
                        self.levelObjects.append(pullOrbTether)
                              
                    elif instance[item] == "End Rocket":
                        
                        rocket = Rocket(self.world, x, y, player=player)
                        self.levelObjects.append(rocket)
                              
                    elif instance[item] == "Earth":
                        pass
                              
                    elif instance[item] == "Bouncy":
                        
                        bouncy = Bouncy(self.world, x, y, player=player)
                        self.levelObjects.append(bouncy)
                    
                    elif instance[item] == "Repel Orb":
                        
                        repelOrb = RepelOrb(self.world, x, y, player=player, cursor=self.cursor)
                        self.levelObjects.append(repelOrb)
                        
        return self.levelObjects
def buildMyMazeRedrawAll(canvas, data):
    color = 'beige'
    # the background must be draw first!
    canvas.create_image(data.width / 2,
                        data.height / 2,
                        image=data.playBGImage)
    # the grid for user to place item
    for i in range(15):
        x = 150 + 30 * i
        y = 120 + 30 * i
        canvas.create_line(x, 120, x, 540, fill=color)
        canvas.create_line(150, y, 570, y, fill=color)
    canvas.create_text(360,
                       15,
                       text='Click the items on the left,',
                       font='fixedsys 15',
                       fill=color)
    canvas.create_text(360,
                       45,
                       text='then click on the grid to place it.',
                       font='fixedsys 15',
                       fill=color)
    canvas.create_text(360,
                       75,
                       text='To delete the item, first click the red cross,',
                       font='fixedsys 15',
                       fill=color)
    canvas.create_text(
        360,
        105,
        text='then click on the item on the board to delete it.',
        font='fixedsys 15',
        fill=color)
    canvas.create_image(data.width / 15,
                        1 * data.height / 10,
                        image=data.dropImage)
    canvas.create_image(data.width / 15,
                        2 * data.height / 10,
                        image=data.brickImage)
    canvas.create_image(data.width / 15,
                        3 * data.height / 10,
                        image=data.targetImage)
    canvas.create_image(data.width / 15,
                        4 * data.height / 10,
                        image=data.scrollImage)
    canvas.create_image(data.width / 15,
                        5 * data.height / 10,
                        image=data.spikeNorthImage)
    canvas.create_image(data.width / 15,
                        6 * data.height / 10,
                        image=data.spikeSouthImage)
    canvas.create_image(data.width / 15,
                        7 * data.height / 10,
                        image=data.spikeEastImage)
    canvas.create_image(data.width / 15,
                        8 * data.height / 10,
                        image=data.spikeWestImage)
    canvas.create_image(data.width / 6,
                        1 * data.height / 10,
                        image=data.crossImage)
    canvas.create_image(data.width / 6,
                        2 * data.height / 10,
                        image=data.bombImage)
    canvas.create_image(data.width / 6,
                        3 * data.height / 10,
                        image=data.wormholeAImage)
    canvas.create_image(data.width / 6,
                        4 * data.height / 10,
                        image=data.wormholeBImage)
    canvas.create_image(data.width / 6,
                        5 * data.height / 10,
                        image=data.trap1Image)
    canvas.create_text(100,
                       600,
                       text='PLAY MY GAME!',
                       font='fixedsys 15',
                       fill=color)
    canvas.create_text(300,
                       590,
                       text='PRESS \'C\'',
                       font='fixedsys 15',
                       fill=color)
    canvas.create_text(300,
                       610,
                       text='TO CLEAR BOARD',
                       font='fixedsys 15',
                       fill=color)
    canvas.create_text(500, 600, text='MENU', font='fixedsys 15', fill=color)
    Drop.draw(canvas, data)
    Brick.draw(canvas, data)
    Target.draw(canvas, data)
    Scroll.draw(canvas, data)
    Spike.draw(canvas, data)
    Bomb.draw(canvas, data)
    WormholeA.draw(canvas, data)
    WormholeB.draw(canvas, data)
    Trap.draw(canvas, data)
    drawSnowflakes(canvas, data)
示例#8
0
def load_level(nombre):
	mapa, fondo, musica, pared, graviswitch = Read_File(nombre)
	
	sprite_list = pygame.sprite.Group()
	updatable_list = pygame.sprite.Group() #Un grupo por tipo de accion a sprites.
	wall_list = pygame.sprite.Group()
	box_list = pygame.sprite.Group()
	col_list = pygame.sprite.Group()
	door_list = pygame.sprite.Group()
	bfilter_list = pygame.sprite.Group()
	checkpoint_list = pygame.sprite.Group()
	
	id_given = 0
	door_id = 0
	pos_y = 0
	for linea in mapa:
		pos_x = 0
		for cuadro in linea:
			if cuadro == 'W':
				wall = Wall(pos_x*BLOCK_SIZE, pos_y*BLOCK_SIZE)
				sprite_list.add(wall)
				col_list.add(wall)
				wall_list.add(wall)
				wall.ID = id_given #Cada bloque va a tener su propio ID, para comparar colisiones.
				id_given += 1 
			elif cuadro == 'P':
				p_inicio = (pos_x*BLOCK_SIZE, pos_y*BLOCK_SIZE)
				p_id = id_given
				id_given += 1
			elif cuadro == 'B':
				box = Box(pos_x*BLOCK_SIZE, pos_y*BLOCK_SIZE)
				sprite_list.add(box)
				col_list.add(box)
				updatable_list.add(box)
				box_list.add(box)
				box.ID = id_given #Cada bloque va a tener su propio ID, para comparar colisiones.
				id_given += 1
			elif cuadro == 'J':
				box = JumpBox(pos_x*BLOCK_SIZE, pos_y*BLOCK_SIZE)
				sprite_list.add(box)
				col_list.add(box)
				updatable_list.add(box)
				box_list.add(box)
				box.ID = id_given #Cada bloque va a tener su propio ID, para comparar colisiones.
				id_given += 1
			elif cuadro == 'S':
				spike = Spike(pos_x*BLOCK_SIZE, pos_y*BLOCK_SIZE)
				sprite_list.add(spike)
				col_list.add(spike)
				spike.ID = id_given
				id_given += 1
			elif cuadro == 'D':
				door = Door(pos_x*BLOCK_SIZE, pos_y*BLOCK_SIZE)
				door.exitID = door_id
				door_list.add(door)
				door_id += 1
			elif cuadro == 'F':
				bfilter = Box_Filter(pos_x*BLOCK_SIZE, pos_y*BLOCK_SIZE)
				bfilter_list.add(bfilter)
				bfilter.ID = id_given
				id_given += 1
			elif cuadro == 'C':
				checkpoint = Checkpoint(pos_x*BLOCK_SIZE, pos_y*BLOCK_SIZE)
				checkpoint_list.add(checkpoint)
				checkpoint.ID = id_given
				id_given += 1
				
			pos_x += 1
		pos_y += 1
	
	grupos =[col_list, box_list, wall_list, door_list, updatable_list, sprite_list, bfilter_list, checkpoint_list]
	info = [p_id, p_inicio, fondo, musica, pared, graviswitch]
	return (info, grupos)
示例#9
0
    def update(self):
        Spike.update(self)
        """ Move the platform.
            If the player is in the way, it will shove the player
            out of the way. This does NOT handle what happens if a
            platform shoves a player into another object. Make sure
            moving platforms have clearance to push the player around
            or add code to handle what happens if they don't. """

        # Move left/right
        self.rect.x += self.change_x

        # See if we hit the player
        hit = pygame.sprite.collide_rect(self, self.player) and not self.player.hit

        if hit:
            # We did hit the player. Shove the player around and
            # assume he/she won't hit anything else.

            # If we are moving right, set our right side
            # to the left side of the item we hit
            if self.change_x < 0:
                self.player.rect.right = self.rect.left
            else:
                # Otherwise if we are moving left, do the opposite.
                self.player.rect.left = self.rect.right


        # Move up/down
        self.rect.y += self.change_y

        # Check and see if we hit the player
        hit = pygame.sprite.collide_rect(self, self.player) and not self.player.hit

        if hit:
            # We did hit the player. Shove the player around and
            # assume he/she won't hit anything else.

            # Reset our position based on the top/bottom of the object.
            if self.change_y < 0:
                self.player.rect.bottom = self.rect.top
            else:
                self.player.rect.top = self.rect.bottom

        #check if the player is on top of the movingplatform and move it with it.

        #check if the player is on top of a lateral moving platform and make it move with it.
        self.player.rect.y += 2
        hit = pygame.sprite.collide_rect(self.player, self) and not self.player.hit
        self.player.rect.y -= 2

        if hit:
            if self.player.location == 'block' and (self.player.status == 'idle_l' or self.player.status == 'idle_r') :
                self.player.change_x = self.change_x
                self.player.mov_plat = True
            else :
                self.player.mov_plat = False

        if self.player.location == 'ground':
            self.player.mov_plat = False

        self.boundaries()
示例#10
0
    def __init__(self):
        """
        All variables, instances and functions for the game functionality
        """
        self.run = True
        self.clock = pygame.time.Clock()
        """Color and Background"""

        self.background = Background(background_game, [0, -20])
        self.fill_color = (100, 100, 100)
        self.color_margin = (238, 232, 170)
        """Types of Spikes"""

        self.spikeBOTTOM = pygame.image.load(spike)
        self.spikeTOP = pygame.transform.flip(self.spikeBOTTOM, True, True)
        """Object BIRD Instance"""

        self.character = Bird(WIDTH / 2, HEIGHT / 2, [2, 0])
        """Object SPIKES Instance"""

        self.Right_or_Left = (
            True  # Saber si el Spike debe ir hacia la derecha o izquierda
        )
        self.createSpikesBool = True
        self.hide = -60
        self.Spike_x = self.hide
        self.Spike_y = self.hide
        self.Spike_List_x = []
        self.Spike_List_y = []
        self.spikeMain = Spike(self.Spike_x, self.Spike_y, self.Right_or_Left)
        self.spikeList = []
        """Rect Sprite"""

        self.rectCharacter = self.character.get_rect()
        self.rectSpike = self.spikeMain.get_rect()
        """Limit of Bird"""

        self.rightlimit = False
        self.leftlimit = False
        self.bottomlimit = False
        self.toplimit = False
        self.createRightlimit = False
        self.createLeftlimit = False
        self.collitionActive = False
        """Handling Font"""

        self.score = 0
        self.HandlingScore = Create_Score(self.score)
        self.life = 3
        self.HandlingLife = Create_life(self.life)
        """Menu"""

        self.HandlingMenu = Create_menu()
        self.ElementMenu = [
            self.HandlingMenu.title1,
            self.HandlingMenu.title2,
            self.HandlingMenu.title3,
            self.HandlingMenu.copy_right,
        ]
        self.mainScreen = True
        self.starGame = False
        """"Try Again Handling"""

        self.HandlingTryAgain = Create_TryAgain()
        self.ElementTryAgain = [
            self.HandlingTryAgain.try_again,
            self.HandlingTryAgain.press_key,
        ]
        self.game_over_pic = Background(gameover, [0, -20])
        self.endGame = False
示例#11
0
class Main(object):
    def __init__(self):
        """
        All variables, instances and functions for the game functionality
        """
        self.run = True
        self.clock = pygame.time.Clock()
        """Color and Background"""

        self.background = Background(background_game, [0, -20])
        self.fill_color = (100, 100, 100)
        self.color_margin = (238, 232, 170)
        """Types of Spikes"""

        self.spikeBOTTOM = pygame.image.load(spike)
        self.spikeTOP = pygame.transform.flip(self.spikeBOTTOM, True, True)
        """Object BIRD Instance"""

        self.character = Bird(WIDTH / 2, HEIGHT / 2, [2, 0])
        """Object SPIKES Instance"""

        self.Right_or_Left = (
            True  # Saber si el Spike debe ir hacia la derecha o izquierda
        )
        self.createSpikesBool = True
        self.hide = -60
        self.Spike_x = self.hide
        self.Spike_y = self.hide
        self.Spike_List_x = []
        self.Spike_List_y = []
        self.spikeMain = Spike(self.Spike_x, self.Spike_y, self.Right_or_Left)
        self.spikeList = []
        """Rect Sprite"""

        self.rectCharacter = self.character.get_rect()
        self.rectSpike = self.spikeMain.get_rect()
        """Limit of Bird"""

        self.rightlimit = False
        self.leftlimit = False
        self.bottomlimit = False
        self.toplimit = False
        self.createRightlimit = False
        self.createLeftlimit = False
        self.collitionActive = False
        """Handling Font"""

        self.score = 0
        self.HandlingScore = Create_Score(self.score)
        self.life = 3
        self.HandlingLife = Create_life(self.life)
        """Menu"""

        self.HandlingMenu = Create_menu()
        self.ElementMenu = [
            self.HandlingMenu.title1,
            self.HandlingMenu.title2,
            self.HandlingMenu.title3,
            self.HandlingMenu.copy_right,
        ]
        self.mainScreen = True
        self.starGame = False
        """"Try Again Handling"""

        self.HandlingTryAgain = Create_TryAgain()
        self.ElementTryAgain = [
            self.HandlingTryAgain.try_again,
            self.HandlingTryAgain.press_key,
        ]
        self.game_over_pic = Background(gameover, [0, -20])
        self.endGame = False

    def listenOtherTurn(self):
        """"
        Check if the bird pass the middle of the screen
        """
        if self.rectCharacter[0] == (WIDTH /
                                     2) or (self.rectCharacter[0] >=
                                            (WIDTH / 2)
                                            and self.rectCharacter[0] <
                                            (WIDTH / 2) + 20):  # Why + 20 ?

            self.collitionActive = False

    def listenCollition(self):
        """"
        Check if bird collide
        The first condition evaluates the 
        collision of the bird with the spikes,
        the other two with the spikes of the 
        lower and upper ends
        """
        for n in self.Spike_List_y:
            if (self.rectCharacter[0] >= self.Spike_x - 10
                    and self.rectCharacter[0] <= self.Spike_x + 60
                    and (self.rectCharacter[1] >= n - 40
                         and self.rectCharacter[1] <= n + 60)):

                if self.rightlimit:
                    while self.collitionActive == False:
                        self.score -= 10
                        self.life -= 1
                        self.HandlingLife = Create_life(self.life)
                        self.collitionActive = True

                elif self.leftlimit:
                    while self.collitionActive == False:
                        self.score -= 10
                        self.life -= 1
                        self.HandlingLife = Create_life(self.life)
                        self.collitionActive = True

        if self.rectCharacter[1] < 80:  # TOP
            self.score -= 10
            self.endGame = True
            self.life -= 1
            self.HandlingLife = Create_life(self.life)
            self.character.pain(random.randint(4, 7))

        elif (self.rectCharacter[1] >= HEIGHT - 130
              and self.rectCharacter[1] <= HEIGHT):  # BOTTOM
            self.score -= 10
            self.endGame = True
            self.life -= 1
            self.HandlingLife = Create_life(self.life)
            self.character.pain(-6)

    def listenLimit(self):
        """
        Check if the bird is on the left or right border
        """
        self.positionTuple = self.character.get_position()
        self.x, self.y = self.positionTuple

        if self.x >= 269:
            while self.rightlimit == False:
                self.leftlimit = False
                self.changeRightLimit()
                self.createSpikes()
                if self.collitionActive == False:
                    self.score += 10
                self.HandlingScore = Create_Score(self.score)

        elif self.x <= 23:
            while self.leftlimit == False:
                self.rightlimit = False
                self.changeLeftLimit()
                self.createSpikes()
                if self.collitionActive == False:
                    self.score += 10
                self.HandlingScore = Create_Score(self.score)

        if self.y < 26:
            while self.toplimit == False:
                self.toplimit = True
                self.bottomlimit = False

        elif self.y > 510:
            while self.bottomlimit == False:
                self.bottomlimit = True
                self.toplimit = False

    def changeRightLimit(self):
        """
        Empty list of spikes and change rightlimit value
        """
        self.rightlimit = True
        self.cleanSpikeList()

        # self.createSpikes()

    def changeLeftLimit(self):
        """
        Empty list of spikes and change leftlimit value
        """
        self.leftlimit = True
        self.cleanSpikeList()

    def cleanSpikeList(self):
        del self.spikeList[:]
        del self.Spike_List_y[:]

    def createSpikes(self):
        """
        Function for creation of sprites
        """

        spikes = self.level()

        if self.rightlimit:
            while not self.createRightlimit:
                self.Spike_x = 25
                for spike in range(0, int(spikes)):
                    self.Spike_y = random.randint(80, 450)
                    self.Right_or_Left = True
                    self.spikeMain = Spike(self.Spike_x, self.Spike_y,
                                           self.Right_or_Left)
                    self.spikeList.append(self.spikeMain)
                    self.Spike_List_y.append(self.Spike_y)
                self.createRightlimit = True
                self.createLeftlimit = False

        elif self.leftlimit:
            while not self.createLeftlimit:
                self.Spike_x = 270
                for spike in range(0, int(spikes)):
                    self.Spike_y = random.randint(80, 450)
                    self.Right_or_Left = False
                    self.spikeMain = Spike(self.Spike_x, self.Spike_y,
                                           self.Right_or_Left)
                    self.spikeList.append(self.spikeMain)
                    self.Spike_List_y.append(self.Spike_y)
                self.createLeftlimit = True
                self.createRightlimit = False

    def drawGame(self):
        if self.run:
            screen.blit(self.background.image, self.background.rect)

            pygame.draw.line(
                screen,
                self.color_margin,
                ([side2 / 2, 0]),
                ([side2 / 2, HEIGHT]),
                side2,
            )
            pygame.draw.line(
                screen,
                self.color_margin,
                [WIDTH - side2 / 2, 0],
                [WIDTH - side2 / 2, HEIGHT],
                side2,
            )
            pygame.draw.line(screen, self.color_margin, [0, 0], [WIDTH, 0],
                             side1 - 9)
            pygame.draw.line(screen, self.color_margin, [0, HEIGHT],
                             [WIDTH, HEIGHT], side1 - 9)

            for i in range(0, 5):
                screen.blit(self.spikeBOTTOM, [22 + i * 62, HEIGHT - 75])
                screen.blit(self.spikeTOP, [22 + i * 62, 22])

            self.HandlingScore.ScoreText.draw(screen)
            self.HandlingLife.LifeText.draw(screen)

            self.listenOtherTurn()

            self.listenCollition()

    def drawSpike(self):
        """
        Update the spikes in the window
        """
        if not self.collitionActive:
            for spike in self.spikeList:
                spike.update()

    def update(self):
        self.drawGame()
        self.listenLimit()
        self.drawSpike()

    def level(self):
        if self.score < 40:
            level = 1
            return level
        elif self.score >= 40 and self.score < 80:
            level = 2
            return level
        elif self.score >= 80 and self.score < 160:
            level = 3
            return level
        elif self.score >= 160:
            level = random.randint(1, 4)
            return level

    def exit_game(self):
        pygame.quit()
        sys.exit()

    def menu(self):
        """
        Main menu of the game
        """
        if self.mainScreen:
            pygame.display.update()
            screen.blit(self.background.image, self.background.rect)

            for text in self.ElementMenu:
                text.draw(screen)

            for e in pygame.event.get():
                if e.type == pygame.QUIT:
                    self.exit_game()
                elif e.type == pygame.KEYUP:
                    self.startGame = True
                    self.mainScreen = False

    def try_again(self):
        """
        Main for choice if play again or exit
        """
        while self.endGame:
            pygame.mixer.music.fadeout(1)
            pygame.display.update()
            screen.blit(self.background.image, self.background.rect)
            screen.blit(self.game_over_pic.image, self.game_over_pic.rect)
            self.HandlingScore.ScoreEnd.draw(screen)

            for text in self.ElementTryAgain:
                text.draw(screen)

            for e in pygame.event.get():
                if e.type == pygame.QUIT:
                    self.endGame = False
                    self.exit_game()
                if e.type == pygame.KEYUP:
                    sleep(1)
                    self.score = 0
                    self.HandlingScore = Create_Score(self.score)
                    self.life = 3
                    self.HandlingLife = Create_life(self.life)
                    pygame.mixer.music.play(-1)
                    self.main()

    def main(self):
        """
        Main method for start the game
        """
        while self.run:
            if self.mainScreen:
                pygame.display.set_caption("Presiona una tecla!")
                self.menu()

            elif self.startGame:
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        self.run = False
                        self.exit_game()
                pygame.display.set_caption(caption)
                pygame.display.update()
                self.update()
                self.character.update(screen)
                if self.life < 1:
                    self.endGame = True
                    self.try_again()

        pygame.quit()
示例#12
0
def init(data):
    data.mode = 'menu'  # This is the menu mode
    data.level = -1  # make the level be -1 to be used for BUILD MY MAZE mode!
    data.totalLevels = 9  # this is 1 larger than the actual levels, for convenient usage.
    data.currentScore = 0
    data.accumulatedScore = 0
    data.currentIndex = -1  # record playback index
    data.playbackMap = [[], [], []]  # record your last solution
    data.playTime = 0  # record yout tour-time
    data.step = 0  # record your tour step index
    data.MINSteps = {
        -1: "?",
        1: "5",
        2: "7",
        3: "3",
        4: "7",
        5: "6",
        6: "7",
        7: "3",
        8: "3"
    }

    # initialize the time of background animation
    data.snowflakeTime = 0
    data.fallingLeavesTime = 0
    data.dogTime = 0

    # record the occupied positions with the item name
    # used in deleting items
    # the first element is set to be (-1,-1), and it is reserved for record drop
    # since drop is different from others, only one drop can exist, this makes finding
    # and checking drop position easy
    data.occupiedMap = [(-1, -1, 'drop')]
    # record the occupied positions only, no more items can be placed overlap
    # used in placing items. The (-1,-1) is the same as data.occupiedMap
    data.occupiedCoordinatesMap = [(-1, -1)]
    data.currentItem = None  # describe the current selected item in BUILD MY MAZE mode
    # This image is cited from https://play.blocksworld.com/play?world_id=26183522
    data.dropImage = PhotoImage(file='pictures/drop.gif')
    # The following 3 images are cited from https://gamejolt.com/games/erayu/109632
    data.menuBGImage = PhotoImage(file='pictures/menuBG.png')
    data.playBGImage = PhotoImage(file='pictures/playBG.png')
    data.helpBGImage = PhotoImage(file='pictures/helpBG.png')
    data.aboutmeBGImage = PhotoImage(file='pictures/aboutmeBG.png')
    # This image is cited from https://www.roblox.com/library/170321226/sanic-ring-1
    data.scrollImage = PhotoImage(file='pictures/scrollImage.gif')
    # This image is cited from http://img.neoseeker.com/v_concept_art.php?caid=36373
    data.brickImage = PhotoImage(file='pictures/brick.png')
    # This image is cited from
    # https://www.brik.co/blogs/pixel-art/super-mario-galaxy-luma-star-pixel-art
    data.targetImage = PhotoImage(file='pictures/target.gif')
    # The following four images are modified from
    # https://www.brik.co/blogs/pixel-art/candy-corn-pixel-art
    data.spikeNorthImage = PhotoImage(file='pictures/spikeNorth.gif')
    data.spikeSouthImage = PhotoImage(file='pictures/spikeSouth.gif')
    data.spikeEastImage = PhotoImage(file='pictures/spikeEast.gif')
    data.spikeWestImage = PhotoImage(file='pictures/spikeWest.gif')
    # This image is cited from http://piq.codeus.net/picture/327376/med_pack
    data.crossImage = PhotoImage(file='pictures/cross.png')
    # This image is cited from http://piq.codeus.net/picture/8582/bomb
    data.bombImage = PhotoImage(file='pictures/bomb.png')
    # This image is cited from https://www.thinglink.com/scene/657786259783024642
    data.wormholeAImage = PhotoImage(file='pictures/wormholeA.png')
    # This image is edited from https://www.thinglink.com/scene/657786259783024642
    data.wormholeBImage = PhotoImage(file='pictures/wormholeB.png')
    # This image is cited from https://lowpolypix.deviantart.
    # com/art/Super-Dragonsin-Saga-Items-Free-Use-345202858
    data.trap1Image = PhotoImage(file='pictures/trap1.png')
    # This image is cited from https://lowpolypix.deviantart.
    # com/art/Super-Dragonsin-Saga-Items-Free-Use-345202858
    data.trap2Image = PhotoImage(file='pictures/trap2.png')
    # This image is cited from https://www.redbubble.com/fr/people/thesaurusrex/works
    # /21656630-wasd-keys-black?p=womens-relaxed-fit
    data.wasdImage = PhotoImage(file='pictures/wasd.png')
    # This image is cited from http://photobucket.com/gifs/pink%20arrow%20pixel
    data.arrowImage = PhotoImage(file='pictures/arrow.png')
    # This image is cited from https://opengameart.org/content/home-button-pixel
    data.menuButtonImage = PhotoImage(file='pictures/menuButton.png')
    # The following 2 images are cited from
    # https://opengameart.org/content/restart-button-pixel
    data.nextButtonImage = PhotoImage(file='pictures/nextButton.png')
    data.prevButtonImage = PhotoImage(file='pictures/prevButton.png')
    # This image is cited from
    # https://free.clipartof.com/details/12-Free-Vector-Illustration-Of-A-Question-Mark-Icon
    data.helpButtonImage = PhotoImage(file='pictures/helpButton.png')
    # This image is cited from http://pixelartmaker.com/art/2fec8acf327f433
    data.playbackButtonImage = PhotoImage(file='pictures/playback.png')

    # The following 4 images are cited from
    # http://www.dickbaldwin.com/XNA/XNA0122/XNA0122.htm
    data.dog1Image = PhotoImage(file='pictures/dog1.png')
    data.dog2Image = PhotoImage(file='pictures/dog2.png')
    data.dog3Image = PhotoImage(file='pictures/dog3.png')
    data.dog4Image = PhotoImage(file='pictures/dog4.png')

    # The next 4 images are cited from
    # https://mrbubblewand.wordpress.com/2010/01/18/animation-magic_004/
    data.snowflake1Image = PhotoImage(file='pictures/snow1.png')
    data.snowflake2Image = PhotoImage(file='pictures/snow2.png')
    data.snowflake3Image = PhotoImage(file='pictures/snow3.png')
    data.snowflake4Image = PhotoImage(file='pictures/snow4.png')
    # The next 4 images are cited and eidted from
    # https://www.pinterest.com/pin/375839531394461912/
    data.leaf1Image = PhotoImage(file='pictures/leaf1.png')
    data.leaf2Image = PhotoImage(file='pictures/leaf2.png')
    data.leaf3Image = PhotoImage(file='pictures/leaf3.png')
    data.leaf4Image = PhotoImage(file='pictures/leaf4.png')

    data.dropMapDict = dropMapDict
    data.brick = Brick()
    data.scroll = Scroll()
    data.target = Target()
    data.spike = Spike()
    data.bomb = Bomb()
    data.wormholeA = WormholeA()
    data.wormholeB = WormholeB()
    data.trap = Trap()

    # update all the maps!
    updateAllMapDicts(data)
    updateAllCurrentGeneralMaps(data)

    ### The following 2 blocks will not affected by adding new classes ###
    # data.ESM/WSM/NSM/SSM are short for data.East/West/North/SouthSpikeMap
    # get spike maps which are seperated by 4 directions!
    data.ESM = makeSpikeMaps(data.spikeMapDict, 'east', data.totalLevels)
    data.WSM = makeSpikeMaps(data.spikeMapDict, 'west', data.totalLevels)
    data.NSM = makeSpikeMaps(data.spikeMapDict, 'north', data.totalLevels)
    data.SSM = makeSpikeMaps(data.spikeMapDict, 'south', data.totalLevels)

    # data.EBM/WBM/NBM/SBM are short for data.East/West/North/SouthBrickMap
    data.EBM = makeBarrierMaps(data.brickMapDict, data.spikeMapDict, 'east',
                               data.totalLevels)
    data.WBM = makeBarrierMaps(data.brickMapDict, data.spikeMapDict, 'west',
                               data.totalLevels)
    data.NBM = makeBarrierMaps(data.brickMapDict, data.spikeMapDict, 'north',
                               data.totalLevels)
    data.SBM = makeBarrierMaps(data.brickMapDict, data.spikeMapDict, 'south',
                               data.totalLevels)

    # update spike related maps!
    updateAllSpikeRealatedMaps(data)

    pass