Example #1
0
 def __init__(self, center, bound, pwm, controller: PlayerController,
              player_turret: Turret, missile_turret: Turret,
              life_turret: Turret):
     super().__init__(center, bound, pwm)
     '''
     INIT PLAYER
     '''
     self.player_turret = player_turret
     self.player = Player(bound, bound, pwm, player_turret, controller)
     self.player.laser.on()
     '''
     INIT MISSILE
     '''
     self.missile_turret = missile_turret
     self.missile = NPC(pwm, missile_turret)
     self.missile.laser.on()
     '''
     INIT LIFE COUNTER
     '''
     self.life_turret = life_turret
     self.life_counter = NPC(pwm, life_turret)
     self.life_pos = int(center + bound / 2)
     # Put life counter out of bounds
     self.life_counter.set_servo(
         int(center - bound / 2) - 10, int(center + bound / 2))
     self.life_counter.laser.on()
     self.life_distance = int(bound / self.lives)
Example #2
0
 def win(self):
     """
     "We're in the endgame now" - Wizard guy.
     :return:
     """
     # Free up the GPIO pin
     del self.player.laser
     del self.missile.laser
     del self.life_counter.laser
     npc1 = NPC(self.pwm, self.player_turret)
     npc2 = NPC(self.pwm, self.missile_turret)
     npc3 = NPC(self.pwm, self.life_turret)
     radius = 20
     rate = 0.1
     circle1 = Circle(415, 375, radius, 0, rate)
     circle2 = Circle(375, 375, radius, 0, rate)
     circle3 = Circle(335, 375, radius, 0, rate, clockwise=False)
     data1 = npc1.follow_path(circle1.data())
     data1.__next__()
     data1.__next__()
     npc1.laser.on()
     data2 = npc2.follow_path(circle2.data())
     data2.__next__()
     data2.__next__()
     npc2.laser.on()
     data3 = npc3.follow_path(circle3.data())
     data3.__next__()
     data3.__next__()
     npc3.laser.on()
     for _ in range(0, 400):
         if _ % 100 == 0:
             circle3.clockwise = False
         data1.__next__()
         data2.__next__()
         data3.__next__()
Example #3
0
 def lose(self):
     """
     "Did we just lose?" - Sun-Count.
     :return:
     """
     # Free up the GPIO pin
     del self.player.laser
     del self.missile.laser
     del self.life_counter.laser
     npc1 = NPC(self.pwm, self.player_turret)
     npc2 = NPC(self.pwm, self.missile_turret)
     npc3 = NPC(self.pwm, self.life_turret)
     npc1.laser.on()
     npc2.laser.on()
     npc3.laser.on()
     rate = 2
     m1 = self.make_missile(rate, npc1)
     m2 = self.make_missile(rate, npc2)
     m3 = self.make_missile(rate, npc3)
     prev_time = 0
     num_losers = 15
     while True:
         if num_losers == 0:
             break
         self.curr_time = time.time()
         if self.curr_time - prev_time >= self.time_rate:
             prev_time = self.curr_time
             try:
                 m1.__next__()
             except StopIteration:
                 m1 = self.make_missile(rate, npc1)
                 num_losers -= 1
             try:
                 m2.__next__()
             except StopIteration:
                 m2 = self.make_missile(rate, npc2)
                 num_losers -= 1
             try:
                 m3.__next__()
             except StopIteration:
                 m3 = self.make_missile(rate, npc3)
                 num_losers -= 1
Example #4
0
 def win(self, player):
     if player == 1:
         del self.player_1.laser
         center = int(self.center + self.bound / 2)
         npc = NPC(self.pwm, self.player_1_turret)
     else:
         del self.player_2.laser
         center = int(self.center - self.bound / 2)
         npc = NPC(self.pwm, self.player_2_turret)
     circle = Circle(center, 375, 25, 0, 2)
     data = npc.follow_path(circle.data())
     data.__next__()
     data.__next__()
     npc.laser.on()
     spin_spin = 0
     prev_time = 0
     while self.playing:
         self.curr_time = time.time()
         if self.curr_time - prev_time >= self.time_rate * 3:
             prev_time = self.curr_time
             data.__next__()
             spin_spin += 1
         if spin_spin == 100:
             self.playing = False
Example #5
0
 def win(self):
     # Free up the GPIO pin
     del self.player.laser
     npc = NPC(self.pwm, self.player_turret)
     radius = 20
     rate = 0.1
     circle = Circle(375, 375, radius, 0, rate)
     data = npc.follow_path(circle.data())
     data.__next__()
     data.__next__()
     npc.laser.on()
     for _ in range(0, 600):
         if _ % 100 == 0:
             circle.clockwise = False
         data.__next__()
Example #6
0
 def __init__(self, center, bound, pwm, player_1_controller,
              player_2_controller, player_1_turret, player_2_turret,
              npc_turret):
     super().__init__(center, bound, pwm)
     self.player_1 = Player(bound,
                            bound,
                            pwm,
                            player_1_turret,
                            player_1_controller,
                            no_x=True,
                            fixed_x=int(center + bound / 2))
     self.player_2 = Player(bound,
                            bound,
                            pwm,
                            player_2_turret,
                            player_2_controller,
                            no_x=True,
                            fixed_x=int(center - bound / 2))
     self.ball = NPC(pwm, npc_turret)
     self.bounce = None
Example #7
0
import time
import Adafruit_PCA9685
from src import NPC
from src.TURRETS import TURRET_1
from paths.math import Hypotrochoid

pwm = Adafruit_PCA9685.PCA9685()
pwm.set_pwm_freq(60)

h = Hypotrochoid(375, 1 / 240, 70, 50, 20)
d = h.data()

npc = NPC(pwm, TURRET_1)
npc.laser.on()
graph = npc.follow_path(d)
curr_time = time.time()
while True:
    if time.time() - curr_time > 1 / 60:
        graph.__next__()