def __init__(self, screen, pos, patrolRadius, golemType, life): self.screen = screen self.life = life self.golemType = golemType self.name = '' self.renameTheGolemType() self.patrolRadius = patrolRadius self.state = 'Idle' self.move_direction = 'right' self.imgGolens = pygame.image.load( "resources/image/enimy/golens/Golem_" + str(self.golemType) + "/" + self.state + "/" + self.move_direction + "/0_Golem_" + self.state + "_0.png").convert_alpha() self.rect = self.imgGolens.get_rect() self.rect.x = pos[0] self.rect.y = pos[1] self.initialPosition = pos[0] self.ai = EnimysAI(self.patrolRadius, 50, self.rect.x) self.collision = Colision() self.move_right = False self.move_left = False self.air_timer = 0 self.vertical_momentum = 0 self.move_frame = 0 self.attacking = False self.isMe = False
def __init__(self, screen, nivel): self.screen = screen self.nivel = nivel self.position = [] self.determinatePositionOfLifItems() self.collision = Colision() self.item = [PlantLife(self.screen) for i in range(len(self.position))] self.item_rects = pygame.Rect(0, 0, 0, 0)
def __init__(self, screen, position): self.screen = screen self.name = 'cactus' self.collision = Colision() self.air_timer = 0 self.vertical_momentum = 0 self.img = pygame.image.load( "resources/image/platform/florest/obstaculo/cactus.png" ).convert_alpha() self.cactusRects = self.img.get_rect() self.cactusRects.x = position[0] self.cactusRects.y = position[1]
def __init__(self, screen, fireType, pos, direction): self.screen = screen self.collision = Colision() self.img = [pygame.image.load("resources/image/Golem/fire/"+direction+"/"+fireType+""+str(i)+".png") for i in range(2)] self.rect = self.img[0].get_rect() self.player_pos = pos self.nrimg = 0 if(direction == "right"): self.rect.x = pos[0]+40 else: self.rect.x = pos[0]-40 self.rect.y = pos[1] + 15 self.direction = direction
class LifeItemAndPlants(object): def __init__(self, screen, nivel): self.screen = screen self.nivel = nivel self.position = [] self.determinatePositionOfLifItems() self.collision = Colision() self.item = [PlantLife(self.screen) for i in range(len(self.position))] self.item_rects = pygame.Rect(0, 0, 0, 0) def drawingTheLifeItem(self, player_rects, scroll): item_list = [] i = 0 # Drawing life items for pos in self.position: if (pos[0] in range(scroll[0] - 450, scroll[0] + 650)): item_list.append(self.item[i].draw(pos, scroll)) else: item_list.append( pygame.image.load("resources/image/life/1.png").get_rect()) i += 1 if (len(self.position) != 0): if (self.position[0][0] < scroll[0] - 250): del self.position[0] return self.controlingColection(item_list, player_rects) def controlingColection(self, item_list, player_rects): move = [0, 0] if (len(item_list) != 0): move[0] += item_list[0].x move[0] += item_list[0].x collision_types, position = self.collision.enimysCollision( move, player_rects, item_list) # print(player_rects) if (collision_types['top'] or collision_types['bottom'] or collision_types['right'] or collision_types['left']): del self.position[position] return True else: return False def determinatePositionOfLifItems(self): if (self.nivel == 0): self.position = [(1542, -20), (2890, 408), (3876, 488), (4238, 408)] self.plantPosition = [(608, 120), (780, 120)] elif (self.nivel == 1): self.position = [(1198, 648), (2282, 216), (3045, 200)] self.plantPosition = [] elif (self.nivel == 2): self.position = [(1178, 410), (3811, -40), (5673, 380)] self.plantPosition = [] elif (self.nivel == 3): self.position = [(2474, 408), (2966, 232), (4081, -24), (4027, -24)] self.plantPosition = []
class Fire(object): def __init__(self, screen, fireType, pos, direction): self.screen = screen self.collision = Colision() self.img = [pygame.image.load("resources/image/Golem/fire/"+direction+"/"+fireType+""+str(i)+".png") for i in range(2)] self.rect = self.img[0].get_rect() self.player_pos = pos self.nrimg = 0 if(direction == "right"): self.rect.x = pos[0]+40 else: self.rect.x = pos[0]-40 self.rect.y = pos[1] + 15 self.direction = direction def draw(self, tile_rect,enimysRects, scroll): fire_move = [0, 0] platfcollision = False enimyCollision = False if(self.direction == 'right'): fire_move[0] += 5 else: fire_move[0] -= 5 ## cheching platoform colision rect, plat_collisions = self.collision.platformCollision(fire_move,self.rect, tile_rect) enimys_colid, pos = self.collision.enimysCollision(fire_move, self.rect, enimysRects) del rect if(plat_collisions['right'] or plat_collisions['left'] or enimys_colid['right'] or enimys_colid['left']): if enimys_colid['right'] or enimys_colid['left']: enimyCollision = True else: enimyCollision = False platfcollision = True else: platfcollision = False self.rect.x += fire_move[0] if self.nrimg == 0: self.nrimg = 1 else: self.nrimg = 0 self.screen.blit(self.img[self.nrimg],(self.rect.x-scroll[0], self.rect.y-scroll[1])) return platfcollision, enimyCollision, pos
def __init__(self, screen, pos, patrolRadius, life): self.screen = screen self.life = life self.name = 'blue wizard' self.patrolRadius = patrolRadius self.rect = pygame.Rect(40, 30, 20, 42) self.rect.x = pos[0] self.rect.y = pos[1] self.initialPosition = pos[0] self.ai = EnimysAI(self.patrolRadius,200, self.rect.x) self.collision = Colision() self.state = 'idle' self.move_direction = 'right' self.move_right = False self.move_left = False self.air_timer = 0 self.vertical_momentum = 0 self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Chara-0.png") self.move_frame = 0 self.impactDelay = 0 self.attacking = False self.isMe = False
def __init__(self, screen, nivel, enimysKilled): self.screen = screen self.nivel = nivel self.enimyskilled = enimysKilled self.collision = Colision() self.allEnimys = [] self.allEnimysPosition = [] self.allCactus = [] self.allCactusPosition = [] self.enimyKilled = 0 self.bossKilled = False self.count = 0 self.addingAllTheAnimys()
def __init__(self, screen, nivel, lastPassPoint): self.collision = Colision() self.screen = screen self.air_timer = 0 self.vertical_momentum = 0 self.player_move = [0, 0] self.move_direction = 'right' self.state = 'Idle' self.skillsInUse = 'kicking' self.move_frame = 0 self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_0.png").convert_alpha() self.player_rect=self.player_img.get_rect() self.player_rect.x = lastPassPoint[0] self.player_rect.y = lastPassPoint[1] ## atributes to control the player state self.moving_right = False self.moving_left = False self.jumping = False self.hurtten = False self.attack = False self.bottomColision = False self.topColision = False self.firing = False self.preCollisionAriaRight = [0,0] self.preCollisionAriaLeft = [0,0] self.vertical_momentum = 0 self.air_timer = 0 self.player_screen_limit = 380 self.nivel = nivel self.impactDelay = 0 self.slashingControl = 0 self.count = 0 self.fireArray = [] self.enimyCollision = False self.enimyType = ''
def __init__(self, screen, pos, patrolRadius, life): self.screen = screen self.life = life self.name = 'minotauro' self.patrolRadius = patrolRadius self.state = 'Idle' self.move_direction = 'right' #resources\image\enimy\minotauro\Minotauro_1\Idle\right\Minotaur_Idle_0.png self.imgMinotaur = pygame.image.load( "resources/image/enimy/minotauro/" + self.state + "/" + self.move_direction + "/Minotaur_" + self.state + "_0.png").convert_alpha() self.rect = self.imgMinotaur.get_rect() self.rect.x = pos[0] self.rect.y = pos[1] self.initialPosition = pos[0] self.ai = EnimysAI(self.patrolRadius, 100, self.rect.x) self.collision = Colision() self.move_right = False self.move_left = False self.air_timer = 0 self.vertical_momentum = 0 self.move_frame = 0 self.attacking = False self.isMe = False
class Cactus: def __init__(self, screen, position): self.screen = screen self.name = 'cactus' self.collision = Colision() self.air_timer = 0 self.vertical_momentum = 0 self.img = pygame.image.load( "resources/image/platform/florest/obstaculo/cactus.png" ).convert_alpha() self.cactusRects = self.img.get_rect() self.cactusRects.x = position[0] self.cactusRects.y = position[1] # Method to check platform colission def controlingCollision(self, move, platform_rects): rct, plat_collisions = self.collision.platformCollision( move, self.cactusRects, platform_rects) del rct # bottom collision if plat_collisions['bottom']: self.air_timer = 0 self.vertical_momentum = 0 else: self.air_timer += 1 # Method to add the cactus def add(self, platform_rects, scroll): move = [0, 0] move[1] += self.vertical_momentum self.vertical_momentum += 0.2 if self.vertical_momentum > 8: self.vertical_momentum = 8 self.controlingCollision(move, platform_rects) self.screen.blit( self.img, (self.cactusRects.x - scroll[0], self.cactusRects.y - scroll[1])) return (self.cactusRects, self.name)
class Graveller: def __init__(self, screen,pos, patrolRadius, life): self.screen = screen self.life=life self.name = 'graveller' self.patrolRadius = patrolRadius self.state = 'Idle' self.move_direction = 'right' self.imgGolens = pygame.image.load("resources/image/enimy/Graveler/"+self.state+"/"+self.move_direction+"/"+self.state+"_0.png").convert_alpha() self.rect = self.imgGolens.get_rect() self.rect.x = pos[0] self.rect.y = pos[1] self.initialPosition = pos[0] self.ai = EnimysAI( self.patrolRadius,150, self.rect.x) self.collision = Colision() self.move_right = False self.move_left = False self.air_timer = 0 self.vertical_momentum = 0 self.move_frame = 0 self.attacking = False self.isMe = False # Method that control the platform collision def controlingCollision(self, golens_move, platform_rects, player_rect, playerOnAttack): rect, plat_collisions = self.collision.platformCollision(golens_move,self.rect, platform_rects) # right, left collision if(plat_collisions['right']): self.move_right = False elif(plat_collisions['left']): self.move_left = False # bottom collision if plat_collisions['bottom']: self.air_timer = 0 self.vertical_momentum = 0 else: self.air_timer += 1 if(self.rect.x in range(player_rect.x - 20, player_rect.x + 20)): if(self.rect.y in range(player_rect.y-40, player_rect.y+40)): self.isMe = True else: self.isMe = False else: self.isMe = False # print(player_rect.x - 20, self.rect.x, player_rect.x + 20) # print(playerOnAttack[0], playerOnAttack[1], self.isMe) if playerOnAttack[0] and playerOnAttack[1] and self.isMe: self.impactDelay = 0 self.collisionImpact() # Method that control the player attack colision def collisionImpact(self): if(self.impactDelay <= 5): # self.player_rect, platformCollisions = self.collision.platformCollision(player_movement,self.player_rect,tile_rects) if(self.move_direction == 'right'): self.move_direction = 'left' self.rect.x -= 5 self.rect.y -= 10 elif(self.move_direction == 'left'): self.move_direction = 'right' self.rect.x += 5 self.rect.y -= 10 self.impactDelay += 1 # Method that control the damage of the player attack def sufferingDamage(self, damage): self.life-=damage # Method that add this animys on the screen def add(self, platform_rects,player_rect,playerOnAttack, scroll): golens_move = [0, 0] if self.move_right: if self.attacking: golens_move[0]+=3 else: golens_move[0] += 1 if self.move_left: if self.attacking: golens_move[0]-=3 else: golens_move[0] -= 1 if self.attacking: self.startAttack() # if move_right and move_left not True call idle if (((not self.move_right)and(not self.move_left))and not self.attacking): self.idle() elif((self.move_right or self.move_left)and not self.attacking): self.walk() golens_move[1] += self.vertical_momentum self.vertical_momentum += 0.2 if self.vertical_momentum > 8: self.vertical_momentum = 8 self.rect.x += golens_move[0] self.move_direction, self.move_right, self.move_left, self.attacking = self.ai.activation(self.rect, player_rect) self.determinateAttack() self.controlingCollision(golens_move, platform_rects, player_rect, playerOnAttack) self.screen.blit(self.imgGolens,(self.rect.x-scroll[0], self.rect.y-scroll[1])) # print(self.attacking, self.move_direction) return self.rect, self.name # Method that control the patrol radios Border def determinateAttack(self): if((self.rect.x - self.initialPosition)>self.patrolRadius): self.move_right = False elif((self.rect.x - self.initialPosition)<(-1*self.patrolRadius)): self.move_left = False # All the sequence method from there are the sprites of this caracter def walk(self): self.state = 'Walk' if(((self.move_right)or(self.move_left))and(self.move_frame <= 9)): #resources\image\enimy\golens\Golem_1\Idle\left\0_Golem_Idle_000.png self.imgGolens = pygame.image.load("resources/image/enimy/Graveler/"+self.state+"/"+self.move_direction+"/"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((self.move_right)or(self.move_left))and(self.move_frame > 9)): self.move_frame = 0 self.imgGolens = pygame.image.load("resources/image/enimy/Graveler/"+self.state+"/"+self.move_direction+"/"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.imgGolens = pygame.image.load("resources/image/enimy/Graveler/"+self.state+"/"+self.move_direction+"/"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() def idle(self): self.state = 'Idle' if(((not self.move_right)or(not self.move_left ))and(self.move_frame <= 9)): self.imgGolens = pygame.image.load("resources/image/enimy/Graveler/"+self.state+"/"+self.move_direction+"/"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((not self.move_right)or(not self.move_left))and(self.move_frame > 9)): self.move_frame = 0 self.imgGolens = pygame.image.load("resources/image/enimy/Graveler/"+self.state+"/"+self.move_direction+"/"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.imgGolens = pygame.image.load("resources/image/enimy/Graveler/"+self.state+"/"+self.move_direction+"/"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() def startAttack(self): self.state = 'Attack' if((self.attacking)and(self.move_frame <= 9)): self.imgGolens = pygame.image.load("resources/image/enimy/Graveler/"+self.state+"/"+self.move_direction+"/"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif((self.attacking)and(self.move_frame > 9)): self.move_frame = 0 self.imgGolens = pygame.image.load("resources/image/enimy/Graveler/"+self.state+"/"+self.move_direction+"/"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.imgGolens = pygame.image.load("resources/image/enimy/Graveler/"+self.state+"/"+self.move_direction+"/"+self.state+"_"+str(self.move_frame)+".png").convert_alpha()
class Wizard: def __init__(self, screen, pos, patrolRadius, life): self.screen = screen self.life = life self.name = 'blue wizard' self.patrolRadius = patrolRadius self.rect = pygame.Rect(40, 30, 20, 42) self.rect.x = pos[0] self.rect.y = pos[1] self.initialPosition = pos[0] self.ai = EnimysAI(self.patrolRadius,200, self.rect.x) self.collision = Colision() self.state = 'idle' self.move_direction = 'right' self.move_right = False self.move_left = False self.air_timer = 0 self.vertical_momentum = 0 self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Chara-0.png") self.move_frame = 0 self.impactDelay = 0 self.attacking = False self.isMe = False # Method that control the platform collision def controlingCollision(self, wizard_move, platform_rects, player_rect, playerOnAttack): rect, plat_collisions = self.collision.platformCollision(wizard_move,self.rect, platform_rects) # right, left collision del rect if(plat_collisions['right']): self.move_right = False elif(plat_collisions['left']): self.move_left = False # bottom collision if plat_collisions['bottom']: self.air_timer = 0 self.vertical_momentum = 0 else: self.air_timer += 1 if(self.rect.x in range(player_rect.x - 20, player_rect.x + 20)): if(self.rect.y in range(player_rect.y-40, player_rect.y+40)): self.isMe = True else: self.isMe = False else: self.isMe = False if playerOnAttack[0] and playerOnAttack[1] and self.isMe: self.impactDelay = 0 self.collisionImpact() # Method that control the player attack colision def collisionImpact(self): if(self.impactDelay <= 10): # self.player_rect, platformCollisions = self.collision.platformCollision(player_movement,self.player_rect,tile_rects) if(self.move_direction == 'right'): self.move_direction = 'left' self.rect.x -= 5 self.rect.y -= 10 elif(self.move_direction == 'left'): self.move_direction = 'right' self.rect.x += 5 self.rect.y -= 10 self.impactDelay += 1 # Method that control the damage of the player attack def sufferingDamage(self, damage): self.life-=damage # Method that add this animys on the screen def add(self, platform_rects,player_rect,playerOnAttack, scroll): wizard_move = [0, 0] if self.move_right: if self.attacking: wizard_move[0]+=10 else: wizard_move[0] += 1 if self.move_left: if self.attacking: wizard_move[0]-=10 else: wizard_move[0] -= 1 if self.attacking: self.startAttack() # if move_right and move_left not True call idle if ((not self.move_right)and(not self.move_left)): self.idle() elif((self.move_right or self.move_left)and not self.attacking): self.walk() wizard_move[1] += self.vertical_momentum self.vertical_momentum += 0.2 if self.vertical_momentum > 8: self.vertical_momentum = 8 self.rect.x += wizard_move[0] self.move_direction, self.move_right, self.move_left, self.attacking = self.ai.activation(self.rect, player_rect) self.determinateAttack() self.controlingCollision(wizard_move, platform_rects, player_rect, playerOnAttack) self.screen.blit(self.img,(self.rect.x-scroll[0], self.rect.y-scroll[1])) # print(self.attacking, self.move_direction) return self.rect, self.name # Method that control the patrol radios Border def determinateAttack(self): if((self.rect.x - self.initialPosition)>self.patrolRadius): self.move_right = False elif((self.rect.x - self.initialPosition)<(-1*self.patrolRadius)): self.move_left = False # All the sequence method from there are the sprites of this caracter def walk(self): self.state = 'walk' if(((self.move_right)or(self.move_left))and(self.move_frame <= 19)): self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Chara-"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((self.move_right)or(self.move_left))and(self.move_frame > 19)): self.move_frame = 0 self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Chara-"+str(self.move_frame)+".png").convert_alpha() else: self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Chara-"+str(self.move_frame)+".png").convert_alpha() def idle(self): self.state = 'idle' if(((not self.move_right)or(not self.move_left ))and(self.move_frame <= 19)): self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Chara-"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((not self.move_right)or(not self.move_left))and(self.move_frame > 19)): self.move_frame = 0 self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Chara-"+str(self.move_frame)+".png").convert_alpha() else: self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Chara-"+str(self.move_frame)+".png").convert_alpha() def startAttack(self): # image = 15 self.state = 'attack' if((self.attacking)and(self.move_frame <= 12)): self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Dash3-"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif((self.attacking)and(self.move_frame > 12)): self.move_frame = 0 self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Dash3-"+str(self.move_frame)+".png").convert_alpha() else: self.img = pygame.image.load("resources/image/enimy/wizard/"+self.state+"/"+self.move_direction+"/Dash3-"+str(self.move_frame)+".png").convert_alpha()
class Player(object): def __init__(self, screen, nivel, lastPassPoint): self.collision = Colision() self.screen = screen self.air_timer = 0 self.vertical_momentum = 0 self.player_move = [0, 0] self.move_direction = 'right' self.state = 'Idle' self.skillsInUse = 'kicking' self.move_frame = 0 self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_0.png").convert_alpha() self.player_rect=self.player_img.get_rect() self.player_rect.x = lastPassPoint[0] self.player_rect.y = lastPassPoint[1] ## atributes to control the player state self.moving_right = False self.moving_left = False self.jumping = False self.hurtten = False self.attack = False self.bottomColision = False self.topColision = False self.firing = False self.preCollisionAriaRight = [0,0] self.preCollisionAriaLeft = [0,0] self.vertical_momentum = 0 self.air_timer = 0 self.player_screen_limit = 380 self.nivel = nivel self.impactDelay = 0 self.slashingControl = 0 self.count = 0 self.fireArray = [] self.enimyCollision = False self.enimyType = '' # Method that limited the player to walk back def controlPlayerScreenMove(self): ## validando o limite que o jogador pode voltar atraz if(self.player_rect.x <= self.player_screen_limit): self.moving_left = False ## atualizando o limite a que o jogador pode voltar para traz if(self.player_rect.x > self.player_screen_limit + 800): self.player_screen_limit += 80 # Method that control all the player move def playerMove(self, tile_rects, player_movement, scroll, tile_rect): if self.moving_right: if self.jumping: self.jump() else: self.walk() player_movement[0] += 4 elif self.moving_left: if self.jumping: self.jump() else: self.walk() player_movement[0] -= 4 if self.jumping: self.jump() if self.air_timer < 8: self.vertical_momentum = -15 if self.hurtten: self.hurt() if self.attack : # self.firing = True self.determinateAttack(player_movement, tile_rect) self.fireEnimyCollision, self.fireCollisionPos = self.fireControl(tile_rects, scroll) if((not self.moving_left)and(not self.moving_right)and not self.attack): self.idle() player_movement[1] += self.vertical_momentum self.vertical_momentum += 0.8 if self.vertical_momentum > 10: self.vertical_momentum = 10 self.player_rect, self.platformCollisions = self.collision.platformCollision(player_movement,self.player_rect,tile_rects) if (self.platformCollisions['bottom']): self.air_timer = 0 self.vertical_momentum = 0 self.bottomColision = True else: self.bottomColision = False if self.platformCollisions['top']: self.vertical_momentum = 10 else: self.topColision = False self.air_timer += 4 if(self.platformCollisions['right']): self.moving_right = False elif(self.platformCollisions['left']): self.moving_left = False if self.air_timer == 4: self.jumping = False self.screen.blit(self.player_img,(self.player_rect.x-scroll[0],self.player_rect.y-scroll[1])) # Method that control the fire collision def fireControl(self, tile_rect, scroll): platfcolision = [] enimyCollision = False pos = 0 if self.firing: platfcolision = [fire.draw(tile_rect,self.enimyRectList, scroll) for fire in self.fireArray] i = 0 ## cheching all the condition to delete one fire for colid in platfcolision: if colid[0]: del self.fireArray[i] enimyCollision = colid[1] pos = colid[2] i = 0 for fire in self.fireArray: if ((fire.rect.x > self.player_rect.x + 700)or(-1*fire.rect.x > (self.player_rect.x - 700)*-1)): del self.fireArray[i] return enimyCollision, pos # Method that control and blit the player on the screen def settingPlayer(self, tile_rects, scroll, allEnimysRectsAndType, inUse): self.platformCollisions = {'top':False,'bottom':False,'right':False,'left':False} self.skillsInUse = inUse player_movement = [0,0] self.determinateMove(scroll) self.controlPlayerScreenMove() self.playerMove(tile_rects, player_movement, scroll, tile_rects) scroll[0] += (self.player_rect.x-scroll[0]-300)/20 scroll[1] += (self.player_rect.y-scroll[1]-300)/10 # Transformando a scroll em um valor inteiro correct_scroll = scroll.copy() correct_scroll[0] = int(correct_scroll[0]) correct_scroll[1] = int(correct_scroll[1]) position = self.checkingEnimysCollision(player_movement,allEnimysRectsAndType) self.collisionInpact(tile_rects, player_movement) return correct_scroll, self.player_rect,self.fireArray, self.enimyCollision, self.enimyType,self.fireEnimyCollision, self.fireCollisionPos, (self.attack,position) # Methodd that control the enimys collision def checkingEnimysCollision(self, player_move,enimysRectsAndType): self.enimyRectList = [] enimyList = [] for enimy in enimysRectsAndType: self.enimyRectList.append(enimy[0]) enimyList.append(enimy[1]) collision, position = self.collision.enimysCollision(player_move,self.player_rect,self.enimyRectList) if(collision['top'] or collision['right'] or collision['bottom'] or collision['left']): self.hurtten = True self.enimyCollision = True self.impactDelay = 0 self.enimyType = enimyList[position] else: self.hurtten = False return position # Method that control the platform collision def collisionInpact(self, tile_rect, playerMove): player_rect, prePlatformCollisionsRight = self.collision.platformCollision(playerMove,pygame.Rect(self.player_rect.x + 20, self.player_rect.y ,30, 40),tile_rect) player_rect, prePlatformCollisionsLeft = self.collision.platformCollision(playerMove,pygame.Rect(self.player_rect.x - 20, self.player_rect.y ,30, 40),tile_rect) del player_rect if(prePlatformCollisionsRight['right']or prePlatformCollisionsRight['left']): self.preCollisionAriaRight = [] self.preCollisionAriaRight.append(self.player_rect.x) self.preCollisionAriaRight.append( self.player_rect.y) if(prePlatformCollisionsLeft['right']or prePlatformCollisionsLeft['left']): self.preCollisionAriaLeft = [] self.preCollisionAriaLeft.append(self.player_rect.x) self.preCollisionAriaLeft.append( self.player_rect.y) if self.enimyCollision and self.attack == False: if((self.impactDelay <= 5)and(self.player_rect.x not in range(self.preCollisionAriaRight[0]-20, self.preCollisionAriaRight[0]+20))and (self.player_rect.x not in range(self.preCollisionAriaLeft[0]-20, self.preCollisionAriaLeft[0]+20))): if(self.move_direction == 'right'): self.player_rect.x -= 4 self.player_rect.y -= 4 elif(self.move_direction == 'left'): self.player_rect.x += 4 self.player_rect.y -= 4 self.impactDelay += 1 else: self.enimyCollision = False # Method that determinate the player move according to the keyboard inputs def determinateMove(self, scroll): key_press = pygame.key.get_pressed() if(key_press[K_RIGHT]): self.move_direction = 'right' self.moving_right = True self.state = 'Walking' if(key_press[K_UP]and self.bottomColision==True): self.jumping = True elif(key_press[K_LEFT]): self.move_direction = 'left' self.moving_left = True self.state = 'Walking' if(key_press[K_UP] and self.bottomColision==True): self.jumping = True elif(key_press[K_UP]and self.bottomColision==True): self.state = 'JumLoop' self.jumping = True # self.state = 'Walking' elif(not key_press[K_RIGHT] and not key_press[K_LEFT]): self.moving_right = False self.moving_left = False elif(key_press[K_UP]and self.bottomColision==True): self.state = 'JumpLoop' if(key_press[K_RIGHT]): self.moving_right = False if(key_press[K_LEFT]): self.moving_left = False self.jumping = True if(key_press[K_RIGHT] or key_press[K_LEFT]): if(key_press[K_UP]and self.bottomColision==True): self.jumping = True ## button for to attack if key_press[K_q]: if((self.skillsInUse == 'bluefire' or self.skillsInUse == 'greenfire') and (self.count >= 10)): self.fireArray.append(Fire(self.screen, self.skillsInUse,(self.player_rect.x, self.player_rect.y), self.move_direction)) self.firing = True self.count = 0 self.attack = True else: self.slashingControl = 0 self.attack = False self.count += 1 # Methods above are all related to the player sprites def walk(self): self.state = 'Walking' if(((self.moving_right)or(self.moving_left))and(self.move_frame <= 23)): self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((self.moving_right)or(self.moving_left))and(self.move_frame > 23)): self.move_frame = 0 self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_0.png").convert_alpha() def idle(self): self.state = 'Idle' if(((not self.moving_right)or(not self.moving_left ))and(self.move_frame <= 17)): self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((not self.moving_right)or(not self.moving_left))and(self.move_frame > 17)): self.move_frame = 0 self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_0.png").convert_alpha() def jump(self): self.state = 'JumpLoop' if(((not self.moving_right)or(not self.moving_left ))and(self.move_frame <= 5)): self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((not self.moving_right)or(not self.moving_left))and(self.move_frame > 5)): self.move_frame = 0 self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_0.png").convert_alpha() def hurt(self): self.state = 'Hurt' if(((not self.moving_right)or(not self.moving_left ))and(self.move_frame <= 11)): self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((not self.moving_right)or(not self.moving_left))and(self.move_frame > 11)): self.move_frame = 0 # self.hurtten = False self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_0.png").convert_alpha() ### the following method is related to the player attack def determinateAttack(self, playerMove, tile_rect): player_rect, prePlatformCollisionsRight = self.collision.platformCollision(playerMove,pygame.Rect(self.player_rect.x + 20, self.player_rect.y ,30, 40),tile_rect) player_rect, prePlatformCollisionsLeft = self.collision.platformCollision(playerMove,pygame.Rect(self.player_rect.x - 20, self.player_rect.y ,30, 40),tile_rect) del player_rect if(prePlatformCollisionsRight['right']or prePlatformCollisionsRight['left']): self.preCollisionAriaRight = [] self.preCollisionAriaRight.append(self.player_rect.x) self.preCollisionAriaRight.append( self.player_rect.y) if(prePlatformCollisionsLeft['right']or prePlatformCollisionsLeft['left']): self.preCollisionAriaLeft = [] self.preCollisionAriaLeft.append(self.player_rect.x) self.preCollisionAriaLeft.append( self.player_rect.y) self.state = self.skillsInUse if (self.skillsInUse == 'kicking'): self.kicking() elif(self.skillsInUse == 'greenfire'): self.throwing() elif(self.skillsInUse == 'bluefire'): self.throwing() ## just for hork elif((self.skillsInUse == 'slashing')and(self.player_rect.x not in range(self.preCollisionAriaRight[0]-20, self.preCollisionAriaRight[0]+20))and (self.player_rect.x not in range(self.preCollisionAriaLeft[0]-20, self.preCollisionAriaLeft[0]+20))): if((self.slashingControl <= 10) and(self.player_rect.x >= self.player_screen_limit)): self.sliding() else: self.attack = False if(self.moving_left or self.moving_right): self.walk() else: self.idle() self.slashingControl += 1 elif(self.skillsInUse == 'battleax'): self.battleax() def kicking(self): self.state = 'Kicking' if(((not self.moving_right)or(not self.moving_left ))and(self.move_frame <= 11)): self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((not self.moving_right)or(not self.moving_left))and(self.move_frame > 11)): self.move_frame = 0 # self.hurtten = False self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_0.png").convert_alpha() def battleax(self): self.state = 'battleax' if(((not self.moving_right)or(not self.moving_left ))and(self.move_frame <= 11)): self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((not self.moving_right)or(not self.moving_left))and(self.move_frame > 11)): self.move_frame = 0 self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_0.png").convert_alpha() def sliding(self): self.state = 'Sliding' if(((not self.moving_right)or(not self.moving_left ))and(self.move_frame <= 5)): self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((not self.moving_right)or(not self.moving_left))and(self.move_frame > 5)): self.move_frame = 0 # self.hurtten = False self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_0.png").convert_alpha() if(self.move_direction=='right'): self.player_rect.x += 9 else: self.player_rect.x -= 9 def throwing(self): self.state = 'Throwing' if(((not self.moving_right)or(not self.moving_left ))and(self.move_frame <= 11)): self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() self.move_frame += 1 elif(((not self.moving_right)or(not self.moving_left))and(self.move_frame > 11)): self.move_frame = 0 # self.hurtten = False self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_"+str(self.move_frame)+".png").convert_alpha() else: self.player_img = pygame.image.load("resources/image/Golem/"+self.state+"/"+self.move_direction+"/0_Goblin_"+self.state+"_0.png").convert_alpha()