Example #1
0
    def __init__(self, center=(0, 0), vitesse=10):
        Screen.__init__(self)
        self.image = pygame.image.load('img/canon-2.png').convert_alpha()
        self.image = pygame.transform.flip(self.image, 1, 1)
        self.rect = self.image.get_rect()
        self.original = self.image.copy()

        self.font = pygame.font.Font("font/space_invaders.ttf", 30)

        self.rect.center = center
        self.current_angle = 0

        self.missile = Missile(self.rect.center, vitesse)
        self.nb_level = vitesse
        self.level = self.font.render(str(vitesse), 1, red)
        self.level_rect = self.level.get_rect(center=self.rect.center)
Example #2
0
 def shoot(self):
     if pygame.time.get_ticks() - self.last_missile > self.missile_time:
         self.missiles.append(
             Missile(self.window, (self.player.x, self.player.y),
                     self.player.angle))
         self.last_missile = pygame.time.get_ticks()
         if len(self.missiles) > self.max_missiles:
             self.missiles = self.missiles[1:]
         self.score -= 1
Example #3
0
    def shoot(self, vector):
        if self.cooldown:
            missile = Missile(self.handler.x, self.handler.y, vector,
                              self.handler.team)
            SpriteManager.spawn(missile)
            self.cooldown = False

        if millis() - self.mark > self.wait:
            self.mark = millis()
            self.cooldown = True
Example #4
0
	def __init__(self, center=(0, 0), vitesse=10):
		Screen.__init__(self)
		self.image    = pygame.image.load('img/canon-2.png').convert_alpha()
		self.image = pygame.transform.flip(self.image, 1, 1)
		self.rect     = self.image.get_rect()
		self.original = self.image.copy()

		self.font = pygame.font.Font("font/space_invaders.ttf", 30)

		self.rect.center = center
		self.current_angle = 0

		self.missile = Missile(self.rect.center, vitesse)
		self.nb_level = vitesse
		self.level = self.font.render(str(vitesse), 1, red)
		self.level_rect = self.level.get_rect(center=self.rect.center)
Example #5
0
 def check_controls(self):
     """Think one player thought - the player's default state to respond to control(ler) inputs."""
     # TODO handle network/remote cases
     # if we crash into a Npc (non-player character), we both die
     for hash in self.go.gs.objects:
         target = self.go.gs.objects[hash]
         if target != self.go:
             if target.position == self.go.position:
                 if isinstance(target, Npc):
                     print(f"Player calls {target.object_hash}.die()")
                     target.die()
                     return self.die_next
                 elif isinstance(target, Exit):
                     return self.win_next
     # process the queued pygame.event's
     for event in pygame.event.get():
         if event.type == KEYDOWN:
             # move or fire
             if event.key == K_d:
                 self.go.turn(90)
             elif event.key == K_a:
                 self.go.turn(-90)
             elif event.key == K_w:
                 self.go.fwd()
             elif event.key == K_z:
                 self.go.back()
             elif event.key == K_f:
                 # launch a missile from player
                 Missile(self.go)
             elif event.key == K_m:
                 # trigger slo mo rendering
                 self.go.gs.camera.in_slo_mo = True
                 self.go.gs.request_refresh()
         elif event.type == QUIT:
             # terminate (cmd-Q or ctrl-Q)
             pygame.quit()
             sys.exit()
Example #6
0
            if event.type == pygame.KEYUP:  # if I release a key
                if event.key == pygame.K_RIGHT:  # right button released
                    pressright = False
                    if pressleft:
                        movimentox = -26
                    else:
                        movimentox = 0
                elif event.key == pygame.K_LEFT:  # left button released
                    pressleft = False
                    if pressright:
                        movimentox = 26
                    else:
                        movimentox = 0
                if event.key == pygame.K_SPACE:
                    y_missile = y - 15
                    missile = missili.append(Missile(x + 30, y_missile))
                    incrementoy = 28
                    spara = True
                    missili_sparati += 1
                if event.key == pygame.K_p:  # PAUSE
                    loop = True
                    while loop:
                        for event in pygame.event.get():
                            if event.type == pygame.KEYUP:
                                if event.key == pygame.K_p:  # RESUME THE GAME
                                    loop = False

        screen.blit(screenDisplay, (0, 0))
        x = x + movimentox
        if x < 0:
            x = 0
