def __init__(self, width, height, title): # Window initializing code self.win_size = width, height self.win = pygame.display.set_mode((width, height)) pygame.display.set_caption(title) self.running = True self.background = (0, 0, 0) # Pymunk initializing code pymunk.pygame_util.positive_y_is_up = False self.space = pymunk.Space() self.space.gravity = 0, 700 # Create game objects self.ground = Ground(self.win_size[0], 150, self.win_size) self.player1 = Tank("red") self.player2 = Tank("blue") self.bullets = [] # Setup code self.current_player = self.player1 self.other_player = self.player2 self.moves_left = 100 self.shoot_wait = 380 self.shooting = False self.player1.body._set_position((100, 250)) self.player2.body._set_position((width-136, 250)) # Add game objects to space self.ground.add_to_space(self.space) self.player1.add_to_space(self.space) self.player2.add_to_space(self.space)
def __init__(self, mw, ball): #self.mw = mw self.ground = Ground() self.points = [0 for _ in range(9)] self.records = [] self.sumrecords = [] self.games = 0 self.top_players = [Player(True, i, mw) for i in range(9)] self.bottom_players = [] for i in range(9): if i == 0: p = Pitcher(False, i, mw) elif i == 1: p = Catcher(False, i, mw) elif i == 2: p = First(False, i, mw) elif i == 3: p = Second(False, i, mw) elif i == 4: p = Third(False, i, mw) elif i == 5: p = Short(False, i, mw) else: p = Player(False, i, mw) self.bottom_players.append(p) self.ball = ball
def __init__(self): pygame.init() self.camera = Vector2(400, 0) self.ground = Ground() self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode((screenWidth, screenHeight)) self.player = Player()
def reset(self, lives: int, settings: dict, score: int): self._settings = settings self._arena = Arena((ARENA_W, ARENA_H)) self._arena.add_to_score(score) Mountain(self._arena, (MOUNTAIN_X, MOUNTAIN_Y)) Hill(self._arena, (HILL_X, HILL_Y), self._settings['level']) self._ground = Ground(self._arena, (GROUND_X, GROUND_Y), self._settings['difficulty']) self._start_time = time() self.bg_list = [Mountain, Hill, Ground] self._time_to_generate_alien = time() self._hero = [] self._hero.append(Rover(self._arena, (ROVER_X, ROVER_Y), 1)) if self._settings['mode'] == 'co-op': self._hero.append(Rover(self._arena, (ROVER_2_X, ROVER_2_Y), 2)) self._start = time() self._playtime = 80 self.hero_lives = lives self._aliens = [] self._obstacles = [] self._type_obstacles = [Rock, Hole] self._rand_x_bomb = 0 self._time_to_generate_bomber = time() self._bomb_ready = False self._second = time() if self._settings['difficulty'] == 'Easy': self.OBS_RANGE = 400 elif self._settings['difficulty'] == 'Normal': self.OBS_RANGE = 300 else: self.OBS_RANGE = 200
def __init__(self): """Initialize the game, and create game resources.""" pygame.init() self.settings = Settings() self.stats = GameStats(self) self.screen = pygame.display.set_mode( (self.settings.screen_width, self.settings.screen_height)) # Fullscreen mode #self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) #self.settings.screen_width = self.screen.get_rect().width #self.settings.screen_height = self.screen.get_rect().height self.block = Block(self) self.bowser = Bowser(self) self.ground = Ground(self) self.axe = Axe(self) self.fireballs = pygame.sprite.Group() self.iceballs = pygame.sprite.Group() self.gravity = self.settings.gravity self.groundY = 0 # Make the Play button. self.play_button = Button(self, "Play")
class Game(object): def __init__(self): pygame.init() self.camera = Vector2(400, 0) self.ground = Ground() self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode((screenWidth, screenHeight)) self.player = Player() def logicLoop(self): self.camera_control() self.player.logic(self) def camera_control(self): lerp = 0.1 self.camera.x += (self.player.bounds.x - screenWidth / 2 - self.camera.x) * lerp self.camera.y += (self.player.bounds.y - screenHeight / 2 - self.camera.y) * lerp def drawLoop(self): self.screen.fill(0) self.player.draw(self.screen, self.camera) self.ground.draw(self.screen, self.camera) pygame.display.flip()
def __init__(self): self.running = False self.window = pygame.display.set_mode( (self.WIN_WIDTH, self.WIN_HEIGHT)) self.clock = pygame.time.Clock() self.score = 0 self.bird = Bird(230, 350) self.ground = Ground(730) self.pipes = [Pipe(600)]
def __init__(self): self.display = (1000, 800) # window'un boyutlari self.mouseX = 0 # mouse hareketinin x koordinati self.mouseY = 0 # mouse hareketinin y koordinati self.flag = False self.flag2 = False self.currentValue = 0 self.antenna = Antenna() self.plane = Plane() self.ground = Ground(100, 100) # ground'un boyutlari self.sidebar = SideBar()
def __init__(self): """ Constructor """ pygame.init() pygame.mixer.init() # Load game icon self.game_icon = pygame.image.load('images/game/icon.png') pygame.display.set_icon(self.game_icon) self.settings = Settings() # Set screen dimensions. self.SCREEN_HEIGHT, self.SCREEN_WIDTH = self.settings.screen_height, self.settings.screen_width pygame.display.set_caption("Flappy Unicorn") self.screen = pygame.display.set_mode( (self.SCREEN_WIDTH, self.SCREEN_HEIGHT)) self.screen_rect = self.screen.get_rect() self.game_active = False self.game_over = False self.pillar_time_elapsed = 0 self.cloud_time_elapsed = 0 self.clock_tick = 0 # Audio instance. self.audio = Audio() # Create start and game over screens. self.start_screen = StartScreen(self) self.game_over_screen = GameOver(self) # Create an animated flying unicorn self.unicorn = Unicorn(self) self.unicorn_sprite = pygame.sprite.Group(self.unicorn) # Create the background self.background = Background(self) # Create ground. self.ground = Ground(self) # Create cloud. self.clouds = pygame.sprite.Group() # Create pillar sprite group. self.pillars = pygame.sprite.Group() # Create the scoreboard. self.scoreboard = Scoreboard(self)
def __init__(self, parent=None, FRA=None): super().__init__(parent) self.isCorrect = None #사용자가 주어진 단어 입력 성공을 확인하는 변수이다 self.noTyping = None #사용자가 주어진 단어 입력 성공을 확인하는 변수이다 self.isClear = None #게임 종료 후 버튼이 눌렸는지 확인하기 위한 변수이다 self.timer = QBasicTimer() # QBasicTimer()=>timer events을 제공한다 self.timer.start( FRAME_PER_MS, self) # .start(int msec)=>주어진 msec주기로 타이머를 시작하거나 재시작한다 self.back1 = Ground() #배경 이미지를 가진 Ground객체를 생성한다 self.back1.setPos(0, GROUND_HEIGHT) # .setPos(x, y)=>위치를 지정한다 self.addItem(self.back1) # .addItem('')=>QGrahphicsScene에 항목을 추가한다 self.back2 = Ground() #배경 이미지를 가진 Ground객체를 생성한다 self.back2.x = 1000 #생성한 객체의 x좌표를 지정한다 self.back1.setPos(0, GROUND_HEIGHT) # .setPos(x, y)=>위치를 지정한다 self.addItem(self.back2) # .addItem('')=>QGrahphicsScene에 항목을 추가한다 self.user = User() #게임 진행 중인 사용자 이미지를 가진 User객체를 생성한다 self.user.setPos(180, 320) # .setPos(x, y)=>위치를 지정한다 self.addItem(self.user) # .addItem('')=>QGrahphicsScene에 항목을 추가한다 self.croco = Croco() #악어 이미지를 가진 Croco객체를 생성한다 self.croco.setPos(-130, 350) # .setPos(x, y)=>위치를 지정한다 self.addItem(self.croco) # .addItem('')=>QGrahphicsScene에 항목을 추가한다 self.house = House() #게임 성공의 목적지인 집의 이미지를 가진 House객체를 생성한다 self.house.setPos(700, 250) # .setPos(x, y)=>위치를 지정한다 self.addItem(self.house) # .addItem('')=>QGrahphicsScene에 항목을 추가한다 self.win = Win() #게임 성공했을 때의 사용자 이미지를 가진 Win객체를 생성한다 self.win.setPos(800, 390) # .setPos(x, y)=>위치를 지정한다 self.addItem(self.win) # .addItem('')=>QGrahphicsScene에 항목을 추가한다 self.win.setVisible(False) #self.win으로 생성한 객체를 보이지 않도록 지정한다 self.view = QGraphicsView( self) #QGrahicsView()=>구상한 QGraphicsScene을 시각화한다 self.view.setHorizontalScrollBarPolicy( Qt.ScrollBarAlwaysOff) #가로 방향 스크롤을 off로 설정한다 self.view.setVerticalScrollBarPolicy( Qt.ScrollBarAlwaysOff) #세로 방향 스크롤을 off로 설정한다 self.view.setFixedSize( SCREEN_WIDTH, SCREEN_HEIGHT) # .setFixedSize()=>self.view의 크기 고정한다 self.setSceneRect( 0, 100, SCREEN_WIDTH, SCREEN_HEIGHT) # .setFixedSize()=>self.view의 시작 위치와 크기 고정한다
def _generate_platforms(self, game): ground1 = Ground(game) ground1.set_size_and_position(3 * 240, 3 * 16, 0, 3 * (226 - 16)) self.platforms.add(ground1) ground2 = Ground(game) ground2.set_size_and_position(3* 40, 3 * 16, 0, 3 * (226 - 64)) self.platforms.add(ground2)
def enter(): gfw.world.init([ 'bg', 'ground', 'enemy_melee', 'enemy_range', 'enemy_charge', 'bullet', 'player' ]) obj_gen.init() global stage_sel stage_sel = stage() global player player = Player() gfw.world.add(gfw.layer.player, player) global bg bg = Bg() bg.image = gfw.image.load(stage_sel.bg_selector()) gfw.world.add(gfw.layer.bg, bg) global ground ground = Ground() gfw.world.add(gfw.layer.ground, ground) global game_state game_state = STATE_IN_GAME global music_bg music_bg = load_wav('res/Bg_music.wav') music_bg.repeat_play()
def add_comp(self, comp, x, y): """ Adds a component to the sprite group of a given type and position""" xpos, ypos = self.grid_snap(x, y) new_component = None if comp == 'r': value = input('Please enter a resistor value (-1 to cancel): ') value = int(value) if not value == -1: new_component = Resistor(value, xpos, ypos) else: print('canceling') elif comp == 'v': value = 5 new_component = Voltage(value, xpos, ypos) self.vcc = new_component elif comp == 'g': value = 0 new_component = Ground(xpos, ypos) else: print('Not an existing component') #just for debugging if not new_component is None: self.components.add(new_component) self.graph.update({(xpos, ypos): (comp, value)}) #component info for analysis self.connections[new_component] = list() print(self.graph)
def enter(): gfw.world.init([ 'bg', 'ground', 'spine', 'jelly', 'h_item', 's_item', 'missile', 'skill_w', 'skill_f', 'skill_g', 'player' ]) global score score = 0 for n, speed in [(1, 10), (2, 100)]: bg = Background('cookie_run_bg_%d.png' % n) bg.speed = speed gfw.world.add(gfw.layer.bg, bg) global ground for l, sp in [(0, n_speed), (500, n_speed), (1000, n_speed), (1500, n_speed)]: ground = Ground(l, sp) gfw.world.add(gfw.layer.ground, ground) global font font = gfw.font.load('res/CookieRun.ttf', 30) global Select Select = cookie_state.Select global player player = Player(Select) gfw.world.add(gfw.layer.player, player)
def enter(): global stage, ground, hp, cookie, jelly, potion, jtrap, djtrap, strap global scoreLabel, Label global jelly_sound, item_sound, collide_sound stage = Stage() # 스테이지 ground = Ground() # 바닥 hp = HP() # 체력 cookie = Cookie() # 캐릭터 game_world.add_object(stage, game_world.layer_bg) game_world.add_object(ground, game_world.layer_bg) game_world.add_object(hp, game_world.layer_bg) game_world.add_object(cookie, game_world.layer_player) # 점수 label = score.Label("Score: ", 50, get_canvas_height() - 50, 45, 0) label.color = (255, 255, 255) score.labels.append(label) scoreLabel = label # 사운드 jelly_sound = load_wav('jelly.wav') jelly_sound.set_volume(32) item_sound = load_wav('item.wav') item_sound.set_volume(32) collide_sound = load_wav('collide.wav') collide_sound.set_volume(50)
def test_connect_database(self): g = Ground() self.assertTrue(g != None) s = Spider() self.assertTrue(s != None) h = Horace() self.assertTrue(h != None)
def enter(): global boy boy = Boy() game_world.add_object(boy, 1) ground = Ground() game_world.add_object(ground, 0)
def enter(): global ground, character, stage, hp global scoreLabel, Label global jelly_sound, collide_sound, item_eat character = Cookie() stage = Stage() ground = Ground() hp = HP() game_world.add_object(character, 1) game_world.add_object(stage, 0) game_world.add_object(ground, 0) game_world.add_object(hp, 0) label = score.Label("Score: ", 50, get_canvas_height() - 50, 45, 0) label.color = (255, 255, 255) score.labels.append(label) scoreLabel = label jelly_sound = load_wav('jelly.wav') jelly_sound.set_volume(32) item_eat = load_wav('item.wav') item_eat.set_volume(32) collide_sound = load_wav('collide.wav') collide_sound.set_volume(50)
def update(self): for col in self._map: for panel in col: if panel.is_road() and panel.update() == 1: ground = Ground(panel.point.x, panel.point.y) self.replace_panel(ground) self.i_manager.update()
def run_game(): pygame.init() settings = Settings() clock = pygame.time.Clock() #tela screen = pygame.display.set_mode(settings.SCREEN_DIMENSION) pygame.display.set_caption('Flappy Bird - Python') surface = pygame.image.load('images/bluebird-midflap.png') pygame.display.set_icon(surface) #objetos bird = Bird(settings, screen) ground = Ground(screen, settings) button = Button(screen, settings) game_over = GameOverButton(screen, settings) score = Scoreboard(screen) #grupos ground_group = Group() pipe_up_group = Group() pipe_down_group = Group() #adições ground_group.add(ground) #------------------------------------------------------------------------------------------------------------------- while True: clock.tick(30) function.check_events(bird, screen, settings, pipe_up_group, pipe_down_group, score) function.update_screen(screen, bird, settings, ground_group, button, game_over, pipe_up_group, pipe_down_group, score)
def run_game(): pygame.init() dino_settings = Settings() screen = pygame.display.set_mode((dino_settings.screen_width, dino_settings.screen_height)) pygame.display.set_caption("dino") score = float(0) while True: ground = Ground(dino_settings, screen) dinosaur = Dinosaur(dino_settings, screen) clouds = Group() birds = Group() cactus = Group() gf.create_clouds(dino_settings, screen, clouds) gf.create_birds(dino_settings, screen, birds) gf.create_cactus(dino_settings, screen, cactus) sb = Scoreboard(dino_settings, screen) while not dinosaur.dead: gf.check_events(dinosaur) ground.update() dinosaur.update() score += 3 dino_settings.score = int(score) sb.prep_score() gf.update_clouds(dino_settings, screen, clouds) gf.update_birds(dino_settings, screen, birds, dinosaur) gf.update_cactus(dino_settings, screen, cactus, dinosaur) gf.update_screen(dino_settings, screen, ground, clouds, dinosaur, cactus, birds, sb) while dinosaur.dead: exit_game = False for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: mouse_x, mouse_y = pygame.mouse.get_pos() if button.rect.collidepoint(mouse_x, mouse_y): exit_game = True if exit_game: if dino_settings.score > dino_settings.high_score: dino_settings.high_score = dino_settings.score sb.prep_high_score() dino_settings.score = 0 score = 0 break button = Button(dino_settings, screen) button.blitme() pygame.display.flip()
def __init__(self): pygame.init() self.w = 576 self.h = 1024 self.clock = pygame.time.Clock() self.win = pygame.display.set_mode((self.w, self.h)) self.gameOverBoucle = False pygame.display.set_caption("Flappy Bird") self.bg = pygame.image.load("assets/bg1.png").convert_alpha() self.startingimage = pygame.image.load( "assets/startingscreen.png").convert_alpha() self.launch = False self.list_pipes = [] self.bird = Bird(self.w // 6, 400 - 25) self.ground = Ground() self.score = Score()
def __init__(self, bg): self.bg = bg #self.x, self.y = 64 * 6, 64 * 2 + 32 # 32 = 플레이어 높이 // 2 self.x = 64 * 6 # 전체 백그라운드 중에서 드로우 좌표 self.y = 360 + 64 * 3 + 32 # 전체 백그라운드 중에서 드로우 좌표 self.canvas_width = get_canvas_width() self.canvas_height = get_canvas_height() self.image = load_image('image\Player\Idle.png') self.runImage = load_image('image\Player\Run.png') self.jumpImage = load_image('image\Player\Jump.png') self.attackImage = load_image('image\Player\Attack.png') self.image_dash = load_image('image\dash_effect.png') self.hurtImage = load_image('image\Player\Hurt.png') self.dir = 1 self.jump_timer = 0.1 self.jumped = False self.workingJump = True self.stop_jump_while_dash = 0 self.dash_timer = 0 self.velocity = 0 self.velocityOnY = 0 self.fall_speed = 400 self.jumping = False self.frame = 0 self.attackFrame = 0 self.hurtFrame = 0 self.hurting = False self.invincibilityTime = 10 self.HP = 100 self.STR = 30 self.INT = 50 self.attack_count = 0 self.coinCount = 0 self.groundList = Ground.groundList self.groundYList = Ground.groundYList self.ax = 0 self.bx = 0 self.ay = 0 self.by = 0 self.ground0 = Ground(0, self.bg) self.ground1 = Ground(1, self.bg) self.ground2 = Ground(2, self.bg) self.ground3 = Ground(3, self.bg) self.ground4 = Ground(4, self.bg) self.ground5 = Ground(5, self.bg) self.ground6 = Ground(6, self.bg) self.chicken = None self.inCure = False self.onFire = False self.onFlatform = False self.potionHealthy = 40 self.itemList = [[], [], []] # Item self.magicList = [[], [], []] # Magic self.fireSpellCount = 0 self.light = None self.fire = None self.font = load_font('ConsolaMalgun.ttf') self.event_que = [] self.cur_state = IdleState self.cur_state.enter(self, None)
def enter(): server.boy = Boy() game_world.add_object(server.boy, 1) server.zombie = Zombie() game_world.add_object(server.zombie, 1) server.ground = Ground() game_world.add_object(server.ground, 0)
def setup(): window = pygame.display.set_mode((WIDTH, HEIGHT)) player = Bird(200, 200) base = Ground(HEIGHT - ground.GROUND_IMG.get_height() / 2) pipes = [Pipe(700)] running = True simulation_speed = 30 clock = pygame.time.Clock() add_pipe = False while running: clock.tick(simulation_speed) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: player.jump() player.update() base.update() for pipe in pipes: if pipe.collide(player): print("you lose") # no real game end if not pipe.passed and pipe.x < player.x: pipe.passed = True add_pipe = True if pipe.x + pipe.img.get_width() < 0: pipes.remove(pipe) if add_pipe: pipes.append(Pipe(700)) add_pipe = False pipe.update() draw(window, player, base, pipes)
def initEnemies(): x = 0 while (x < cfg.numPipes): pipeSet = PipeSet(x, enemy_list) pipeSets.append(pipeSet) x += 1 x = 0 while (x < cfg.numGround): ground = Ground(x) enemy_list.add(ground) x += 1
def enter(): global boy boy = Boy() game_world.add_object(boy, 1) global zombie zombie = Zombie() game_world.add_object(zombie, 1) ground = Ground() game_world.add_object(ground, 0)
def __init__(self, player): self.platform_list = pygame.sprite.Group() self.enemy_list = pygame.sprite.Group() self.chest_list = pygame.sprite.Group() self.teleporter_list = pygame.sprite.Group() self.player = player self.world_shift = 0 ground = Ground() wall = Wall() self.platform_list.add(ground) self.platform_list.add(wall)
def create_ground_slice(filename): with open(filename) as f: lines = f.readlines() clay_coords = set() for line in lines: raw_coords = line.strip().split(', ') intermediate_coords = parse_coordinates(raw_coords, reverse=line[0] == 'y') clay_coords = clay_coords.union(set(intermediate_coords)) return Ground(clay_coords)
def __init__(self, images, gravity=1): super(World, self).__init__() self.background = images['sky'] self.image = self.background.copy() self.scroll = cycle(range(self.background.get_width())) self.rect = self.image.get_rect() self.ground = Ground(images['ground'], self.rect.midleft) self.background.fill((33, 22, 7), self.ground.rect) self.gravity = gravity self.start_locs = [ tuple(map(add, (0, self.ground.rect.height), loc)) for loc in self.ground.start_locs ]
def __init__(self, window, data): self.window = window self.data = data Mob.data = data Human.data = data self.interface = Interface() self.ground = Ground() self.objects = Objects() self.player = Player() self.timer = sf.Clock() self.load_map("data/amd/elvine")
def startGame(self,fenetre): ground = Ground() # Tour par tour yellow = (0, 0, 0) while(self.continueGame == True): # Clear screen every turn os.system('cls' if os.name == 'nt' else 'clear') self.updateScore() currentPlayer = self.tour % 2 player = self.players[currentPlayer] #Update graphique myfont = pygame.font.SysFont("Arial", 35) labelTour = myfont.render(" Tour :" +str(self.tour), 2, yellow) fenetre.blit(labelTour, (600,250)) pygame.display.update(0, 0, 800, 600) #Quand les deux ont joues on invoque un nouveau terrain if( ( self.tour % 2 ) == 0): ground.groundAction(self.players) #Affichage console print("\n\n- Tour " + str(self.tour) + " -----------------\n") print("Hey "+player.name+ ", a ton tour, voici ta main -------\n") player.hand.pickCard(player.deck.getCard()) hasPlayCard = True while(hasPlayCard == True): player.hand.getHand() card = input("Quel carte souhaitez vous mettre en jeu ? (Entrée pour ne rien jouer et laisser son tour) ") #none if not card : print("\n ------- ! Attention: Vous n'avez jouer aucune carte ! \n") else: card = int(card) cardName = player.hand.getCard(card) print("Vous avez jouer " + cardName.name ) if cardName.type == "1" : print("il s'agit d'une carte special") self.specialAttack(cardName, player) else: player.playCard(card) hasPlayCard = False #ICI LES ATTAQUESSSSSSS if( self.tour >= 1): print("\n\n###### ATTAQUE\n") print("\n################# Vos cartes ") player.getCardsOnGame(); tmp = ((self.tour+1) % 2 ) playerO = self.players[tmp] #Aucun adversaire, le joueur perd 5 point direct if playerO.noCardOnGame() == True: playerO.popularity -= 5 player.popularity += 3 playerO.getCardsOnGame() print("\n\n --- STOP : Votre adversaire n'a aucune carte en jeu, vous ne pouvez pas l'attaquer\n\n") print("\n\n --- Vous gagnez 3 points de popularite - votre adversaire en perd 5\n\n") else: card0 = input("Avec quelle carte souhaite tu attaquer ? ") #none if not card0 : print("\n ------- ! Attention: Vous n'avez jouer aucune carte ! \n") elif int(card0) >= 0 : card0 = int(card0) card0 = player.getCard(card0) print("\n### Adversaire") playerO.getCardsOnGame(); print("\n\n\n") card1 = input("Quelle carte souhaite tu attaquer ? ") self.attackCard(currentPlayer, card0, playerO.getCard(int(card1))) # tmp = ((self.tour+1) % 2 ) playerO = self.players[tmp] if (player.popularity >= 100)or (playerO.popularity <= 0) : self.Winner = player self.Loser = playerO self.continueGame = False # if (playerO.popularity) >= 100 or (player.popularity <= 0): self.Winner = playerO self.Loser = player self.continueGame = False #Next self.tour += 1 #Winning game label = [] myfont = pygame.font.SysFont("Arial", 100) red = (210,2,2) green = (0,128,0) label.append(myfont.render("Vainqueur :" +str(self.Winner.name), 2, green)) label.append(myfont.render("Perdant :" +str(self.Loser.name), 2, red)) fenetre.blit(label[0], (50,10)) fenetre.blit(label[1], (50,500)) mireille = pygame.image.load("images/mireille.jpg").convert() fenetre.blit(mireille, (50,100)) pygame.display.update(0, 0, 800, 600) pygame.mixer.stop() pygame.mixer.music.load("datas/marseillaise.mp3") pygame.mixer.music.set_volume(1) pygame.mixer.music.play(1) pygame.display.set_caption("Hymne national") pygame.display.flip()
def run(self): while self.paused[0] == 1: pass sky = Sky(self.queue) sun = Sun(self.queue, 300, 100) moon = Moon(self.queue, 300, 100) ground = Ground(self.queue) time = 75 self.shared[0] = time day = 0 seasons = ["spring", "summer", "fall", "winter"] season = "spring" self.shared[2] = seasons.index(season) seasonStages = ["early", "mid", "mid", "late"] seasonStage = "mid" weatherOptions = ["clear", "clear", "clear", "clear", "cloudy", "cloudy", "overcast", "rain", "rain", "storm"] weather = choice(weatherOptions) self.shared[1] = weatherOptions.index(weather) self.queue.put(QueueItem("cont")) self.paused[0] = 1 self.paused[3] = 0 while self.paused[0] == 1: pass while True: sky.update(time) sun.update(time) moon.update(time, day) ground.update(time, season, seasonStage, seasons) sun.draw() moon.draw() ground.draw() time += 3 if time > 1600: time = 0 day += 1 if day > 15: day = 0 season = seasons[int(day/4)] self.shared[2] = seasons.index(season) seasonStage = seasonStages[day%len(seasonStages)] if season == "winter" and seasonStage == "early": weather = "rain" else: weather = choice(weatherOptions) self.shared[0] = time self.shared[1] = weatherOptions.index(weather) self.queue.put(QueueItem("cont")) self.paused[0] = 1 sleep(0.05) while self.paused[0] == 1: pass
class Game: def __init__(self, window, data): self.window = window self.data = data Mob.data = data Human.data = data self.interface = Interface() self.ground = Ground() self.objects = Objects() self.player = Player() self.timer = sf.Clock() self.load_map("data/amd/elvine") def run(self): clock = sf.Clock() fps = sf.Text() fps.position = (620, 10) self.loop = True while self.loop: for event in self.window.events: if type(event) is sf.CloseEvent: self.loop = False if type(event) is sf.KeyEvent: if event.code == sf.Keyboard.LEFT and event.pressed: self.window.view.move(-5, 0) elif event.code == sf.Keyboard.RIGHT and event.pressed: self.window.view.move(5, 0) elif event.code == sf.Keyboard.UP and event.pressed: self.window.view.move(0, -5) elif event.code == sf.Keyboard.DOWN and event.pressed: self.window.view.move(0, 5) self.update() self.window.clear() self.window.draw(self.ground) self.window.draw(self.objects) self.window.draw(self.interface) self.window.draw(fps) self.window.display() fps.string = str(1000/clock.restart().milliseconds)[:4] def update(self): elapsed_time = self.timer.restart() self.objects.update(elapsed_time) def load_map(self, filename): self.amd = Amd(filename) self.ground.load_map(self.amd, self.data.tiles) self.objects.load_map(self.amd, self.data.objects) def unload_map(self): pass