def init(): global logger, screen, clock, resolution, background, camera, stage loadConfigs() logger = outputLogger(" GAME ") logger.info("Initializing.") pygame.init() pygame.display.set_caption("Spellworld") screen = pygame.display.set_mode(resolution) clock = pygame.time.Clock() camera = pygame.Rect(map_size["width"] / 2, map_size["height"] / 2, resolution[0], resolution[1] - ui.height) camera.x -= camera.w / 2 camera.y -= camera.h / 2 stage = pygame.surface.Surface(resolution) rect = pygame.Rect(0, 0, resolution[0], resolution[1] - ui.height) background = stage.subsurface(rect) background.fill(colors.BLUE) aether.init() createPlayer() ui.init() world.init(resolution) pygame.mouse.set_visible(False) mouseInteraction("standard") logger.info("Creating {0} game.".format(resolution))
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 start(): pygame.init() pygame.display.set_caption(GAME_NAME) screen = pygame.display.set_mode(SCREEN_SIZE) world.init(GAME_SIZE) clock = pygame.time.Clock() game_exit = False while not game_exit: for event in pygame.event.get(): if event.type == QUIT: game_exit = True world.update(event, screen) ui.update(event, screen) pygame.display.update() clock.tick(FPS) pygame.quit()
def main(width, height, fps): pygame.init() screen = pygame.display.set_mode((width, height)) background = create_background(width, height) clock = pygame.time.Clock() the_world_is_a_happy_place = 0 world.init(width, height, 10, 5) while True: the_world_is_a_happy_place += 1 for event in pygame.event.get(): if is_trying_to_quit(event): return for c in world.cells: c.update(world.cells, world.foods) if c.cellState != cell.state.EATING: print(colored("cell energy= " + str(c.energy), 'green')) if c.energy < 0: world.cells.remove(c) draw_grid(screen, width, height) pygame.display.update() clock.tick(fps)
def main(): """ CLI entry function """ playerName = parseOptions() try: gameWorld = world.init(playerName, DEBUG) ui.start(gameWorld, MSG_INTRO) ret = True except Exception as err: if DEBUG: traceback.print_exception(Exception, err, None) ret = False if not ret: sys.exit(EXIT_FAILED) else: sys.exit(EXIT_SUCCESS)
s=start history = [] while not s == world.goal: history.append(s) s=transition[s][selectionAction(Q,s,history,world.transition)] history.append(s) printSolution(history) #parametres learning alpha=0.8 gamma=0.05 print("Paramètres d'apprentissage : "+ str(alpha)) #init the world sizex,sizey,start,goal,cliff,transition,rewards=world.init() nbTrial=500 if len(sys.argv) <= 1 else int(sys.argv[1]) s_rwd,Q_sarsa=learning.sarsa(nbTrial,gamma,alpha) q_rwd,Q_Qlearning=learning.QLearning(nbTrial,gamma,alpha) print("Solution SARSA") solution(Q_sarsa) print("Solution QLearning") solution(Q_Qlearning) ylim(-20,10) plt.plot(range(nbTrial), s_rwd, label="SARSA") plt.plot(range(nbTrial), q_rwd, label="Qlearning") plt.xlabel("trials") plt.ylabel("rwd/trials") plt.legend()
option_parser.add_option('-v', '--verbose', action='store_const', const=4, dest='verbosity', help='Output debug information about game events') option_parser.add_option('--trace', action='store_const', const=5, dest='verbosity', help='Output all system events as well as game events (lots of output)') option_parser.add_option('-l', '--logfile', action='store', type='string', dest='logfile', default='-', help='Destination for log output') # Networking Options option_parser.add_option('-s', '--server', action='store_true', dest='server', default=False, help='Run as a server.') option_parser.add_option('-c', '--client', action='store', dest='ip', type='string', default='0.0.0.0', help='Run as a client, connecting to the server at IP.') option_parser.add_option('-p', '--port', action='store', dest='port', type='int', default='4242', help='Port number for TCP connections.') world.add_options(option_parser) options, args = option_parser.parse_args() pygame.init() world.init(options) class SelectSocket: def __init__(self, file): self.inbuf = '' self.outbuf = '' self.open = True self.fileobj = None if isinstance(file, int): self.fd = file elif hasattr(file, 'fileno'): self.fd = file.fileno() self.fileobj = file else: self.fd = os.open(file, os.O_WRONLY | os.O_APPEND)
import tkinter as tk from tkinter import Tk, Canvas from entity import entity, vector import sound import images import world import background window = Tk() window.attributes('-fullscreen', True) # Initialisation de sound images et world sound.init() images.init() world.init() window.title("SpaceShooter") # Récupération de la taille de l'écran de l'utilisateur width = window.winfo_screenwidth() height = window.winfo_screenheight() # Création de la fenêtre principale can = Canvas(window, height = height, width = width) can.pack() can.focus_set() background.init(can, window)