def fire(self): laser1 = la.Laser(self.screen, (self.x + 10, self.y + self.image_h / 2 - 10)) laser2 = la.Laser( self.screen, (self.x + self.image_w - 10, self.y + self.image_h / 2 - 10)) self.lasers.append(laser1) self.lasers.append(laser2)
def addLaser(): global laserCounter global player laser = Laser(20, player.x, player.y, 15, 82, 10) if laserCounter < 30: laserCounter += 1 laser.x = player.x + (player.width / 2) - (laser.width / 2) laser.y = player.y - laser.height lasers.append(laser) laserSound.play()
def spawnandshoot(paddle, laser_group): sys_name = os.path.join(sys.path[0], "Pybreaker-sounds", "laser_shoot.ogg") shoot = pygame.mixer.Sound(sys_name) laser = Laser(paddle.rect.centerx, paddle.rect.centery) laser.shoot(paddle) shoot.play() laser_group.add(laser) return laser_group
def pressKeyOnce(self, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: laser = myLaser.Laser(self.x + self.image_w / 2, self.y, self.screen) self.lasers.append(laser) laser.laserSound()
def Fight(self): self.printHeader() logger.info( f"Hitting webserver in mode {self.method} with {self.workers} workers running {self.coros} coroutine each" ) logger.debug(f"Starting {self.workers} concurrent Laser workers") # Start workers for i in range(int(self.workers)): worker = Laser.Laser(self.url, self.coros, self.counter, agents, self.no_payload, debug=DEBUG) self.workersQueue.append(worker) worker.start() try: # self.Run() #p = Laser.Laser(self.url, self.coros, self.counter, DEBUG) pass except (Exception): error(f"Failed to start worker {i}") pass print("Initiating monitor") self.monitor()
def key_control(hero): for event in pygame.event.get(): if event.type == QUIT: print('exit') exit() if event.type == KEYDOWN: if event.key == K_RIGHT or event.key == K_d: hero.move_right() hero.display() print('right') elif event.key == K_LEFT or event.key == K_a: hero.move_left() hero.display() print('left') elif event.key == K_UP or event.key == K_w: hero.move_up() hero.display() print('up') elif event.key == K_DOWN or event.key == K_s: hero.move_down() hero.move_down() print('down') elif event.key == K_SPACE: print('发射') tmp_x = hero.hero_x tmp_y = hero.hero_y tmp_laser = Laser(tmp_x, tmp_y, screen) tmp_laser.display() del tmp_laser pass elif event.type == KEYUP: move_x, move_y = 0, 0 # screen.fill((0, 0, 0)) screen.blit(bg, (0, 0)) hero.display() # print(hero.hero_x, ' ', hero.hero_y) pygame.display.update()
def tick(self): (mx, my) = pygame.mouse.get_pos() (cx, cy) = self.rect.center #if self.shooting is true, add a new laser to the object pool if self.shooting == True: l = Laser(self.angle, self.rect.center, self.gs) self.gs.lasers.append(l) self.laserNoise.play() else: self.laserNoise.stop() #calculate the new angle self.angle = math.atan2(mx - cx, my - cy) index = int(math.floor(self.angle * 180 / math.pi + 180) + 42) if index >= 360: index = index - 360 self.image = self.rotated_images[index]
def angleDetermine(laserX1, laserY1, laserX2, laserY2, closestCollisionX, closestCollisionY, collisionLineX1, collisionLineY1, collisionLineX2, collisionLineY2, img): #The normal for the rectangles line is calulated here normalY = collisionLineX2 - collisionLineX1 normalX = collisionLineY1 - collisionLineY2 temp = ((collisionLineX2 - collisionLineX1)**2) + ( (collisionLineY2 - collisionLineY1)**2) normalLength = math.sqrt(temp) normalX = normalX / normalLength normalY = normalY / normalLength #If the vector is too short, so it can not be properly reflected it will be made longer here if laserX2 < collisionLineX1 or laserY1 < collisionLineY1: laserVectorX = laserX2 - laserX1 laserVectorY = laserY2 - laserY1 laserX2 = laserVectorX + closestCollisionX laserY2 = laserVectorY + closestCollisionY else: laserX2 = laserX2 laserY2 = laserY2 #The vector that goes byound the rectangle side, is found, so it can be reflected in the normal from above. rayX = laserX2 - closestCollisionX rayY = laserY2 - closestCollisionY #The normal is moved to the end of the laser that goes into the rectangle dotProduct = (rayX * normalX) + (rayY * normalY) dotNormalX = dotProduct * normalX dotNormalY = dotProduct * normalY #The end of the reflection is found reflectionEndX = laserX2 - (dotNormalX * 2) reflectionEndY = laserY2 - (dotNormalY * 2) #cv2.line(img, (laserX1,laserY1), (closestCollisionX, closestCollisionY), (0, 0, 255), 5) return Laser.Laser(closestCollisionX, closestCollisionY, int(reflectionEndX), int(reflectionEndY))
if game_board.list_pawn[el].name_pawn == "pharaoh": if game_board.end_game == True: game = 0 again = 1 if boolean_Select: #display signboard to change pawn's direction if a pawn is select game_board.draw_signboard(fenetre, index_pawn) box_X, box_Y, index_box = Box.find_index_box( game_board, posX, posY) pygame.display.update() if next_Round == True: #end turn, shot a laser autimaticaly if index_player == 1: laser_shot = Laser( game_board.list_pawn[0].direction_pawn ) #first direction of laser is the same as sphinx of player pygame.time.delay(500) if laser_shot.direction_laser == 'east': laser_shot.automatic_shot(game_board, fenetre, 0, 1) elif laser_shot.direction_laser == 'south': laser_shot.automatic_shot(game_board, fenetre, 0, 10) #shot a laser else: laser_shot = Laser( game_board.list_pawn[len(game_board.list_pawn) - 1].direction_pawn) if laser_shot.direction_laser == 'north': laser_shot.automatic_shot(game_board, fenetre, len(game_board.list_pawn) - 1, 69)
def update(self, delta_time): """Updates the ship, by handling the player input. Arguments: delta_time {float} -- Time to elapse in seconds """ # Update shot cooldown time self.current_shot_cooldown = self.current_shot_cooldown - delta_time keys = pygame.key.get_pressed() # Reset thruster strength (for visual effect) self.thruster_m = self.thruster_r = self.thruster_l = 0 # Accelerate ship if (keys[pygame.K_UP]): self.add_velocity(self.acceleration * delta_time * self.get_direction_vector()) self.thruster_m = self.thruster_r = self.thruster_l = 1 if (self.engine_sound != None): self.engine_sound.set_volume(0.1) else: if (self.engine_sound != None): self.engine_sound.set_volume(0.0) # Rotate ship rotationSpeed = delta_time * GameDefs.player_defs.rotationSpeed if (keys[pygame.K_LEFT]): self.thruster_m = 0 self.thruster_r = 0.5 self.thruster_l = 0 self.rotation -= rotationSpeed if (keys[pygame.K_RIGHT]): self.thruster_m = 0 self.thruster_r = 0 self.thruster_l = 0.5 self.rotation += rotationSpeed # Break ship if (keys[pygame.K_DOWN]): self.add_velocity(-self.break_acceleration * delta_time * self.get_direction_vector()) # Fire if (keys[pygame.K_LCTRL]): if (self.current_shot_cooldown <= 0): laser_pos, laser_dir = self.get_mountpoint("laser_pos0") Engine.Scene.main.add( Laser("PlayerLaser", (64, 255, 64), 4, 20, laser_pos, laser_dir * 400, 2)) self.current_shot_cooldown = self.shot_cooldown Engine.SoundManager.play("Laser", 0.5) Ship.update(self, delta_time) # Check bounds and wrap around position if (self.position.x < -self.max_radius): self.position.x = 1280 + self.max_radius elif (self.position.x > (1280 + self.max_radius)): self.position.x = self.max_radius if (self.position.y < -self.max_radius): self.position.y = 720 + self.max_radius elif (self.position.y > (720 + self.max_radius)): self.position.y = -self.max_radius
def make_lasers(laser_list, difficulty): if len(laser_list) < (difficulty * LASER_ADD) + LASER_START and LASER_RESPAWN: laser_shot = Laser.Laser(difficulty) laser_list.append(laser_shot)
def shoot(self): if self.weapon == "laser": return Laser.Laser([ self.pos[0] - Constants.LASER_IMAGE_SHIFT - 3, self.pos[1] - Constants.PLAYER_SIZE[1] / 1.8 ])
def fire(self): self.laser.add(Laser(game=self.game))
# coding:utf-8 import pygame import sys import Laser import math import config laser = Laser.Laser(com=config.PORT) pygame.init() screen = pygame.display.set_caption('laser data view') screen = pygame.display.set_mode([800, 800]) screen.fill([0, 0, 0]) x1 = y1 = 400 pygame.display.flip() laser.start() while True: screen.fill([0, 0, 0]) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() for deg, length, intensity, rpm, rpms in laser.read_data(): if length < 0.000001 and intensity < 0.00000001: # 删除为0的数据 continue
def handle_events(self, event): laser = None bull = [] adj_old = m.cos(m.pi / 12) * self.b_speed adj_new = m.sin(m.pi / 12) * self.b_speed if event.type in G.Globals.BUTTONDOWN: if G.Globals.JOY_IN_USE: # using joystick, so configure for joy if event.type == PG.JOYBUTTONDOWN: event_value = event.button #elif event.type == PG.JOYAXISMOTION: # event_value = event.axis elif event.type == PG.JOYBALLMOTION: event_value = event.rel elif event.type == PG.JOYHATMOTION: event_value = event.value else: # otherwise, using keyboard so configure event for keyboard event_value = event.key if event_value == G.Globals.SHOOT_UP: if self.s_time >= self.fire_rate: G.Globals.FX_CHANNEL.play(Player.SHOT_SOUND) self.shot_dir = 1 self.s_time = 0.0 bull.append( B.Bullet( self.world_coord_x + Player.WIDTH / 2 - B.Bullet.WIDTH, self.world_coord_y, 0, -self.b_speed, self.b_distance, self.drunk)) if self.shot_type == 1: bull.append( B.Bullet( self.world_coord_x + Player.WIDTH / 2 - B.Bullet.WIDTH, self.world_coord_y, adj_new, -adj_old, self.b_distance, False)) bull.append( B.Bullet( self.world_coord_x + Player.WIDTH / 2 - B.Bullet.WIDTH, self.world_coord_y, -adj_new, -adj_old, self.b_distance, False)) elif event_value == G.Globals.SHOOT_DOWN: if self.s_time >= self.fire_rate: G.Globals.FX_CHANNEL.play(Player.SHOT_SOUND) self.shot_dir = 2 self.s_time = 0.0 bull.append( B.Bullet( self.world_coord_x + Player.WIDTH / 2 - B.Bullet.WIDTH, self.world_coord_y + Player.HEAD_HEIGHT, 0, self.b_speed, self.b_distance, self.drunk)) if self.shot_type == 1: bull.append( B.Bullet( self.world_coord_x + Player.WIDTH / 2 - B.Bullet.WIDTH, self.world_coord_y + Player.HEAD_HEIGHT, adj_new, adj_old, self.b_distance, False)) bull.append( B.Bullet( self.world_coord_x + Player.WIDTH / 2 - B.Bullet.WIDTH, self.world_coord_y + Player.HEAD_HEIGHT, -adj_new, adj_old, self.b_distance, False)) elif event_value == G.Globals.SHOOT_RIGHT: if self.s_time >= self.fire_rate: G.Globals.FX_CHANNEL.play(Player.SHOT_SOUND) self.shot_dir = 3 self.s_time = 0.0 bull.append( B.Bullet( self.world_coord_x + Player.WIDTH, self.world_coord_y + Player.HEAD_HEIGHT - B.Bullet.HEIGHT, self.b_speed, 0, self.b_distance, self.drunk)) if self.shot_type == 1: bull.append( B.Bullet( self.world_coord_x + Player.WIDTH, self.world_coord_y + Player.HEAD_HEIGHT - B.Bullet.HEIGHT, adj_old, -adj_new, self.b_distance, False)) bull.append( B.Bullet( self.world_coord_x + Player.WIDTH, self.world_coord_y + Player.HEAD_HEIGHT - B.Bullet.HEIGHT, adj_old, adj_new, self.b_distance, False)) elif event_value == G.Globals.SHOOT_LEFT: if self.s_time >= self.fire_rate: G.Globals.FX_CHANNEL.play(Player.SHOT_SOUND) self.shot_dir = 4 self.s_time = 0.0 bull.append( B.Bullet( self.world_coord_x, self.world_coord_y + Player.HEAD_HEIGHT - B.Bullet.HEIGHT, -self.b_speed, 0, self.b_distance, self.drunk)) if self.shot_type == 1: bull.append( B.Bullet( self.world_coord_x, self.world_coord_y + Player.HEAD_HEIGHT - B.Bullet.HEIGHT, -adj_old, adj_new, self.b_distance, False)) bull.append( B.Bullet( self.world_coord_x, self.world_coord_y + Player.HEAD_HEIGHT - B.Bullet.HEIGHT, -adj_old, -adj_new, self.b_distance, False)) #Adding the new key press to the end of #the array elif event_value in Player.MOVE_KEYS or \ event_value in Player.MOVE_JOYS: self.key.append(event_value) self.time = 0 elif event_value == G.Globals.ACT_KEY: if self.activated_item == 0 and self.activate_ready: self.shield_on = True self.shield_timer = 0 self.activate_ready = False self.activate_timer = 0 if self.activated_item == 1 and self.activate_ready: self.activate_ready = False self.activate_timer = 0 laser = Laser.Laser( (self.world_coord_x + 5, self.world_coord_y), self.laser_angle) G.Globals.FX_CHANNEL.play(Player.LASER_SOUND) elif event.type in G.Globals.BUTTONUP: if G.Globals.JOY_IN_USE: if event.type == PG.JOYHATMOTION: pass else: event_value = event.button else: event_value = event.key #Remove the key from the array if #it is there if event_value in self.key: self.key.remove(event_value) return bull, laser
def get_laser(self, configuration=priorityConfiguration): """ Read the current values from the laser """ return Laser( self.send('GetLDSScan').split('\r\n')[2:362], configuration)
# Activate two team objects. They contain points and a name. team1 = Team.Team(name1) team2 = Team.Team(name2) # Teamcolors color1 = (60, 224, 31) color2 = (244, 66, 203) # Laser start position and direction # Team 1 start_X1 = 200 start_Y1 = height end_X1 = 200 end_Y1 = 0 team1_laser_start = Laser.Laser(start_X1, start_Y1, end_X1, end_Y1) # Team 2 start_X2 = width-200 start_Y2 = height end_X2 = width-200 end_Y2 = 0 team2_laser_start = Laser.Laser(start_X2, start_Y2, end_X2, end_Y2) # Crop values cropYTop = 82 cropYbottom = 94 cropXLeft = 109 cropXRight = 127 # The new height and width is calculated
while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # player controls playerMovementChange = 0 if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: playerMovementChange = -0.3 if event.key == pygame.K_RIGHT: playerMovementChange = 0.3 if event.key == pygame.K_SPACE: laserList.append(Laser.Laser(player.locationX)) screen.fill((0, 255, 255)) screen.blit(background, (0, 0)) player.move(playerMovementChange) # enemy schedule.run_pending() for ship in enemyList: if ship.locationY >= 480: print('x') running = False ship.move() addToScreen(ship.playerImg, ship.locationX, ship.locationY)
def laser_fired(self): if self.active: laser = Laser(self.screen, [self.x + self.image_w / 2, self.y]) self.laserlist.append(laser) self.laser_sound.play(0)
screen.fill(black) if mode == 'menu': message = myfont.render("Click to Start the Game" , 1, pygame.color.THECOLORS['white']) screen.blit(message, (220, 240)) title = titlefont.render("ASTEROIDS" , 1, pygame.color.THECOLORS['white']) screen.blit(title, (130, 100)) pygame.display.update() if mode == 'play': keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: spaceship.rotate("left") if keys[pygame.K_RIGHT]: spaceship.rotate("right") if keys[pygame.K_SPACE] and shot_counter > 9: laser = Laser(spaceship.spaceship_direction,spaceship.spaceship_x,spaceship.spaceship_y) lasers.append(laser) shot_counter = 0 laser_sound.play() if keys[pygame.K_UP]: spaceship.booster() rocket_sound.play() if keys[pygame.K_SLASH] and special > .5 and shot_counter > 9: special = special - 1 shot_counter = 0 bullet_spray() shot_counter = shot_counter + 1 #doing / movement / collisions for asteroid in asteroid_list:
# coding:utf-8 import pygame, sys import Laser import math laser = Laser.Laser(com="COM3") pygame.init() screen = pygame.display.set_caption('laser data view') screen = pygame.display.set_mode([800, 800]) screen.fill([0, 0, 0]) x1 = y1 = 400 pygame.draw.circle(screen, [255, 0, 0], [x1, y1], 2, 0) pygame.display.flip() laser.start() while True: screen.fill([0, 0, 0]) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() for deg, length, intensity, rpm, rpms in laser.read_data(): if length < 0.000001 and intensity < 0.00000001: # 删除为0的数据 continue d = (360 - deg) * math.pi / 180.0 # 转为弧度
def flagged_arctrigo(aFunc): return lambda x: (aFunc(x) if i15 else math.degrees(aFunc(x))) atan2 = lambda y: (math.atan2(y, q0) if i15 else math.degrees(math.atan2(y, q0))) cos = flagged_trigo(math.cos) sin = flagged_trigo(math.sin) tan = flagged_trigo(math.tan) acos = flagged_arctrigo(math.acos) asin = flagged_arctrigo(math.asin) atan = flagged_arctrigo(math.atan) # Init laser object L = Laser() # Predefined Q variables q161 = 1 q301 = 0 p211 = 0 p212 = 0 p213 = 0 # Tilt q120 = 0 q121 = 0 q122 = 0 # Platform specific rotation q130 = 0
def collisionDetection(self, img): laserX1 = self.laserX1 laserX2 = self.laserX2 laserY1 = self.laserY1 laserY2 = self.laserY2 #gets the collision point on all the sides of the cube, and the collisionState, to check if it has even collided topCollisionX, topCollisionY, topCollisionState = self.collisionTop( img) bottomCollisionX, bottomCollisionY, bottomCollisionState = self.collisionBottom( img) rightCollisionX, rightCollisionY, rightCollisionState = self.collisionRight( img) leftCollisionX, leftCollisionY, leftCollisionState = self.collisionLeft( img) #Variables to store the points that acctually collides on the squares collisionX1 = 0 collisionY1 = 0 collisionX2 = 0 collisionY2 = 0 #Checks what sides the colission happens on, and returnes the collision coordiates if topCollisionState == 1: collisionX1 = topCollisionX collisionY1 = topCollisionY if bottomCollisionState == 1: collisionX2 = bottomCollisionX collisionY2 = bottomCollisionY elif rightCollisionState == 1: collisionX2 = rightCollisionX collisionY2 = rightCollisionY elif leftCollisionState == 1: collisionX2 = leftCollisionX collisionY2 = leftCollisionY elif bottomCollisionState == 1: collisionX1 = bottomCollisionX collisionY1 = bottomCollisionY if rightCollisionState == 1: collisionX2 = rightCollisionX collisionY2 = rightCollisionY elif leftCollisionState == 1: collisionX2 = leftCollisionX collisionY2 = leftCollisionY elif rightCollisionState == 1: collisionX1 = rightCollisionX collisionY1 = rightCollisionY if leftCollisionState == 1: collisionX2 = leftCollisionX collisionY2 = leftCollisionY elif leftCollisionState == 1: collisionX1 = leftCollisionX collisionY1 = leftCollisionY #After the right collision points have been found, the point closest to the laser origin is found. closestCollisionX, closestCollisionY = self.findSmallDistance( laserX1, laserY1, collisionX1, collisionY1, collisionX2, collisionY2) #We check if the collision point is not bugged and in the corner of the screen. #We also check if the rectangle, the laser hits is a mirror. if 0 < closestCollisionX and 0 < closestCollisionY and self.isMirror != 0: collisionLineX1 = 0 collisionLineY1 = 0 collisionLineX2 = 0 collisionLineY2 = 0 #We check what sides the collision happens on, and get the x and y of the line, so we can pass it to the # reflection function if closestCollisionX == topCollisionX: collisionLineX1, collisionLineY1 = self.rectangleX4, self.rectangleY4 collisionLineX2, collisionLineY2 = self.rectangleX1, self.rectangleY1 elif closestCollisionX == bottomCollisionX: collisionLineX1, collisionLineY1 = self.rectangleX2, self.rectangleY2 collisionLineX2, collisionLineY2 = self.rectangleX3, self.rectangleY3 elif closestCollisionX == rightCollisionX: collisionLineX1, collisionLineY1 = self.rectangleX3, self.rectangleY3 collisionLineX2, collisionLineY2 = self.rectangleX4, self.rectangleY4 elif closestCollisionX == leftCollisionX: collisionLineX1, collisionLineY1 = self.rectangleX1, self.rectangleY1 collisionLineX2, collisionLineY2 = self.rectangleX2, self.rectangleY2 self.reflected = True self.blocked = False #The right coordinates are put into the reflection function return Mirror.angleDetermine(self.laserX1, self.laserY1, self.laserX2, self.laserY2, closestCollisionX, closestCollisionY, collisionLineX1, collisionLineY1, collisionLineX2, collisionLineY2, img) elif 0 < closestCollisionX and 0 < closestCollisionY: #If the block is a blocker it will stop the laser at the collision point # print('Laser Blocked') self.reflected = False self.blocked = True return Laser.Laser(self.laserX1, self.laserY1, closestCollisionX, closestCollisionY) else: #If the laser does not collide with any blocker or Mirror it will return the laser again, this laser is # then made longer in the laserFire function # print("Laser screenCollision") self.reflected = False self.blocked = False return Laser.Laser(self.laserX1, self.laserY1, self.laserX2, self.laserY2)