Example #1
0
    def update(self, gameState):
        gs = gameState

        self.x = self.x + self.dx
        self.y = self.y + self.dy
        self.dx = self.dx + self.ddx
        if not self.onGround:
            self.dy = self.dy + 1
        if self.dx > self.limit or self.dx < -self.limit:
            self.ddx = -self.ddx
            self.limit = random.randint(4, 7)
            if self.onGround:
                self.dy = -random.randint(5, 15)
                if (
                    self.x + gs.scrollx < gs.thor.x + self.range
                    and self.x + gs.scrollx > gs.thor.x - self.range
                    and self.y + gs.scrolly < gs.thor.y + self.range
                    and self.y + gs.scrolly > gs.thor.y - self.range
                ):
                    enemy = Flamenemy()
                    enemy.setposition(self.x - 100, self.y)
                    gs.map.addEnemy(enemy)
                    gameLogic.loadvisible(gs)
        if self.dy > 100:
            print "flameboy fell down"
            gs.map.enemies.remove(self)
            gameLogic.loadvisible(gs)
        if self.rect.collidelist(gs.map.blocks) != -1:
            if self.dy > 0:
                self.dy, self.ddy = 0, 0
                self.onGround = True
        else:
            self.onGround = False
        self.rect.topleft = self.x + gs.scrollx, self.y + gs.scrolly
Example #2
0
 def createGO(self, gameState):
     gs = gameState
     
     if self.entity == 0:
         block = Block()
         block.setposition(self.x - gs.scrollx, self.y - gs.scrolly)
         gs.map.addBlock(block)    
     elif self.entity == 1:
         block = Block()
         block.setposition(self.x - gs.scrollx, self.y - gs.scrolly)
         block.setimage(self.images[self.entity], None)
         gs.map.addBlock(block)
     elif self.entity == 2:
         enemy = Flamenemy()
         enemy.setposition(self.x - gs.scrollx, self.y - gs.scrolly)
         gs.map.addEnemy(enemy)
     elif self.entity == 3:
         door = Door()
         import guiTools
         door.setTargetDoor( guiTools.ask(gs.screen, "Which map number should the door lead to?") )
         door.setposition(self.x - gs.scrollx, self.y - gs.scrolly)
         gs.map.addDoor(door)
     elif self.entity == 4:
         flameboy = Flameboy()
         flameboy.setposition(self.x - gs.scrollx, self.y - gs.scrolly)
         gs.map.addEnemy(flameboy)
     
     gameLogic.loadvisible(gs)
Example #3
0
def initializeGame(gameState):
    gs = gameState
    
    pygame.init()
        
    gs.window = pygame.display.set_mode(pygame.display.list_modes()[0]) # Fonsterstorlek
    gs.screen = pygame.display.get_surface() # Skarmyta
    gs.back_file_name = os.path.join("data", "background.bmp") # bakgrundsfilnamnsokvag
    gs.back_surface = pygame.image.load(gs.back_file_name)
    gs.clock = pygame.time.Clock()
    gs.background = pygame.Surface(gs.screen.get_size())
    gs.scrollx = 0
    gs.scrolly = 0
    gs.scoore = 0
    gs.scooresurface = pygame.Surface((50, 25))
    
    pygame.display.set_caption('Goatboy: the hoorned avanger') #Fonstertitel
    pygame.display.flip()
    gs.background.blit(gs.back_surface, (0, 0))
    
    gs.map = mapLogic.Map()     # skapa ett map-objekt
    gs.map.loadmap("map1.map") # ladda banan fran fil

    from gameObjects import Goatboy
    gs.thor = Goatboy(gs) # skapa ett goatboy-objekt =)
    from levelEditor import LevelEditor
    gs.leveleditor = LevelEditor()
    
    gameLogic.loadvisible(gs)
    
    gs.frameCounter = 0                    # Set up FPS counter
    gs.startingTime = time.time()          #
Example #4
0
 def die(self, gameState):
     self.life = self.life - 1
     if self.life < 1:
         gameState.scoore = gameState.scoore + 1
         gameState.map.enemies.remove(self)
         gameLogic.loadvisible(gameState)
     else:
         self.dy = -10