Example #7
0
class Tower(Screen):
    def __init__(self, center=(0, 0), vitesse=10):
        Screen.__init__(self)
        self.image = pygame.image.load('img/canon-2.png').convert_alpha()
        self.image = pygame.transform.flip(self.image, 1, 1)
        self.rect = self.image.get_rect()
        self.original = self.image.copy()

        self.font = pygame.font.Font("font/space_invaders.ttf", 30)

        self.rect.center = center
        self.current_angle = 0

        self.missile = Missile(self.rect.center, vitesse)
        self.nb_level = vitesse
        self.level = self.font.render(str(vitesse), 1, red)
        self.level_rect = self.level.get_rect(center=self.rect.center)

    def _spin(self, angle):
        self.current_angle = angle
        prev_rect_center = self.rect.center
        self.image = pygame.transform.rotate(self.original, self.current_angle)
        self.rect = self.image.get_rect(center=prev_rect_center)

    def fire(self, ship_pos):
        angle = self.missile.fire(self.rect.x, self.rect.y, ship_pos[0],
                                  ship_pos[1])
        if angle:
            if angle < 0:
                angle = 360 - abs(angle)

            self._spin(int(angle))

    def get_pos(self):
        return self.rect.x, self.rect.y

    def get_center(self):
        return self.rect.center

    def get_rect(self):
        return self.rect

    def render(self):
        self.missile.move(self.rect)

        image, rect = self.missile.render()
        self.screen.blit(image, rect)

        self.screen.blit(self.image, self.rect)
        self.screen.blit(self.level, self.level_rect)

    def collision(self, rect):
        return self.rect.colliderect(rect)

    def get_missile_rect(self):
        return self.missile.rect

    def remove_missile(self):
        self.missile.rect.center = self.rect.center

    def get_level(self):
        return self.nb_level
Example #8
0
class Tower(Screen):
	def __init__(self, center=(0, 0), vitesse=10):
		Screen.__init__(self)
		self.image    = pygame.image.load('img/canon-2.png').convert_alpha()
		self.image = pygame.transform.flip(self.image, 1, 1)
		self.rect     = self.image.get_rect()
		self.original = self.image.copy()

		self.font = pygame.font.Font("font/space_invaders.ttf", 30)

		self.rect.center = center
		self.current_angle = 0

		self.missile = Missile(self.rect.center, vitesse)
		self.nb_level = vitesse
		self.level = self.font.render(str(vitesse), 1, red)
		self.level_rect = self.level.get_rect(center=self.rect.center)


	def _spin(self, angle):
		self.current_angle = angle
		prev_rect_center = self.rect.center
		self.image = pygame.transform.rotate(self.original, self.current_angle)
		self.rect  = self.image.get_rect(center=prev_rect_center)

	def fire(self, ship_pos):
		angle = self.missile.fire(self.rect.x, self.rect.y, ship_pos[0], ship_pos[1])
		if angle:
			if angle < 0:
				angle = 360 - abs(angle)

			self._spin(int(angle))

	def get_pos(self):
		return self.rect.x, self.rect.y

	def get_center(self):
		return self.rect.center

	def get_rect(self):
		return self.rect

	def render(self):
		self.missile.move(self.rect)

		image, rect = self.missile.render()
		self.screen.blit(image, rect)
		
		self.screen.blit(self.image, self.rect)
		self.screen.blit(self.level, self.level_rect)

	def collision(self, rect):
		return self.rect.colliderect(rect)

	def get_missile_rect(self):
		return self.missile.rect

	def remove_missile(self):
		self.missile.rect.center = self.rect.center

	def get_level(self):
		return self.nb_level
Example #9
0
def shoot(window, player, missiles):
    global lastshot
    if pygame.time.get_ticks() - lastshot > 100:
        lastshot = pygame.time.get_ticks()
        missiles.append(Missile(window, player.x + player.width // 2,
                                player.y))
Example #10
0
 def create_missile(self, color, x, y, x2, y2):
     return Missile(x=x, y=y, color=color, x2=x2, y2=y2)