def play_simulation(): while not input.key_press(gs.InputDevice.KeyEscape): clock.update() fps.update(clock.get_dt()) render.set_camera3d(fps.pos.x, fps.pos.y, fps.pos.z, fps.rot.x, fps.rot.y, fps.rot.z) render.clear() for perso in array_perso: perso.draw() perso.update(physic_world) array_perso[0].kohonen_behaviour.draw(render.get_renderer().GetCurrentOutputWindow().GetSize().x, render.get_renderer().GetCurrentOutputWindow().GetSize().y) physic_world.draw() # render text if input.key_down(gs.InputDevice.KeyL): render.text2d(10, 120, 'Frag in Mem: %d' % KohonenBehaviour.memory.GetNbFragment()) for action in range(perso_actions.nb_actions): render.text2d(10, 140 + 20*action, 'Frag for %s: %d, %d%%' % (perso_actions.get_current_action_name(action), KohonenBehaviour.memory.m_NbFragmentPerActionArray[action], KohonenBehaviour.memory.m_TabPercentFragmentPerAction[action]), 12, array_perso[0].kohonen_behaviour.color_array[action]) render.text2d(10, 50, str(perso.selected_action)+" "+perso_actions.get_current_action_name(perso.selected_action)) #draw it to the screen render.flip()
def intro(): text_blink = 0.0 angle = 0 fps = camera.fps_controller(0, 2, -10) fps.update(clock.update()) render.set_camera3d(fps.pos.x, fps.pos.y, fps.pos.z, fps.rot.x, fps.rot.y, fps.rot.z) while not input.key_press(gs.InputDevice.KeyEnter): render.clear(gs.Color.White) text_blink += clock.update() if text_blink > 1.0: text_blink = 0.0 # Effet de background animé à la "Street Fighter" (hem) dessine_fond_qui_scroll() for z in range(-100, 100, 5): for x in range(-100, 100, 5): render.geometry3d(x, 0, z, cube) afficheTexte(500, 400, 'Quel est ton gourou ?', size=2) afficheTexte(500, 365, 'Choisis le sens de ta vie ~~~~~~~~~~~~~~') afficheTexte(500, 325, '...et appuie sur [enter]', text_blink) afficheTexte(815,20, 'Made by Trofis #CODE and Safae #DESIGN' , size=0.5) render.flip() angle += 0.01 while input.key_press(gs.InputDevice.KeyEnter): render.clear() render.flip()
def render_landscape_screen(): seq_duration = 40.0 fx_timer = 0.0 y_offset = 50 logo_freq = 6 while fx_timer < seq_duration: dt_sec = clock.update() fx_timer += dt_sec render.clear() render.set_blend_mode2d(render.BlendAlpha) render.image2d( (demo_screen_size[0] - 320 * zoom_size()) * 0.5, (demo_screen_size[1] - (34 + y_offset) * zoom_size()) * 0.5, zoom_size(), "@assets/landscape_mountains.png") render.image2d( (demo_screen_size[0] - 100 * zoom_size()) * 0.5, (demo_screen_size[1] - (80 + y_offset) * zoom_size()) * 0.5, zoom_size(), "@assets/landscape_stones.png") x, y = math.cos( fx_timer / seq_duration * math.pi * 2 * logo_freq) * 16, math.sin( fx_timer / seq_duration * math.pi * 5 * logo_freq) * 16 render.image2d( (demo_screen_size[0] - (187 + x) * zoom_size()) * 0.5, (demo_screen_size[1] - (106 - 80 + y) * zoom_size()) * 0.5, zoom_size(), "@assets/logo_exxos.png") render.set_blend_mode2d(render.BlendOpaque) render.flip()
def render_space_screen(): seq_duration = 20.0 fx_timer = 0.0 while fx_timer < seq_duration: dt_sec = clock.update() fx_timer += dt_sec render.clear() render.set_blend_mode2d(render.BlendAlpha) x_star = RangeAdjust(fx_timer, 0.0, seq_duration, demo_screen_size[0], -53 * zoom_size()) x_moon = RangeAdjust(fx_timer, seq_duration * 0.475, seq_duration, demo_screen_size[0], -60 * zoom_size()) x_planet = RangeAdjust(fx_timer, seq_duration * 0.65, seq_duration, demo_screen_size[0], -95 * zoom_size()) render.image2d(x_star, (demo_screen_size[1] - 53 * zoom_size()) * 0.5, zoom_size(), "@assets/space_star.png") render.image2d(x_moon, (demo_screen_size[1] - 60 * zoom_size()) * 0.5, zoom_size(), "@assets/space_moon.png") render.image2d(x_planet, 0, zoom_size(), "@assets/space_planet.png") render.set_blend_mode2d(render.BlendOpaque) render.flip()
def render_text_screen(strings=None, duration=4.0, fade_duration=1.0, render_callback=None): if strings is None: return fonts_dict = {} fx_timer = 0.0 while fx_timer < duration: dt_sec = clock.update() fx_timer += dt_sec if fx_timer < fade_duration: fade = RangeAdjust(fx_timer, 0.0, fade_duration, 0.0, 1.0) else: if fx_timer < duration - fade_duration: fade = 1.0 else: fade = RangeAdjust(fx_timer, duration - fade_duration, duration, 1.0, 0.0) render.clear() fonts_dict = render_strings_array(strings, fade, fonts_dict) if fade > 0.2: if render_callback is not None: render_callback() render.flip()
def dessine_fond_qui_scroll(): global dt_text_scroll dt_text_scroll += clock.update() dt_text_scroll %= 1.0 line_str = '' char_list = '_\\|/' for i in range(80): line_str += char_list[int(dt_text_scroll * 10) % 3] + ' ' for i in range(25): j = i + dt_text_scroll afficheTexte(j * -10.0, (j * 50) + 100, line_str, 0.15)
if 4 < timeline < 5: draw_line(lerp(timeline-4, pos.x+cursor_point[4].x, pos.x+cursor_point[0].x), lerp(timeline-4, pos.y+cursor_point[4].y, pos.y+cursor_point[0].y), pos.x+cursor_point[0].x, pos.y+cursor_point[0].y, get_random_color()) draw_line(pos.x+cursor_point[0].x, pos.y+cursor_point[0].y, lerp(timeline-4, pos.x+cursor_point[0].x, pos.x+cursor_point[1].x), lerp(timeline-4, pos.y+cursor_point[0].y, pos.y+cursor_point[1].y), get_random_color()) def draw_cursor(): mouse_pos = input.get_mouse_pos() mouse_pos = gs.Vector3(mouse_pos[0] / size_pixel.x, mouse_pos[1] / size_pixel.y, 0) draw_pentacle(mouse_pos, 5, 15) reduce_speed = 15 increase_speed = 15 while not input.key_press(gs.InputDevice.KeyEscape) and not exit: dt_sec = clock.update() time_pass += dt_sec def check_clicked(): global radius_circle_eye, counter_seed, lose, win, array_point, array_size_point, array_full_point, array_id_line, next_symbol, reducing, start, reset if not input.mouse_button_was_down() and input.mouse_button_down(): counter_seed = 0 lose = False win = False array_point = [] array_size_point = [] array_full_point = [] array_id_line = [] next_symbol = True reducing = 0.0 start = True
def render_mask_screen(): mask_segment_list = wireframe_json_to_segment_list( "@assets/exxos_mask.json") scn = scene.new_scene() while not scn.IsReady(): scene.update_scene(scn, 0.0) # Add an environment to the scene env = gs.Environment() env.SetBackgroundColor(gs.Color.Black) scn.AddComponent(env) # Add a camera render_camera = gs.Node() render_camera.AddComponent(gs.Transform()) render_camera.AddComponent(gs.Camera()) scn.AddNode(render_camera) scn.SetCurrentCamera(render_camera) render_camera.GetTransform().SetPosition(gs.Vector3(0, 0, -50)) # Create a (parent) node to rotate the mask master_node = gs.Node() master_node.AddComponent(gs.Transform()) scn.AddNode(master_node) # Init the starfield starfield.init_stars() starfield.set_camera_velocity(gs.Vector3(0, 0, -50)) segment_nodes_list = [] for seg in mask_segment_list: node_a, node_b = gs.Node(), gs.Node() tr_a, tr_b = gs.Transform(), gs.Transform() tr_a.SetPosition(gs.Vector3(seg[0][0], seg[0][1], seg[0][2])) tr_b.SetPosition(gs.Vector3(seg[1][0], seg[1][1], seg[1][2])) tr_a.SetParent(master_node) tr_b.SetParent(master_node) node_a.AddComponent(tr_a) node_b.AddComponent(tr_b) scn.AddNode(node_a) scn.AddNode(node_b) segment_nodes_list.append([node_a, node_b]) seq_duration = 20.0 fx_timer = 0.0 while fx_timer < seq_duration: render.clear() dt_sec = clock.update() master_node.GetTransform().SetRotation( master_node.GetTransform().GetRotation() + gs.Vector3(1, 1, 1) * dt_sec * 0.25) scene.update_scene(scn, dt_sec) # render.commit_3d() # render.set_depth_write3d(False) starfield.update_stars(dt_sec) starfield.draw_stars(render) for seg in segment_nodes_list: pos_a = seg[0].GetTransform().GetWorld().GetTranslation() pos_b = seg[1].GetTransform().GetWorld().GetTranslation() render.line3d(pos_a.x, pos_a.y, pos_a.z, pos_b.x, pos_b.y, pos_b.z, start_color=gs.Color.Blue, end_color=gs.Color.Blue) render.flip() fx_timer += dt_sec
# fps = camera.fps_controller(0, 3.5, -12.5) thrown_bullet = False fixed_step = True record_motion = False record_done = False dt_sum = 0.0 # Start simulation & record while not input.key_press(gs.InputDevice.KeyEscape) and not record_done: if fixed_step: dt_sec = 1.0 / 120.0 else: dt_sec = clock.update() dt_sum += dt_sec print(dt_sum) if not thrown_bullet and dt_sum > 1.0: world = gs.Matrix4.TransformationMatrix(make_solid_pos(-0.25, 40), gs.Vector3()) new_cube, rigid_body = scene.add_physic_cube(scn, world, width, height, length, 2) rigid_body.ApplyLinearImpulse(world.GetY() * -5) node_list.append(new_cube) world = gs.Matrix4.TransformationMatrix(make_solid_pos(-0.65, 55), gs.Vector3()) new_cube, rigid_body = scene.add_physic_cube(scn, world, width, height,
SCR_DISP_WIDTH = 320 * 2 SCR_DISP_HEIGHT = 200 * 2 SCR_SCALE_FACTOR = min(SCR_DISP_WIDTH / SCR_PHYSIC_WIDTH, SCR_DISP_HEIGHT / SCR_PHYSIC_HEIGHT) SCR_MARGIN_X = (SCR_DISP_WIDTH - (SCR_PHYSIC_WIDTH * SCR_SCALE_FACTOR)) / 2.0 gs.LoadPlugins(gs.get_default_plugins_path()) render.init(SCR_DISP_WIDTH, SCR_DISP_HEIGHT, "pkg.core") # provide access to the data folder gs.MountFileDriver(gs.StdFileDriver("assets/"), "@assets/") gameReset() player.initial_pox_z = (board.board_length * 0.45) player.reset() while not input.key_press(gs.InputDevice.KeyEscape): dt = clock.update() # 1.0 / 60.0 # update mouse gs.GetInputSystem().Update() # get the mouse device mouse_device = gs.GetInputSystem().GetDevice("mouse") gameMainLoop(mouse_device) render.flip()
#launch fade out with the new scene if state == state_fade_out: fade_percent -= fade_speed * globals.dt_sec if fade_percent < 0: fade_percent = 0 state = state_ready if fade_percent > 0: color = gs.Color(0, 0, 0, fade_percent) size = render.get_renderer().GetCurrentOutputWindow().GetSize() render.triangle2d(0, 0, size.x, size.y, size.x, 0, color, color, color) render.triangle2d(0, 0, 0, size.y, size.x, size.y, color, color, color) while not input.key_press(gs.InputDevice.KeyEscape): globals.dt_sec = clock.update() render.clear(gs.Color.Black) if state == state_ready or state == state_fade_out: if globals.current_scene is not None: globals.current_scene.draw() globals.current_scene.update() else: if globals.prev_scene_fade is not None: globals.prev_scene_fade.draw() globals.prev_scene_fade.update() fade_between_scene() render.flip()
def update(): global dt_sec dt_sec = clock.update() scene.update_scene(scn, dt_sec) if input.key_press(gs.InputDevice.KeyEnter): globals.current_scene = level_game