Exemplo n.º 1
0
    def shoot(self):
        if self.facing_right:
            bullet = Bullet(1)
            bullet.rect.x = self.rect.right + self.x_change
            bullet.rect.y = self.rect.centery
        else:
            bullet = Bullet(-1)
            bullet.rect.x = self.rect.x - Bullet.WIDTH + self.x_change
            bullet.rect.y = self.rect.centery

        self.game.all_sprites_list.add(bullet)
        self.game.projectile_list.add(bullet)
        self.shoot_sound.play()
Exemplo n.º 2
0
 def shoot(self):
     # those are the bullets firing sideways. will be added at any level
     self.bullets.append(Bullet(self.x, self.y + self.pic.get_height() / 2))
     self.bullets.append(
         Bullet(self.x + self.pic.get_width(),
                self.y + self.pic.get_height() / 2,
                xvel=5))
     if self.lvl >= 2:  # those are the bullets moving up and down
         self.bullets.append(
             Bullet(self.x + self.pic.get_width() / 2,
                    self.y,
                    xvel=0,
                    yvel=-5))
         self.bullets.append(
             Bullet(self.x + self.pic.get_width() / 2,
                    self.y + self.pic.get_height(),
                    xvel=0,
                    yvel=5))
     if self.lvl >= 3:  # bullets going 'slant ways'
         self.bullets.append(Bullet(self.x, self.y, xvel=-5, yvel=-5))
         self.bullets.append(
             Bullet(self.x + self.pic.get_width(),
                    self.y + self.pic.get_height(),
                    xvel=5,
                    yvel=5))
         self.bullets.append(
             Bullet(self.x, self.y + self.pic.get_height(), xvel=-5,
                    yvel=5))
         self.bullets.append(
             Bullet(self.x + self.pic.get_width(), self.y, xvel=5, yvel=-5))
Exemplo n.º 3
0
 def shoot(self):
     if self.shootTimer == 0:
         # Alternate the gun barrels
         if self.currentGunBarrel == 0:
             # Spawn on the end of the gun barrel
             xb = self.x + self.gunImage.width / 2 * cos(
                 self.currentGunOrientation
             ) + self.gunImage.height / 5 * sin(self.currentGunOrientation)
             yb = self.y + self.gunImage.width / 2 * sin(
                 self.currentGunOrientation
             ) - self.gunImage.height / 5 * cos(self.currentGunOrientation)
             self.currentGunBarrel = 1
         else:
             xb = self.x + self.gunImage.width / 2 * cos(
                 self.currentGunOrientation
             ) - self.gunImage.height / 5 * sin(self.currentGunOrientation)
             yb = self.y + self.gunImage.width / 2 * sin(
                 self.currentGunOrientation
             ) + self.gunImage.height / 5 * cos(self.currentGunOrientation)
             self.currentGunBarrel = 0
         # Generate the bullet
         self.bullets.append(
             Bullet(xb, yb, self.currentGunOrientation, self.bulletImage,
                    self.gunFlashImage))
         self.shootTimer = self.fireRate
         self.piew.play()
Exemplo n.º 4
0
    def shoot(self, char):
        x_gap = self.rect.centerx - char.rect.centerx
        y_gap = self.rect.centery - char.rect.centery
        distance = math.sqrt((self.rect.centerx - char.rect.centerx)**2 +
                             (self.rect.centery - char.rect.centery)**2)
        stops = (distance / 16)

        self.bullets.append(
            Bullet(self.x,
                   self.rect.centery,
                   max_distance=distance,
                   xvel=x_gap / stops,
                   yvel=y_gap / stops))
Exemplo n.º 5
0
def game_loop(server_address: str, player_name: str) -> None:
    fps = 60
    clock = pygame.time.Clock()
    running = True
    network = Network(server_address)
    player, trees = network.connect()
    if not player:
        print("No response from server")
        return None

    graphics_handler = GraphicsHandler()
    turret_reload_speed = 90
    turret_reload_cooldown = 0

    while running:
        clock.tick(fps)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()
                return None

        mouse_position = pygame.mouse.get_pos()
        player.update_turret_rotation(
            (mouse_position[0] - width // 2, mouse_position[1] - height // 2))
        keys = pygame.key.get_pressed()
        if keys is not None:
            player.move(keys)

        mouse_pressed = pygame.mouse.get_pressed()
        new_bullet = None
        if mouse_pressed[0] and turret_reload_cooldown == 0:
            new_bullet = Bullet(player.x + 60 * cos(player.turret_rotation),
                                player.y - 60 * sin(player.turret_rotation),
                                player.turret_rotation)
            turret_reload_cooldown = turret_reload_speed

        if turret_reload_cooldown != 0:
            turret_reload_cooldown -= 1

        data = network.send((player, new_bullet))
        if data:
            graphics_handler.update_display(data, player.x, player.y, trees)
        else:
            running = False
Exemplo n.º 6
0
	def update(self, screen_scroll, bullet_group, p):
		if self.health:
			self.rect.x += (self.dx + screen_scroll)
			self.x += screen_scroll
			if abs(self.rect.x - self.x) >= 2 * TILE_SIZE:
				self.dx *= -1

		if self.health <= 0:
			self.on_death_bed = True

		self.counter += 1
		if self.counter % 5 == 0:
			if self.on_death_bed:
				self.death_index += 1
				if self.death_index >= len(self.death_list):
					self.kill()
					self.alive = False
			if self.hit:
				self.hit_index += 1
				if self.hit_index >= len(self.hit_list):
					self.hit_index = 0
					self.hit = False
			else:
				self.walk_index  = (self.walk_index + 1) % len(self.walk_left)
				
		if self.counter % 50 == 0:
			if self.health > 0 and (abs(p.rect.x - self.rect.x) <= 200):
				x, y = self.rect.center
				direction = self.dx
				bullet = Bullet(x, y, direction, (160, 160, 160), 2, self.win)
				bullet_group.add(bullet)
				bullet_fx.play()

		if self.alive:
			if self.on_death_bed:
				self.image = self.death_list[self.death_index]
			elif self.hit:
				self.image = self.hit_list[self.hit_index]
			else:
				if self.dx == -1:
					self.image = self.walk_left[self.walk_index]
				elif self.dx == 1:
					self.image = self.walk_right[self.walk_index]
Exemplo n.º 7
0
				event.key == pygame.K_q:
				running = False

		if event.type == pygame.KEYDOWN:
			if event.key == pygame.K_LEFT:
				moving_left = True
			if event.key == pygame.K_RIGHT:
				moving_right = True
			if event.key == pygame.K_UP:
				if not p.jump:
					p.jump = True
					jump_fx.play()
			if event.key == pygame.K_SPACE:
				x, y = p.rect.center
				direction = p.direction
				bullet = Bullet(x, y, direction, (240, 240, 240), 1, win)
				bullet_group.add(bullet)
				bullet_fx.play()

				p.attack = True
			if event.key == pygame.K_g:
				if p.grenades:
					p.grenades -= 1
					grenade = Grenade(p.rect.centerx, p.rect.centery, p.direction, win)
					grenade_group.add(grenade)
					grenade_throw_fx.play()

		if event.type == pygame.KEYUP:
			if event.key == pygame.K_LEFT:
				moving_left = False
			if event.key == pygame.K_RIGHT:
Exemplo n.º 8
0
 def shoot(self):
     self.bullets.append(
         Bullet(self.x, self.y + self.pic.get_height() / 2 - 3))