def move(self, enemies): self.speedY -= 0.05 self.speedX *= .999 self.posX += self.speedX * displayManager.getFrameTimeSeconds() self.posY += self.speedY * displayManager.getFrameTimeSeconds() self.posZ += self.speedZ * displayManager.getFrameTimeSeconds() if self.posY < 0 or abs(self.posZ - 500 * displayManager.SCALE ) > 500 * displayManager.SCALE: return True self.angle -= 5 self.rotatedTexture = pygame.transform.rotate(self.texture, self.angle) self.rectangle = self.rotatedTexture.get_rect() self.rectangle.center = (self.posX, displayManager.HEIGHT - self.posY - self.posZ / 2) if self.active == 0: for enemy in enemies: if enemy.active and abs( enemy.posZ - self.posZ ) < 100 * displayManager.SCALE and self.rectangle.colliderect( enemy.rectangle): enemy.hit(self.damage) return True else: self.active -= 1 return False
def move(self, player): if self.health <= 0: self.dead = True return True if not self.active and abs(player.posX - self.posX) < displayManager.WIDTH * .8: self.active = True elif self.active: if abs(player.posX - self.posX) > displayManager.WIDTH * .9: self.active = False if abs(player.posX - self.posX) > displayManager.WIDTH * .8: self.posX += self.speed * sign( player.posX - self.posX) * displayManager.getFrameTimeSeconds() self.mainPosZ += min( self.speed * sign(player.posZ - self.mainPosZ), player.posZ - self.mainPosZ, key=lambda x: abs(x)) * displayManager.getFrameTimeSeconds() self.posZ = self.mainPosZ + 200 * math.sin( displayManager.getCurrentTime() / 128 + self.timeOffset) * displayManager.SCALE if self.posZ < 0: self.posZ = 0 elif self.posZ > 1000 * displayManager.SCALE: self.posZ = 1000 * displayManager.SCALE if player.posX - self.posX > 0 and not self.facingRight: self.facingRight = True self.texture = pygame.transform.flip(self.texture, True, False) self.gun.offsetX *= -1 self.gun.texture = pygame.transform.flip( self.gun.texture, True, False) elif player.posX - self.posX < 0 and self.facingRight: self.facingRight = False self.texture = pygame.transform.flip(self.texture, True, False) self.gun.offsetX *= -1 self.gun.texture = pygame.transform.flip( self.gun.texture, True, False) self.jump -= GRAVITY * displayManager.getFrameTimeSeconds() self.posY += self.jump if self.posY < 0: self.posY = 0 self.rectangle.centerx = self.posX self.rectangle.bottom = displayManager.HEIGHT - self.posY - self.posZ / 2 self.gun.reload() bullets = self.gun.shoot(self) if bullets is not None: for bullet in bullets: bullet.texture.fill((0xCC, 0, 0)) loader.data.enemyBullets.append(bullet) return False
def move(self): playSound = False if eventState.getState(K_w): self.posZ += self.speed * displayManager.getFrameTimeSeconds() playSound = True if self.posZ > 1000 * displayManager.SCALE: self.posZ = 1000 * displayManager.SCALE if eventState.getState(K_s): self.posZ -= self.speed * displayManager.getFrameTimeSeconds() playSound = True if self.posZ < 0: self.posZ = 0 if eventState.getState(K_a): self.posX -= self.speed * displayManager.getFrameTimeSeconds() * .7 playSound = True if self.posX < 0: self.posX = 0 if self.facingRight: self.facingRight = False self.texture = pygame.transform.flip(self.texture, True, False) for gun in self.guns: gun.offsetX *= -1 gun.texture = pygame.transform.flip( gun.texture, True, False) if eventState.getState(K_d): self.posX += self.speed * displayManager.getFrameTimeSeconds() * .7 playSound = True if not self.facingRight: self.facingRight = True self.texture = pygame.transform.flip(self.texture, True, False) for gun in self.guns: gun.offsetX *= -1 gun.texture = pygame.transform.flip( gun.texture, True, False) if self.walkSound.get_num_channels() == 0: self.walkChannel = self.walkSound.play(-1) if playSound: self.walkChannel.unpause() else: self.walkChannel.pause() if eventState.getState(K_SPACE): if self.posY == 0: self.jump = self.jumpPower self.jump -= GRAVITY * displayManager.getFrameTimeSeconds() self.posY += self.jump if self.posY < 0: self.posY = 0 self.rectangle.centerx = self.posX self.rectangle.bottom = displayManager.HEIGHT - self.posY - self.posZ / 2 self.guns[self.activeGun].reload()
def move(self, player=None, entities=None, posX=None): if posX is None: minX = player.posX maxX = player.posX for entity in entities: if entity.active: if entity.posX < minX: minX = entity.posX elif entity.posX > maxX: maxX = entity.posX else: minX = posX maxX = posX cursorX = pygame.mouse.get_pos()[0] - displayManager.WIDTH / 2 cursorX /= 10 length = self.posX - (minX + maxX) / 2 + displayManager.WIDTH / 2 - cursorX if (abs(length) < 10 and not self.lastLength) or (abs(length) < 1.5 and self.lastLength): self.posX -= length self.lastLength = False else: self.posX -= length * 3 * displayManager.getFrameTimeSeconds() self.lastLength = True if self.posX < 0: self.posX = 0 self.lastLength = False
def reload(self, reload=False): # method called every frame if self.delaying > 0: self.delaying -= displayManager.getFrameTimeSeconds() if self.delaying <= 0: self.delaying = 0 if self.bulletNumber == 0 or self.bulletInMagazine == self.magazineSize: return if reload and self.reloading <= 0: self.reloading = self.reloadTime if self.reloading <= 0: bulletsToReload = self.magazineSize - self.bulletInMagazine self.bulletInMagazine += min(bulletsToReload, self.bulletNumber) self.bulletNumber -= min(bulletsToReload, self.bulletNumber) else: if self.reloading > 0: self.reloading -= displayManager.getFrameTimeSeconds() if self.reloading <= 0: self.reloading = 0 bulletsToReload = self.magazineSize - self.bulletInMagazine self.bulletInMagazine += min(bulletsToReload, self.bulletNumber) self.bulletNumber -= min(bulletsToReload, self.bulletNumber)