def new_game(): global player, alive, state, current_turn starting_items = ui.item_choice_menu() if starting_items is None: #player closed window during starting item dialog return terrain.map = mapgen.generate_map() (x, y) = terrain.map.player_start_pos terrain.map[x][y] = terrain.Floor() player = mob.Player((x, y)) for i in starting_items: player.get(i((0, 0))) terrain.map.init_fov_and_pathfinding() for i in range(50): randomly_spawn_enemies() update_objects() terrain.map.mobs.append(player) ui.clear_messages() render.init() compute_fov() render.draw_all_tiles() alive = True state = 'playing' current_turn = 1 ui.message('For this mission something something you need to get to the other side of this battlefield! Go 100 tiles to the right!')
def new_game(): global player, alive, state, current_turn starting_items = ui.item_choice_menu() if starting_items is None: # player closed window during starting item dialog return terrain.map = mapgen.generate_map() pos = terrain.map.player_start_pos player = mob.Player(pos) for i in starting_items: player.get(i((0, 0))) # terrain.map.init_fov_and_pathfinding() for i in range(50): update_objects() terrain.map.objects.append(player) ui.clear_messages() render.init() compute_fov() render.draw_all_tiles() alive = True state = 'playing' current_turn = 1 ui.message( 'Good job! You managed to sneak into the fortress of the dwarves and nabbed a priceless artifact while the dwarves were busy repelling a seige. Unfortunately, your escape route is now encased in battle! Can you navigate 200 tiles of mayhem?')
def main(): # initialise pygame here so all modules # have instant access to pygame functions pygame.init() render.init() import game game.init() game.run()
def main(): render.init() world.init() render.register_background(config.BG1) pyglet.app.event_loop.idle = idle pyglet.clock.schedule_interval(world.update, 1.0/config.updates_per_second) pyglet.clock.schedule_interval(draw, 1.0/config.frames_per_second) ## pyglet.clock.schedule(draw) pyglet.app.run()
def load_game(): file = shelve.open('savegame', 'r') terrain.map = file['map'] terrain.map.init_fov_and_pathfinding() objindex = file['player_location'] game.player = terrain.map.mobs[objindex] game.alive = file['alive'] game.state = file['state'] game.current_turn = file['turn'] ui.messages = file['messages'] game.compute_fov() render.init() render.draw_all_tiles() print('game loaded') file.close()
"To write 3D applications or achieve optimal performance in your 2D applications you'll need to work with OpenGL directly" I'm not going to use this. Someone with more knowlege than me can modify the code to use opengl. For now I will just get things up and running. """ class maingame: """ The top level class for the game. For now it only displays the current fps """ def __init__(self): self.fpslabel = pyglet.text.Label('', font_name='Times New Roman', font_size=12, x=render.window.width-50, y=render.window.height-12-3) self.tilemap = tilemap.TileMap(config.TEST_MAP) self.tilegrid = tilegrid.TileGrid(config.WINDOW_RESOLUTION, self.tilemap) render.renderstack.add(self.fpslabel) render.renderstack.add(self.tilegrid) def this_is_where_it_all_begins(self, dt): self.fpslabel.text = "%.2f" % pyglet.clock.get_fps() if __name__ == "__main__": render.init() m = maingame() userinput.initEventHandlers(render.window, m) pyglet.clock.set_fps_limit(30) pyglet.clock.schedule(m.this_is_where_it_all_begins) pyglet.app.run()
from camera import * """ Set up screen and some basic variables -> 'Read only' globals These all get processed when 'states' is first called """ settings = settings.load() ORIGIN = (0, 0) VIEW_WIDTH = settings['screen-width'] VIEW_HEIGHT = settings['screen-height'] DIMENSIONS = (VIEW_WIDTH, VIEW_HEIGHT) screen = render.init(DIMENSIONS) pygame.display.set_icon(pygame.image.load('ico.png').convert_alpha()) pygame.display.set_caption("Tittle's Adventures") background = imageload('background/sky_city.png') player = None gfont = font.gamefont() """ Starts the game, loads the player and first level (temporary, to be placed into its own handler) """ def startGame(cont = False): # startgame should init a new 'playstate' object