def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs).__init__(vsync=False) self.frame_rate = 1 / FPS pyglet.clock.schedule_interval(self.update, self.frame_rate) # pyglet.clock.set_fps_limit(FPS) self.set_location(20, 20) self.keys = { key.A: False, key.W: False, key.D: False, key.S: False, key.TAB: False } # self.set_exclusive_mouse(True) self.mouse_down = False self.respawn = False self.buy_menu = False self.dc = False self.fps_draw = FPSDisplay(self) self.fps_draw.label.font_size = 50 self.fps_draw.label.anchor_y = "top" self.fps_draw.label.y = WINDOW_HEIGHT
def __init__(self, *args, **kwargs): super(GameWindow, self).__init__(*args, **kwargs) self.set_location(400, 100) self.frame_rate = 1 / 60.0 self.fps_display = FPSDisplay(self) self.fps_display.label.font_size = 50 self.fps_display.label.y = 300 self.right = False self.left = False self.player_speed = 300 self.fire = False self.player_fire_rate = 0 player_spr = pyglet.sprite.Sprite(preload_image('Carrot.png')) self.player = GameObject(500, 100, 0, 0, player_spr) self.player_laser = preload_image('laser.png') self.player_laser_list = [] self.grass_list = [] self.grass_img = preload_image('Grass.png') for i in range(3): self.grass_list.append( GameObject(0, i * 675, 0, -200, Sprite(self.grass_img)))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.keysDown = [] self.label = pyglet.text.Label("test", font_name='Times New Roman', font_size=36, x=self.width // 2, y=self.height // 2, anchor_x='center', anchor_y='center') self.space = pymunk.Space() self.options = DrawOptions() self.score = 0 self.playerCar = car.Car(self.space) self.course = walls.Walls(self.space) self.coins = coins.Coins(self.space) self.fps = FPSDisplay(self) self.nearestCoinPos = self.coins.usedCoinPos[0] handler = self.space.add_collision_handler(1, 2) handler.begin = self.hitWall coinHandler = self.space.add_collision_handler(1, 3) coinHandler.begin = self.collectCoin
def __init__(self, framework, fov_diag=math.radians(46.8)): super(LunarLanderWindow, self).__init__(resizable=True, visible=False, config=gl.Config(double_buffer=True, depth_size=24, stencil_size=1)) self.framework = framework self.push_handlers(framework.agent) self.simulator = framework.simulator self.dt = self.simulator.dt self.fov_diag = fov_diag self.scaleFactor = 100 self.load_resources() self.set_caption('Lunar Lander') self.fps_display = FPSDisplay(self) self.set_visible(True) self.start() pyglet.app.run() pyglet.clock.unschedule(self.update)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.settings = Settings()['game_window'] self.set_minimum_size(self.settings['min_size_x'], self.settings['min_size_y']) self.keys = key.KeyStateHandler() self.push_handlers(self.keys) pyglet.clock.schedule(self.update) self.how_far = self.settings['chunks'] self.fps_display = FPSDisplay(self) # self.fps_display.label.y = self.height - 50 # self.fps_display.label.x = self.width - 150 self.cross = pyglet.image.load('images/cross.png') self.label = pyglet.text.Label("", font_name='Times New Roman', font_size=18, x=self.width // 2, y=40, anchor_x='center', anchor_y='center') self.model = Model() self.y = 0 position = self.settings['player_start_position'] player_start_coords = (position['x'], position['y'], position['z']) player_start_rotation = (position['rot_x'], position['rot_y']) self.player = Player(self.model, player_start_coords, player_start_rotation)
def __init__(self, window, debug=False): self.window = window self.background_colour = pyglet.image.SolidColorImagePattern((143, 187, 247, 255)).\ create_image(window_width, window_height) self.world_batch = pyglet.graphics.Batch() self.background = pyglet.graphics.OrderedGroup(0) label_y_position = window_height - 35 self.score_label = pyglet.text.Label(text="Score: 0", x=10, y=label_y_position, font_size=24, bold=True, color=(255, 255, 255, 255)) self.lives_label = pyglet.text.Label(text="Lives: 0", x=200, y=label_y_position, font_size=24, bold=True, color=(255, 255, 255, 255)) self.level_label = pyglet.text.Label(text="Level: 0", x=340, y=label_y_position, font_size=24, bold=True, color=(255, 255, 255, 255)) self.fps_display = FPSDisplay(window) self.levels = [Level1(self), Level2(self)] self.on_new_level() self.draw_options = DrawOptions() self.debug = debug
def __init__(self): self.agent = agent super().__init__(windowWidth, windowHeight, gameName) # The game loop pyglet.clock.schedule_interval(self.update, 1 / 60.0) self.fps_display = FPSDisplay(self) self.player1 = Player(375, 50, (255, 0, 0)) self.player_laser = preload_image('laser.png') self.player1_laser_list = [] self.player2 = Player(375, 700, (0, 0, 255)) self.player2_laser_list = [] state_init1 = self.agent.get_state(self.player1_laser_list, self.player2, self.player1) #action = key.RIGHT #Dunno if I should do this yet action = [0, 0, 0, 0, 1] self.player2.do_move(action, self.player2.posx, self.player2.posy, self.player1, self.player2) state_init2 = self.agent.get_state(self.player1_laser_list, self.player2, self.player1) reward1 = agent.set_reward(self.player2, self.player2.death) agent.remember(state_init1, action, reward1, state_init2, self.player2.death) agent.replay_new(agent.memory)
def __init__(self, width=1152, height=720): super().__init__(width, height, vsync=False, caption="Spring Pendulum") self.refresh_rate = 500.0 self.fps = FPSDisplay(self) self.spring_pendulum = SpringPendulum(m=5) self.T = 0 self.is_playing = False
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_location(1000, 50) self.fps_draw = FPSDisplay(self) self.fps_draw.label.font_size = 50 self.fps_draw.label.y = 800 - 50 - 10 self.frame_rate = 1/60.0
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_minimum_size(200, 100) self.frame_rate = 1 / 60 self.fps_display = FPSDisplay(self) self.main_batch = pyglet.graphics.Batch() pyglet.clock.schedule_interval(self.update, self.frame_rate) pyglet.window.Window.switch_to(self) self.u = u self.g = g glClearColor(0.6, 0.7, 0.7, 1.0) gluPerspective(45.0, (1200 / 700), 1, -100.0) glTranslatef(0.0, 0.0, -(4 * self.u)) glEnable(GL_PROGRAM_POINT_SIZE) glEnable(GL_DEPTH_TEST) glLineWidth(4) self.frame = Frame(vertices) glLineWidth(1) self.window_x = 10 self.window_y = 10 self.grid = Grid(self.u) self.marker = Marker(self.u) self.color_rotate = [0, 1, 2, 3, 4, 5] # read the text data file data_file = open('res/datalist.txt') content = data_file.readline() data_file.close() # strip and split the file and turn it into a list of integers datalist = [int(x) for x in content.strip().split(',')] # plot the data self.scatter_plot = scatter self.scatter = ScatterPlot(datalist) # self.rotate_axis = 1 self.equation = [] self.eq_list = [] self.active = 0 self.eq = '' self.left = False self.right = False self.up = False self.down = False self.forward = False self.backward = False self.rotatexp = False self.rotatexn = False self.rotateyp = False self.rotateyn = False self.rotatezp = False self.rotatezn = False self.x_rot = 0 self.y_rot = 0 self.move = 10 # set the base translation speed # start with the greeting panel self.rotate_axis = 0 greet_panel = GreetWindow(100, 100, vsync=True) greet_panel.set_location(100, 150)
def __init__(self, width=1152, height=720, fullscreen=False): super().__init__(width, height, vsync=False, fullscreen=fullscreen, caption="Simple Pendulum") self.fps = FPSDisplay(self) self.T = 0 self.ball = Ball() self.run = False self.trace = [] pyglet.gl.glPointSize(10)
def __init__(self, *args, **kwargs): super(MyWindow, self).__init__(*args, **kwargs) #this clear thing affect the background color #comment it out to get a black background glClearColor(1, 1.0, 1.0, 1) self.fps_display = FPSDisplay(self) self.car = CarSprite() print(self.car.theta) self.key_handler = key.KeyStateHandler()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_location(100, 100) self.set_caption('Pong') self.set_mouse_visible(False) self.frame_rate = 1 / 60. self.fps_display = FPSDisplay(self) self.keys = key.KeyStateHandler() main_batch = pyglet.graphics.Batch() self.ai = True self.play_sounds = True if self.play_sounds: self.sounds = Sounds() self.paddle_left = Paddle('left', self.sounds, self.width, self.height, self.keys, self.ai) self.paddle_right = Paddle('right', self.sounds, self.width, self.height, self.keys) self.ball = Ball(self.sounds, self.width, self.height, self.keys) self.line = Line(self.width, self.height, self.keys) self.score_left = Score('left', self.width, self.height, '0', batch=main_batch) self.score_right = Score('right', self.width, self.height, '0', batch=main_batch) score = {'left': 0, 'right': 0} self.scores = [score, self.score_left, self.score_right] self.game_menu = True self.start_game = MenuItem(self.width, self.height, "Start Game", modifier=2) self.start_game.bold = True self.difficulty = MenuItem(self.width, self.height, "Difficulty: ", modifier=4) self.game_difficulty = 'normal' self.difficulty.label.text += self.game_difficulty self.exit_game = MenuItem(self.width, self.height, "Exit Game", modifier=6) self.menu_items = [self.start_game, self.difficulty, self.exit_game] self.current_index = 0 self.current_selection = self.menu_items[0].label
def __init__(self, width=1152, height=720, fullscreen=False): super().__init__(width, height, vsync=False, fullscreen=fullscreen, caption="Simple Pendulum") self.fps = FPSDisplay(self) self.T = 0 self.pendulums = [Pendulum(length=100)]
def __init__(self, *args, **kwargs): super(MyWindow, self).__init__(*args, **kwargs) #this clear thing affect the background color #comment it out to get a black background glClearColor(1, 1.0, 1.0, 1) self.fps_display = FPSDisplay(self) self.car = CarSprite() self.key_handler = key.KeyStateHandler() self.testTrack = Track([40, 60, 1200, 600], [240, 260, 800, 200]) self.testGrid = Grid(40, 60, 1200, 600, 50)
def __init__(self, aspect_ratio, dt_for_physicx, *args, **kwargs): super().__init__(*args, **kwargs) # set window location position = aspect_ratio.scale(300, 50) self.set_location(position.x, position.y) # framerate display self.fps = FPSDisplay(self) self.engine = GameEngine(aspect_ratio, dt_for_physicx) self.dt_for_physicx = dt_for_physicx self.remain_time_for_updating_physicx = dt_for_physicx
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.frame_rate = 1 / FPS self.fps_display = FPSDisplay(self) self.load_keyevent_dicts() self.wait_for_response = False self.update_queue = queue.Queue()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_location(300, 50) self.fps = FPSDisplay(self) self.space = pymunk.Space() self.options = DrawOptions() self.player = Player(self.space) self.ball = Ball(self.space, self.player.position) self.walls = Walls(self.space) self.bricks = Bricks(self.space)
class GameWindow(pyglet.window.Window): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_location(100, 100) self.frame_rate = 1/60.0 self.fps_display = FPSDisplay(self) self.fps_display.label.font_size = 24 # Hier wird der Pfad zum Verzeichnis des ».py«-Files gesetzt # Erspart einem das Herumgehample in TextMate mit dem os.getcwd() # und os.path.join() file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) self.space_list = [] self.space_img = preload_image("farback.gif") for i in range(2): self.space_list.append(GameObject(i*1782, 0, Sprite(self.space_img))) for space in self.space_list: space.velx = SPACESPEED player_spr = Sprite(preload_image_animation("Spritesheet_64x29.png", 4, 1, 64, 29)) self.player = GameObject(50, 300, player_spr) def on_key_press(self, symbol, modifiers): if symbol == key.UP: self.player.vely = PLAYERSPEED if symbol == key.DOWN: self.player.vely = -PLAYERSPEED def on_key_release(self, symbol, modifiers): if symbol in (key.UP, key.DOWN): self.player.vely = 0 def on_draw(self): self.clear() for space in self.space_list: space.draw() self.player.draw() self.fps_display.draw() def update_space(self, dt): for space in self.space_list: space.update(dt) if space.posx <= -1882: self.space_list.remove(space) self.space_list.append(GameObject(1682, 0, Sprite(self.space_img))) space.velx = SPACESPEED def update(self, dt): self.player.update(dt) self.update_space(dt)
def __init__(self, warpmap, dt_for_physicx, space, *args, **kwargs): super().__init__(*args, **kwargs) # set window location position = Vec2d(300, 50) self.set_location(position.x, position.y) self.warpmap = warpmap self.dt_for_physicx = dt_for_physicx self.remain_time_for_updating_physicx = dt_for_physicx self.space = space # framerate display self.fps = FPSDisplay(self)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_location(500, 50) self.fps = FPSDisplay(self) self.space = pymunk.Space() self.options = DrawOptions() self.player = Player(self.space) self.puck = Puck(self.space) self.rail = Rail(self.space)
def __init__(self, window, keys): """ window: the window for the game to be run in keys: <pyglet.window.key.KeyStateHandler> object that handles keys """ self.window = window self.keys = keys self.mouse_position = Vector2D() self.options = Options() self.show_fps = True self.fps_clock = FPSDisplay(self.window) self.player1 = Paddle(self.window, self.keys, 0) self.player2 = Paddle(self.window, self.keys, 1) self.players = self.player1, self.player2 self.puck = Puck(self.window) self.is_paused = False self.is_running = False self.menus = {} self.last_menu = None self.visible_menu = "main_menu" self.current_save = None self.current_page = 0 self.load_menu_pages = {} self.varsets = { "P1COLOR": self.player1.color, "P2COLOR": self.player2.color, "PUCKCOLOR": self.puck.color } self.functions = { "toggle_fullscreen": self.toggle_fullscreen, "toggle_show_fps": self.toggle_show_fps, "goto_mainmenu": self.goto_mainmenu, "goto_loadmenu": self.goto_loadmenu, "goto_options": self.goto_options, "unpause_game": self.unpause_game, "reset_game": self.full_reset, "start_game": self.start_game, "pause_game": self.pause_game, "load_game": self.load_game, "save_game": self.save_game, "exit_game": self.exit_game, "delete": self.delete_save, "go_back": self.go_back } self.load_menus()
def __init__(self): super(MyWindow, self).__init__(setup.screen_width, setup.screen_height, "Click The Knight", vsync=True, fullscreen=False) self.gui = glooey.Gui(self, batch=resources.gui_batch) self.knights = [] self.fps_display = FPSDisplay(self) self.gameRunning = False self.createGui(None)
class GameWindow(pyglet.window.Window): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_location(1000, 50) self.fps_draw = FPSDisplay(self) self.fps_draw.label.font_size = 50 self.fps_draw.label.y = 800 - 50 - 10 self.frame_rate = 1/60.0 def load_data(self): player_sprite = Sprite(preload_img("PlayerShip.png")) space_sprite = preload_img("space.jpg") self.player = GameObject(500, 100, player_sprite) self.space_list = [] for i in range(2): self.space_list.append(GameObject(0, i * 1200, Sprite(space_sprite))) self.space_list[i].vely = -600 def on_key_press(self, symbol, modifiers): if symbol == key.RIGHT: self.player.velx = 300 if symbol == key.LEFT: self.player.velx = -300 def on_key_release(self, symbol, modifiers): if symbol in (key.RIGHT, key.LEFT): self.player.velx = 0 def on_draw(self): self.clear() for space in self.space_list: space.draw() self.player.draw() self.fps_draw.draw() def update_space(self, dt): for space in self.space_list: space.update(dt) if space.posy <= -1300: space.posy = 1000 def update(self, dt): self.update_space(dt) self.player.update(dt)
class Simulation(pyglet.window.Window): def __init__(self, width=1152, height=720, fullscreen=False): super().__init__(width, height, vsync=False, fullscreen=fullscreen, caption="Simple Pendulum") self.fps = FPSDisplay(self) self.T = 0 self.ball = Ball() self.run = False self.trace = [] pyglet.gl.glPointSize(10) @property def center(self): return self.width // 2, self.height // 2 def update(self, dt): if not self.run: return self.ball.step(dt) self.T += dt def on_draw(self): self.clear() offset = (self.width // 2, 0) if self.run and (int(self.T * 100) % 10 == 0): self.trace.extend(self.ball.position_after_offset(offset)) pyglet.graphics.draw(len(self.trace)//2, pyglet.gl.GL_POINTS, ('v2f', self.trace), ('c3B', [255, 0, 0]*(len(self.trace)//2)), ) self.ball.draw(offset) label = pyglet.text.Label(f"T = {self.T:.3f}", font_name='Halvetica Nenu', font_size=16, x=self.width - 10, y=10, anchor_x="right", anchor_y="bottom") label.draw() self.fps.draw() def on_key_press(self, symbol, modifiers): if symbol == key.Q and modifiers == key.MOD_COMMAND: pyglet.app.exit() def on_key_release(self, symbol, modifiers): if symbol == key.SPACE: self.run = not self.run
class GameWindow(pyglet.window.Window): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_location(300, 50) self.fps = FPSDisplay(self) self.space = pymunk.Space() self.options = DrawOptions() self.player = Player(self.space) self.ball = Ball(self.space, self.player.position) self.walls = Walls(self.space) self.bricks = Bricks(self.space) def on_draw(self): self.clear() self.space.debug_draw(self.options) self.fps.draw() def on_key_press(self, symbol, modifiers): if symbol == key.RIGHT: self.player.velocity = 600, 0 if self.ball.on_paddle: self.ball.velocity = self.player.velocity if symbol == key.LEFT: self.player.velocity = -600, 0 if self.ball.on_paddle: self.ball.velocity = self.player.velocity if symbol == key.SPACE: if self.ball.on_paddle: self.ball.shoot() if symbol == key.R: self.reset_game() def on_key_release(self, symbol, modifiers): if symbol in (key.RIGHT, key.LEFT): self.player.velocity = 0, 0 if self.ball.on_paddle: self.ball.velocity = 0, 0 def reset_game(self): for shape in self.space.shapes: if shape.body != self.space.static_body and shape.body.body_type != pymunk.Body.KINEMATIC: self.space.remove(shape.body, shape) for constraint in self.space.constraints: self.space.remove(constraint) self.player = Player(self.space) self.ball = Ball(self.space, self.player.position) def update(self, dt): self.space.step(dt) self.ball.update()
def __init__(self): super().__init__(windowWidth, windowHeight, gameName) # The game loop pyglet.clock.schedule_interval(self.update, 1 / 60.0) self.fps_display = FPSDisplay(self) self.player1 = Player(375, 50, (255, 0, 0)) self.player_laser = preload_image('laser.png') self.player1_laser_list = [] self.player2 = Player(375, 700, (0, 0, 255)) self.player2_laser_list = []
class GameWindow(pyglet.window.Window): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_location(100, 100) self.frame_rate = 1 / 60.0 self.fps_display = FPSDisplay(self) def on_draw(self): self.clear() self.fps_display.draw() def update(self, dt): pass
class GameWindow(pyglet.window.Window): """ """ def __init__(self, aspect_ratio, dt_for_physicx, *args, **kwargs): super().__init__(*args, **kwargs) # set window location position = aspect_ratio.scale(300, 50) self.set_location(position.x, position.y) # framerate display self.fps = FPSDisplay(self) self.engine = GameEngine(aspect_ratio, dt_for_physicx) self.dt_for_physicx = dt_for_physicx self.remain_time_for_updating_physicx = dt_for_physicx def on_draw(self): self.clear() self.engine.on_draw() self.fps.draw() def on_key_press(self, symbol, modifiers): try: self.engine.on_action_command_press(map_key_command[symbol]) except KeyError: if symbol == key.ESCAPE: self.quit_game() def on_key_release(self, symbol, modifiers): try: self.engine.on_action_command_release(map_key_command[symbol]) except KeyError: pass def update(self, dt): """ :param dt: :return: """ # dt: deltatime from display self.remain_time_for_updating_physicx -= dt while self.remain_time_for_updating_physicx < 0.0: self.engine.update(self.dt_for_physicx) self.remain_time_for_updating_physicx += self.dt_for_physicx def quit_game(self): # http://nullege.com/codes/search/pyglet.app.exit pyglet.app.exit()
def __init__(self, *args, **kwargs): # WINDOW INITIALIZATIONS super().__init__(*args, **kwargs) self.frame_rate = 1 / 60.0 self.fps_display = FPSDisplay(self) self.fps_display.label.font_size = 50 # MAKING THE PRIMITIVE DRAWINGS TRANSPARENT glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # GAME MENU INITIALIZATIONS self.status = GameStatus() self.menu = GameMenu(resolution, self.status.game_menu_text) self.smenu = SelectionMenu(resolution, self.status.game_selection_text) self.cmenu = ControlsMenu() self.amenu = AboutMenu() self.start_time = time.time() # INITIALLY PLAYING THE MENU BG SONG bg_player.play() # SPACE BG INITIALIZATIONS self.space_list = [] self.space_img = preload_image(space_bg_img) for i in range(2): self.space_list.append( DisplayObjects(0, i * 1080, Sprite(self.space_img))) for space in self.space_list: space.vel_y = -space_scroll_speed # PLAYER INITIALIZATIONS # CREATING PLAYER OBJECTS self.player1 = DisplayPlayers(p1_pos_x, p1_pos_y, p1_fire_type) self.player2 = DisplayPlayers(p2_pos_x, p2_pos_y, p2_fire_type) # PLAYER HP QUAD CREATION self.player1.hp = Quad(p1_hp_pos, p1_hp_size, p1_hp_color, 'p1') self.player2.hp = Quad(p2_hp_pos, p2_hp_size, p2_hp_color, 'p2') # PLAYER GAURD QUAD CREATION self.player1.gaurd = Quad(p1_gaurd_pos, p1_gaurd_size, p1_gaurd_color, 'p1') self.player2.gaurd = Quad(p2_gaurd_pos, p2_gaurd_size, p2_gaurd_color, 'p2') # PLAYER DAMAGE HP QUAD CREATION self.player1.dhp = Quad(p1_dhp_pos, p1_dhp_size, p1_dhp_color, 'p1') self.player2.dhp = Quad(p2_dhp_pos, p2_dhp_size, p2_dhp_color, 'p2')