def setUp(self): # doc = FreeCAD.newDocument() # self.missile = doc.addObject( # "Part::FeaturePython", "Missile") self.missile = DocumentMock() self.missile = Missile(self.missile) self.fp = FeaturePythonMock()
def create_missile(self): random_int = random.randint(0,3) if random_int < 2: if random_int == 0: direction = self.south move_to = UP else: direction = self.north move_to = DOWN position = ( random.randint(260,370), direction, 15, 40 ) else: if random_int == 2: direction = self.ouest move_to = RIGHT else: direction = self.east move_to = LEFT position = ( direction, random.randint(180,280), 40, 15 ) missile = Missile( 2, position, ) missile.direction_set(move_to) return missile
def fire(self): self.shooting_time = 0 x, y = self.pos halfX = 16 # 32 // 2 halfY = 24 # 48 // 2 m1 = Missile(x - halfX, y + halfY) m2 = Missile(x + halfX, y + halfY) gfw.world.add(gfw.layer.missile, m1) gfw.world.add(gfw.layer.missile, m2)
def launch_bullet(self): speed = 500. scale = Vec3(0.05) color = Vec4(0, 1, 0, 1) mask = BitMask32(0x2) lookat = Vec3(0, 100, 0) Missile(self, "bullet", speed, scale, color, mask, self.fighter, Vec3(-0.5, 0, 0), self.fighter, lookat, 0.5) Missile(self, "bullet", speed, scale, color, mask, self.fighter, Vec3(+0.5, 0, 0), self.fighter, lookat, 0.5) self.snd_launch.play()
def init_bullet(self): bullet = Missile() sprite = pygame.image.load("assets/images/missile.png") sprite = pygame.transform.scale(sprite, (4, 10)) bullet.image = sprite bullet.rect = bullet.image.get_rect() bullet.vector = -1 bullet.speed = 10 bullet.rect.x = self.player.rect.x + 10 bullet.rect.y = self.player.rect.y return bullet
def init_alien_missile(self, shooter): missile = Missile() sprite = pygame.image.load("assets/images/missile.png") sprite = pygame.transform.scale(sprite, (4, 10)) missile.image = sprite missile.rect = missile.image.get_rect() missile.rect.x = shooter.rect.x + 15 missile.rect.y = shooter.rect.y + 40 missile.speed = 5 missile.vector = 1 return missile
def on_mouse_press(self, x: float, y: float, button: int, modifiers: int): # Fire! angle = self._get_angle_degrees(x, y) if modifiers == arcade.key.MOD_SHIFT: missile = Missile() missile.fire(angle) self.missiles.append(missile) else: bullet = Bullet() bullet.fire(angle) self.bullets.append(bullet)
def fire(self): if self.cool_down_timer <= 0: pygame.event.post(pygame.event.Event(PLAYER_SHOOT_EVENT)) m = Missile(MISSILE_IMAGE_PATH[self.missile_image]) m.rect.centerx = self.rect.centerx m.rect.y = self.rect.top - MISSILE_SIZE_Y // 2 if self.attack >= 3: m.attack = BASIC_ATTACK + 1 self.missile_group.add(m) self.cool_down_timer = self.fire_cool_down return m return None
def fire(self): trigger = random.randint(1, 100) if trigger <= ENEMY_MEDIUM_FIRE_CHANCE and self.cool_down_timer <= 0: pygame.event.post(pygame.event.Event(ENEMY_SHOOT_EVENT)) missile = Missile(MISSILE_IMAGE_PATH[0]) missile.speed = MISSILE_SPEED missile.rect.centerx = self.rect.centerx missile.rect.y = self.rect.bottom - ENEMY_MEDIUM_SIZE_Y//2 self.missile_group.add(missile) self.cool_down_timer = self.fire_cool_down return missile return None
def get_missiles(data): missiles = [] for missileData in data['Missiles']: moveDirection = int(missileData['MoveDirection']) parsedLocation = get_location_from_string(missileData['Location']) location = Location(parsedLocation[0], parsedLocation[1]) explosionRadius = int(missileData['ExplosionRadius']) missile = Missile(moveDirection, location, explosionRadius) missile.print_debug() missiles.append(missile) return missiles
def update(self, pressed_keys): # flight motion if pressed_keys[self.kWarp]: if self.gas - self.gas_use_delta > 0: self.gas -= self.gas_use_delta dx = int(self.x + self.x_warp_speed) - int(self.x) dy = int(self.y + self.y_warp_speed) - int(self.y) self.x += self.x_warp_speed self.y += self.y_warp_speed self.rect.move_ip(dx, dy) if pressed_keys[self.kLeft]: self.set_direction(self.dir_degree - self.turn_speed) if pressed_keys[self.kRight]: self.set_direction(self.dir_degree + self.turn_speed) if not pressed_keys[self.kWarp]: self.gas = min(self.max_gas, self.gas_regain_delta + self.gas) dx = int(self.x + self.x_speed) - int(self.x) dy = int(self.y + self.y_speed) - int(self.y) self.x += self.x_speed self.y += self.y_speed self.rect.move_ip(dx, dy) if self.x < 0: self.rect.move_ip(self.SCREEN_WIDTH, 0) self.x = self.rect.left + self.radius if self.x > self.SCREEN_WIDTH: self.rect.move_ip(-self.SCREEN_WIDTH, 0) self.x = self.rect.left + self.radius if self.y <= 0: self.rect.move_ip(0, self.SCREEN_HEIGHT) self.y = self.rect.top + self.radius if self.y >= self.SCREEN_HEIGHT: self.rect.move_ip(0, -self.SCREEN_HEIGHT) self.y = self.rect.top + self.radius # fire if pressed_keys[self.kFire] and len(self.bullets) < self.bullet_limit: self.bullet_list.append(Bullet(self)) self.bullets.add(self.bullet_list[-1]) self.start_fire_bullet_sound() else: self.stop_fire_bullet_sound() # contrails self.contrails.add(Contrail(self)) # missile if pressed_keys[self.kMissile]: if (len(self.missiles) == 0): play_list(sfx_weapon_c_art_cruier_missile_fire) for degree_delta in self.missiles_range: self.missiles.add(Missile(self, degree_delta, self.flights)) # draw & blit self.update_and_blits(self.contrails) self.update_and_blits(self.bullets) self.update_and_blits(self.missiles) self.screen.blit(self.surf, self.rect)
def missile_launch(self): if self.m_energy - MLAUNCHENERGY > 0: self.m_energy -= MLAUNCHENERGY if self.m_energy < 0: self.m_energy = 0 return Missile(self) return None
def event_type(game_para, rocket, screen, missiles): """Function to respond key presses.""" for event in pygame.event.get(): if event.type == pygame.QUIT: # Turn off game window. sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: # Make Rocket smooth movement right side flag True. rocket.moving_right = True if event.key == pygame.K_LEFT: # Make Rocket smooth movement left side flag True. rocket.moving_left = True elif event.key == pygame.K_SPACE: # Create a new missile and store it to missiles Group() with a limitation condition. if len(missiles) < game_para.missile_amount: new_missile = Missile(game_para, screen, rocket) missiles.add(new_missile) elif event.key == pygame.K_q: # Turn off game window with keyboard 'q' button. sys.exit() elif event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: # Make Rocket smooth movement right side flag False. rocket.moving_right = False if event.key == pygame.K_LEFT: # Make Rocket smooth movement left side flag False. rocket.moving_left = False
def generate(score): dx = random.random() # 0.0~1.0 값 if dx < 0.5: dx -= 1 dy = random.random() if dy < 0.5: dy -= 1 mag = 1 + score / 60 dx *= mag dy *= mag side = random.randint(1, 4) if side == 1: #left x = 0 y = random.uniform(0, get_canvas_height()) if dx < 0: dx = -dx elif side == 2: #bottom x = random.uniform(0, get_canvas_width()) y = 0 if dy < 0: dy = -dy elif side == 3: #right x = get_canvas_width() y = random.uniform(0, get_canvas_height()) if dx > 0: dx = -dx else: #top x = random.uniform(0, get_canvas_width()) y = get_canvas_height() if dy > 0: dy = -dy m = Missile((x, y), (dx, dy)) gfw.world.add(gfw.layer.missile, m)
def generate_m(score): dx = random.random() # 이동속도 랜덤 if dx < 0.5: dx -= 1.0 # 만들어진 방향에서 화면으로 오도록 하기 위함 ex) 위에서 만들어지면 아래로 이동 dy = 0 mag = 1 + score / 40 # 점수에 따른 속도 배율 40점 -> 속도 2배 dx *= mag dy *= mag side = random.randint(1, 2) # 1 : left 2 : right if side == 1: x = 0 y = random.uniform(player.pos[1] - 300, get_canvas_height() * 0.5 + player.pos[1]) if dx < 0: dx = -dx elif side == 2: x = get_canvas_width() y = random.uniform(player.pos[1] - 300, get_canvas_height() * 0.5 + player.pos[1]) if dx > 0: dx = -dx m = Missile((x, y), (dx, dy)) gfw.world.add(gfw.layer.missile, m)
def generate(score): dx = random.random() if dx < 0.5: dx -= 1.0 dy = random.random() if dy < 0.5: dy -= 1.0 mag = 1 + score /60 dx *= mag dy *= mag #dx = random.uniform(-1.0, 1.0) #dy = random.uniform(-1.0, 1.0) side = random.randint(1,4) if side == 1: x = 0 y =random.uniform(0,get_canvas_height()) if dx < 0: dx = - dx elif side == 2: x =random.uniform(0,get_canvas_width()) y = 0 if dy < 0: dy = -dy elif side == 3: x = get_canvas_width() y = random.uniform(0,get_canvas_height()) if dx > 0: dx = -dx else: x = random.uniform(0,get_canvas_width()) y = get_canvas_height() if dy > 0: dy = -dy m = Missile((x,y), (dx,dy)) gfw.world.add(gfw.layer.missile, m)
def shoot(self) : if not self.shooting : # print("fire") self.missile = Missile(self.x + self.width / 2, self.y, -1) # dir = -1 -> UP self.shooting = True # else : # print("not fire")
def shootArea(self, tnk): opponents = [ t.getPos() for t in pygame.sprite.spritecollide( Area(tnk.getPos(), missile.SHOOT_RANGE), self._opponent['tanks'], False, pygame.sprite.collide_circle) ] if not opponents: return x, y = tnk.getPos() bx, by = angleVector(2.0 * math.pi * tnk.barrel / 32) opponents.sort( key=lambda (ox, oy): abs(vectorAngle((bx, by), (ox - x, oy - y)))) for dx, dy in opponents: mis = Missile(self._engine, self._map, tnk, (x + 20 * bx, y + 20 * by), (bx, by), True) canshoot = False while True: temp = mis.update() if temp == None: continue if temp == False: break if temp == True: canshoot = True break if canshoot: break angle = vectorAngle((bx, by), (dx - x, dy - y)) if abs(angle) < 12 and random.randint(1, 5) == 3: tnk.shoot() if angle > 11: tnk.barrelRight() elif angle < -11: tnk.barrelLeft() if abs(angle) < 12 and random.randint(1, 5) == 3: tnk.shoot() tnk.updateImage()
def launch_missile(self): speed = 100 scale = Vec3(0.2) color = Vec4(1, 0, 0, 1) mask = BitMask32(0x2) lookat = Vec3(0, 0, 0) self.missile = Missile(self, "missile", speed, scale, color, mask, self.fighter, Vec3(0, 0, -2), self.target.np, lookat, 3) self.snd_launch.play() self.taskMgr.add(self.guide_missile, "task-guide-missile")
def process_right_missile(self, agent, command): name = 'missile{0}'.format(len(self.missiles) + 1) start_pos = agent.right_missile_position() missile = Missile(agent.team, name, agent.name, start_pos, agent.bearing) self.missile_action(agent) self.missiles.append(missile) agent.right_missile = False agent.command_finished()
def check_keydown_events(event, game_settings, screen, aircraft, missiles): # respond to keypresses if event.key == pygame.K_RIGHT: aircraft.moving_right = True elif event.key == pygame.K_LEFT: aircraft.moveing_left = True elif event.key == pygame.K_SPACE: # new missile and add it to the group new_missile = Missile(game_settings, screen, aircraft) missiles.add(new_missile)
def handle_events(): global BoundingBox global Bossdie events = get_events() for event in events: if event.type == SDL_QUIT: game_framework.quit() else: if (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE): game_framework.quit() else: player.handle_event(event) if event.type == SDL_KEYDOWN and event.key == SDLK_SPACE and player.state != 0: if map.kind != 3: player.missile_sound.play() newmissile = Missile(player.x, player.y) if player.missile_level == 1: newmissile.level = 0 if player.missile_level == 2: newmissile.level = 1 Player_missile.append(newmissile) else: ui.playerlife = 2 Bossdie = 0 close_canvas() game_framework.change_state(start_state) if event.type == SDL_KEYDOWN and event.key == SDLK_b and player.state!= 0: if ui.bomb != 0: newbomb = Bomb(player.x, player.y) newbomb.angle = 3 bomb.append(newbomb) newbomb = Bomb(player.x, player.y) newbomb.angle = -3 newbomb.angle = -3 bomb.append(newbomb) ui.bomb -= 1 if event.type == SDL_KEYDOWN and event.key == SDLK_h and player.state != 0: if BoundingBox == 0: BoundingBox = 1 elif BoundingBox == 1: BoundingBox = 0 if event.type == SDL_KEYDOWN and event.key == SDLK_q: ui.score =205
class DescribeMissile(unittest.TestCase): def setUp(self): # doc = FreeCAD.newDocument() # self.missile = doc.addObject( # "Part::FeaturePython", "Missile") self.missile = DocumentMock() self.missile = Missile(self.missile) self.fp = FeaturePythonMock() def test_should_only_update_if_live_update_property_is_true(self): self.fp.live_update = True self.missile.execute = Mock(return_value=True) self.missile.onChanged(self.fp, 'body_length') self.assertTrue(self.missile.execute.called) self.fp.live_update = False self.missile.execute = Mock(return_value=True) self.missile.onChanged(self.fp, 'body_length') self.assertFalse(self.missile.execute.called)
def shootArea(self, tnk): opponents = [t.getPos() for t in pygame.sprite.spritecollide(Area(tnk.getPos(), missile.SHOOT_RANGE), self._opponent['tanks'], False, pygame.sprite.collide_circle)] if not opponents: return x, y = tnk.getPos() bx, by = angleVector(2.0 * math.pi * tnk.barrel / 32) opponents.sort(key = lambda (ox, oy): abs(vectorAngle((bx, by), (ox - x, oy - y)))) for dx, dy in opponents: mis = Missile(self._engine, self._map, tnk, (x + 20 * bx, y + 20 * by), (bx, by), True) canshoot = False while True: temp = mis.update() if temp == None: continue if temp == False: break if temp == True: canshoot = True break if canshoot: break angle = vectorAngle((bx, by), (dx - x, dy - y)) if abs(angle) < 12 and random.randint(1, 5) == 3: tnk.shoot() if angle > 11: tnk.barrelRight() elif angle < -11: tnk.barrelLeft() if abs(angle) < 12 and random.randint(1, 5) == 3: tnk.shoot() tnk.updateImage()
def getMissile(self): indices = [0] for i in range(1, self.shotQuantity): indices += [-i, i] missiles = [] for i in indices: newTheta = self.theta + i * np.pi / 1000 vx = self.v * np.cos(newTheta) vy = self.v * np.sin(newTheta) x = self.x + self.r * np.cos(newTheta) y = self.y + self.r * np.sin(newTheta) missiles.append(Missile(pos=[x, y], vel=[vx, vy])) return missiles
def check_keydown_events(event, settings, screen, rocket, missiles): if event.key == pygame.K_DOWN: rocket.moving_down = True if event.key == pygame.K_UP: rocket.moving_up = True if event.key == pygame.K_LEFT: rocket.moving_left = True if event.key == pygame.K_RIGHT: rocket.moving_right = True if event.key == pygame.K_SPACE: if len(missiles) < settings.missiles_allowed: new_missile = Missile(settings, screen, rocket) missiles.add(new_missile)
def move(self, instruction): pship = self.screen[self.x][self.y] if (instruction == 'left'): self.x, self.y = pship.move( 'left', self.screen) # should update the screen too if (instruction == 'right'): self.x, self.y = pship.move('right', self.screen) if (instruction == '2'): msl = Missile(pship) pass
def launch_rocket(self, x, y, baseidx=None): if y > self.HEIGHT - self.BASE_HEIGHT * 1.4: return if baseidx is not None: base = self.bases[baseidx] else: base = self.get_nearest_able_base(x, y) if base and (base.ammo > 0 or self.force_fire): base.ammo = max(base.ammo - 1, 0) self.interceptors.append( Missile(self.ctx, base.x, self.HEIGHT - self.BASE_HEIGHT, x, y, self.INTERCEPTOR_SPEED, 0, 'friend'))
class DescribeMissile(unittest.TestCase): def setUp(self): self.missile = DocumentMock() self.missile = Missile(self.missile) self.fp = FeaturePythonMock() def test_should_be_init_with_4_children(self): children_length = len(self.missile.children) self.assertEqual(children_length, 4) def test_missile_should_get_properies_from_all_children(self): child_properies_list = [ child.Proxy.properties for child in self.missile.children] for child_properies in child_properies_list: for prop in child_properies: self.assertTrue(prop in self.missile.properties) def test_missile_should_update_when_value_ischanged(self): self.fp.missile_radius = 5 self.missile.execute = Mock(return_value=True) self.missile.onChanged(self.fp, 'missile_radius') self.assertTrue(self.missile.execute.called)
def shoot(self): if self.repair: return if not self._reload and self.missiles: vx, vy = angleVector(2.0 * math.pi * self.barrel / 32) pos = list(self._pos) pos[0] += 20 * vx pos[1] += 20 * vy self._map.explosions.add(Shot(pos)) self._map.missiles.add(Missile(self._engine, self._map, self, pos, (vx, vy))) self._reload = 40 self.missiles -= 1 self.updateImage()
def event(): update() if request.headers['Content-Type'] == 'application/json': jsonStr = json.loads(request.data) id = jsonStr['id'] action = jsonStr['action'] if action == "launch_missile": missle = jsonStr['param'] manager.push(Missile(missle['pos']['x'], \ missle['pos']['y'],\ missle['vel']['x'],\ missle['vel']['y'])) return jsonify({'ok': True}) else: return jsonify({'ok': False}) else: return jsonify({'ok': False})
def fire_missile(missiles, ai_settings, aliens, screen): # create a missle that is fired by a randomly selected alien # reassign numbers so that all aliens are in the pool for random selection for firing missle reassign_alien_number(aliens) # do not change the missile_number parameter in settings, use a proxy to accept changes missile_number = ai_settings.missile_number # if number of alien is smaller than missile number, make missile number always 1 smaller than alien number if len(aliens) < missile_number: missile_number = len(aliens) - 1 # choose randomly the number of aliens to fire missile designated_aliens = sample(range(len(aliens)), missile_number) for alien in aliens.sprites(): # find the designated alien if alien.number in designated_aliens: if len(missiles) < missile_number: # make the missile missile = Missile(ai_settings, screen, alien) missiles.add(missile)
def move(self, instruction): pship = self.sess.screen[self.x][self.y] if (instruction == 'left'): self.x, self.y = pship.move( 'left', self.sess) # should update the screen too if (instruction == 'right'): self.x, self.y = pship.move('right', self.sess) if (instruction == '1'): msl = Missile(pship) self.sess.screen[msl.x][msl.y] = msl self.sess.misslist.append(msl) msl.move(self.sess) if (instruction == '2'): msl = Timebomb(pship) self.sess.screen[msl.x][msl.y] = msl self.sess.misslist.append(msl) msl.move(self.sess)
def update(self, missile_list, explosion_list, city_list): # generate incoming missiles if self.missile_frequency % self.missile_interval == 0 and self.missile_count < self.max_missile_count: missile_list.append(Missile(self.get_origin(), self.get_target())) self.missile_count += 1 # increment the frequency count self.missile_interval += 1 if self.missile_interval > self.missile_loop: self.missile_interval = 1 # check for collisions self.player_score += check_collisions(missile_list, explosion_list, city_list) # check if all cities have been destroyed if city_list == []: return GAME_STATE_OVER # start next level if missile_list == [] and explosion_list == []: return GAME_STATE_NEW_LEVEL return GAME_STATE_RUNNING
def init_level_1(self, reset_player=True): # Initialize characters and associated sprites. if reset_player: self.player = Player("graphics/blocky_right_1.png", 25, 472, [ "graphics/blocky_right_0.png", "graphics/blocky_right_1.png", "graphics/blocky_right_2.png", "graphics/blocky_right_1.png" ], [ "graphics/blocky_left_0.png", "graphics/blocky_left_1.png", "graphics/blocky_left_2.png", "graphics/blocky_left_1.png" ]) else: self.player.set_position(25, 472) self.bomb = Missile("graphics/bomb.png", -100, -1000) # Initialize sprite groups. self.enemy_group = pygame.sprite.Group() self.enemy_defeated_by_missile_group = pygame.sprite.Group() self.missile_group = pygame.sprite.Group() self.axe_group = pygame.sprite.Group() self.tree_group = pygame.sprite.Group() self.pipe_group = pygame.sprite.Group() # Add sprites to groups. self.add_enemy_to_group("graphics/snake.png", 300, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 600, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 1200, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 1300, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 1700, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 2200, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 2900, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 3500, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 4000, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 4100, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 4200, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group( "graphics/snake.png", 5000, 529, self.enemy_group, [self.enemy_defeated_by_missile_group, self.axe_group]) self.add_enemy_to_group("graphics/snake.png", 5500, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 5600, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/snake.png", 6000, 529, self.enemy_group, [self.enemy_defeated_by_missile_group]) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 375, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 395, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 415, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 875, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 895, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 1450, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 1470, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 1490, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 1710, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 1730, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 1750, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 1900, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 1920, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 1940, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 2300, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 2500, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 2700, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 3500, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 3520, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 3540, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 3700, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 3900, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 4500, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 4900, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 5300, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 5320, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 5340, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 6000, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 6200, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 6400, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 7000, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 7020, 570, self.enemy_group, []) self.add_enemy_to_group("graphics/poison_grapes_sm.png", 7040, 570, self.enemy_group, []) self.add_enemy_to_group( "graphics/tree.png", 8000, 100, self.enemy_group, [self.enemy_defeated_by_missile_group, self.tree_group]) self.add_enemy_to_group("graphics/pipe.png", 8700, 336, self.enemy_group, [self.pipe_group]) self.missile_group.add(self.bomb) # Initialize background. self.background = Background("graphics/background.jpg", 0, 0, 2)
from enemy import Enemy ctr = Controller(0) # create the game object s = SCREEN() s.setController(ctr) s.initLevel("levels//palletTown.pkl") s.level.setPC(PC(image="images//mog.png", x=10, y=7, spd=300, frameSpeed=50, cycle=3, direction=0, frames=12), x=10, y=7) watergun = Missile(x=0, y=0, image="images//waterGunOne.png", frames=1, level=s.level, char=s.level.PC, damage=1, frameSpeed=30) s.level.PC.attatchWeapon(watergun) s.run()
def handle_events(self): """Function to handle user input.""" for event in pygame.event.get(): #quit game if event.type == QUIT: command_queue.put("Exit"); #sys.exit() #If user has pressed a key if event.type == KEYDOWN: bomb = None missile = None #get mouse position pos = pygame.mouse.get_pos() if self.TYPE == "Bombs": #if player still has bombs to drop if (self.nbombs < self.maxbombs): #if 1-9 pressed, set off bomb by creating a new object and adding it to self.bombs if event.key == pygame.K_1: bomb = Bomb(pos[0], 0, self.bases[0].rect.centerx, self.size[1] - self.city_width, self.bomb_speed, 0) if event.key == pygame.K_2: bomb = Bomb(pos[0], 0, self.cities[0].rect.centerx, self.size[1] - self.city_width, self.bomb_speed, 1) if event.key == pygame.K_3: bomb = Bomb(pos[0], 0, self.cities[1].rect.centerx, self.size[1] - self.city_width, self.bomb_speed, 2) if event.key == pygame.K_4: bomb = Bomb(pos[0], 0, self.cities[2].rect.centerx, self.size[1] - self.city_width, self.bomb_speed, 3) if event.key == pygame.K_5: bomb = Bomb(pos[0], 0, self.bases[1].rect.centerx, self.size[1] - self.city_width, self.bomb_speed, 4) if event.key == pygame.K_6: bomb = Bomb(pos[0], 0, self.cities[3].rect.centerx, self.size[1] - self.city_width, self.bomb_speed, 5) if event.key == pygame.K_7: bomb = Bomb(pos[0], 0, self.cities[4].rect.centerx, self.size[1] - self.city_width, self.bomb_speed, 6) if event.key == pygame.K_8: bomb = Bomb(pos[0], 0, self.cities[5].rect.centerx, self.size[1] - self.city_width, self.bomb_speed, 7) if event.key == pygame.K_9: bomb = Bomb(pos[0], 0, self.bases[2].rect.centerx, self.size[1] - self.city_width, self.bomb_speed, 8) #if a bomb has been created, add it to the command_queue and to self.bombs if bomb != None: data = pickle.dumps(bomb) command_queue.put(data) bomb.gs = self self.bombs.append(bomb) self.nbombs = self.nbombs + 1 if self.TYPE == "Missiles": #fire missiles from bases with a, s, d. First make sure that there are enough missiles left in the base if event.key == pygame.K_a: if (self.bases[0].count > 0): self.bases[0].count = self.bases[0].count - 1 missile = Missile(self.bases[0].rect.centerx, self.size[1] - self.city_width, pos[0], pos[1], self.missile_speed, 0) if event.key == pygame.K_s: if (self.bases[1].count > 0): self.bases[1].count = self.bases[1].count - 1 missile = Missile(self.bases[1].rect.centerx, self.size[1] - self.city_width, pos[0], pos[1], self.missile_speed, 1) if event.key == pygame.K_d: if (self.bases[2].count > 0): self.bases[2].count = self.bases[2].count - 1 missile = Missile(self.bases[2].rect.centerx, self.size[1] - self.city_width, pos[0], pos[1], self.missile_speed, 2) #if a missile has been created, add it to the command_queue and to self.missiles if missile != None: data = pickle.dumps(missile) command_queue.put(data) missile.gs = self self.missiles.append(missile)
def setUp(self): self.missile = DocumentMock() self.missile = Missile(self.missile) self.fp = FeaturePythonMock()
def fire(self): self.missileCount += 1 return Missile(-1, "missile", (self.posx + (self.imagew - 18), self.posy + (self.imageh)), 8, 32, self.row, self.col)
def _fire_missile(self): """Create a new missile and add it to the missiles group.""" if len(self.missiles) < self.settings.missiles_allowed: new_missile = Missile(self) self.missiles.add(new_missile)