def main_loop(): clock = pygame.time.Clock() action = True while action: for event in pygame.event.get(): # window terminating event if event.type == pygame.QUIT: action = False # player move if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: player.vel = -VEL_ADD if event.key == pygame.K_RIGHT: player.vel = VEL_ADD if event.key == pygame.K_SPACE: # bullet = Bullet(player.x, player.y) # bullet.add_to_list(bullets) bullet1 = Bullet(player.x - 10, player.y) bullet2 = Bullet(player.x + 10, player.y) bullet1.add_to_list(bullets) bullet2.add_to_list(bullets) # stoping infinite move if event.type == pygame.KEYUP: # if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: player.vel = 0 # setting the frame rate clock.tick(60) redraw()
def fire_bullet(ai_settings, screen, ship, bullets): # Bắn ra một bullet nếu như chưa vượt quá giới hạn số bullet cho 1 lần bắn if len( bullets ) < ai_settings.bullets_allowed: # nếu số bullet bắn ra nhỏ hơn giới hạn bullet cho phép # Tạo ra một bullet mới và thả nó vào bullets group new_bullet = Bullet(ai_settings, screen, ship) bullets.add(new_bullet)
def fire(self): """ Creates a new bullet object and adds it to the list of child objects """ bullet_x = self.x bullet_y = self.y new_bullet = Bullet(self.game_state, self.game_assets, x=bullet_x, y=bullet_y, batch=self.batch, group=self.group) # mentioning group is important new_bullet.velocity_x = self.bullet_speed * math.sin( self.rotation * math.pi / 180) new_bullet.velocity_y = self.bullet_speed * math.cos( self.rotation * math.pi / 180) new_bullet.rotation = self.rotation self.child_objects.append(new_bullet) self.game_assets.audio_assets["snd_player_fire"].play()
def makeBullet(self): if self.isReady and len(self.bullets) < c.BULLETS_LIMIT: bullet = Bullet({ 'speed': random.uniform(c.BULLET_MIN_SPEED, c.BULLET_MAX_SPEED) }) bullet.goto(self.ship.position) bullet.add(self.bullets)
def fire_bullet(ai_settings, screen, ship, bullets): """Fire a bullet, if limit not reached yet.""" # Create a new bullet, add to bullets group. if len(bullets) < ai_settings.bullets_allowed: new_bullet = Bullet(ai_settings, screen, ship) bullets.add(new_bullet)
def fire_bullet(game_settings, screen, ship, bullets): """fire a bullet if limit not reached yet""" #create new bullet and add to bullets group if len(bullets) < game_settings.bullets_allowed: new_bullet = Bullet(game_settings, screen, ship) bullets.add(new_bullet)
def fire_bullet(ai_settings, screen, ship, bullets): """ Fire a bullet if the limit of possible bullets in the screen has not been reached yet. """ # create a new bullet and add it to the bullets group. if len(bullets) < ai_settings.bullets_allowed: new_bullet = Bullet(ai_settings, screen, ship) bullets.add(new_bullet)
import env from modules.actor import Actor from modules.actor_state import ActorState from modules.fonts import Fonts from modules.digest import Digest from modules.util import Util from modules.bullet import Bullet from modules.tlog import Targetlog from modules.monolith import Monolith from modules.netmap import Netmap WINDOW_WIDTH = 255 WINDOW_HEIGHT = 255 util = Util() draw_bullets = Bullet(env.TIME_AREA_X, env.TIME_AREA_Y) draw_tlog = Targetlog(env.LOG_AREA_X, env.LOG_AREA_Y, env.CHAR_WIDTH, env.CHAR_HEIGHT) draw_mono = Monolith(env.MONOLITH_X1, env.MONOLITH_Y1, env.MONOLITH_X2, env.MONOLITH_Y2, env.MONOLITH_MARGIN_LEFT, env.MONOLITH_MARGIN_TOP, env.MONOLITH_TITLE_LENGTH, env.MONOLITH_PREVIOUS_AMOUNT1, env.MONOLITH_PREVIOUS_AMOUNT2, env.MONOLITH_NEXT_AMOUNT1, env.MONOLITH_NEXT_AMOUNT2, env.TIME_AREA_X, env.TIME_AREA_Y, env.CHAR_WIDTH, env.CHAR_HEIGHT) draw_netmap = Netmap(env.VISUALIZE_TIME_RANGE, env.CHAR_WIDTH, env.CHAR_HEIGHT, env.LEVEL_1, env.LEVEL_2, env.LEVEL_3, env.LEVEL_4, env.LEVEL_5, env.WORLDMAP, env.CLASS_A, env.CLASS_B, env.CLASS_C, env.HOST, env.NETMAP_OBJ_WIDTH, env.NETMAP_OBJ_HEIGHT, env.NETMAP_OBJ_MARGIN_TOP, env.NETMAP_OBJ_MARGIN_DOWN, env.NETMAP_OBJ_MARGIN_RIGHT,