def bonus_triggered(self): # 觸發分數bonus if pygame.sprite.spritecollide(self.character, self.score_sprite, True): self.character.score += 1 self.bonus = Bonus() self.bonus.score() self.score_sprite.add(self.bonus) self.sound.bonusSound.play() # 觸發加速bonus elif pygame.sprite.spritecollide(self.character, self.shoes_sprite, True): #print("加速") ########改!! const.speed += 5 self.speed_up_time = 0 self.speed_up = True self.sound.speedSound.play() # 觸發回血bonus elif pygame.sprite.spritecollide(self.character, self.heart_sprite, True): self.character.hp += 0.5 self.sound.hpSound.play()
class CakeCollector(object): cakeList = [] bombList = [] def __init__(self): self.bg = pygame.image.load("cake.png") self.bg2 = pygame.image.load("bomb.png") self.bg3 = pygame.image.load("cake2.png") self.cakeList = [(Cake()),(Cake()),(Cake()),(Cake()),(Cake()),(Cake()),(Cake()),(Cake()),(Cake()),(Cake())] self.bombList = [(Bomb()),(Bomb()),(Bomb())] self.bonus = Bonus() self.player = Player(100,400) self.gameOver = False def update(self,player, gameOver): for i in self.cakeList: i.update(player, gameOver) for j in self.bombList: j.update(player, gameOver) self.bonus.update(player, gameOver) def render(self,surface): for i in self.cakeList: i.render(surface,self.bg) for j in self.bombList: j.render(surface,self.bg2) self.bonus.render(surface,self.bg3) def setGameOver(self, gameOver): self.gameOver = gameOver
def assign_bonuses(ai_settings, screen, alien, number_aliens_x, number_rows, bonuses, ship): """Randomly decide if an alien should be assigned a bonus.""" if randint(0, number_aliens_x * number_rows) % ( ai_settings.bonus_chance[0]) == ai_settings.bonus_chance[1]: if ai_settings.level in range (6, 11): bonus = Bonus(screen, ai_settings, alien, ship, True) else: bonus = Bonus(screen, ai_settings, alien, ship) bonuses.add(bonus) if ai_settings.level < 6: bonuses.empty()
def can_drop(enemy): """ Метод ставит Bonus на Объектную карту. :param enemy: Параметр врага, который оставил после смерти Bonus. :return: None. """ set_object(enemy.position, Bonus(enemy.position))
def bonus_event(self): self.bonus = Bonus() # 添加分數bonus if self.bonus.type == "score": self.score_sprite.add(self.bonus) # 添加加速bonus elif self.bonus.type == "shoes": self.shoes_sprite.add(self.bonus) # 添加回血bonus elif self.bonus.type == "heart": ########改!! if self.character.hp <= 2.5: self.heart_sprite.add(self.bonus)
def end_lvl(self): """ Метод создания партала для перехода на сл. уровень. :return: None """ bonus = Bonus(self.position, portal=True, color=QColor(*COLOR_RED)) map.set_object(self.position, bonus) constants.SET_BONUS.add(bonus)
def boom(__): if __.des: if not randrange(3): Bonus(__.x, __.y) try: G.MURS.remove(__) except: pass
def spawn_bonus(self): x = randint(1, self.field.width - 1) y = randint(1, self.field.height - 1) if isinstance(self.field.level[y][x], EmptyCell): bonus = BonusesTypes.Roll[randint(*BonusesTypes.RollRange)] bonus = Bonus(self, x, y, bonus['name']) self.active_bonuses.add(bonus) return bonus return None
def hit(self, points): self.life -= points if self.life <= 0: self.gone = True self.scene.engine.player['score'] += (self.type + 1) * 10 self.scene.anibricks.add( AniBrick(self.scene, self.type, self.pos, self.size)) if self.type % 2 == 0 and random.randint(0, 1): self.scene.bonus.add(Bonus(self.scene, self.pos))
def __init__(self): self.bg = pygame.image.load("cake.png") self.bg2 = pygame.image.load("bomb.png") self.bg3 = pygame.image.load("cake2.png") self.cakeList = [(Cake()),(Cake()),(Cake()),(Cake()),(Cake()),(Cake()),(Cake()),(Cake()),(Cake()),(Cake())] self.bombList = [(Bomb()),(Bomb()),(Bomb())] self.bonus = Bonus() self.player = Player(100,400) self.gameOver = False
def playSnake(stdscr): curses.curs_set(0) # Hide the cursor! S = Snake(stdscr, l=4) B = Bonus(stdscr) L = LvlFile(0) draw(S, B, L, stdscr) num_frames = 0 frame_so_far = 0.0 stdscr.nodelay(1) while True: c = stdscr.getch() if c != -1: # So something actually happened... if c == ord('q'): break elif c == curses.KEY_UP: S.setDirection(DIR_NORTH) elif c == curses.KEY_RIGHT: S.setDirection(DIR_EAST) elif c == curses.KEY_DOWN: S.setDirection(DIR_SOUTH) elif c == curses.KEY_LEFT: S.setDirection(DIR_WEST) sleep(FRAME_DELAY) frame_so_far += FRAME_DELAY if frame_so_far > FRAME_LENGTH * FRAME_DELAY: frame_so_far = 0.0 num_frames += 1 # S Should move now try: S.move() except CollisionException: # Hit something! break except BonusException: S.lengthen() B = Bonus(stdscr) S.addToScore(10) draw(S, B, L, stdscr)
def spawn_bonus(self, x, y): self.choix = random.randint(0,8) if self.choix == 0: self.image = pygame.image.load(os.path.join(os.path.dirname(__file__),'assets/BonusLigne.png')) self.bonus = Bonus(self, x, y,self.image) self.all_bonus.append(self.bonus) self.bonus.different = 1 elif self.choix == 1: self.image = pygame.image.load(os.path.join(os.path.dirname(__file__),'assets/bonus.png')) self.bonus = Bonus(self, x, y,self.image) self.all_bonus.append(self.bonus) self.bonus.different = 0 elif self.choix == 2: self.image = pygame.image.load(os.path.join(os.path.dirname(__file__),'assets/malus.png')) self.bonus = Bonus(self, x, y,self.image) self.all_bonus.append(self.bonus) self.bonus.different = 2
def __init__(self): super().__init__(W_X, W_Y, "Snake") self.score = pyglet.text.Label( "0", x=W_X, y=W_Y, anchor_x="right", anchor_y="top", ) self.chrono = 0 self.snake = Snake() self.bonus = Bonus() self.mort = False self.direction = STOP self.direction_stockee = HAUT pyglet.clock.schedule_interval(self.update, 1 / 10)
def clear_sectors(self, map, bonuses): for i in self.sectors: for bonus in bonuses: if (bonus.x == i[0]) and (bonus.y == i[1]): bonuses.remove(bonus) if map[i[0]][i[1]] != 0: map[i[0]][i[1]] = 0 rand_bonus = choice([0, 0, 0, 0, 0, 0, 1, 1, 2, 2]) if rand_bonus != 0: bonuses.append(Bonus(i[0], i[1], rand_bonus))
def __init__(self, screen): super(Level2, self).__init__(screen) self.id = 2 self.should_exit = False self.background = image.load("assets/background.png").convert_alpha() self.player = Player() self.players = sprite.Group([self.player] + self.load_shields()) self.player_bullets = sprite.Group() self.aliens = sprite.Group([Pechatron()]) self.alien_bullets = sprite.Group() self.bonus = sprite.Group([Bonus()])
class TestBonus(unittest.TestCase): def setUp(self): self.bonus = Bonus(WINDOWWIDTH/2, 5, "rheart.png", 1) def test_position(self): self.assertEqual(self.bonus.x, WINDOWWIDTH/2) self.assertEqual(self.bonus.y, 5) def test_bonus_has_image(self): self.assertIsNotNone(self.bonus.image, 'The hero doesn\'t have an image') def test_bonus_rect(self): self.assertIsInstance(self.bonus.rect, pygame.Rect) def test_bonus_type(self): self.assertEqual(self.bonus.bonus_type, 1) def test_get_bonus(self): start_pos = self.bonus.x self.bonus.get_bonus() self.assertEqual(self.bonus.y, 5 + BONUS_SPEED)
def death(self): """ Метод смерти и дропа Bonus после смерти, если это последний монстр на карте, дроп партала на сл. уровень. :return: None """ map.set_object(self.position, None) constants.LIST_ENEMY.remove(self) if len(constants.LIST_ENEMY) == 0: self.end_lvl() else: bonus = Bonus(self.position) map.set_object(self.position, bonus) constants.SET_BONUS.add(bonus) if self.screen: self.anime_enemy.clear()
def check_hp(self, scene): if self.health <= 0: scene.removeItem(self) scene.enemys.remove(self) for bullet in self.bullets: scene.removeItem(bullet) scene.player.score += self.value explosion = Explosion(self.rect.center(), 'BIG') scene.addItem(explosion) scene.play_sound('explosion') scene.map.objects.append(explosion) if self.isBonus: bonus = Bonus() scene.map.objects.append(bonus) scene.addItem(bonus)
def test_move_bonus(self): map.read_map('map\map.txt') direction = 'right' self.player.position = [1, 1] bonus = Bonus([2, 1]) map.set_object(self.player.position, self.player) map.set_object(bonus.position, bonus) maybe_new_position = list(self.player.position) maybe_new_position[0] += self.player.step self.player.move(direction) self.assertEqual(map.get_object(maybe_new_position), map.get_object(self.player.position))
def check_events(self): for evt in event.get(): if evt.type == QUIT: self.should_exit = True self.running = False elif evt.type == CUSTOM_EVENTS['ADD_PLAYER_BULLET']: if len(self.player_bullets) < 2: self.player_bullets.add(evt.particle) elif evt.type == CUSTOM_EVENTS['ADD_ALIEN_BULLET']: if len(self.alien_bullets) < 4: self.alien_bullets.add(evt.particle) elif evt.type == CUSTOM_EVENTS['ADD_BONUS']: self.bonus.add(Bonus()) elif evt.type == CUSTOM_EVENTS['ADD_BONUS_BULLET']: self.alien_bullets.add(evt.particle)
def destroy(self): from breakout import bricks if random.choice([ True, False, False, 0, 0, 0, 0, 0, ]): bonus = Bonus(self.x, self.y) from breakout import bonuses bonuses.append(bonus) bricks.remove(self)
def _check_rockets_meteor_collision(self): """Обработка коллизий ракет с метеорами.""" # Проверка попаданий в метеор. # При обнаружении попадания удалить ракеты и метеор. collisions = pygame.sprite.groupcollide(self.rockets, self.meteors, False, False) if collisions: for element in collisions.values(): for el in element: collision_rezult = randint( 0, (self.settings.bonus_type_number * 2) - 1) if collision_rezult % 2 == 0: bonus_type = collision_rezult // 2 new_bonus = Bonus(self, el, bonus_type) self.bonuses.add(new_bonus) self.meteors.remove(el)
def create_room(self, x=1, y=1): room = Room(self.room_size) for i in range(self.room_size): block_width = self.width block_height = self.height block_x = (x * self.room_size + i * i) * block_width block_y = round((i * math.sin(y * self.room_size + i) * block_width) + (y * self.room_size + 0) * block_height) room.blocks.append( Block(block_x, block_y, block_width, block_height, '/images/ground.png').convert_to_json()) block_x = (x * self.room_size + i) * block_width block_y = round((random.randint(0, self.room_size) * math.sin(y * self.room_size + i) * block_width) + (y * self.room_size + 0) * block_height) room.blocks.append( Block(block_x, block_y, block_width, block_height, '/images/ground.png').convert_to_json()) block_x = random.randint(x * block_width, x * self.room_size * block_width) block_y = random.randint(y * block_width, y * self.room_size * block_width) room.blocks.append( Bonus(block_x, block_y, block_width, block_height).convert_to_json()) block_x = random.randint(x * block_width, x * self.room_size * block_width) block_y = random.randint(y * block_width, y * self.room_size * block_width) teleport = Trigger(block_x, block_y, block_width, block_height, "teleport") room.blocks.append(teleport.convert_to_json()) return {'blocks': room.blocks}
def check_events(self): for evt in event.get(): if evt.type == QUIT: self.should_exit = True self.running = False elif evt.type == CUSTOM_EVENTS['ADD_ALIEN']: self.aliens.add(load_aliens(randint(0, 4), randint(0, 8))) time.set_timer(CUSTOM_EVENTS['ADD_ALIEN'], randint(5000, 10000)) elif evt.type == CUSTOM_EVENTS['ADD_PLAYER_BULLET']: if len(self.player_bullets) < 2: self.player_bullets.add(evt.particle) elif evt.type == CUSTOM_EVENTS['ADD_ALIEN_BULLET']: if len(self.alien_bullets) < 6: self.alien_bullets.add(evt.particle) elif evt.type == CUSTOM_EVENTS['ADD_BONUS']: self.bonus.add(Bonus()) elif evt.type == CUSTOM_EVENTS['ADD_BONUS_BULLET']: self.alien_bullets.add(evt.particle)
def check_events(ai_settings, screen, stats, ship, aliens, bullets, COUNT, bonus, meteors, meteor_images, shoot_sound, p_button, quit_button): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: check_keydown_events(event, ai_settings, stats, screen, ship, bullets, shoot_sound) elif event.type == pygame.KEYUP: check_keyup_events(event, ship) elif event.type == pygame.MOUSEBUTTONDOWN: mouse_x, mouse_y = pygame.mouse.get_pos() check_button(stats, p_button, quit_button, mouse_x, mouse_y) elif event.type == COUNT and stats.game_active: new_bonus = Bonus(screen, ai_settings) bonus.add(new_bonus) for i in range(6): new_meteor = Meteor(screen, ai_settings, meteor_images) meteors.add(new_meteor)
def close(self): self.mainWindows.setCentralWidget(Bonus(self.mainWindows))
def test_moveable_obj_overlap(): bonus = Bonus() scene.addItem(bonus) scene.map.objects.append(bonus) player.processing_overlap(scene, bonus) assert player.bonus is not None
client.connect((target_host, target_port)) INSTRUKCJA = pygame.image.load('Instrukcje.png') TEXT = pygame.image.load('txt.png') pygame.font.init() myfont = pygame.font.SysFont('monospace', 25) small_font = pygame.font.SysFont('monospace', 15) while (1): done = False p = Players(pygame) b = Bullets() m = Meteors(pygame) e = Enemies(pygame) bo = Bonus(pygame) g = Game() while (1): menu_ret = Menu() if menu_ret == 1: break elif menu_ret == 2: instrukcja() elif menu_ret == 3: exit() screen.fill((0, 0, 0)) game_start_time = time.time()
def test_bonus_up_portal(self): bonus_d = Bonus(self.player.position, True) bonus_d.up_player() self.assertEqual(4, LIST_ENEMY.__len__())
def test_bonus_up(self): current_count_bomb = self.player.count_bomb bonus = Bonus(self.player.position) bonus.up_player() self.assertEqual(current_count_bomb + 0.5, self.player.count_bomb)
def setUp(self): self.bonus = Bonus(WINDOWWIDTH/2, 5, "rheart.png", 1)
def generateCmsTableWork(self): """子线程函数:生成提成表单并写入数据库""" try: dm = DataManager() src_dict, src_data = dm.get_table( self.dataSourceComboBox.currentText()) rul_dict, rul_data = dm.get_table(self.ruleComboBox.currentText()) calc_ratio = CalcRatio(rul_dict, rul_data) clt_dict, clt_data = dm.get_table( self.clientComboBox.currentText()) client_dict = {} # 映射关系:客户编号->该客户对应行 for row in clt_data: client_dict[row[clt_dict['客户编号']]] = row sht2_head, sht2 = dm.get_table(self.priceComboBox.currentText()) price = [] for row in sht2: price.append([ row[sht2_head['编号']], row[sht2_head['指导单价(未税)\n元/KG']], row[sht2_head['备注']], row[sht2_head['出货开始时间']], row[sht2_head['出货结束时间']] ]) sht4_head, sht4 = dm.get_table(self.managerComboBox.currentText()) slr_dict, slr_data = dm.get_table( self.aftersalesComboBox.currentText()) places = [] # 售后员表中的地点名 for row in slr_data: if row[1] != 'None': places.append([row[1], row[5], row[6]]) self.genProgressBar.setValue(10) # 每次增加的进度=剩余进度(90)/每个表的阶段数(3)/要生成的表数 piece = 30 / len([ x for x in [self.cmsLineEdit.text(), self.asCmsLineEdit.text()] if x != '' ]) if self.cmsLineEdit.text() != '': bs = Bonus(price) h1, r1, r2 = bs.calc_commission(src_dict, src_data, clt_dict, client_dict, rul_dict, rul_data, places, sht4) self.genProgressBar.setValue(self.genProgressBar.value() + piece) # 下面的h1应该是与ExcelCheck.headers["业务员提成明细"]完全相同的 dm.create_table("业务员提成明细", self.cmsLineEdit.text(), h1) self.genProgressBar.setValue(self.genProgressBar.value() + piece) dm.insert_data(self.cmsLineEdit.text(), h1, r1) self.genProgressBar.setValue(self.genProgressBar.value() + piece) self.generateCmsSignal.emit(self.cmsLineEdit.text()) self.cmsLineEdit.setText("") # 清空表名 if self.asCmsLineEdit.text() != '': after_sales = AfterSales(slr_dict, slr_data) as_header, as_content = after_sales.calc_commission( src_dict, src_data, clt_dict, client_dict, calc_ratio) self.genProgressBar.setValue(self.genProgressBar.value() + piece) # 下面的as_header应该是与ExcelCheck.headers["售后员提成明细"]完全相同的 dm.create_table("售后员提成明细", self.asCmsLineEdit.text(), as_header) self.genProgressBar.setValue(self.genProgressBar.value() + piece) dm.insert_data(self.asCmsLineEdit.text(), as_header, as_content) self.genProgressBar.setValue(self.genProgressBar.value() + piece) self.generateCmsSignal.emit(self.asCmsLineEdit.text()) self.asCmsLineEdit.setText("") # 清空表名 self.cmsTableGenPushButton.setEnabled(True) self.tableManagePushButton.setEnabled(True) self.tableViewPushButton.setEnabled(True) except Exception as e: logging.exception(e) QMessageBox.warning(self, "生成出错", str(e))
def bonus(self): self.setCentralWidget(Bonus(self)) self.enableTools()
bug = Bug(x=rand, speed=rand_speed) bug_army.append(bug) sprite_group.add(bug) # Створюємо не баги if len(bug_police) < 2: while len(bug_police) != 2: rand = random.randrange(10, 550) rand_speed = random.randrange(1, 5) notbug = NotBug(x=rand, speed=rand_speed) bug_police.append(notbug) sprite_group.add(notbug) if not bonus_array and int(timer.lost_time()) % 10 == 0: rand = random.randrange(10, 550) rand_speed = random.randrange(10, 11) bonus = Bonus(x=rand, speed=rand_speed) bonus_array.append(bonus) sprite_group.add(bonus) sprite_group.draw(screen) for b in bug_army: b.move(player, bug_army, suriken_move) for b in bug_police: b.move(player, bug_police, screen) for i in suriken_move: i.move(suriken_move) for i in bonus_array: i.move(player, bonus_array, timer) info_screen.blit(inf_font.render(u'Багов закрыто: '+str(player.bug_kill), 1, (212, 120, 49)), (10,5)) info_screen.blit(inf_font.render(u'Время до релиза: ' + str(int(timer.lost_time())), 1, (212, 120, 49)), (190, 5))
def draw(self, screen): """ Draw everything in game, such as panel, players, planets, bullets, bonuses, status bar. """ pl = self.players[self.active_player] coord = lambda x, y: (int(x), int(y)) scale = 1 if self.bullet is not None and\ not self.bullet.is_visible_near() and\ self.bullet.is_visible_far(): scale = 3 coord = lambda x, y: ( int(x / 3 + Options.Video.view_width / 3.0), int(y / 3 + Options.Video.height / 3.0) ) for player in self.players: angle = -player.heading / math.pi * 180 rotated = pygame.transform.rotozoom( self.images.spaceship[player.color], angle, 1.0 / scale) rect = rotated.get_rect() rect.center = coord(player.x, player.y) screen.blit(rotated, rect) for planet in self.planets: scaled = pygame.transform.scale(self.images.planets[planet.type], (planet.rad * 2 / scale + 1, planet.rad * 2 / scale + 1)) rect = scaled.get_rect() rect.center = coord(planet.x, planet.y) screen.blit(scaled, rect) if self.bonus is not None: b = self.bonus dw = b.dwh / 10 dh = -dw rect = pygame.Rect( coord(b.x - b.rad - dw, b.y - b.rad - dh), ((b.rad + dw) * 2 / scale, (b.rad + dh) * 2 / scale) ) # print rect # print b.x, b.y, b.rad, b.dwh, "->", dw, dh pygame.draw.ellipse(screen, Bonus.color(self.bonus.type), rect) if self.bullet is not None: bullet_color = (255, 255, 255) if self.bullet.bonustype is not None: bullet_color = Bonus.color(self.bullet.bonustype) pygame.draw.circle(screen, bullet_color, coord(self.bullet.x, self.bullet.y), 3 / scale) # draw panel pygame.draw.line(screen, (255, 255, 255), (Options.Video.view_width, 0), (Options.Video.view_width, Options.Video.height), 2) # draw pretty gradient as power half_box = Rect( self.Boxes.power_box.topleft, (self.Boxes.power_box.width, self.Boxes.power_box.height / 2) ) fill_gradient(screen, half_box, (255, 0, 0), (255, 255, 0)) half_box.centery += self.Boxes.power_box.height / 2 fill_gradient(screen, half_box, (255, 255, 0), (0, 255, 0)) coeff = pl.get_rest_power_coeff() empty_box = Rect( self.Boxes.power_box.topleft, (self.Boxes.power_box.width, int(self.Boxes.power_box.height * coeff)) ) pygame.draw.rect(screen, (0, 0, 0), empty_box) pygame.draw.rect(screen, (255, 255, 255), self.Boxes.power_box, 1) pygame.draw.rect(screen, (255, 0, 64), self.Boxes.fire_button_box, 1) if pl.bonustype is not None: pygame.draw.rect(screen, Bonus.color(pl.bonustype), self.Boxes.extra_button_box, 1) circle_rad = int(self.Boxes.extra_button_box.width * 0.5 * 0.8) pygame.draw.circle(screen, Bonus.color(pl.bonustype), self.Boxes.extra_button_box.center, circle_rad) # draw scores red_score = "Red score: %d" % self.players[0].score blue_score = "Blue score: %d" % self.players[1].score width, height = self.font_score.size(red_score) label = self.font_score.render(red_score, True, (192, 0, 0)) label_rect = pygame.Rect(5, 5, width, height) screen.blit(label, label_rect) width, height = self.font_score.size(blue_score) label = self.font_score.render(blue_score, True, (0, 0, 192)) label_rect.width, label_rect.height = width, height label_rect.right = Options.Video.view_width - 5 screen.blit(label, label_rect) if self.bullet is not None: timeout = "Timeout: %d" % (self.bullet.ttl / 5) label_rect.width, label_rect.height = self.font_ttl.size(timeout) label_rect.centerx = Options.Video.view_width / 2 label_rect.top = 12 label = self.font_ttl.render(timeout, True, (220, 220, 220)) screen.blit(label, label_rect)