Example #5
0
def proceed(gameState):
    gs = gameState
    gs.clock.tick(60)   # Delay
    gs.screen.blit(gs.background, (0, 0)) # Rita bakgrunden
        
    gs.thor.update(gs)
    gs.leveleditor.update()
    gs.map.update(gs)
    gs.panel.update()
    gameLogic.loadvisible(gs)
    
    if pygame.event.peek(): # Titta om det finns en event i event-kon
        if not handleInput(pygame.event.get(), gs):  # Om det finns skicka event till input()
            return False
    gs.allsprites.draw(gs.screen) # Rita alla sprites
    pygame.display.flip()   # vand fram dubbelbufferten
    
    return True
Example #6
0
    def update(self, gameState):
        gs = gameState
        self.x = self.x + self.dx
        self.y = self.y + self.dy
        self.dy = self.dy + self.ddy
        self.imagenr = (self.imagenr + 1) % len(self.filenames)
        self.image = self.images[self.imagenr]
        if self.dy > self.limit or self.dy < -self.limit:

            self.ddy = -self.ddy
        self.rect.topleft = self.x + gs.scrollx, self.y + gs.scrolly
        if self.x + gs.scrollx > gs.thor.x + self.range or self.x + gs.scrollx < gs.thor.x - self.range:
            gs.map.shots.remove(self)  # ta bort skottet fran listan i kartan o hopppas garbagecollectorn fixar biffen
            gameLogic.loadvisible(gs)
        elif self.rect.collidelist(gs.map.enemies) != -1:
            gs.map.shots.remove(self)
            gs.map.enemies[self.rect.collidelist(gs.map.enemies)].die(gs)
            gameLogic.loadvisible(gs)
Example #7
0
    def update(self, gameState):  #
        gs = gameState

        # Testa goatboys ben mot alla block
        if gs.thor.boneRect.collidelist(gs.map.blocks) != -1:
            if gs.thor.dy > 0:  # Om man nuddar ett block pa vagen ner,
                gs.thor.dy = 0  # faller man inte langre nedat
                gs.thor.onGround = True  # och har fotterna pa fast mark.
        else:
            gs.thor.onGround = False  # nuddar man inget block, star man inte pa marken

        # Om ens sprite krockar med en elakings, dor man
        if gs.thor.rect.collidelist(gs.map.enemies) != -1:
            gs.thor.die(gs)

        # Om man inte krockat med en fiende, men med en dorr, sa beamas man till nasta level
        elif gs.thor.rect.collidelist(gs.map.doors) != -1:
            gs.map.doors[gs.thor.rect.collidelist(gs.map.doors)].open(gs)  # Oppna dorren

        self.x = self.x + self.dx  # Flytta goatboy i hans horisontella hastighet
        if self.dx < self.maxspeed and self.dx > -self.maxspeed:  # Om goatboys maxhastiget inte ar mott,
            self.dx = self.dx + self.ddx  # oka hans hastighet med hans acceleration

        self.y = self.y + self.dy  # Flytta goatboy i hans vertikala hastighet
        if self.dy > 100:  # Om goatboy faller fortare an 100
            self.die(gs)  # sa dor han!

        if self.shooting:
            if random.randint(1, 2) == 2:
                shot = Shot(gs)
                shot.limit = self.weapon
                shot.dy = random.randint(-self.weapon, self.weapon)
                if shot.dy < 0:
                    shot.ddy = -1
                else:
                    shot.ddy = 1
                gs.map.addShot(shot)
            gameLogic.loadvisible(gs)

        # -- This is the frame of goatboys scroll :
        if self.y > self.bottomscroll:
            gs.scrolly = gs.scrolly + (self.bottomscroll - self.y)
            self.y = self.bottomscroll
        elif self.y < self.topscroll:
            gs.scrolly = gs.scrolly - (self.y - self.topscroll)
            self.y = self.topscroll
        if self.x > self.rightscroll:
            gs.scrollx = gs.scrollx + (self.rightscroll - self.x)
            self.x = self.rightscroll
        elif self.x < self.leftscroll:
            gs.scrollx = gs.scrollx - (self.x - self.leftscroll)
            self.x = self.leftscroll

        # If goatboy doesn't stand on the ground, he will fall down
        if not self.onGround:
            self.dy = self.dy + 1

        # If goatboy is on a moving block, he should be moving along with it
        if self.onGround:
            pass

        self.rect.topleft = self.x, self.y  # Satt goatboys sprite till hans nya koordinater
        self.boneRect = pygame.Rect(self.x + 30, self.y + 74, 22, 1)  # Flytta fotterna efter de nya koordinaterna