def _update_wrapper(i): timer.request_animation_frame(_update_wrapper) # time between frames dt = 1 / 60 * application.time_scale time.dt = dt mouse.update() if hasattr(__main__, 'update') and not application.paused: __main__.update() for seq in application.sequences: seq.update() for entity in scene.entities: if entity.enabled == False or entity.ignore: continue if application.paused and entity.ignore_paused == False: continue if hasattr(entity, 'update'): entity.update() if hasattr(entity, 'scripts'): for script in entity.scripts: if script.enabled and hasattr(script, 'update'): script.update()
def __init__(self): global test_buff, PyAngeloWorker, array self.commands = [] # get the canvas element self.canvas = document["canvas"] self.ctx = self.canvas.getContext('2d') self.width = self.canvas.width self.height = self.canvas.height self.timer_id = None self.stopped = False self.resources = {} self.loadingResources = 0 self.keys = dict([(a, False) for a in range(255)] + [(a, False) for a in range(0xff00, 0xffff)]) document.bind("keydown", self._keydown) document.bind("keyup", self._keyup) self.soundPlayers = {} self.state = self.STATE_WAIT self.anim_timer = 0 self.anim_time = 200 self.starting_text = "Starting up" self.loading_text = "Loading resources" #timer.set_interval(self.update, 16) # clear to cornflower blue (XNA!) by default self.__clear(0.392, 0.584, 0.929) keys_buff = window.SharedArrayBuffer.new(512) array = window.Int8Array.new(keys_buff) window.console.log("Attempting to send shared data") PyAngeloWorker.send(keys_buff) #PyAngeloWorker.send(input_buff) self.pixel_id = self.ctx.createImageData(1, 1) self.pixel_color = self.pixel_id.data self.last_frame_commands = [] self.just_halted = False self.input_concluded = False self.input_buffer_index = 0 timer.request_animation_frame(self.update)
def main(): document.bind('keypress', keypress_handler) update_game_names(loop=True, select_newest=True) window._animate_lock = False favorites.update_button.bind('click', update_button_handler) favorites.keyboard_help_button.bind('click', keyboard_help_button_handler) timer.request_animation_frame(window.animate)
def update(self, deltaTime): document["runPlay"].style.cursor = "pointer" document["runPause"].style.cursor = "pointer" document["output_runPlay"].style.cursor = "pointer" document["output_runPause"].style.cursor = "pointer" if self.state == self.STATE_STOP: if "auto" in document["output_run"].attrs: button_play(None) del document["output_run"].attrs["auto"] self.clear(0.392, 0.584, 0.929) width = self.measureText("Ready", fontSize=30)[0] self.drawText("Ready", 250 - width / 2, 170, fontSize=30) elif self.state == self.STATE_RUN: if self.main_loop is not None: try: self.main_loop() except Exception as e: do_print( "Error: " + str(e) + "\n" + traceback.format_exc(), "red") self.stop() elif self.state == self.STATE_INPUT: # display the commands in the queue to date if self.input_concluded: # TODO: if the program halts after the input, then this causes # Pyangelo to keep looping in it's run state ===> FIX! self.state = self.STATE_RUN self.input_concluded = False elif self.state == self.STATE_LOAD: self.clear(0.192, 0.384, 0.729) text = "Loading: " + self.loading_filename width = self.measureText(text, fontSize=20)[0] self.drawText(text, 250 - width / 2, 170, fontSize=20) elif self.state == self.STATE_LOADED: self.clear(0.192, 0.384, 0.729) text = "Successfully Loaded:" width = self.measureText(text, fontSize=20)[0] self.drawText(text, 250 - width / 2, 200, fontSize=20) text = self.loading_filename width = self.measureText(text, fontSize=20)[0] self.drawText(text, 250 - width / 2, 170, fontSize=20) timer.request_animation_frame(self.update)
def __init__(self): self.commands = [] # get the canvas element self.canvas = document["canvas"] self.ctx = self.canvas.getContext('2d') self.width = self.canvas.width self.height = self.canvas.height self.timer_id = None self.main_loop = None self.stopped = False self.resources = {} self.loadingResources = 0 self.keys = dict([(a, False) for a in range(255)] + [(a, False) for a in range(0xff00, 0xffff)]) self.keys[KEY_V_LEFT] = False self.keys[KEY_V_RIGHT] = False self.keys[KEY_V_UP] = False self.keys[KEY_V_DOWN] = False self.keys[KEY_V_FIRE] = False document.bind("keydown", self._keydown) document.bind("keyup", self._keyup) self.mouse_x = 0 self.mouse_y = 0 document.bind("mousedown", self._mousedown) document.bind("mouseup", self._mouseup) document.bind("mousemove", self._mousemove) self.touches = {} document.bind("touchstart", self._touchstart) document.bind("touchend", self._touchend) document.bind("touchmove", self._touchmove) self.soundPlayers = {} self.state = self.STATE_STOP self.anim_timer = 0 self.anim_time = 200 self.starting_text = "Starting up" self.loading_text = "Loading resources" # clear to cornflower blue (XNA!) by default self.clear(0.392, 0.584, 0.929) self.pixel_id = self.ctx.createImageData(1, 1) self.pixel_color = self.pixel_id.data self.last_frame_commands = [] self.just_halted = False self.input_concluded = False self.input_buffer_index = 0 self.loading_filename = "" timer.request_animation_frame(self.update)
def animated_move(timestamp, x_dir, y_dir, step, max_step, castle_dir): moving_piece.left += int(x_dir) moving_piece.top += int(y_dir) if step < max_step: timer.request_animation_frame(lambda timestamp: animated_move( timestamp, x_dir, y_dir, step + 1, max_step, castle_dir)) else: if castle_dir != 0: destiny.innerHTML = '' put_piece_in_square(str(int(origin_id + 2 * castle_dir)), 'king', team_str) put_piece_in_square(str(int(origin_id) + castle_dir), 'rook', team_str) t_value = 0 if team_str == 'WHITE' else 1 C.has_king_moved[t_value] = True C.has_rook_moved[t_value][int(not dx == 0)] = True else: global can_move, turn destiny.innerHTML = moving_piece_img if promotion == True and turn == PieceTeam.WHITE: # Display menu for options can_move = False selection_box = DIV(id='piece-select') for name in (PieceName.QUEEN, PieceName.ROOK, PieceName.BISHOP, PieceName.KNIGHT): container = DIV( Class="container", onclick= f'promote_pawn({dx}, {dy}, "{name}", "{team_str}");' ) container <= IMG( src= f'static/pieces/{team_str.lower()}_{name.name.lower()}.png' ) selection_box <= container offset_x = (moving_piece.clientWidth // 2) - (52 * 2) offset_y = -50 if team_str == 'WHITE' else moving_piece.clientWidth selection_box.style.left = str(moving_piece.left + offset_x) + 'px' selection_box.style.top = str(moving_piece.top + offset_y) + 'px' document <= selection_box elif promotion == True and turn == PieceTeam.BLACK: piece = choice(['ROOK', 'BISHOP', 'KNIGHT']) C.replace_piece(dx, dy, eval('PieceName.' + piece), turn.name) put_piece_in_square(destiny_id, piece, turn.name) piece_columns = { PieceTeam.WHITE: document['rpieces'], PieceTeam.BLACK: document['lpieces'], } if destiny_name != None and castle_dir == 0: piece_columns[destiny_team] <= IMG( src= f'static/pieces/{destiny_team.name.lower()}_{destiny_name.name.lower()}.png' ) if not promotion: turn = PieceTeam.BLACK if turn == PieceTeam.WHITE else PieceTeam.WHITE can_move = turn == PieceTeam.WHITE and not promotion del document['moving-piece'] display_message()
def set_answer(self, event): first_answer = self.answer is None self.answer = int(radio_val('q%d'%self.data['id'])) self.show_party_votes() game.update_results() timer.request_animation_frame(game.add_question if first_answer else game.save_vote)
def start(self): for question in self.questions: if question.answer is None: break else: timer.request_animation_frame(self.add_question)
def update(self, deltaTime): global my_turtle self.anim_timer -= 16 if self.anim_timer <= 0: self.anim_timer = 0 document["runPlay"].style.cursor = "pointer" document["runPause"].style.cursor = "pointer" if self.state == self.STATE_WAIT: document["runPlay"].style.cursor = "not-allowed" self.ctx.fillStyle = "#000000" self.ctx.fillRect(0, 0, self.width, self.height) self.ctx.fillStyle = "#ffffff" self.ctx.fillStyle = "#ffffff" self.ctx.font = "40px Georgia" if self.anim_timer <= 0: self.anim_timer = self.anim_time self.starting_text += "." if self.starting_text.count(".") > 5: self.starting_text = self.starting_text[:-5] self.ctx.fillText(self.starting_text, 100, 200) elif self.state == self.STATE_RUN: self.execute_commands() # do turtle stuff my_turtle.update() my_turtle.draw() # now draw the turtle #if my_turtle.visible: # self.__drawText("*", my_turtle.x, my_turtle.y, fontSize = 16) elif self.state == self.STATE_STOP: self.__clear(0.392, 0.584, 0.929) elif self.state == self.STATE_HALT: #print(len(my_turtle.commands)) if len(my_turtle.commands) > 0: # do turtle stuff my_turtle.update() my_turtle.draw() # program has finished (halted) - just leave the display as is # execute the command in the queue (to show the results if they didn't call reveal()) # TODO: fix this??? should this be == 0 instead of > 0 # we would like to keep repeating if there are resources to be loaded # this is to ensure that the images etc. will eventually be displayed # HOWEVER, watch if the current frame contains an 'input' this could result in # an infinite loop #self.commands = copy.deepcopy(self.last_frame_commands) if self.loadingResources > 0: window.console.log("Still loading resources...") #self.commands = copy.deepcopy(self.last_frame_commands) #return else: # repeating is required in case not all the resources have loaded yet # window.console.log("repeating last frame") # window.console.log(len(self.last_frame_commands)) # window.console.log(len(self.commands)) if self.just_halted: # just_halted is used to send the KEY_ESC signal to the worker only once self.just_halted = False #else: # keep repeating the commands from the last frame before halting #self.commands = copy.deepcopy(self.last_frame_commands) self.execute_commands() elif self.state == self.STATE_INPUT: # display the commands in the queue to date if self.input_concluded: # TODO: if the program halts after the input, then this causes # Pyangelo to keep looping in it's run state ===> FIX! self.state = self.STATE_RUN self.input_concluded = False timer.request_animation_frame(self.update)