Ejemplo n.º 1
0
    def update(self):

        for eachBlock in objects.blockList:
            if funcs.checkCollision(self, eachBlock):
                if eachBlock.canCollide:
                    while funcs.checkCollision(self, eachBlock):
                        self.xPos += self.xDir
                        self.yPos += self.yDir
Ejemplo n.º 2
0
    def update(self):

        self.walkTimer += 1
        
        if self.dir == 1:
            self.xPos += self.speed

            if self.walkTimer > self.walkTime:
                if not (self.sprite == self.spriteFrameRight2 or
                        self.sprite == self.spriteFrameRight1):
                    self.sprite = self.spriteFrameRight1
                if self.sprite == self.spriteFrameRight1:
                    self.sprite = self.spriteFrameRight2
                else:
                    self.sprite = self.spriteFrameRight1
                    
                self.walkTimer = 0

            for eachBlock in objects.blockList:
                if funcs.checkCollision(self, eachBlock):
                    while True:
                        if funcs.checkCollision(self, eachBlock):
                            self.xPos -= 1
                        else:
                            game_vars.robot_hit_wall.play()
                            self.dir = -1
                            self.sprite = self.spriteFrameLeft1
                            break
        else:
            self.xPos -= self.speed

            if self.walkTimer > self.walkTime:
                if not (self.sprite == self.spriteFrameLeft2 or
                        self.sprite == self.spriteFrameLeft1):
                    self.sprite = self.spriteFrameLeft1
                if self.sprite == self.spriteFrameLeft1:
                    self.sprite = self.spriteFrameLeft2
                else :
                    self.sprite = self.spriteFrameLeft1

                self.walkTimer = 0

            for eachBlock in objects.blockList:
                if funcs.checkCollision(self, eachBlock):
                    while True:
                        if funcs.checkCollision(self, eachBlock):
                            self.xPos += 1
                        else:
                            game_vars.robot_hit_wall.play()
                            self.dir = 1
                            self.sprite = self.spriteFrameRight1
                            break
Ejemplo n.º 3
0
    def update(self):
        self.movment()

        if self.reloadTimer > 0:
            self.reloadTimer -= 1
        else:
            if funcs.keyPressed(K_SPACE):
                game_vars.throw.play()
                objects.bulletList.append(bullets.basicBullet((self.xPos), (self.yPos + 6), self.dir))
                if self.dir == 1:
                    self.sprite = self.spriteFrameRight4
                else:
                    self.sprite = self.spriteFrameLeft4
                self.reloadTimer = self.reloadTime

        for eachEnemy in objects.enemyList:
            if funcs.checkCollision(self, eachEnemy):
                self.health -= eachEnemy.damage

        objects.energyBar.update(self.energy)
        if self.health > 100:
            self.health = 100
        objects.healthBar.update(self.health)

        if self.dead():
            self.xPos = game_vars.saveXPos
            self.yPos = game_vars.saveYPos
            funcs.changeLevel(game_vars.saveLevel[0],game_vars.saveLevel[1])
            self.health = 100
            self.energy = 100
Ejemplo n.º 4
0
 def checkDeath(self):
     if self.xPos > WIN_WIDTH + self.width or self.xPos < 0 or self.yPos > WIN_HEIGHT + self.height or  self. yPos <  0:
         return True
     else:
         for eachBlock in objects.blockList:
             if funcs.checkCollision(self, eachBlock):
                 return True
                 break
Ejemplo n.º 5
0
 def update(self):
     if game_vars.saveLevel == level.levelSpawner.level and self.xPos == game_vars.saveXPos and self.yPos == game_vars.saveYPos:
         self.sprite = self.sprite2
     else:
         self.sprite = self.sprite1
         if funcs.checkCollision(self, objects.player):
             game_vars.check.play()
             game_vars.saveLevel = level.levelSpawner.level
             game_vars.saveXPos = self.xPos
             game_vars.saveYPos = self.yPos
