def init(self): for x in range(8): temp = [] for y in range(8): # print(not blocksState[x][y] & 0x10 == 0) temp.append(block.Block(self.getPosX(x), self.getPosY(y))) self.blocks.append(temp) for x in range(8): for y in range(8): # print(not blodcksState[x][y] & 0x10 == 0) self.groups()[0].add(self.blocks[x][y]) self.redBomb = bomb.Bomb('red', 1200, 200) self.blackBomb = bomb.Bomb('black', 1200, 200) self.blackBomb.show() self.redBomb.setPos(1729, 18) self.groups()[0].add(self.blackBomb) self.board = over.Over() self.groups()[0].add(self.board) for _ in range(3): self.blackRadar.append(radar.Radar('black')) for _ in range(3): self.redRadar.append(radar.Radar('red')) for n in range(3): self.groups()[0].add(self.blackRadar[n]) self.blackRadar[n].setPos(18, n * 106 + 18) for n in range(3): self.groups()[0].add(self.redRadar[n]) self.redRadar[n].setPos(1814, n * 106 + 18) pygame.mouse.set_visible(False)
def _spawnBomb(self): randomNumber = random.randint(1, 3) if randomNumber == 1: randomPosition = random.randint(0, config.DISPLAY_WIDTH - 1), random.randint(0, config.DISPLAY_HEIGHT - 1) bomb = BOMB.Bomb(randomPosition, self._pygame) self.addBomb(bomb) self._bombTimer = 5
def loop(p): global score c = getch() getchtime = time.time() if getchtime - p[0] < level.man_time and c in ['w', 's', 'a', 'd']: return p if c == 'q': score += (level.enemy_no - enemies.__len__()) * 100 msg = "Your score is " + str(score) os.system('clear') b.print_message(msg) sys.exit(0) if c in ['w', 's', 'a', 'd', 'x', 'b', 'o']: if c == 'w': man.move_up(board_grid, man) elif c == 's': man.move_down(board_grid, man) elif c == 'a': man.move_left(board_grid, man) elif c == 'd': man.move_right(board_grid, man) elif c in ['x', 'b', 'o']: if bomb_list.__len__() == 0: bomb_list.append(bomb.Bomb(man, board_grid)) u = update() if u == 1: return TimeoutError p[0] = getchtime p[1] = c return p
def Plant_Bomb(self): if self.bomb_num > 0: tempbomb = bomb.Bomb() tempbomb.SetXY(self.x, self.y) self.bomblist.append(tempbomb) game_world.add_object(tempbomb, game_world.LAYER_ISSAC) self.bomb_num -= 1
def __init__(self, frame, time): self.bomb = bomb.Bomb(frame, time) self.totalStrikes = 0 self.state = 'ND' self.lastinput = 0 #Wii remote setup! self.wiiSetUp() self.keyinput = 0
def tick(self): """action in tick""" if self.bombs['max'] > self.bombs['current'] and \ random.randint(1, 100) < self.bombs['chance']: self.bombs['current'] += 1 self.objects.append(bomb.Bomb(self.pos_x + 1, self.pos_y, self)) direction = [] if self.pos_x > 2: direction.append(-1) if self.pos_x < self.max_x - len(self.sprite) - 1: direction.append(1) self.pos_x += random.choice(direction)
def main(): failcount = 0 print('Creating bomb with three modules.') b = bomb.Bomb(3) if (isinstance(b, bomb.Bomb)): testresult = 'PASS' else: testresult = 'FAIL' failcount += 1 print('Type test: ' + testresult) b.start() print('Checking number of modules in bomb') print(str(len(b.moduleList))) if (len(b.moduleList) == bomb.numModules): testresult = 'PASS' else: testresult = 'FAIL' failcount += 1 print('Module count test: ' + testresult) print('Checking initial states of bombs') b.checkModStates() print('Changing bomb states') b.moduleList[0].changeStateComplete() b.moduleList[1].changeStateIncomplete() b.moduleList[2].changeStateStrike() if (b.moduleList[0].getState() == 'COMPLETE' and b.moduleList[1].getState() == 'INCOMPLETE' and b.moduleList[2].getState() == 'STRIKE'): testresult = 'PASS' else: testresult = 'FAIL' failcount += 1 print('Change states test: ' + testresult) b.checkModStates() print("Tests finished running.") print("Tests failed: " + str(failcount))
def proccess_event(self, event): if not self.dead(): if event.type == pygame.KEYDOWN: if event.key == config.controls.web_shift: self.switch_movement_state() elif event.key == config.controls.venom: self.shoot() elif event.key == config.controls.bomb: for buzzy in wasp.all_wasps: if buzzy.webbed is True and buzzy.rect.colliderect(self.rect): bomb.Bomb(buzzy) elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: self.movement = True elif event.button == 3: for x in flingable.all_flingables: if x.get_rect().collidepoint(event.pos): self.fling_object = x x.grab() break for enemy in frog.all_frogs + wasp.all_wasps: if enemy.rect.collidepoint(event.pos): self.web_enemy = enemy break if self.fling_object is None and self.web_enemy is None: self.try_create_web(event.pos) elif event.type == pygame.MOUSEBUTTONUP: if event.button == 1: self.movement = False elif event.button == 3: if self.fling_object is not None: self.fling(event.pos) if self.web_enemy is not None: self.web_enemy = None self.web_enemy_time = 0 elif event.type == pygame.MOUSEMOTION: self.movement_target = Vec2d(event.pos)
def updateActor(self, interval, world): global posX, posY, testposX, testposY #update everything, this func is constantly updated super(Player, self).updateActor(interval, world) #init this class with the coordinates of the player checktile = CheckTile(posX, posY) #check tile to the right canMoveRight = checktile.checkright(world) #left canMoveLeft = checktile.checkleft(world) #up canMoveUp = checktile.checkup(world) #down canMoveDown = checktile.checkdown(world) """ pseudo code, ignore this canmoveto(x,y) posx+delta,posy posx,posy+delta posx-delta,posy posx,posy-delta check(x,y) check(x+w-1,y) check(x,y+w-1) check(x+w-1,y+w-1) """ #where does the player want to go #the var 'facing' was implemented for different sprites, depending on #where the player was facing at the current moment. if self.keyboard.isDown(pygame.K_LEFT) and canMoveLeft is True: direction0 = -1 direction1 = 0 testposX = posX - self.movespeed facing = "left" elif self.keyboard.isDown(pygame.K_RIGHT) and canMoveRight is True: direction0 = +1 direction1 = 0 testposX = posX + self.movespeed facing = "right" elif self.keyboard.isDown(pygame.K_UP) and canMoveUp is True: direction0 = 0 direction1 = -1 testposY = posY - self.movespeed facing = "up" elif self.keyboard.isDown(pygame.K_DOWN) and canMoveDown is True: direction0 = 0 direction1 = +1 testposY = posY + self.movespeed facing = "down" #drop the bomb when space is pressed elif self.keyboard.isClicked(pygame.K_SPACE): b = bomb.Bomb(posX + 32, posY + 32) world.addActor(b) direction0, direction1 = 0, 0 testposX = posX testposY = posY facing = "forward" #if nothing is pressed, do the following. else: direction0, direction1 = 0, 0 testposX = posX testposY = posY facing = "forward" #fulfill the task, move (if possible) #should be noted, the sprite moves indefinitely. #collision detection prevents the sprite from moving when it shouldn't #NB - coordinates of the sprite are taken from its upper left corner if posX in range(resoX - tilesizeX + 1) and posY in range(resoY - tilesizeY + 1): for i in range(self.movespeed): if posX < 0: for j in range(self.movespeed - 1): self.move(+1, 0) testposX += 1 facing = "left" print facing elif posX > resoX - tilesizeX: for k in range(self.movespeed - 1): self.move(-1, 0) testposX -= 1 facing = "right" print facing elif posY < 0: for l in range(self.movespeed - 1): self.move(0, +1) testposY += 1 facing = "up" print facing elif posY > resoY - tilesizeY: for m in range(self.movespeed - 1): self.move(0, -1) testposY -= 1 facing = "down" print facing self.move(direction0, direction1) posX = testposX posY = testposY #debug stuff global facingoutput global coordoutput if facingoutput is True: print facing if coordoutput is True: print "Pos", posX, posY
def dropBomb(self): if self.currentBomb > 0: self.currentBomb -= 1 b = bomb.Bomb(self) return b return None
def create_bomb(self): self.bomb = bomb.Bomb(self) self.add_bomb(self.bomb)
def deploy_bomb(self): if self.current_bomb > 0: self.current_bomb -= 1 return bomb.Bomb(self) return None
def set_bomb(self, bombs_group): bombs_group.add(bomb.Bomb(self.rect.x, self.rect.y, self.fire_length)) self.set_bomb_timer = pygame.time.get_ticks() self.can_set_bomb = False self.state = "wait" self.wait_timer = pygame.time.get_ticks()
def update(self, keys, screenWidth, window): if self.playerNumber == 1: #basic timer pour les shoots un par un if self.shootLoop > 0: self.shootLoop += 1 if self.shootLoop > 5: self.shootLoop = 0 for bmb in self.bombs: if self.__versus_player != None: if bmb.timeToExplode <= 0: if bmb.y - bmb.radius < self.__versus_player.hitbox[ 1] + self.__versus_player.hitbox[ 3] and bmb.y + bmb.radius > self.__versus_player.hitbox[ 1]: if bmb.x + ( 40 * 5 ) > self.__versus_player.hitbox[0] and bmb.x - ( 40 * 5) < self.__versus_player.hitbox[ 0] + self.__versus_player.hitbox[2]: self.__versus_player.hit() self.bombs.pop(self.bombs.index(bmb)) else: if bmb.y - bmb.radius < self.__versus_player.hitbox[ 1] + self.__versus_player.hitbox[ 3] and bmb.y + bmb.radius > self.__versus_player.hitbox[ 1]: if bmb.x + bmb.radius > self.__versus_player.hitbox[ 0] and bmb.x - bmb.radius < self.__versus_player.hitbox[ 0] + self.__versus_player.hitbox[2]: self.__versus_player.hit() self.bombs.pop(self.bombs.index(bmb)) if bmb.x < 800 and bmb.x > 0: bmb.x += bmb.velocity bmb.update(50) if bmb.timeToExplode <= 0: bmb.explode(window) else: self.bombs.pop(self.bombs.index(bmb)) if keys[pygame.K_DOWN] and self.shootLoop == 0: facing = 1 if self.left: facing = -1 if len(self.bombs) < 5: self.bombs.append( bomb.Bomb(int(self.x + self.width // 2), int(self.y + self.height // 2), facing, 10, self.playerNumber)) self.shootLoop = 1 if keys[pygame.KMOD_CTRL]: for bomb_explode in self.bombs: if bomb_explode.player == self.playerNumber: bomb_explode.explode(window) if keys[pygame.K_LEFT] and self.x > self.velocity: self.x -= self.velocity self.left = True self.right = False self.standing = False elif keys[ pygame. K_RIGHT] and self.x < screenWidth - self.width - self.velocity: self.x += self.velocity self.left = False self.right = True self.standing = False else: self.standing = True self.walkCount = 0 if not (self.isJumping): if keys[pygame.K_UP]: self.isJumping = True else: if self.jumpHeight >= -10: neg = 1 if self.jumpHeight < 0: neg = -1 self.y -= (self.jumpHeight**2) * 0.5 * neg self.jumpHeight -= 1 else: self.isJumping = False self.jumpHeight = 10 else: # basic timer pour les shoots un par un if self.shootLoop > 0: self.shootLoop += 1 if self.shootLoop > 5: self.shootLoop = 0 for bmb in self.bombs: if self.__versus_player != None: if bmb.timeToExplode <= 0: if bmb.y - bmb.radius < self.__versus_player.hitbox[ 1] + self.__versus_player.hitbox[ 3] and bmb.y + bmb.radius > self.__versus_player.hitbox[ 1]: if bmb.x + (40 * 5) > self.__versus_player.hitbox[0] and bmb.x - (40 * 5) < \ self.__versus_player.hitbox[0] + self.__versus_player.hitbox[2]: self.__versus_player.hit() self.bombs.pop(self.bombs.index(bmb)) else: if bmb.y - bmb.radius < self.__versus_player.hitbox[ 1] + self.__versus_player.hitbox[ 3] and bmb.y + bmb.radius > self.__versus_player.hitbox[ 1]: if bmb.x + bmb.radius > self.__versus_player.hitbox[0] and bmb.x - bmb.radius < \ self.__versus_player.hitbox[0] + self.__versus_player.hitbox[2]: self.__versus_player.hit() self.bombs.pop(self.bombs.index(bmb)) for bmb in self.bombs: if bmb.x < 800 and bmb.x > 0: bmb.x += bmb.velocity bmb.update(50) if bmb.timeToExplode <= 0: bmb.explode(window) else: self.bombs.pop(self.bombs.index(bmb)) facing = -1 if self.right: facing = 1 if keys[pygame.K_s] and self.shootLoop == 0: intx = int(self.x + self.width // 2) inty = int(self.y + self.height // 2) if len(self.bombs) < 5: self.bombs.append( bomb.Bomb(intx, inty, facing, 10, self.playerNumber)) if keys[pygame.K_a] and self.x > self.velocity: self.x -= self.velocity self.left = True self.right = False self.standing = False elif keys[ pygame. K_d] and self.x < screenWidth - self.width - self.velocity: self.x += self.velocity self.left = False self.right = True self.standing = False else: self.standing = True self.walkCount = 0 if not (self.isJumping): if keys[pygame.K_w]: self.isJumping = True else: if self.jumpHeight >= -10: neg = 1 if self.jumpHeight < 0: neg = -1 self.y -= (self.jumpHeight**2) * 0.5 * neg self.jumpHeight -= 1 else: self.isJumping = False self.jumpHeight = 10
def main(): # 游戏帧数: frame_num = 60 # 分数记录 score = 0 # 生成圣诞老人 mysanta = santa.Santa(bg_size) # 生成雪 mysnow = [] for i in range(30): mysnow.append(snow.Snow(bg_size)) # 生成炸弹 mybomb = pygame.sprite.Group() for i in range(10): mybomb.add(bomb.Bomb(bg_size)) # 生成糖果 mycandy = pygame.sprite.Group() for i in range(5): mycandy.add(goods.Candy(bg_size)) # 生成礼物 mypresent = goods.Present(bg_size) # 建立Clock类 clock = pygame.time.Clock() # 暂停操作 pause = False # 游戏结束操作 gameover = False # 建立延迟 delay = 100 # 载入暂停图片 pause_nor_image = pygame.image.load(r'images\pause1.png').convert_alpha() pause_pressed_image = pygame.image.load( r'images\pause2.png').convert_alpha() pause_nor_image = pygame.transform.scale(pause_nor_image, (50, 50)) pause_pressed_image = pygame.transform.scale(pause_pressed_image, (50, 50)) pause_rect = pause_nor_image.get_rect() pause_rect.right = width - 30 pause_rect.top = 10 resume_nor_image = pygame.image.load(r'images\resume1.png').convert_alpha() resume_pressed_image = pygame.image.load( r'images\resume2.png').convert_alpha() resume_nor_image = pygame.transform.scale(resume_nor_image, (80, 50)) resume_pressed_image = pygame.transform.scale(resume_pressed_image, (80, 50)) resume_rect = resume_nor_image.get_rect() resume_rect.midtop = pause_rect.midtop pause_image = pause_nor_image # 暂停操作 pause = False # 载入游戏开始画面 play_nor_image = pygame.image.load(r'images\play1.png').convert_alpha() play_pressed_image = pygame.image.load(r'images\play2.png').convert_alpha() play_rect = play_nor_image.get_rect() play_rect.center = width // 2, height // 2 + 100 play_image = play_nor_image # 载入yes yes_nor_image = pygame.image.load(r'images\yes1.png').convert_alpha() yes_pressed_image = pygame.image.load(r'images\yes2.png').convert_alpha() yes_rect = yes_nor_image.get_rect() yes_rect.center = width // 2 - 100, height // 2 + 150 yes_image = yes_nor_image # 载入no no_nor_image = pygame.image.load(r'images\no1.png').convert_alpha() no_pressed_image = pygame.image.load(r'images\no2.png').convert_alpha() no_rect = no_nor_image.get_rect() no_rect.center = width // 2 + 100, height // 2 + 150 no_image = no_nor_image # 开始状态 play = False # 圣诞老人图片切换 switch = 0 # 礼物计时器 PRESENTTIMER = 5 * frame_num # 面板载入 board_image = pygame.image.load(r'images\board.png').convert_alpha() board_image = pygame.transform.scale(board_image, (450, 300)) board_rect = board_image.get_rect() board_rect.midtop = (250, 50) # 音乐播放控制 music = False # 生命设置 life_num = 3 life_image = pygame.image.load(r'images\圣诞老人1.png').convert_alpha() life_image = pygame.transform.scale(life_image, (40, 40)) life_rect = life_image.get_rect() # 读入字体 score_font = pygame.font.Font(r'font\奇妙圣诞夜.ttf', 40) font1 = pygame.font.Font(r'font\奇妙圣诞夜.ttf', 50) # 阅读时间限制 timelimit = 0 # 获胜状态 win = False # 问题状态 question = 0 while True: if gameover: pygame.quit() sys.exit() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == MOUSEMOTION: if not play: # 开始按钮切换 if play_rect.collidepoint(event.pos): play_image = play_pressed_image else: play_image = play_nor_image else: if not win: if life_num > 0: # 暂停按钮切换 if not pause: if pause_rect.collidepoint(event.pos): pause_image = pause_pressed_image else: pause_image = pause_nor_image else: if pause_rect.collidepoint(event.pos): pause_image = resume_pressed_image else: pause_image = resume_nor_image else: # yes,no 按钮切换 if yes_rect.collidepoint(event.pos): yes_image = yes_pressed_image else: yes_image = yes_nor_image if no_rect.collidepoint(event.pos): no_image = no_pressed_image else: no_image = no_nor_image else: # yes,no 按钮切换 if yes_rect.collidepoint(event.pos): yes_image = yes_pressed_image else: yes_image = yes_nor_image if no_rect.collidepoint(event.pos): no_image = no_pressed_image else: no_image = no_nor_image elif event.type == MOUSEBUTTONDOWN: if not play: # 开始操作 if event.button == 1 and play_rect.collidepoint(event.pos): play = True # 播放背景音乐 pygame.mixer.music.play(-1) else: if not win: if life_num > 0: # 暂停操作 if event.button == 1 and pause_rect.collidepoint( event.pos): if pause == False: pause = True pause_image = resume_pressed_image pygame.mixer.music.pause() else: pause = False pause_image = pause_pressed_image pygame.mixer.music.unpause() else: if event.button == 1 and yes_rect.collidepoint( event.pos): life_num = 3 elif event.button == 1 and no_rect.collidepoint( event.pos): gameover = True else: if question == 1: if event.button == 1 and yes_rect.collidepoint( event.pos): timelimit += 1 elif event.button == 1 and no_rect.collidepoint( event.pos): gameover = True if question == 2: if event.button == 1 and yes_rect.collidepoint( event.pos): getpresent = True timelimit += 1 elif event.button == 1 and no_rect.collidepoint( event.pos): getpresent = False timelimit += 1 screen.blit(bg_image, (0, 0)) if not play: screen.blit(play_image, play_rect) screen.blit(board_image, board_rect) text1 = font1.render('MERRT CHRISTMAS', True, (255, 255, 255)) text2 = font1.render('TO MY BABY KY', True, (255, 255, 255)) screen.blit(text1, (60, 120)) screen.blit(text2, (100, 220)) else: if not gameover: if life_num > 0: if score > 10000: win = True if win: if not music: pygame.mixer.music.load( r'sound\We Wish You A Merry Christmas.ogg') pygame.mixer.music.set_volume(0.5) pygame.mixer.music.play(-1) music = True screen.blit(board_image, board_rect) timelimit += 1 if timelimit < 180: text1 = font1.render('CONGRATULATIONS!', True, (255, 255, 255)) screen.blit(text1, (40, 150)) elif timelimit == 180: question = 1 text1 = font1.render('DO YOU WANT', True, (255, 255, 255)) text2 = font1.render('A PRESENT ?', True, (255, 255, 255)) screen.blit(text1, (115, 120)) screen.blit(text2, (130, 200)) screen.blit(yes_image, yes_rect) screen.blit(no_image, no_rect) timelimit -= 1 elif timelimit > 180 and timelimit < 360: text1 = font1.render('BUT YOU NEED TO', True, (255, 255, 255)) text2 = font1.render('ANSWER SANTA WU', True, (255, 255, 255)) text3 = font1.render('A QUESTION', True, (255, 255, 255)) screen.blit(text1, (65, 100)) screen.blit(text2, (60, 175)) screen.blit(text3, (130, 250)) elif timelimit == 360: question = 2 text1 = font1.render('ARE YOU BOYFRIEND', True, (255, 255, 255)) text2 = font1.render('A HANDSOME BOY?', True, (255, 255, 255)) screen.blit(text1, (50, 120)) screen.blit(text2, (65, 200)) screen.blit(yes_image, yes_rect) screen.blit(no_image, no_rect) timelimit -= 1 else: if getpresent: text1 = font1.render('PASSWORD IS', True, (255, 255, 255)) text2 = font1.render('CKYISPIG1224', True, (255, 255, 255)) screen.blit(text1, (110, 120)) screen.blit(text2, (105, 200)) timelimit -= 1 else: text1 = font1.render('PLAY AGAIN!! : (', True, (255, 255, 255)) screen.blit(text1, (60, 150)) if timelimit > 540: win = False score = 0 else: if music and not getpresent: pygame.mixer.music.load(r'sound\jingle bells.ogg') pygame.mixer.music.set_volume(0.5) pygame.mixer.music.play(-1) music = False if not pause: # 礼物掉落 PRESENTTIMER -= 1 if PRESENTTIMER == 0: mypresent.reset() PRESENTTIMER = 5 * frame_num # 炸弹碰撞检测 bomb_down = pygame.sprite.spritecollide( mysanta, mybomb, False, pygame.sprite.collide_mask) if bomb_down: for each in bomb_down: each.active = False mysanta.active = False life_num -= 1 # 得分检测 candy_down = pygame.sprite.spritecollide( mysanta, mycandy, False, pygame.sprite.collide_mask) if candy_down: for each in candy_down: each.active = False score += 100 if mypresent.active: present_down = pygame.sprite.collide_mask( mysanta, mypresent) if present_down: mypresent.active = False score += 500 # 绘制圣诞老人 if mysanta.active: key_pressed = pygame.key.get_pressed() # 获取键盘状态 if key_pressed[K_a] or key_pressed[K_LEFT]: mysanta.move_left() if key_pressed[K_d] or key_pressed[K_RIGHT]: mysanta.move_right() if delay % 5 == 0: switch += 1 if switch == 9: switch = 0 else: mysanta.reset() delay = 0 switch = 0 screen.blit(mysanta.image[switch], mysanta.rect) # 延迟减少 delay -= 1 if delay == -99: delay = 0 # 绘制生命 for each in range(1, life_num + 1): screen.blit(life_image, (width - each * life_rect.width, height - life_rect.height)) # 绘制糖果 for each in mycandy: screen.blit(each.image, each.rect) if not each.active: each.reset() else: each.move() # 绘制礼物 if mypresent.active: mypresent.move() screen.blit(mypresent.image, mypresent.rect) # 绘制炸弹 for each in mybomb: screen.blit(each.image, each.rect) if not each.active: each.reset() else: each.move() if not pause: screen.blit(pause_image, pause_rect) else: screen.blit(pause_image, resume_rect) score_text = score_font.render('Score:' + str(score), True, (255, 255, 255)) screen.blit(score_text, (10, 5)) else: screen.blit(board_image, board_rect) text1 = font1.render('DO YOU NEED', True, (255, 255, 255)) text2 = font1.render('ANOTHER CHANCE ?', True, (255, 255, 255)) screen.blit(text1, (120, 120)) screen.blit(text2, (60, 220)) screen.blit(yes_image, yes_rect) screen.blit(no_image, no_rect) # 下雪 for each in mysnow: screen.blit(each.image, each.rect) each.move() pygame.display.flip() clock.tick(frame_num)
def bombing(self, timedelta): nuke = bomb.Bomb() self.add(nuke) launch_pos = self.game.get_cell_near_player() nuke.launch(launch_pos) print "Bombing @ " + str(launch_pos)
# poweruparray.append(powerup.shrink(7, 66)) colorama.init() starttime = time.time() leveltime = time.time() bombtime = time.time() if __name__ == "__main__": flag = 0 padd = paddle.paddle() ball = ball.Ball() initial_bricks() # os.system('aplay -q sound1.wav&') bombcount = 0 bombs = [] for i in range(11): bombs.append(bomb.Bomb()) init_power() while (1): obj = abc.Get() inp = abc.input_to(obj) if inp == 'p': global_var.play *= -1 if inp == 'l': global_var.level += 1 # os.system('aplay -q ./.wav&') leveltime = time.time() bombtime = time.time() if global_var.level >= 4: break global_var.paddle_mid = 50 global_var.paddle_start = 47
import time import _thread import sys import tty import termios from random import randint import board import person import bomberman import enemy import bomb bomber_man = bomberman.Bomberman() enemy = enemy.Enemy() bomb = bomb.Bomb() def input_thread(L): pos_dict = board.board.get_dict() fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) board.board.printscr() ch = sys.stdin.read(1) if (ch == 'd' and pos_dict['posx3'] + 4 < 132 and pos_dict['arr'][pos_dict['posy0']][pos_dict['posx3'] + 4] != '#' and pos_dict['arr'][pos_dict['posy0']][pos_dict['posx3'] + 4] != 'X'
def set_bomb(self, bombs_group): bombs_group.add(bomb.Bomb(self.rect.x, self.rect.y, self.fire_length))
green = (10, 123, 10) blue = (0, 0, 100) bg_color = green window_width = 992 window_height = 800 FPS = 30 level = map.Map(32) level.load_map("mapa2") neuralnet = neuralnetwork.neuralnetwork() entity_manager = entity_manager.Entity_manager() entity_manager.add(bomb.Bomb(7, 12, "bomba.gif", level, neuralnet)) entity_manager.add(bomb.Bomb(8, 15, "bomba.gif", level, neuralnet)) entity_manager.add(bomb.Bomb(11, 5, "bomba.gif", level, neuralnet)) entity_manager.add(trash.Trash(15, 4, "bomba.gif", level, neuralnet)) entity_manager.add(bomb.Bomb(3, 7, "bomba.gif", level, neuralnet)) entity_manager.add(saper.Saper(4, 3, 0, "saper.gif", level, entity_manager)) #-------------------------------------------------------------------------------- gameDisplay = pygame.display.set_mode((window_width, window_height)) pygame.display.set_caption('Inteligentny Saper') clock = pygame.time.Clock() gameExit = False while not gameExit: #game_loop for event in pygame.event.get(): #event_loop
self.addManAt(man, (nx, ny)) self.addFootsteps((nx, ny), (dx, dy)) def screenLocation(self, (x, y)): """Return the screen location of a cell""" px, py = self.layout.getCoords((x, y)) return px + self.x - self.width / 2, py + self.y - self.height / 2 def dropBomb(self, man): """Drop a bomb at a man's location""" x, y = self.men[man] self.dropBombAt((x, y)) def dropBombAt(self, (x, y), auto_explode=True): """Drop a bomb at a location""" new_bomb = bomb.Bomb(self, auto_explode=auto_explode) self.world.addActor(new_bomb) self.addManAt(new_bomb, (x, y)) # # Mark squares around the bomb as dangerous if new_bomb.auto_explode: w, h = self.size # for direction in 'nesw': dx, dy = serge.blocks.directions.getVectorFromCardinal( direction) for i in range(new_bomb.max_distance + 1): safe_time = new_bomb.fuse + ( i + 2 ) * new_bomb.propagation_time + new_bomb.explosion_time if 0 < x + dx < w and 0 < y + dy < h:
def fire(self): b = bomb.Bomb(self.mX + self.mWidth/2, self.mY + (self.mHeight + 1), self.mWorldWidth, self.mWorldHeight) return b
def deployBomb(self): if self.currentBomb > 0: self.currentBomb -= 1 b = bomb.Bomb(self, self.isGraphics) return b return None
def dropBomb(self): if self.avail_bombs >0: self.avail_bombs-=1 bomb.Bomb(self.game, self.rect.x,self.rect.y)