Beispiel #1
0
 def calcAsteroid(self, win, object):
     if object.getType() > 1:
         amnt = randrange(1, 4)
         pos = object.pos
         for i in range(amnt):
             dest = Point(-250, randrange(100, win.getWidth() - 100))
             self.asteroids.append(
                 Asteroid(pos, dest, win, 250,
                          object.getType() - 1))
Beispiel #2
0
 def __init__(self, name, width, height):
     super().__init__( name, width, height )
     self.ship = Ship()  # Creates a ship
     self.asteroids=[]   # A list of all asteroids
     for i in range(4):                  # Change for different amount of Asteroids
         self.asteroids.append(Asteroid(random.randrange(0, 1280, 5),random.randrange(0, 720, 5)))
     self.stars=[]       # A list of all background stars
     for i in range(50):                # Change for different amount of background Stars
         self.stars.append(Star())
     self.bullets = []   # A list of all bullets
Beispiel #3
0
 def __init__(self, name, width, height):
     super().__init__(name, width, height)
     # TODO: should create a Ship object here
     self.ship = Ship()  # None
     # TODO: should create asteroids
     self.asteroids = []
     for i in range(8):  # Change for different amount of Asteroids
         self.asteroids.append(Asteroid())
     self.stars = []
     for i in range(250):  # Change for different amount of background Stars
         self.stars.append(Star())
     # TODO: should create bullets
     self.bullets = []
Beispiel #4
0
 def __init__(self, name, width, height):
     super().__init__(name, width, height)
     self.width = width
     self.height = height
     self.ship = Ship()  # Creates a ship
     self.asteroids = []  # A list of all asteroids
     for i in range(5):  # Change for different amount of Asteroids
         self.asteroids.append(
             Asteroid(random.randrange(0, width, 5),
                      random.randrange(0, height, 5)))
     self.stars = []  # A list of all background stars
     for i in range(25):  # Change for different amount of background Stars
         self.stars.append(Star())
     self.bullets = []  # A list of all bullets
     self.score = 0  # Possible score variable
Beispiel #5
0
    def __init__(self, name, width, height):
        super().__init__(name, width, height)

        self.ship = Ship()  # None  # TODO: should create a Ship object here
        # TODO: should create asteroids
        self.asteroids = [
            Asteroid(),
            Asteroid(),
            Asteroid(),
            Asteroid(),
            Asteroid(),
            Asteroid(),
            Asteroid()
        ]
        # TODO: should create stars
        self.stars = []
        self.bullets = []
Beispiel #6
0
 def handle_input(self):
     super().handle_input()
     pygame.key.set_repeat(0, 100)
     keys_pressed = pygame.key.get_pressed()
     if keys_pressed[K_LEFT] and self.ship:
         self.ship.rotate(-3)
     if keys_pressed[K_RIGHT] and self.ship:
         self.ship.rotate(3)
     if keys_pressed[K_UP] and self.ship:
         self.ship.accelerate(0.05)
     if keys_pressed[K_DOWN] and self.ship:
         self.ship.accelerate(
             0
         )  #TODO: Set to (0) to stop the ship instantly with down-key AKA EASYMODE.
     if keys_pressed[K_SPACE] and self.ship:
         if time.time(
         ) - self.ship.shot_timer > self.ship.shot_delay:  #Limits the rate of fire. Cannot fire more often than shot_delay value
             self.ship.shot_timer = time.time(
             )  #if it shoots, saves last fired timestamp
             self.ship.spawnProtection = False  #removes Spawn protection if bullet is fired
             if len(
                     self.bullets
             ) >= 15:  #Does not allow more than 15 bullets in total. deletes the oldest if more than 15.
                 del self.bullets[0]
                 self.bullets.append(
                     Bullet(self.ship.position.copy(), self.ship.rotation,
                            self.ship.shot_timer)
                 )  #Spawns a bullet with ships location. rotation and timestamp when fired.
             else:
                 self.bullets.append(
                     Bullet(self.ship.position.copy(), self.ship.rotation,
                            self.ship.shot_timer))
     if keys_pressed[K_f] and self.ship:
         self.asteroids.append(
             Asteroid(
                 random.randrange(0, self.width, 5),
                 random.randrange(0, self.height,
                                  5)))  #Command for spawning more asteroids
     if keys_pressed[K_t] and self.ship:
         if time.time(
         ) - self.ship.jump_timer > self.ship.jump_delay:  #Checks if jumpdrive is on cooldown
             self.ship.jump_timer = time.time()  #Saves timestamp for jump
             self.ship.jumpDrive()  #Jumps the ship
Beispiel #7
0
                if event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        running = False
                    if event.key == K_SPACE:
                        pos = rocket.rect[:2]
                        bullet = Bullet(pos, rocket.dir, SIZE)
                        bullets.add(bullet)
                        all_sprites.add(bullet)
                        gunshot_sound.play()
                    if event.key == K_q:
                        rocket.rotate_left()
                    if event.key == K_e:
                        rocket.rotate_right()

                elif event.type == ADDAST1:
                    ast = Asteroid(1, SIZE)
                    asteroids.add(ast)
                    all_sprites.add(ast)
                elif event.type == ADDAST2:
                    ast = Asteroid(2, SIZE)
                    asteroids.add(ast)
                    all_sprites.add(ast)
                elif event.type == ADDAST3:
                    ast = Asteroid(3, SIZE)
                    asteroids.add(ast)
                    all_sprites.add(ast)
                elif event.type == ADDAST4:
                    ast = Asteroid(4, SIZE)
                    asteroids.add(ast)
                    all_sprites.add(ast)
                elif event.type == ADDAST5:
Beispiel #8
0
 def createAsteroids(self, win):
     pos = Point(win.getWidth() + 100, randrange(-250,
                                                 win.getWidth() + 250))
     dest = Point(-250, randrange(200, win.getWidth() - 200))
     self.asteroids.append(Asteroid(pos, dest, win, 250, randrange(1, 4)))