Ejemplo n.º 6
0
def main():

    #---Reset Screen and Draw Background
    game_vars.screen.fill((0,0,0))

    level.background.draw()

    #---Get events---
    game_vars.events = pygame.event.get()

    #---Update Blocks---
    for eachBlock in  objects.blockList:
        try:
            eachBlock.update()
        except:
            pass

    for eachBlock in  objects.blockList:
        try:
            if eachBlock.checkDeath():
                objects.blockList.remove(eachBlock)
        except:
            pass

    for eachBlock in  objects.blockList:
        eachBlock.draw()

    #---Update checkpoint---
    try:
        objects.checkpoint.update()
        objects.checkpoint.draw()
    except:
        pass

    #---Update Bullets---
    for eachBullet in objects.bulletList:
        for eachEnemy in objects.enemyList:
            if funcs.checkCollision(eachBullet, eachEnemy):
                try: objects.bulletList.remove(eachBullet)
                except: pass
                if not eachEnemy.lives == -1:
                    if eachEnemy.lives > 1:
                        eachEnemy.lives -= 1
                    else:
                        if eachEnemy.canCollide:
                            eachEnemy.falling = True
                        else:
                            if eachEnemy.damage == BALLDAMAGE:
                                game_vars.ball_death.play()
                            else:
                                game_vars.robot_death.play()
                            objects.enemyList.remove(eachEnemy)


    for eachBullet in objects.bulletList:
        eachBullet.update()

    for eachBullet in objects.bulletList:
        if eachBullet.checkDeath():
            try: objects.bulletList.remove(eachBullet)
            except: pass


    for eachBullet in objects.bulletList:
        eachBullet.draw()

    #---Update Enemys---
    for eachEnemy in objects.enemyList:
        try: eachEnemy.update()
        except: pass

        try:
            if eachEnemy.checkDeath():
                objects.enemyList.remove(eachEnemy)

        except:
            pass
    for eachEnemy in objects.enemyList:
        eachEnemy.draw()

    #---Update Decals---
    for eachDecal in  objects.decalList:
        try:
            eachDecal.update()
        except:
            pass

        try:
            if eachDecal.checkDeath():
                objects.decalList.remove(eachDecal)
        except:
            pass

        eachDecal.draw()

    #---Update Healths and Batteriess---
    for item in objects.health_battery:
        try:
            item.update()
        except:
            pass
        item.draw()


    #---Update Player---
    objects.player.update()
    objects.player.draw()

    #---Change Screen---
    try:
        if objects.player.xPos + objects.player.width > WIN_WIDTH:
            funcs.changeLevel(level.levelSpawner.level[0]+1, level.levelSpawner.level[1])
            objects.player.xPos = 0
        elif objects.player.xPos < 0:
            funcs.changeLevel(level.levelSpawner.level[0]-1, level.levelSpawner.level[1])
            objects.player.xPos = WIN_WIDTH - objects.player.width
        elif objects.player.yPos + objects.player.height > WIN_HEIGHT:
            funcs.changeLevel(level.levelSpawner.level[0], level.levelSpawner.level[1]+1)
            objects.player.yPos = 0
        elif objects.player.yPos < 0:
            funcs.changeLevel(level.levelSpawner.level[0], level.levelSpawner.level[1]-1)
            objects.player.yPos = WIN_HEIGHT - objects.player.height
    except IndexError:
        level.levelSpawner.level = game_vars.startLevel
        objects.player.health = 0

    #---Update Bars-------
    objects.energyBar.draw()
    objects.healthBar.draw()
    if game_vars.powerJetPack:
        funcs.printText('J', 10, 10, 33, BLACK)
    if game_vars.powerTeleport:
        funcs.printText('T', 10, 25, 33, BLACK)

    #---Check if closed---
    for event in game_vars.events:
        if event.type == pygame.QUIT:
            game_vars.runGame = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                funcs.gameReset()
            if event.key == pygame.K_p:
                game_vars.gameScreen = "paused"

    # Show time and fps
    funcs.printText('%s s' %(round(game_vars.time/1000.0,2)), 20, 120, 10, BLACK, 1)
    funcs.printText('%s' %(round(game_vars.clock.get_fps(),2)), 20, 5, WIN_HEIGHT-15, LIGHTGREY, 1)


    #---Update Screen---
    pygame.display.flip()
Ejemplo n.º 7
0
 def update(self):
     if funcs.checkCollision(self, objects.player) and not self.used:
         game_vars.battery_pickup.play()
         self.used = True
         objects.player.energy = 100
Ejemplo n.º 8
0
 def update(self):
     if funcs.checkCollision(self, objects.player) and not self.used:
         game_vars.heal.play()
         self.used = True
         objects.player.health += 50
Ejemplo n.º 9
0
 def update(self):
     if funcs.checkCollision(self, objects.player) and not game_vars.powerJetPack:
         game_vars.jet_pack.play()
         game_vars.powerJetPack = True
Ejemplo n.º 10
0
 def update(self):
     if funcs.checkCollision(self, objects.player) and not game_vars.powerTeleport:
         game_vars.powerTeleport = True
