def loop(self, screen): img_manager.draw_rect(screen, Vector2(), Rect(Vector2(),engine.get_screen_size()),self.bg_color) snd_manager.update_music_status() """ if CONST.render == 'kivy': for layer in self.objects: for img in layer: #set img pos outside the screen if isinstance(img, AnimImage): for kivy_img in img.anim.img_indexes: kivy_img.x = -engine.get_screen_size().x kivy_img.y = -engine.get_screen_size().y """ '''Event If mouse_click on element, execute its event, of not null''' if self.show_mouse: show_mouse() mouse_pos, pressed = get_mouse() if pressed[0] and not self.click: event = None self.click = True for layer in self.objects: for image in layer: if image.check_click(mouse_pos, self.screen_pos): event = image.event if event: event.execute() elif not pressed[0]: self.click = False if not self.lock: physics_manager.loop() '''Show images''' if self.player and self.player.anim: self.screen_pos = self.player.anim.get_screen_pos() remove_image = [] for i, layer in enumerate(self.objects): if i == 2: NetworkGamestate.loop(self, screen) for j, img in enumerate(layer): img.loop(screen, self.screen_pos) if img.remove: remove_image.append(img) for r in remove_image: self.objects[i].remove(r) '''GUI''' GUI.loop(self, screen) '''Editor''' if CONST.debug: Editor.loop(self, screen, self.screen_pos)
def loop(self, screen): """Loop of the GUI part of the Gamestate""" '''Event If mouse_click on element, execute its event, of not null''' if self.show_mouse: show_mouse() mouse_pos, pressed = get_mouse() if pressed[0] and not self.gui_click: event = None self.gui_click = True if not self.dialog: for layer in self.objects: for image in layer: if image.check_click(mouse_pos, self.screen_pos): event = image.event else: if self.dialog_text2.time >= self.dialog_text2.gradient: if len(self.answers_image) == 0: self.dialog = False self.dialog_event.answer() for i, answer_image in enumerate(self.answers_image): if answer_image.check_click(mouse_pos, self.screen_pos): self.dialog = False self.dialog_event.answer(self.answers_text[i].text) break else: self.dialog_text.end_gradient() self.dialog_text2.end_gradient() if event: event.execute() elif not pressed[0]: self.gui_click = False '''Dialog''' if self.dialog and self.dialog_text and not self.editor: show_mouse() if self.dialog_text.time >= self.dialog_text.gradient: for button in self.answers_image: '''show answers''' button.loop(screen, self.screen_pos) for answer in self.answers_text: answer.loop(screen, self.screen_pos) self.dialog_box.loop(screen, self.screen_pos) self.dialog_text.loop(screen, self.screen_pos) if self.dialog_text.time >= self.dialog_text.gradient: self.dialog_text2.loop(screen, self.screen_pos)
def loop(self, screen,screen_pos): if not (self.editor_click or not get_button('editor')): self.editor = not self.editor self.lock = self.editor self.editor_click = True if self.editor: log("Editor mode activate") else: self.current_selected = None if not get_button('editor'): self.editor_click = False if self.editor: show_mouse() mouse_pos, pressed = get_mouse() if not self.editor: return self.gui_editor_mode.loop(screen,screen_pos) '''Save Level''' if self.save_clicked: self.gui_saved.loop(screen,screen_pos) if get_button('save') and not self.save_clicked: save_level(self) self.save_clicked = True elif not get_button('save'): self.save_clicked = False '''Left click, select a object and move it''' if not get_button('box'): self.new_obj = None if pressed[0] and not self.mouse_clicked[0]: '''Set current_selected''' self.current_selected = None for layer in self.objects: for image in layer: if not image.screen_relative and image.check_click(mouse_pos, self.screen_pos): log("Current_object is: " + str(image)) self.current_selected = image self.obj_init_pos = self.current_selected.pos self.mouse_init_pos = mouse_pos + self.screen_pos self.mouse_clicked = (1, self.mouse_clicked[1], self.mouse_clicked[2]) elif pressed[0] and self.mouse_clicked[0]: '''Move the current object''' if self.current_selected is not None: self.current_selected.set_pos(self.obj_init_pos, mouse_pos + self.screen_pos - self.mouse_init_pos) else: """Create a static physic with CTRL-left mouse""" if pressed[0] and not self.mouse_clicked[0]: self.mouse_clicked = (1, self.mouse_clicked[1], self.mouse_clicked[2]) self.new_obj = GameObject() self.new_obj.pos = mouse_pos + self.screen_pos self.objects[4].append(self.new_obj) elif self.mouse_clicked[0]: self.new_obj.size = mouse_pos + self.screen_pos - self.new_obj.pos if not pressed[0]: """Create a static physics body""" self.new_obj.body = add_static_object(self.new_obj, self.new_obj.pos+self.new_obj.size/2) add_static_box(self.new_obj.body, Vector2(), self.new_obj.size/2, data=11) self.new_obj.update_rect() if not pressed[0] and self.mouse_clicked[0]: self.mouse_clicked = (0, self.mouse_clicked[1], self.mouse_clicked[2]) if self.current_selected: self.gui_current_selected.change_text(str(self.current_selected.__class__)+" "+str(self.current_selected.id) +" "+str(self.current_selected.angle)) self.gui_current_selected.loop(screen, screen_pos) '''Size scale''' scale_x = get_button("scale_x_up")-get_button("scale_x_down") scale_y = get_button("scale_y_up")-get_button("scale_y_down") if self.current_selected: self.current_selected.scale(scale_x,scale_y) '''Angle''' angle = get_button("angle_up")-get_button("angle_down") if self.current_selected: self.current_selected.set_angle(self.current_selected.angle+angle)