Exemplo n.º 1
0
    def shoot(self, paddle):

        """
        make new shot, from paddle
        """

        self.shot = shot.Shot(paddle, self)
Exemplo n.º 2
0
def setup():
    global detector, vs, frame_rate, prev, shotDetector, ppm, cp5, heightField, distField, backboard, rim, courtFloor, rects
    size(width, height)

    detector = Detector.Detector()
    vs = VideoStream(src=0).start()
    shotDetector = shot.Shot(2.35)
    frame_rate = 20
    prev = 0
    ppm = height / 5  # pixels per meter
    backboard = Rect(width - BACKBOARD_WIDTH * ppm - 5, height - TOP_BACKBOARD * ppm, BACKBOARD_WIDTH * ppm,
                     BACKBOARD_HEIGHT * ppm)
    rim = Rect(width - BACKBOARD_WIDTH * ppm - 5 - HOOP_D * ppm, height - HOOP_HEIGHT * ppm, HOOP_D * ppm, 5)
    courtFloor = Rect(0, height - 10, width, 10)
    rects = [backboard, rim, courtFloor]
Exemplo n.º 3
0
 def shoot(self, fighter):
     if time.time() - fighter.gun_cdown > fighter.cdown_rate:
         self.shots.append(
             sh.Shot(self.shot, fighter.angle, fighter.gun_port,
                     fighter.vel_x, fighter.vel_y, fighter.id))
         fighter.gun_cdown = time.time()
Exemplo n.º 4
0
 def _create_shots(self):
     while len(self.shot_group) < self.settings.n_shots:
         t0 = pygame.time.get_ticks()/1000
         n_shot = shot.Shot(self, t0)
         self.shot_group.append(n_shot)
Exemplo n.º 5
0
 def shot(self, enemie):
     self._shotList.append(
         shot.Shot(self.getPosition(), 8, 8, "imagens/shot.png", 0.5,
                   enemie.getPosition(), self.getDamage(), "NULL"))
Exemplo n.º 6
0
def main():
    
    pygame.init()
    
    logo = pygame.image.load("logo32x32.png")
    pygame.display.set_icon(logo)
    pygame.display.set_caption("Space Impact")
    
    screen_width = 480
    screen_height = 320
    screen = pygame.display.set_mode((screen_width, screen_height))
    
    ship_img = pygame.image.load("spaceship.png")
    enemy_img = pygame.image.load("enemy.png")
    shot_img = pygame.image.load("shot.png")
        
    #initial position
    xpos = 20
    ypos = screen_height // 2 - 20
    
    step_x = 5
    step_y = 5
    
    screen.blit(ship_img, (xpos, ypos))
    
    pygame.display.flip()
    
    # a clock for controlling the fps
    clock = pygame.time.Clock()
    
    running = True

    shots = []

    display_score = pygame.font.Font(pygame.font.get_default_font(), 20)
    score = 0
    
    enemies = []
    enemy_time = 400
    enemy_control = 0 #time    
    enemy_max_speed = 5    

    still_down = False
    key_pressed = None

    xmax = screen_width - ship_img.get_width() #spaceship width
    ymax = screen_height - ship_img.get_height() #spaceship height
    
    while running:
        
        evento = pygame.event.poll()

        if evento.type == pygame.QUIT:            
            running = False
            
        if evento.type == pygame.KEYUP:
            if evento.key != pygame.K_SPACE:
                still_down = False

        if evento.type == pygame.KEYDOWN:
            
            if evento.key == pygame.K_ESCAPE:
                running = False                

            if evento.key == pygame.K_SPACE:
                shots.append(shot.Shot(xpos+ship_img.get_width(), ypos+(ship_img.get_height()//2 - shot_img.get_height()//2)))
                evento = None
            if evento:
                if still_down:                
                    pygame.event.post(evento)
                else:
                    still_down = True                
                    arrow_pressed = evento.key               

        if still_down:
            if arrow_pressed == pygame.K_UP and ypos > 0:
                ypos -= step_y                    
            elif arrow_pressed == pygame.K_DOWN and ypos < ymax:
                ypos += step_y 
            elif arrow_pressed == pygame.K_LEFT and xpos > 0:
                xpos -= step_x 
            elif arrow_pressed == pygame.K_RIGHT and xpos < xmax:
                xpos += step_x      
                
        screen.fill((116,166,129))
        
        screen.blit(ship_img, (xpos, ypos))

        for projec in shots:
            screen.blit(shot_img, (projec.xpos, projec.ypos))
            projec.update(boundary = screen_width)
        
        if (pygame.time.get_ticks() - enemy_control) >= enemy_time:            
            enemy_control = pygame.time.get_ticks()
            enemies.append(enemy.Enemy(xpos = screen_width, ypos= random.random()*(screen_height-enemy_img.get_height()), speed=(random.random()+1)*enemy_max_speed))
        
        for target in enemies:
            screen.blit(enemy_img, (target.xpos, target.ypos))
            target.update()
            #colision enemy ship
            if target.xpos < xpos + ship_img.get_width() and target.xpos + ship_img.get_height() > xpos and target.ypos < ypos + ship_img.get_height() and ship_img.get_width() + target.ypos > ypos:
                running = False
            #colision enemy shot
            for projec in shots:
                if projec.xpos < target.xpos + enemy_img.get_width() and projec.xpos + shot_img.get_width() > target.xpos and projec.ypos < target.ypos + enemy_img.get_height() and shot_img.get_width() + projec.ypos > target.ypos:
                    target.destroy()
                    projec.destroy()
                    score+=1                    

        f = display_score.render("Destruidos: "+str(score), True, [0, 0, 0], [116,166,129])

        screen.blit(f, ((screen_width//2)-(display_score.size("Destruidos: "+str(score))[0]//2),0))
        pygame.display.flip()

        for i in range(len(shots)):
            try:
                if not shots[i].isOnScreen():
                    del shots[i]
            except IndexError:
                pass
        for i in range(len(enemies)):
            try:
                if not enemies[i].isOnScreen():
                    del enemies[i]
            except IndexError:
                pass
        
        
        clock.tick(30)#fps