Ejemplo n.º 11
0
    def movment(self):

        if not self.jumped:
            if self.dir == 1:
                self.sprite = self.spriteFrameRight1
            else:
                self.sprite = self.spriteFrameLeft1

        #---------Teleport
        for event in game_vars.events:
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    if game_vars.powerTeleport and self.energy >= 75:
                        game_vars.teleport.play()
                        self.xPos = event.pos[0] - self.width/2
                        self.yPos = event.pos[1] - self.height/2
                        self.energy -= 75
                        self.teleported = True

        #---------X movment
        if funcs.keyPressed(K_d)or funcs.keyPressed(K_RIGHT):
            if not (self.sprite == self.spriteFrameRight2 or
                    self.sprite == self.spriteFrameRight3):
                self.sprite = self.spriteFrameRight2
            self.dir = 1
            self.xPos += PLAYERSPEED
            self.walkTimer += 1
            if self.walkTimer > self.walkTime:
                if self.sprite == self.spriteFrameRight3:
                    self.sprite = self.spriteFrameRight2
                else:
                    self.sprite = self.spriteFrameRight3
                self.walkTimer = 0
                
            if self.energy < 100:
                self.energy += 0.1


            for eachBlock in objects.blockList:
                if funcs.checkCollision(self, eachBlock):
                    if 'door' in eachBlock.image:
                        game_vars.gameScreen = 'finish'
                    if eachBlock.canCollide:
                        while funcs.checkCollision(self, eachBlock):
                            self.xPos -= 1

        elif funcs.keyPressed(K_a) or funcs.keyPressed(K_LEFT):
            if not (self.sprite == self.spriteFrameLeft2 or
                    self.sprite == self.spriteFrameLeft3):
                self.sprite = self.spriteFrameLeft2
            self.dir = -1
            self.xPos -= PLAYERSPEED
            self.walkTimer += 1
            if self.walkTimer > self.walkTime:
                if self.sprite == self.spriteFrameLeft3:
                    self.sprite = self.spriteFrameLeft2
                else:
                    self.sprite = self.spriteFrameLeft3
                self.walkTimer = 0

            for eachBlock in objects.blockList:
                if funcs.checkCollision(self, eachBlock):
                    if 'door' in eachBlock.image:
                        game_vars.gameScreen = 'finish'
                    if eachBlock.canCollide:
                        while funcs.checkCollision(self, eachBlock):
                            self.xPos += 1
         
            if self.energy < 100:
                self.energy += 0.1
        else:
            if self.jumped:
                if self.dir == 1:
                    self.sprite = self.spriteFrameRight5
                else:
                    self.sprite = self.spriteFrameLeft5

        if self.teleported:
            if self.dir == 1:
                self.sprite = self.spriteFrameRight5
            else:
                self.sprite = self.spriteFrameLeft5
            self.teleported = False


        #-------Y movment

        for event in game_vars.events:
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_w or event.key == pygame.K_UP:
                    if not self.jumped:
                        if self.dir == 1:
                            self.sprite = self.spriteFrameRight5
                        else:
                            self.sprite = self.spriteFrameLeft5
                        self.yVel = JUMP_FORCE
                        self.jumped = True
                        
                    if self.energy < 100:
                        self.energy += 1
                        
        if funcs.keyPressed(K_s) or funcs.keyPressed(K_DOWN):
            if game_vars.powerJetPack and self.energy >= 5:
                self.yVel += FLY_FORCE
                self.energy -= 2
                if self.dir ==1:
                    self.sprite = self.spriteFrameRight5
                else:
                    self.sprite = self.spriteFrameLeft5


        if self.yVel != 0 and self.jumped == False:
            self.jumped = True

        self.yPos -= self.yVel

        if self.yVel > -10:
            self.yVel -= GRAVITY


        if self.yVel >= 1:

            for eachBlock in objects.blockList:
                if funcs.checkCollision(self, eachBlock):
                    if eachBlock.canCollide:
                        while True:
                            if funcs.checkCollision(self, eachBlock):
                                self.yPos += 1
                            else:
                                self.yVel = 0
                                break
            for eachEnemy in objects.enemyList:
                if funcs.checkCollision(self, eachEnemy):
                    if eachEnemy.canCollide:
                        eachEnemy.falling = True
                        self.health -= eachEnemy.damage
                        while True:
                            if funcs.checkCollision(self, eachEnemy):
                                self.yPos += 1
                            else:
                                self.yVel = 0
                                break

        else:

            for eachBlock in objects.blockList:
                if funcs.checkCollision(self, eachBlock):
                    if eachBlock.canCollide:
                        while True:
                            if funcs.checkCollision(self, eachBlock):
                                self.yPos -= 1
                            else:
                                self.jumped = False
                                self.yVel = 0
                                break
            for eachEnemy in objects.enemyList:
                if funcs.checkCollision(self, eachEnemy):
                    if eachEnemy.canCollide:
                        eachEnemy.falling = True
                        self.health -= eachEnemy.damage
                        while True:
                            if funcs.checkCollision(self, eachEnemy):
                                self.yPos -= 1
                            else:
                                self.jumped = False
                                self.yVel = 0
                                break