예제 #1
0
파일: main.py 프로젝트: nutnicha-t/tk-space
    def generate(self, space_game, ship):
        # def create_enemy_star(self):
        self.enemies = []

        self.x = randint(100, CANVAS_WIDTH - 100)
        self.y = randint(100, CANVAS_HEIGHT - 100)

        while vector_len(self.x - self.ship.x, self.y - self.ship.y) < 200:
            self.x = randint(100, CANVAS_WIDTH - 100)
            self.y = randint(100, CANVAS_HEIGHT - 100)

        for d in range(18):
            self.dx, self.dy = direction_to_dxdy(d * 20)
            self.enemy = Enemy(self, self.x, self.y,
                               self.dx * ENEMY_BASE_SPEED,
                               self.dy * ENEMY_BASE_SPEED)
            self.enemies.append(self.enemy)

        return self.enemies

        # def create_enemy_from_edges(self):
        self.x, self.y = random_edge_position()
        self.vx, self.vy = normalize_vector(self.ship.x - self.x,
                                            self.ship.y - self.y)

        self.vx *= ENEMY_BASE_SPEED
        self.vy *= ENEMY_BASE_SPEED

        self.enemy = Enemy(self, self.x, self.y, self.vx, self.vy)
        return [self.enemy]
예제 #2
0
파일: elements.py 프로젝트: vitvara/space
    def fire(self):
        if self.app.bullet_count() >= MAX_NUM_BULLETS:
            return

        dx, dy = direction_to_dxdy(-self.angle)
        bullet0 = TieBullet(self.app, self.x, self.y, dx * BULLET_BASE_SPEED,
                            dy * BULLET_BASE_SPEED)
        self.app.add_enemy(bullet0)
예제 #3
0
    def fire(self):
        if self.app.bullet_count() >= MAX_NUM_BULLETS:
            return

        dx, dy = direction_to_dxdy(self.direction)

        bullet = Bullet(self.app, self.x, self.y, dx * BULLET_BASE_SPEED, dy * BULLET_BASE_SPEED)

        self.app.add_bullet(bullet)
예제 #4
0
    def update(self):
        dx, dy = direction_to_dxdy(self.direction)

        self.x += dx * SHIP_SPEED
        self.y += dy * SHIP_SPEED

        if self.is_turning_left:
            self.turn_left()
        elif self.is_turning_right:
            self.turn_right()
예제 #5
0
    def generate(self, space_game, ship):
        enemies = []
        x = randint(100, CANVAS_WIDTH - 100)
        y = randint(100, CANVAS_HEIGHT - 100)

        while vector_len(x - ship.x, y - ship.y) < 200:
            x = randint(100, CANVAS_WIDTH - 100)
            y = randint(100, CANVAS_HEIGHT - 100)

        for d in range(18):
            dx, dy = direction_to_dxdy(d * 20)
            enemy = Enemy(space_game, x, y, dx * ENEMY_BASE_SPEED, dy * ENEMY_BASE_SPEED)
            enemies.append(enemy)
        return enemies
예제 #6
0
    def create_enemy_star(self):
        enemies = []

        x = randint(100, CANVAS_WIDTH - 100)
        y = randint(100, CANVAS_HEIGHT - 100)

        while vector_len(x - self.ship.x, y - self.ship.y) < 200:
            x = randint(100, CANVAS_WIDTH - 100)
            y = randint(100, CANVAS_HEIGHT - 100)

        for d in range(18):
            dx, dy = direction_to_dxdy(d * 20)
            enemy = Enemy(self, x, y, dx * ENEMY_BASE_SPEED, dy * ENEMY_BASE_SPEED)
            enemies.append(enemy)

        return enemies
예제 #7
0
파일: main.py 프로젝트: nutnicha-t/tk-space
    def generate(self, space_game, ship):
        self.enemies = []

        self.x = randint(100, CANVAS_WIDTH - 100)
        self.y = randint(100, CANVAS_HEIGHT - 100)

        while vector_len(self.x - self.ship.x, self.y - self.ship.y) < 200:
            self.x = randint(100, CANVAS_WIDTH - 100)
            self.y = randint(100, CANVAS_HEIGHT - 100)

        for d in range(18):
            self.dx, self.dy = direction_to_dxdy(d * 20)
            self.enemy = Enemy(self, self.x, self.y,
                               self.dx * ENEMY_BASE_SPEED,
                               self.dy * ENEMY_BASE_SPEED)
            self.enemies.append(self.enemy)

        return self.enemies
예제 #8
0
    def generate(self, space_game, ship):
        ## ##
        # TODO: extracted from method create_enemy_star
        self.ship = ship
        enemies = []

        x = randint(100, CANVAS_WIDTH - 100)
        y = randint(100, CANVAS_HEIGHT - 100)

        while vector_len(x - self.ship.x, y - self.ship.y) < 200:
            x = randint(100, CANVAS_WIDTH - 100)
            y = randint(100, CANVAS_HEIGHT - 100)

        for d in range(18):
            dx, dy = direction_to_dxdy(d * 20)
            enemy = Enemy(self.ship, x, y, dx * ENEMY_BASE_SPEED, dy * ENEMY_BASE_SPEED)
            enemies.append(enemy)

        return enemies
예제 #9
0
파일: elements.py 프로젝트: vitvara/space
 def turbo_start(self):
     dx, dy = direction_to_dxdy(self.direction)
     self.x += dx * 2 * SHIP_SPEED
     self.y += dy * 2 * SHIP_SPEED