コード例 #1
0
def update_tone_sound(dt):
	global shooting, tone_channel
	vol = max(0.0, mixer.GetChannelState(tone_channel).volume - 15.0 * hg.time_to_sec_f(dt))
	if shooting:
		vol = min(1.0, mixer.GetChannelState(tone_channel).volume + 10.0 * hg.time_to_sec_f(dt))

	mixer.SetChannelState(tone_channel, hg.MixerChannelState(0, vol * 0.5, hg.MixerRepeat))
コード例 #2
0
def display_title_screen(plus, scn):
	plus.Text2D(screen_width * 0.15, screen_height * 0.625, "BOULDER\nATTACKS", font_size * 4.25, hg.Color(0,0,0,0.25), screen_font)
	plus.Text2D(screen_width * 0.15, screen_height * 0.65, "BOULDER\nATTACKS", font_size * 4.25, hg.Color.Green, screen_font)

	fade = abs(sin(hg.time_to_sec_f(plus.GetClock())))
	plus.Text2D(screen_width * 0.35, screen_height * 0.35, "PRESS SPACE", font_size * 1.25,
				hg.Color.Green * hg.Color(1, 1, 1, fade), screen_font)
コード例 #3
0
def display_title_screen(plus, scn):
	plus.Text2D(screen_width * 0.15, screen_height * 0.625, "BOULDER\nATTACKS", font_size * 4.25, hg.Color(0,0,0,0.25), screen_font)
	plus.Text2D(screen_width * 0.15, screen_height * 0.65, "BOULDER\nATTACKS", font_size * 4.25, hg.Color.Green, screen_font)

	fade = abs(sin(hg.time_to_sec_f(plus.GetClock())))
	plus.Text2D(screen_width * 0.35, screen_height * 0.35, "PRESS SPACE", font_size * 1.25,
				hg.Color.Green * hg.Color(1, 1, 1, fade), screen_font)
コード例 #4
0
ファイル: HUD.py プロジェクト: TomJohnson2003/Jetstrike
def display_hud(Main, plus, aircraft: Aircraft,targets):
	f =Main.HSL_postProcess.GetL()
	tps = hg.time_to_sec_f(plus.GetClock())
	a_pulse = 0.1 if (sin(tps * 25) > 0) else 0.9
	hs, vs = aircraft.get_world_speed()

	plus.Text2D(0.05 * Main.resolution.x, 0.95 * Main.resolution.y, "Health: %d" % (aircraft.health_level*100),
				0.016 * Main.resolution.y, (hg.Color.White*aircraft.health_level+hg.Color.Red*(1-aircraft.health_level)) * f)

	plus.Text2D(0.49 * Main.resolution.x, 0.95 * Main.resolution.y, "Cap: %d" % (aircraft.cap),
				0.016 * Main.resolution.y, hg.Color.White * f)

	plus.Text2D(0.8 * Main.resolution.x, 0.90 * Main.resolution.y, "Altitude (m): %d" % (aircraft.get_altitude()),
				0.016 * Main.resolution.y, hg.Color.White * f)
	plus.Text2D(0.8 * Main.resolution.x, 0.88 * Main.resolution.y, "Vertical speed (m/s): %d" % (vs), 0.016 * Main.resolution.y,
				hg.Color.White * f)

	plus.Text2D(0.8 * Main.resolution.x, 0.03 * Main.resolution.y, "horizontal speed (m/s): %d" % (hs), 0.016 * Main.resolution.y,
				hg.Color.White * f)

	plus.Text2D(0.8 * Main.resolution.x, 0.13 * Main.resolution.y, "Pitch attitude: %d" % (aircraft.pitch_attitude),
				0.016 * Main.resolution.y, hg.Color.White * f)

	plus.Text2D(0.8 * Main.resolution.x, 0.11 * Main.resolution.y,
				"Roll attitude: %d" % (aircraft.roll_attitude), 0.016 * Main.resolution.y,
				hg.Color.White * f)

	ls=aircraft.get_linear_speed()*3.6
	plus.Text2D(0.8 * Main.resolution.x, 0.05 * Main.resolution.y,
				"Linear speed (km/h): %d" % (ls), 0.016 *Main. resolution.y,
				hg.Color.White * f)
	if ls<250 and not aircraft.flag_landed:
		plus.Text2D(749/1600 * Main.resolution.x, 120/900 * Main.resolution.y, "LOW SPEED",
					0.018 * Main.resolution.y, hg.Color(1.,0,0,a_pulse))

	plus.Text2D(0.8 * Main.resolution.x, 0.01 * Main.resolution.y,
				"Linear acceleration (m.s2): %.2f" % (Main.p1_aircraft.get_linear_acceleration()), 0.016 * Main.resolution.y,
				hg.Color.White * f)

	plus.Text2D(749 / 1600 * Main.resolution.x, 94 / 900 * Main.resolution.y,
				"Thrust: %d %%" % (Main.p1_aircraft.thrust_level * 100), 0.016 * Main.resolution.y, hg.Color.White * f)
	if Main.p1_aircraft.brake_level > 0:
		plus.Text2D(688 / 1600 * Main.resolution.x, 32 / 900 * Main.resolution.y,
					"Brake: %d %%" % (Main.p1_aircraft.brake_level * 100), 0.016 * Main.resolution.y, hg.Color(1, 0.4, 0.4) * f)
	if Main.p1_aircraft.flaps_level > 0:
		plus.Text2D(824 / 1600 * Main.resolution.x, 32 / 900 * Main.resolution.y,
					"Flaps: %d %%" % (Main.p1_aircraft.flaps_level * 100), 0.016 * Main.resolution.y, hg.Color(1, 0.8, 0.4) * f)


	#if Main.p1_aircraft.post_combution:
	#    plus.Text2D(710 / 1600 * Main.resolution.x, 76 / 900 * Main.resolution.y, "POST COMBUSTION", 0.02 * Main.resolution.y,
	#                hg.Color.Red)

	update_radar(Main, plus, aircraft, targets)
	update_target_sight(Main, plus, aircraft)

	if not Main.satellite_view:
		update_machine_gun_sight(Main, plus, aircraft)
コード例 #5
0
def init_scene(plus):
	Main.scene = plus.NewScene()
	Main.camera = plus.AddCamera(Main.scene, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 10, -10)))

	Main.camera.SetName("Camera")
	Main.camera.GetCamera().SetZNear(1.)
	Main.camera.GetCamera().SetZFar(40000)

	plus.LoadScene(Main.scene, "assets/aircraft/aircraft.scn")
	plus.LoadScene(Main.scene, "assets/ennemyaircraft/ennemy_aircraft.scn")
	plus.LoadScene(Main.scene, "assets/aircraft_carrier/aircraft_carrier.scn")
	plus.LoadScene(Main.scene, "assets/island/island.scn")
	plus.LoadScene(Main.scene, "assets/feed_backs/feed_backs.scn")

	init_lights(plus)

	while not Main.scene.IsReady():  # Wait until scene is ready
		#plus.UpdateScene(Main.scene, plus.UpdateClock())
		Main.scene.Commit()
		Main.scene.WaitCommit()

	#for i in range(256):
	#   plus.UpdateScene(Main.scene, plus.UpdateClock())
	#	Main.scene.Commit()
	#	Main.scene.WaitCommit()

	Main.satellite_camera = plus.AddCamera(Main.scene, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 1000, 0)))
	setup_satellite_camera(Main.satellite_camera)

	# ---- Clouds:
	json_script = hg.GetFilesystem().FileToString("assets/scripts/clouds_parameters.json")
	if json_script != "":
		clouds_parameters = json.loads(json_script)
		Main.clouds = Clouds(plus, Main.scene, Main.scene.GetNode("Sun"), Main.resolution, clouds_parameters)

	Main.island = Main.scene.GetNode("island")
	Main.island.GetTransform().SetPosition(hg.Vector3(0, 0, 3000))
	Main.island.GetTransform().SetRotation(hg.Vector3(0, 0, 0))

	Main.sea_render_script = hg.RenderScript("assets/lua_scripts/sea_render.lua")
	Main.sea_render_script.SetEnabled(False)
	Main.sea_render = SeaRender(plus, Main.scene, Main.sea_render_script)
	Main.sea_render.load_json_script()

	Main.sea_render.update_render_script(Main.scene, Main.resolution, hg.time_to_sec_f(plus.GetClock()))
	Main.scene.AddComponent(Main.sea_render_script)

	Main.water_reflection = WaterReflection(plus, Main.scene, Main.resolution, Main.resolution.x / 4)

	#Main.clouds_render_script=hg.LogicScript("assets/lua_scripts/clouds_render.lua")
	#Main.scene.AddComponent(Main.clouds_render_script)

	#plus.UpdateScene(Main.scene)
	Main.scene.Commit()
	Main.scene.WaitCommit()
	load_scene_parameters()
コード例 #6
0
def display_game_over(plus, scn, score):
	plus.Text2D(screen_width * 0.2, screen_height * 0.625, "GAME\n  OVER", font_size * 4.25, hg.Color(0,0,0,0.25), screen_font)
	plus.Text2D(screen_width * 0.2, screen_height * 0.65, "GAME\n  OVER", font_size * 4.25, hg.Color.Red, screen_font)

	plus.Text2D(screen_width * 0.3, screen_height * 0.35, "YOU SCORED " + str(score), font_size * 1.25,
				hg.Color.Red, screen_font)

	fade = abs(sin(hg.time_to_sec_f(plus.GetClock())))
	plus.Text2D(screen_width * 0.3, screen_height * 0.25, "PRESS SPACE", font_size * 1.25,
				hg.Color.Red * hg.Color(1, 1, 1, fade), screen_font)
コード例 #7
0
def display_game_over(plus, scn, score):
	plus.Text2D(screen_width * 0.2, screen_height * 0.625, "GAME\n  OVER", font_size * 4.25, hg.Color(0,0,0,0.25), screen_font)
	plus.Text2D(screen_width * 0.2, screen_height * 0.65, "GAME\n  OVER", font_size * 4.25, hg.Color.Red, screen_font)

	plus.Text2D(screen_width * 0.3, screen_height * 0.35, "YOU SCORED " + str(score), font_size * 1.25,
				hg.Color.Red, screen_font)

	fade = abs(sin(hg.time_to_sec_f(plus.GetClock())))
	plus.Text2D(screen_width * 0.3, screen_height * 0.25, "PRESS SPACE", font_size * 1.25,
				hg.Color.Red * hg.Color(1, 1, 1, fade), screen_font)
コード例 #8
0
ファイル: HUD.py プロジェクト: hermeszhang/game-dogfight
def update_target_sight(Main, plus, aircraft: Aircraft):
    tps = hg.time_to_sec_f(plus.GetClock())
    target = aircraft.get_target()
    f = Main.render_to_texture.value
    if target is not None:
        p2D = get_2d(Main.scene.GetCurrentCamera(), plus.GetRenderer(),
                     target.get_parent_node().GetTransform().GetPosition())
        if p2D is not None:
            a_pulse = 0.5 if (sin(tps * 20) > 0) else 0.75
            if aircraft.target_locked:
                c = hg.Color(1., 0.5, 0.5, a_pulse)
                msg = "LOCKED - " + str(int(aircraft.target_distance))
                x = (p2D.x - 32 / 1600)
                a = a_pulse
            else:
                msg = str(int(aircraft.target_distance))
                x = (p2D.x - 12 / 1600)
                c = hg.Color(0.5, 1, 0.5, 0.75)

            c.a *= f
            plus.Sprite2D(p2D.x * Main.resolution.x, p2D.y * Main.resolution.y,
                          32 / 1600 * Main.resolution.x,
                          "assets/sprites/target_sight.png", c)

            if aircraft.target_out_of_range:

                plus.Text2D((p2D.x - 40 / 1600) * Main.resolution.x,
                            (p2D.y - 24 / 900) * Main.resolution.y,
                            "OUT OF RANGE", 0.012 * Main.resolution.y,
                            hg.Color(0.2, 1, 0.2, a_pulse * f))
            else:
                plus.Text2D(x * Main.resolution.x,
                            (p2D.y - 24 / 900) * Main.resolution.y, msg,
                            0.012 * Main.resolution.y, c)

            if aircraft.target_locking_state > 0:
                t = sin(aircraft.target_locking_state * pi -
                        pi / 2) * 0.5 + 0.5
                p2D = hg.Vector2(0.5, 0.5) * (1 - t) + p2D * t
                plus.Sprite2D(p2D.x * Main.resolution.x,
                              p2D.y * Main.resolution.y,
                              32 / 1600 * Main.resolution.x,
                              "assets/sprites/missile_sight.png", c)

        c = hg.Color(0, 1, 0, f)
        plus.Text2D(0.05 * Main.resolution.x, 0.93 * Main.resolution.y,
                    "Target dist: %d" % (aircraft.target_distance),
                    0.016 * Main.resolution.y, c)
        plus.Text2D(0.05 * Main.resolution.x, 0.91 * Main.resolution.y,
                    "Target cap: %d" % (aircraft.target_cap),
                    0.016 * Main.resolution.y, c)
        plus.Text2D(0.05 * Main.resolution.x, 0.89 * Main.resolution.y,
                    "Target alt: %d" % (aircraft.target_altitude),
                    0.016 * Main.resolution.y, c)
コード例 #9
0
def render_text_screen(strings=None,
                       duration=4.0,
                       fade_duration=1.0,
                       render_callback=None,
                       plus=None,
                       exit_callback=None):

    if strings is None:
        return

    if plus is None:
        return

    fonts_dict = {}
    fx_timer = 0.0
    while fx_timer < duration:
        if exit_callback is not None:
            exit_callback()
        dt_sec = hg.time_to_sec_f(plus.UpdateClock())
        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)

        plus.Clear()
        fonts_dict = render_strings_array(strings, fade, fonts_dict, plus=plus)
        if fade > 0.2:
            if render_callback is not None:
                render_callback()
        plus.Flip()
        plus.EndFrame()
コード例 #10
0
def renderScript_flow(plus, t,dts):
	Main.sea_render_script.SetEnabled(True)
	if Main.sea_render.render_scene_reflection and not Main.satellite_view:
		Main.water_reflection.render(plus, Main.scene, Main.camera)

	Main.sea_render.reflect_map = Main.water_reflection.render_texture
	Main.sea_render.reflect_map_depth = Main.water_reflection.render_depth_texture
	Main.sea_render.update_render_script(Main.scene, Main.resolution, hg.time_to_sec_f(plus.GetClock()))
	# Main.scene.Commit()
	# Main.scene.WaitCommit()
	renderer = plus.GetRenderer()
	renderer.EnableDepthTest(True)
	renderer.EnableDepthWrite(True)
	renderer.EnableBlending(True)
	renderer = plus.GetRenderer()
	renderer.ClearRenderTarget()

	# Volumetric clouds:
	if Main.render_volumetric_clouds:
		Main.clouds.update(t,dts, Main.scene, Main.resolution)
		Main.scene.Commit()
		Main.scene.WaitCommit()

	plus.UpdateScene(Main.scene)
コード例 #11
0
def GameControlCamera(dt):
	mouse_device = hg.GetInputSystem().GetDevice("mouse")

	mouse_wheel = mouse_device.GetValue(hg.InputRotY)
	if mouse_wheel != 0.0:
		gg.camera_zoom_target += gg.zoom_speed * hg.time_to_sec_f(dt) * mouse_wheel
		gg.camera_zoom_target = max(min(gg.camera_zoom_target, gg.zoom_min_max.y), gg.zoom_min_max.x)
		print(gg.camera_zoom_target)

	if mouse_device.IsButtonDown(hg.Button0):
		gg.mouse = hg.Vector2(mouse_device.GetValue(hg.InputAxisX), mouse_device.GetValue(hg.InputAxisY))
		mouse_speed = gg.prev_mouse - gg.mouse
		gg.prev_mouse = hg.Vector2(gg.mouse)
		# print("Mouse X: %f, Mouse Y: %f" % (mouse_speed.x, mouse_speed.y))

		gg.camera_target_angle.x -= radians(mouse_speed.y * hg.time_to_sec_f(dt) * gg.camera_rot_x_speed)
		gg.camera_target_angle.x = max(min(gg.camera_target_angle.x, gg.camera_rot_x_min_max.y), gg.camera_rot_x_min_max.x)
		gg.camera_target_angle.y += radians(mouse_speed.x * hg.time_to_sec_f(dt) * gg.camera_rot_y_speed)
	else:
		gg.mouse = hg.Vector2(mouse_device.GetValue(hg.InputAxisX), mouse_device.GetValue(hg.InputAxisY))
		gg.prev_mouse = hg.Vector2(gg.mouse)

	cam_dt = gg.camera_target_angle - gg.camera_angle
	zoom_dt = gg.camera_zoom_target - gg.camera_zoom

	if gg.camera_lazyness == 0:
		cam_dt *= hg.time_to_sec_f(dt)
		zoom_dt *= hg.time_to_sec_f(dt)
	else:
		cam_dt *= hg.time_to_sec_f(dt) * (1.0 / gg.camera_lazyness)
		zoom_dt *= hg.time_to_sec_f(dt) * (1.0 / gg.camera_lazyness)

	gg.camera_angle += cam_dt
	gg.camera.GetTransform().SetRotation(gg.camera_angle * hg.Vector3(1.0, 0.0, 0.0))
	gg.camera_y_controller.GetTransform().SetRotation(gg.camera_angle * hg.Vector3(0.0, 1.0, 0.0))

	gg.camera_zoom += zoom_dt
	gg.camera.GetCamera().SetZoomFactor(gg.camera_zoom)
コード例 #12
0
simple_graphic_scene_overlay = hg.SimpleGraphicSceneOverlay(False)
scn.AddComponent(simple_graphic_scene_overlay)

cam = plus.AddCamera(scn, mat4.TranslationMatrix(vec3(0, 0, -5)))
cam.GetCamera().SetZNear(1)
cam.GetCamera().SetZFar(100000)  # 100km

fps = hg.FPSController(0, 0, -2)
fps.SetSmoothFactor(0.3, 0.3)

font = hg.RasterFont("@assets/fonts/Handel Gothic D Bold.ttf", 16)

navier_stokes.setup()

while not plus.IsAppEnded():
    dt_sec = plus.UpdateClock()
    #fps.UpdateAndApplyToNode(cam, dt_sec)

    navier_stokes.simulation_step(simple_graphic_scene_overlay,
                                  hg.time_to_sec_f(dt_sec))

    fps.ApplyToNode(cam)
    plus.GetRenderer().SetProjectionMatrix(cam.GetCamera().GetProjectionMatrix(
        plus.GetRenderer().GetAspectRatio()))
    plus.UpdateScene(scn, dt_sec)

    plus.Flip()
    plus.EndFrame()

os._exit(0)
コード例 #13
0
ファイル: HUD.py プロジェクト: hermeszhang/game-dogfight
def update_radar(Main, plus, aircraft, targets):
    value = Main.render_to_texture.value
    t = hg.time_to_sec_f(plus.GetClock())
    rx, ry = 150 / 1600 * Main.resolution.x, 150 / 900 * Main.resolution.y
    rs = 200 / 1600 * Main.resolution.x
    rm = 6 / 1600 * Main.resolution.x

    radar_scale = 4000
    plot_size = 12 / 1600 * Main.resolution.x / 2

    plus.Sprite2D(rx, ry, rs, "assets/sprites/radar.png",
                  hg.Color(1, 1, 1, value))
    mat = aircraft.get_parent_node().GetTransform().GetWorld()

    aZ = mat.GetZ()
    aZ.y = 0
    aZ.Normalize()
    aY = mat.GetY()
    if aY.y < 0:
        aY = hg.Vector3(0, -1, 0)
    else:
        aY = hg.Vector3(0, 1, 0)
    aX = hg.Cross(aY, aZ)
    mat_trans = hg.Matrix4.TransformationMatrix(mat.GetTranslation(),
                                                hg.Matrix3(aX, aY,
                                                           aZ)).InversedFast()

    for target in targets:
        if not target.wreck and target.activated:
            t_mat = target.get_parent_node().GetTransform().GetWorld()
            aZ = t_mat.GetZ()
            aZ.y = 0
            aZ.Normalize()
            aY = hg.Vector3(0, 1, 0)
            aX = hg.Cross(aY, aZ)
            t_mat_trans = mat_trans * hg.Matrix4.TransformationMatrix(
                t_mat.GetTranslation(), hg.Matrix3(aX, aY, aZ))
            pos = t_mat_trans.GetTranslation()
            v2D = hg.Vector2(pos.x, pos.z) / radar_scale * rs / 2
            if abs(v2D.x) < rs / 2 - rm and abs(v2D.y) < rs / 2 - rm:

                if target.type == Destroyable_Machine.TYPE_MISSILE:
                    plot = Main.texture_hud_plot_missile
                elif target.type == Destroyable_Machine.TYPE_AIRCRAFT:
                    plot = Main.texture_hud_plot_aircraft
                elif target.type == Destroyable_Machine.TYPE_SHIP:
                    plot = Main.texture_hud_plot_ship
                t_mat_rot = t_mat_trans.GetRotationMatrix()
                ps = plot_size
                a = 0.5 + 0.5 * abs(sin(t * uniform(1, 500)))
            else:
                if target.type == Destroyable_Machine.TYPE_MISSILE: continue
                dir = v2D.Normalized()
                v2D = dir * (rs / 2 - rm)
                ps = plot_size
                plot = Main.texture_hud_plot_dir
                aZ = hg.Vector3(dir.x, 0, dir.y)
                aX = hg.Cross(hg.Vector3.Up, aZ)
                t_mat_rot = hg.Matrix3(aX, hg.Vector3.Up, aZ)
                a = 0.5 + 0.5 * abs(sin(t * uniform(1, 500)))

            cx, cy = rx + v2D.x, ry + v2D.y

            if target.nationality == 1:
                c = hg.Color(0.25, 1., 0.25, a)
            elif target.nationality == 2:
                c = hg.Color(1., 0.5, 0.5, a)

            c.a *= value
            p1 = t_mat_rot * hg.Vector3(-plot_size, 0, -ps)
            p2 = t_mat_rot * hg.Vector3(-plot_size, 0, ps)
            p3 = t_mat_rot * hg.Vector3(plot_size, 0, ps)
            p4 = t_mat_rot * hg.Vector3(plot_size, 0, -ps)
            plus.Quad2D(cx + p1.x, cy + p1.z, cx + p2.x, cy + p2.z, cx + p3.x,
                        cy + p3.z, cx + p4.x, cy + p4.z, c, c, c, c, plot)

    c = hg.Color(1, 1, 1, value * max(pow(1 - aircraft.health_level, 2), 0.05))
    plus.Quad2D(rx - rs / 2, ry - rs / 2, rx - rs / 2, ry + rs / 2,
                rx + rs / 2, ry + rs / 2, rx + rs / 2, ry - rs / 2, c, c, c, c,
                Main.texture_noise, 0.25 + 0.25 * sin(t * 103),
                (0.65 + 0.35 * sin(t * 83)), 0.75 + 0.25 * sin(t * 538),
                0.75 + 0.25 * cos(t * 120))
    c = hg.Color(1, 1, 1, value)
    plus.Sprite2D(rx, ry, rs, "assets/sprites/radar_light.png",
                  hg.Color(1, 1, 1, 0.3 * value))
    plus.Sprite2D(rx, ry, rs, "assets/sprites/radar_box.png", c)
コード例 #14
0
		tower_height += 1
	elif plus.KeyPress(hg.KeyF3):
		if tower_height > 1:
			tower_height -= 1

	if tower_radius != old_tower_radius or tower_height != old_tower_height:
		remove_kapla_tower(scn, nodes)
		nodes = add_kapla_tower(scn, 0.5, 2, 2, tower_radius, tower_height)

	if plus.KeyPress(hg.KeySpace):
		world = cam.GetTransform().GetWorld()
		ball, body = plus.AddPhysicSphere(scn, world)
		body.ApplyLinearImpulse(world.GetZ() * 50)
		nodes.append(ball)

	# update the camera controller and synchronize the camera node
	dt = plus.UpdateClock()
	fps.UpdateAndApplyToNode(cam, dt)

	# update scene
	plus.UpdateScene(scn, dt)

	# display on-screen instructions
	plus.Text2D(5, 25, "F1/F2 modify tower radius, F3/F4 modify tower height (%d blocks) @%.2fFPS" % (len(nodes), 1 / hg.time_to_sec_f(dt)))
	plus.Text2D(5, 5, "Move around with QSZD, left mouse button to look around, space to shoot")

	plus.Flip()
	plus.EndFrame()

plus.RenderUninit()
コード例 #15
0
def main_phase(plus, delta_t):
	dts = hg.time_to_sec_f(delta_t)
	camera = Main.scene.GetNode("Camera")

	acc=Main.p1_aircraft.get_linear_acceleration()
	noise_level = max(0, Main.p1_aircraft.get_linear_speed() * 3.6 / 2500 * 0.1 + pow(
		min(1, abs(acc / 7)), 2) * 1)
	if Main.p1_aircraft.post_combution:
		noise_level += 0.1

	if Main.satellite_view:
		update_satellite_camera(Main.satellite_camera, Main.resolution.x / Main.resolution.y, dts)
	Main.camera_matrix = update_camera_tracking(camera, dts, noise_level)
	Main.camera_v_move = camera_move * dts
	#Main.fps.UpdateAndApplyToNode(camera, delta_t)
	#Main.camera_matrix = None

	update_radial_post_process(acc)

	# Kinetics:
	fade_in_delay = 1.
	if Main.fading_cptr < fade_in_delay:
		Main.fading_cptr = min(fade_in_delay, Main.fading_cptr + dts)
		Main.HSL_postProcess.SetS( Main.fading_cptr / fade_in_delay * 0.75)

	animations(dts)
	Main.carrier.update_kinetics(Main.scene, dts)
	Main.p1_aircraft.update_kinetics(Main.scene, dts)
	Main.p2_aircraft.update_kinetics(Main.scene, dts)

	pk, rk, yk = control_aircraft_keyboard(dts, Main.p1_aircraft)
	if Main.controller is not None:
		pp, rp, yp = control_aircraft_paddle(dts, Main.p1_aircraft)

	Main.p1_aircraft.stabilize(dts, pk & pp, yk & yp, rk & rp)
	# Hud
	display_hud(Main, plus, Main.p1_aircraft, Main.p1_targets)

	control_views()

	# SFX:
	Main.p1_sfx.update_sfx(Main, dts)
	Main.p2_sfx.update_sfx(Main, dts)

	# rendering:
	render_flow(plus,delta_t)

	if Main.fadout_flag:
		Main.fadout_cptr += dts
		fadout_delay = 1
		f = Main.fadout_cptr / fadout_delay
		Main.audio.SetMasterVolume(1 - f)
		Main.HSL_postProcess.SetL(max(0, 1 - f))
		if Main.fadout_cptr > fadout_delay:
			Main.HSL_postProcess.SetL(0)
			return init_start_phase()

	back = False
	if Main.controller is not None:
		if Main.controller.WasButtonPressed(hg.ButtonBack): back = True
	if plus.KeyPress(hg.KeyBackspace) or back:
		Main.fadout_flag = True

	if Main.p1_aircraft.wreck:
		Main.p1_success = False
		return init_end_phase()

	if Main.p2_aircraft.wreck:
		Main.p1_success = True
		return init_end_phase()

	return main_phase
コード例 #16
0
	dt = plus.UpdateClock()
	fps.UpdateAndApplyToNode(cam, dt)

	scn.Update(dt)

	# NOTE: Here we break out of the high-level scene.Update call in order to
	# take profit of multiple core and run the following script code while the
	# scene systems are updating.
	# You can move the WaitUpdate(True) above this command to see the effect on
	# performance of updating the scene and its content sequencially.
	if plus.KeyPress(hg.KeySpace):
		animate = not animate

	if animate:
		for j, row in enumerate(rows):
			crow = cos(angle + j * 0.1)
			for i, node_pos in enumerate(row):
				node_pos[1].y = crow * sin(angle + i * 0.1) * 6 + 6.5
				node_pos[0].GetTransform().SetPosition(node_pos[1])
		angle += hg.time_to_sec_f(dt)

	scn.WaitUpdate(True)  # move this call right after the Update call to reduce performance
	scn.Commit()
	scn.WaitCommit(True)

	plus.Text2D(5, 25, "40000 dynamic objects @%.2fFPS" % (1 / hg.time_to_sec_f(dt)))
	plus.Text2D(5, 5, "Move around with QSZD, left mouse button to look around, space to toggle script animation")
	plus.Flip()
	plus.EndFrame()

plus.RenderUninit()
コード例 #17
0
hg.LoadPlugins()

plus = hg.GetPlus()

plus.CreateWorkers()
plus.RenderInit(640, 400)

scn = plus.NewScene()

cam = plus.AddCamera(scn, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 1, -10)))
plus.AddLight(scn, hg.Matrix4.RotationMatrix(hg.Vector3(0.6, -0.4, 0)), hg.LightModelLinear, 150)
plus.AddLight(scn, hg.Matrix4.RotationMatrix(hg.Vector3(0.6, pi, 0.2)), hg.LightModelLinear, 0, True, hg.Color(0.3, 0.3, 0.4))
plus.AddPhysicPlane(scn)

nodes = add_kapla_tower(scn, 0.5, 2, 2, 6, 16)

fps = hg.FPSController(0, 16, -80)

while not plus.IsAppEnded():
	dt = plus.UpdateClock()
	fps.UpdateAndApplyToNode(cam, dt)

	plus.UpdateScene(scn, dt)

	plus.Text2D(5, 25, "@%.2fFPS" % (1 / hg.time_to_sec_f(dt)))
	plus.Text2D(5, 5, "Move around with QSZD, left mouse button to look around")
	plus.Flip()
	plus.EndFrame()

plus.RenderUninit()
コード例 #18
0
            spawn_rate_control += 1 / particle_spawn_rate

            # teleport the particle rigid body to its spawn position, wake it up and reset its world matrix
            rigid_body = particle['body']
            particle['life'] = particle_count / particle_spawn_rate

            rigid_body.SetIsSleeping(False)
            rigid_body.ResetWorld(
                hg.Matrix4.TransformationMatrix(
                    start_pos,
                    hg.Vector3(random.random(), random.random(),
                               random.random())))
            rigid_body.ApplyLinearImpulse(direction +
                                          hg.Vector3(random.random() * 0.5,
                                                     random.random() * 0.5,
                                                     random.random() * 0.5))


while not plus.IsAppEnded():
    dt_sec = plus.UpdateClock()

    fps.UpdateAndApplyToNode(cam, dt_sec)

    update_particles(hg.time_to_sec_f(dt_sec), hg.Vector3(2.5, 3, -1),
                     hg.Vector3(-1, 2, 3))

    plus.UpdateScene(scn, dt_sec)
    plus.Flip()
    plus.EndFrame()

plus.RenderUninit()
コード例 #19
0
ファイル: main.py プロジェクト: harfang3d/game-winter-z
	start_ambient_sound()

	Main.score = 0
	Main.score_max = 0
	reset_intro_phase()
	game_phase = intro_phase

	while not keyboard.Pressed(hg.K_Escape):
		keyboard.Update()
		mouse.Update()
		dt = hg.TickClock()
		Sprite.z_depth = 100

		hg.SetViewClear(0, hg.CF_Color | hg.CF_Depth, hg.ColorI(64, 64, 64), 1, 0)
		hg.SetViewRect(0, 0, 0, int(Main.resolution.x), int(Main.resolution.y))

		Main.delta_t = hg.time_to_sec_f(dt) * Main.game_speed[Main.difficulty_level]

		hg.SetViewOrthographic(0, 0, 0, int(Main.resolution.x), int(Main.resolution.y), hg.TransformationMat4(hg.Vec3(Main.resolution.x / 2, Main.resolution.y / 2, 0), hg.Vec3(0, 0, 0), hg.Vec3(1, 1, 1)), 0, 101, int(Main.resolution.y))

		Main.sprites["background"].draw()

		game_phase = game_phase()

		hg.Frame()
		hg.UpdateWindow(win)

	hg.AudioShutdown()
	hg.InputShutdown()
	hg.RenderShutdown()
	hg.DestroyWindow(win)
コード例 #20
0
ファイル: main.py プロジェクト: harfang3d/game-winter-z
	def waiting(self):
		self.inc_frame()
		self.position.y = 0.67 + convy(5) * sin(hg.time_to_sec_f(hg.GetClock()) * 4)
コード例 #21
0
	# emitter_angle += -hg.time_to_sec_f(dt) * 0.5
	emitter_angle = mat_head.GetRotation().y + (current_tower * 2 * math.pi / 3.0)
	emitter_pos = hg.Vector3(emitter_distance * math.sin(emitter_angle), 0, emitter_distance * math.cos(emitter_angle))
	# print(emitter_angle)
	plus.Text2D(16, 16, "emitter_angle = " + str(math.radians(emitter_angle)))
	plus.Text2D(16, 32, "timer         = " + str(timer))
	plus.Text2D(16, 48, "game_state    = " + game_state)
	plus.Text2D(16, 64, "shooting      = " + str(shooting))
	if len(word_list) > 0 and current_word < len(word_list):
		plus.Text2D(16, 64 + 16, "current word = " + word_list[max(0, current_word - 1)])
		plus.Text2D(16, 64 + 32, "next word = " + word_list[current_word])

	if channel is not None:
		mixer.SetChannelLocation(channel, hg.MixerChannelLocation(emitter_pos))

	if dispatch is not None:
		dispatch()

	if channel_tower is not None:
		mixer.SetChannelLocation(channel_tower, hg.MixerChannelLocation(emitter_pos))

	emit_controller()
	update_tone_sound(dt)

	timer += hg.time_to_sec_f(dt)

	plus.UpdateScene(scene)
	plus.Flip()
	plus.EndFrame()

mixer.Close()
コード例 #22
0
plus = hg.GetPlus()

plus.CreateWorkers()
plus.RenderInit(640, 400)

scn = plus.NewScene()

cam = plus.AddCamera(scn, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 1, -10)))
plus.AddLight(scn, hg.Matrix4.RotationMatrix(hg.Vector3(0.6, -0.4, 0)),
              hg.LightModelLinear, 150)
plus.AddLight(scn, hg.Matrix4.RotationMatrix(hg.Vector3(0.6, pi, 0.2)),
              hg.LightModelLinear, 0, True, hg.Color(0.3, 0.3, 0.4))
plus.AddPhysicPlane(scn)

nodes = add_kapla_tower(scn, 0.5, 2, 2, 6, 16)

fps = hg.FPSController(0, 16, -80)

while not plus.IsAppEnded():
    dt = plus.UpdateClock()
    fps.UpdateAndApplyToNode(cam, dt)

    plus.UpdateScene(scn, dt)

    plus.Text2D(5, 25, "@%.2fFPS" % (1 / hg.time_to_sec_f(dt)))
    plus.Text2D(5, 5,
                "Move around with QSZD, left mouse button to look around")
    plus.Flip()
    plus.EndFrame()

plus.RenderUninit()
コード例 #23
0
def game():
	plus = hg.GetPlus()
	plus.RenderInit(screen_width, screen_height)
	al = hg.CreateMixer()
	al.Open()
	hg.MountFileDriver(hg.StdFileDriver())
	keyboard = hg.GetInputSystem().GetDevice("keyboard")

	scn, ground = setup_game_level(plus)
	turret, cannon, turret_mass = create_turret(plus, scn)

	game_state = "GAME_INIT"

	while not plus.IsAppEnded():
		dt = plus.UpdateClock()

		# Initialize Game
		if game_state == "GAME_INIT":
			enemy_list = []
			debris_list = []
			spawn_timer = 0.0
			turret_cool_down = 0.0
			enemy_spawn_interval = max_enemy_spawn_interval
			player_life = max_player_life
			target_angle = 0.0
			score = 0
			play_sound_fx(al, 'game_start')
			game_state = "TITLE"

		# Title screen
		if game_state == "TITLE":
			display_title_screen(plus, scn)
			if plus.KeyReleased(hg.KeySpace):
				game_state = "GAME"
		# Game
		elif game_state == "GAME":
			# Turret
			if plus.KeyDown(hg.KeyRight):
				target_angle += hg.time_to_sec_f(dt) * aim_rotation_speed
			else:
				if plus.KeyDown(hg.KeyLeft):
					target_angle -= hg.time_to_sec_f(dt) * aim_rotation_speed

			if plus.KeyPress(hg.KeySpace):
				if turret_cool_down < 0.0:
					throw_bullet(plus, scn, cannon.GetTransform().GetWorld().GetTranslation(), cannon.GetTransform().GetWorld().GetRow(1))
					turret_cool_down = turret_cool_down_duration
					play_sound_fx(al, 'shoot')
				else:
					play_sound_fx(al, 'error')
					turret_cool_down += 10.0 * hg.time_to_sec_f(dt)

			turret_cool_down -= hg.time_to_sec_f(dt)

			target_angle = max(min(target_angle, aim_angle_range['max']), aim_angle_range['min'])

			rotate_turret(turret, target_angle, turret_mass)

			# Enemies
			spawn_timer += hg.time_to_sec_f(dt)
			if spawn_timer > enemy_spawn_interval:
				spawn_timer = 0
				spawn_pos = hg.Vector3(uniform(-10, 10), 2.5, uniform(5.5, 6.5))
				spawn_pos.Normalize()
				spawn_pos *= 10.0
				spawn_pos.y = 5.0
				new_enemy = spawn_enemy(plus, scn, spawn_pos)
				enemy_list.append([new_enemy[0], new_enemy[1]])

			for enemy in enemy_list:
				# make enemy crawl toward the player
				enemy_dir = turret[0].GetTransform().GetPosition() - enemy[0].GetTransform().GetPosition()
				enemy_dir.Normalize()
				enemy[1].SetIsSleeping(False)
				enemy[1].ApplyLinearForce(enemy_dir * 0.25 * enemy_mass)

				col_pairs = scn.GetPhysicSystem().GetCollisionPairs(enemy[0])
				for col_pair in col_pairs:
					if 'turret' in [col_pair.GetNodeA().GetName(), col_pair.GetNodeB().GetName()]:
						destroy_enemy(plus, scn, enemy[0])
						debris_list.extend(create_explosion(plus, scn, enemy[0].GetTransform().GetPosition()))
						enemy_list.remove(enemy)
						play_sound_fx(al, 'explosion')
						play_sound_fx(al, 'hit')
						player_life -= 1
						turret_cool_down = 0.0
						if player_life < 1:
							play_sound_fx(al, 'game_over')
							game_state = "GAME_OVER"
					else:
						if 'bullet' in [col_pair.GetNodeA().GetName(), col_pair.GetNodeB().GetName()]:
							play_sound_fx(al, 'explosion')
							pos = col_pair.GetNodeB().GetTransform().GetPosition()
							debris_list.extend(create_explosion(plus, scn, pos, 8, 0.25))

							pos = enemy[0].GetTransform().GetPosition()
							destroy_enemy(plus, scn, enemy[0])
							enemy_list.remove(enemy)
							scn.RemoveNode(col_pair.GetNodeB())
							debris_list.extend(create_explosion(plus, scn, pos))

							score += 10

				# Game difficulty
				enemy_spawn_interval = max(1.0, enemy_spawn_interval - hg.time_to_sec_f(dt) * 0.025)

				# Cleanup debris
				if len(debris_list) > max_debris:
					tmp_debris = debris_list[0]
					debris_list.remove(debris_list[0])
					tmp_debris.RemoveComponent(tmp_debris.GetRigidBody())
					# scn.RemoveNode(tmp_debris)

			render_aim_cursor(plus, scn, target_angle)
			display_hud(plus, player_life / max_player_life, max(0, turret_cool_down) / turret_cool_down_duration, score)

		# Game over screen
		elif game_state == "GAME_OVER":
			display_game_over(plus, scn, score)
			if plus.KeyReleased(hg.KeySpace):
				game_state = "SCENE_RESET"

		# Reset the playfield for a new game
		elif game_state == "SCENE_RESET":
			for enemy in enemy_list:
				destroy_enemy(plus, scn, enemy[0])

			for debris in debris_list:
				debris.RemoveComponent(debris.GetRigidBody())

			game_state = "GAME_INIT"

		plus.UpdateScene(scn, dt)
		plus.Flip()
		plus.EndFrame()

	return plus
コード例 #24
0
	init_game(plus)

	#plus.UpdateScene(Main.scene)
	Main.scene.Commit()
	Main.scene.WaitCommit()

	# -----------------------------------------------
	#                   Main loop
	# -----------------------------------------------

	game_phase = init_start_phase()

	while not plus.KeyDown(hg.KeyEscape) and not plus.IsAppEnded():
		delta_t = plus.UpdateClock()
		dts = hg.time_to_sec_f(delta_t)

		if plus.KeyPress(hg.KeyF12):
			if Main.display_gui:
				Main.display_gui = False
			else:
				Main.display_gui = True
		if Main.display_gui:
			hg.ImGuiMouseDrawCursor(True)
			gui_interface_sea_render(Main.sea_render, Main.scene, Main.fps)
			gui_interface_scene(Main.scene, Main.fps)
			gui_interface_game(Main.scene)
			gui_post_rendering()
			gui_clouds(Main.scene, Main.clouds)
		# edition_clavier(Main.sea_render)
		# autopilot_controller(Main.p1_aircraft)
コード例 #25
0
def end_phase(plus, delta_t):
	dts = hg.time_to_sec_f(delta_t)

	camera = Main.scene.GetNode("Camera")
	Main.camera_matrix = update_camera_follow(camera, dts)
	Main.camera_v_move = camera_move * dts

	# Kinetics:
	if Main.p1_success:
		msg = "MISSION SUCCESSFUL !"
		x = 435 / 1600
		fade_in_delay = 10
		s = 50 / 900
	else:
		msg = "R.I.P."
		x = 685 / 1600
		fade_in_delay = 1
		s = 72 / 900
	if Main.fading_cptr < fade_in_delay:
		Main.fading_cptr = min(fade_in_delay, Main.fading_cptr + dts)
		Main.HSL_postProcess.SetS((1 - Main.fading_cptr / fade_in_delay) * Main.fading_start_saturation)

	animations(dts)
	Main.carrier.update_kinetics(Main.scene, dts)
	Main.p1_aircraft.update_kinetics(Main.scene, dts)
	Main.p2_aircraft.update_kinetics(Main.scene, dts)

	# Hud

	f = Main.HSL_postProcess.GetL()
	plus.Text2D(x * Main.resolution.x, 611 / 900 * Main.resolution.y, msg, s * Main.resolution.y,
				hg.Color(1., 0.9, 0.3, 1) * f)

	plus.Text2D(645 / 1600 * Main.resolution.x, 531 / 900 * Main.resolution.y, "Hit Space or Start",
				0.025 * Main.resolution.y,
				hg.Color(1, 1, 1, (1 + sin(hg.time_to_sec_f(plus.GetClock() * 10))) * 0.5) * f)

	# SFX:
	Main.p1_sfx.update_sfx(Main, dts)
	Main.p2_sfx.update_sfx(Main, dts)

	# rendering:
	render_flow(plus,delta_t)

	start = False
	if Main.controller is not None:
		if Main.controller.WasButtonPressed(hg.ButtonStart): start = True

	if plus.KeyPress(hg.KeySpace) or start:
		Main.fadout_flag = True
		Main.fadout_cptr = 0

	if Main.fadout_flag:
		Main.fadout_cptr += dts
		fadout_delay = 1
		f = Main.fadout_cptr / fadout_delay
		Main.audio.SetMasterVolume(1 - f)
		Main.HSL_postProcess.SetL(max(0, 1 - f))
		if Main.fadout_cptr > fadout_delay:
			Main.HSL_postProcess.SetL(0)
			return init_start_phase()

	return end_phase
コード例 #26
0
terrain = hg.Terrain()
terrain.SetSize(hg.Vector3(68767, 5760, 68767))
terrain.SetHeightmap("@data/terrain/island.r16")
terrain.SetHeightmapResolution(hg.IntVector2(1024, 1024))
terrain.SetMinPrecision(50)  # don't bother with a very fine grid given the low resolution heightmap in use
terrain.SetSurfaceShader("@data/terrain/island.isl")

terrain_node = hg.Node()
terrain_node.AddComponent(hg.Transform())
terrain_node.AddComponent(terrain)
scn.AddNode(terrain_node)

#
fps = hg.FPSController(0, 3000, -30000, 100, 400)

while not plus.IsAppEnded():
	dt = plus.UpdateClock()

	old_pos = fps.GetPos()
	fps.UpdateAndApplyToNode(cam, dt)
	speed = hg.Dist(fps.GetPos(), old_pos) / hg.time_to_sec_f(dt) if dt > 0 else 0

	plus.UpdateScene(scn, dt)

	plus.Text2D(5, 25, "Current speed: %d m/s" % int(speed))
	plus.Text2D(5, 5, "Move around with QSZD, left mouse button to look around (hold shift to go faster)")
	plus.Flip()
	plus.EndFrame()

plus.RenderUninit()
コード例 #27
0
ファイル: main.py プロジェクト: harfang3d/game-winter-z
def play_animations():
	anims_playing = False
	for animation in Main.animations:
		anims_playing |= animation.update_animation(hg.time_to_sec_f(hg.GetClock()))
	return anims_playing
コード例 #28
0
	spawn_rate_control -= dt_sec

	for i in range(particle_count):
		particle = particles[i]

		if particle['life'] > 0:
			particle['life'] -= dt_sec # update life
		elif spawn_rate_control < 0:
			spawn_rate_control += 1 / particle_spawn_rate

			# teleport the particle rigid body to its spawn position, wake it up and reset its world matrix
			rigid_body = particle['body']
			particle['life'] = particle_count / particle_spawn_rate

			rigid_body.SetIsSleeping(False)
			rigid_body.ResetWorld(hg.Matrix4.TransformationMatrix(start_pos, hg.Vector3(random.random(), random.random(), random.random())))
			rigid_body.ApplyLinearImpulse(direction + hg.Vector3(random.random() * 0.5, random.random() * 0.5, random.random() * 0.5))


while not plus.IsAppEnded():
	dt_sec = plus.UpdateClock()

	fps.UpdateAndApplyToNode(cam, dt_sec)

	update_particles(hg.time_to_sec_f(dt_sec), hg.Vector3(2.5, 3, -1), hg.Vector3(-1, 2, 3))

	plus.UpdateScene(scn, dt_sec)
	plus.Flip()
	plus.EndFrame()

plus.RenderUninit()
コード例 #29
0
ファイル: 5_isometric_view.py プロジェクト: nwy140/Tutorials
    scn,
    hg.Matrix4.TransformationMatrix(hg.Vector3.Zero, hg.Vector3(0.075, 0, 0)),
    hg.LightModelLinear, 50)
plus.AddPlane(scn, hg.Matrix4.Identity, 1, 1)

# create a few boxes
boxes = []
for i in range(63):
    box = plus.AddCube(scn, hg.Matrix4.Identity, 0.1, 0.25, 0.1)
    boxes.append(box)

# main rendering loop
t = 0
while not plus.IsAppEnded():
    # get the boxes dancing
    t += hg.time_to_sec_f(plus.UpdateClock())

    for i, box in enumerate(boxes):
        t_ = t + i * 0.1
        pos = hg.Vector3(math.cos(t_), 0, math.sin(t_))
        rot = hg.Vector3(t_ * 2, t_ * -3, t_ + t * 4)
        box.GetTransform().SetWorld(
            hg.Matrix4.TransformationMatrix(pos, rot, hg.Vector3.One))

    # Update the scenegraph, process the render
    plus.UpdateScene(scn)
    plus.Flip()
    plus.EndFrame()

# Release all render ressources and close the screen
plus.RenderUninit()
コード例 #30
0
#
scn = plus.NewScene()
cam = plus.AddCamera(scn, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 1, -10)))
plus.AddLight(scn, hg.Matrix4.RotationMatrix(hg.Vector3(0.6, -0.4, 0)), hg.LightModelLinear, 300)
plus.AddPlane(scn)

renderable_system = scn.GetRenderableSystem()

a = 0
while not plus.IsAppEnded():
	dt = plus.UpdateClock()
	fps.UpdateAndApplyToNode(cam, dt)

	geo = update_field(a)
	a += hg.time_to_sec_f(dt) * 0.5

	renderable_system.DrawGeometry(geo, hg.Matrix4.Identity)

	plus.UpdateScene(scn, dt)

	draw_bench(bench_fill_field, hg.Color.Red)
	draw_bench(bench_polygonise, hg.Color.Green)
	draw_bench(bench_create_geo, hg.Color.Blue)

	plus.Text2D(800, 45, "Update scalar field", 16, hg.Color.Red)
	plus.Text2D(800, 25, "Polygonise scalar field", 16, hg.Color.Green)
	plus.Text2D(800, 5, "Prepare render geometry", 16, hg.Color.Blue)

	plus.Text2D(5, 25, "Iso-surface @%.2fFPS (%d triangle)" % (1 / hg.time_to_sec_f(dt), iso.GetTriangleCount()))
	plus.Text2D(5, 5, "Move around with QSZD, left mouse button to look around")
コード例 #31
0
cam.GetCamera().SetZFar(10)

plus.AddLight(scn, hg.Matrix4.TransformationMatrix(hg.Vector3.Zero, hg.Vector3(0.075, 0, 0)), hg.LightModelLinear, 50)
plus.AddPlane(scn, hg.Matrix4.Identity, 1, 1)

# create a few boxes
boxes = []
for i in range(63):
	box = plus.AddCube(scn, hg.Matrix4.Identity, 0.1, 0.25, 0.1)
	boxes.append(box)

# main rendering loop
t = 0
while not plus.IsAppEnded():
	# get the boxes dancing
	t += hg.time_to_sec_f(plus.UpdateClock())

	for i, box in enumerate(boxes):
		t_ = t + i * 0.1
		pos = hg.Vector3(math.cos(t_), 0, math.sin(t_))
		rot = hg.Vector3(t_ * 2, t_ * -3, t_ + t * 4)
		box.GetTransform().SetWorld(hg.Matrix4.TransformationMatrix(pos, rot, hg.Vector3.One))

	# Update the scenegraph, process the render
	plus.UpdateScene(scn)
	plus.Flip()
	plus.EndFrame()

# Release all render ressources and close the screen
plus.RenderUninit()
コード例 #32
0
def render_flow(plus,delta_t):
	t = hg.time_to_sec_f(plus.GetClock())
	dts=hg.time_to_sec_f(delta_t)

	renderScript_flow(plus, t,dts)
コード例 #33
0
def start_phase(plus, delta_t):
	dts = hg.time_to_sec_f(delta_t)
	camera = Main.scene.GetNode("Camera")

	# Main.fps.UpdateAndApplyToNode(camera, delta_t)
	Main.camera_matrix = update_camera_follow(camera, dts)
	Main.camera_v_move = camera_move * dts

	# Kinetics:

	animations(dts)
	Main.carrier.update_kinetics(Main.scene, dts)
	Main.p1_aircraft.update_kinetics(Main.scene, dts)
	# Main.p2_aircraft.update_kinetics(Main.scene, dts)

	# fade in:
	fade_in_delay = 1.
	Main.fading_cptr = min(fade_in_delay, Main.fading_cptr + dts)

	Main.HSL_postProcess.SetL(Main.fading_cptr / fade_in_delay)

	if Main.fading_cptr >= fade_in_delay:
		# Start infos:
		f = Main.HSL_postProcess.GetL()
		plus.Text2D(514 / 1600 * Main.resolution.x, 771 / 900 * Main.resolution.y, "GET READY",
					0.08 * Main.resolution.y, hg.Color(1., 0.9, 0.3, 1) * f)

		plus.Text2D(554 / 1600 * Main.resolution.x, 671 / 900 * Main.resolution.y,
					"Ennemy aircraft detected : Shoot it down !", 0.02 * Main.resolution.y,
					hg.Color(1., 0.9, 0.3, 1) * f, Main.hud_font)

		plus.Text2D(640 / 1600 * Main.resolution.x, 591 / 900 * Main.resolution.y, "Hit space or Start",
					0.025 * Main.resolution.y,
					hg.Color(1, 1, 1, (1 + sin(hg.time_to_sec_f(plus.GetClock() * 10))) * 0.5) * f)

		s = 0.015
		x = 470 / 1600 * Main.resolution.x
		y = 350
		c = hg.Color(1., 0.9, 0.3, 1) * f
		# Function
		plus.Text2D(x, y / 900 * Main.resolution.y, "Thrust level", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 20) / 900 * Main.resolution.y, "Pitch", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 40) / 900 * Main.resolution.y, "Roll", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 60) / 900 * Main.resolution.y, "SYaw", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 80) / 900 * Main.resolution.y, "Gun", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 100) / 900 * Main.resolution.y, "Missiles", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 120) / 900 * Main.resolution.y, "Target selection", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 140) / 900 * Main.resolution.y, "Brake", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 160) / 900 * Main.resolution.y, "Flaps", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 180) / 900 * Main.resolution.y, "Post combustion (only thrust=100%)", s * Main.resolution.y,
					c, Main.hud_font)
		plus.Text2D(x, (y - 200) / 900 * Main.resolution.y, "Reset game", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 220) / 900 * Main.resolution.y, "Set View", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 240) / 900 * Main.resolution.y, "Satellite Zoom", s * Main.resolution.y, c, Main.hud_font)
		# Keyboard
		c = hg.Color.White
		x = 815 / 1600 * Main.resolution.x
		plus.Text2D(x, y / 900 * Main.resolution.y, "Home / End", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 20) / 900 * Main.resolution.y, "Up / Down", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 40) / 900 * Main.resolution.y, "Right / Left", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 60) / 900 * Main.resolution.y, "Suppr / Page down", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 80) / 900 * Main.resolution.y, "ENTER", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 100) / 900 * Main.resolution.y, "F1", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 120) / 900 * Main.resolution.y, "T", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 140) / 900 * Main.resolution.y, "B / N", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 160) / 900 * Main.resolution.y, "C / V", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 180) / 900 * Main.resolution.y, "Space", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 200) / 900 * Main.resolution.y, "Backspace", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 220) / 900 * Main.resolution.y, "2/4/8/6/5", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 240) / 900 * Main.resolution.y, "Insert / Page Up", s * Main.resolution.y, c, Main.hud_font)

		# Paddle
		x = 990 / 1600 * Main.resolution.x
		plus.Text2D(x, y / 900 * Main.resolution.y, "Right pad up / down", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 20) / 900 * Main.resolution.y, "Left pad", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 40) / 900 * Main.resolution.y, "Left pad", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 60) / 900 * Main.resolution.y, "RT / LT", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 80) / 900 * Main.resolution.y, "A", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 100) / 900 * Main.resolution.y, "X", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 120) / 900 * Main.resolution.y, "Y", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 140) / 900 * Main.resolution.y, "Cross Up / Down", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 160) / 900 * Main.resolution.y, "Cross Right / LEft", s * Main.resolution.y, c,
					Main.hud_font)
		plus.Text2D(x, (y - 180) / 900 * Main.resolution.y, "B", s * Main.resolution.y, c, Main.hud_font)
		plus.Text2D(x, (y - 200) / 900 * Main.resolution.y, "Back", s * Main.resolution.y, c, Main.hud_font)

		start = False
		if Main.controller is not None:
			if Main.controller.WasButtonPressed(hg.ButtonStart): start = True
		if plus.KeyPress(hg.KeySpace) or start:
			return init_main_phase()

	# rendering:
	render_flow(plus,delta_t)

	return start_phase
コード例 #34
0
def game():
	plus = hg.GetPlus()
	plus.RenderInit(screen_width, screen_height)
	al = hg.CreateMixer()
	al.Open()
	hg.MountFileDriver(hg.StdFileDriver())
	keyboard = hg.GetInputSystem().GetDevice("keyboard")

	scn, ground = setup_game_level(plus)
	turret, cannon, turret_mass = create_turret(plus, scn)

	game_state = "GAME_INIT"

	while not plus.IsAppEnded():
		dt = plus.UpdateClock()

		# Initialize Game
		if game_state == "GAME_INIT":
			enemy_list = []
			debris_list = []
			spawn_timer = 0.0
			turret_cool_down = 0.0
			enemy_spawn_interval = max_enemy_spawn_interval
			player_life = max_player_life
			target_angle = 0.0
			score = 0
			play_sound_fx(al, 'game_start')
			game_state = "TITLE"

		# Title screen
		if game_state == "TITLE":
			display_title_screen(plus, scn)
			if plus.KeyReleased(hg.KeySpace):
				game_state = "GAME"
		# Game
		elif game_state == "GAME":
			# Turret
			if plus.KeyDown(hg.KeyRight):
				target_angle += hg.time_to_sec_f(dt) * aim_rotation_speed
			else:
				if plus.KeyDown(hg.KeyLeft):
					target_angle -= hg.time_to_sec_f(dt) * aim_rotation_speed

			if plus.KeyPress(hg.KeySpace):
				if turret_cool_down < 0.0:
					throw_bullet(plus, scn, cannon.GetTransform().GetWorld().GetTranslation(), cannon.GetTransform().GetWorld().GetRow(1))
					turret_cool_down = turret_cool_down_duration
					play_sound_fx(al, 'shoot')
				else:
					play_sound_fx(al, 'error')
					turret_cool_down += 10.0 * hg.time_to_sec_f(dt)

			turret_cool_down -= hg.time_to_sec_f(dt)

			target_angle = max(min(target_angle, aim_angle_range['max']), aim_angle_range['min'])

			rotate_turret(turret, target_angle, turret_mass)

			# Enemies
			spawn_timer += hg.time_to_sec_f(dt)
			if spawn_timer > enemy_spawn_interval:
				spawn_timer = 0
				spawn_pos = hg.Vector3(uniform(-10, 10), 2.5, uniform(5.5, 6.5))
				spawn_pos.Normalize()
				spawn_pos *= 10.0
				spawn_pos.y = 5.0
				new_enemy = spawn_enemy(plus, scn, spawn_pos)
				enemy_list.append([new_enemy[0], new_enemy[1]])

			for enemy in enemy_list:
				# make enemy crawl toward the player
				enemy_dir = turret[0].GetTransform().GetPosition() - enemy[0].GetTransform().GetPosition()
				enemy_dir.Normalize()
				enemy[1].SetIsSleeping(False)
				enemy[1].ApplyLinearForce(enemy_dir * 0.25 * enemy_mass)

				col_pairs = scn.GetPhysicSystem().GetCollisionPairs(enemy[0])
				for col_pair in col_pairs:
					if 'turret' in [col_pair.GetNodeA().GetName(), col_pair.GetNodeB().GetName()]:
						destroy_enemy(plus, scn, enemy[0])
						debris_list.extend(create_explosion(plus, scn, enemy[0].GetTransform().GetPosition()))
						enemy_list.remove(enemy)
						play_sound_fx(al, 'explosion')
						play_sound_fx(al, 'hit')
						player_life -= 1
						if player_life < 1:
							play_sound_fx(al, 'game_over')
							game_state = "GAME_OVER"
					else:
						if 'bullet' in [col_pair.GetNodeA().GetName(), col_pair.GetNodeB().GetName()]:
							play_sound_fx(al, 'explosion')
							pos = col_pair.GetNodeB().GetTransform().GetPosition()
							debris_list.extend(create_explosion(plus, scn, pos, 8, 0.25))

							pos = enemy[0].GetTransform().GetPosition()
							destroy_enemy(plus, scn, enemy[0])
							enemy_list.remove(enemy)
							scn.RemoveNode(col_pair.GetNodeB())
							debris_list.extend(create_explosion(plus, scn, pos))

							score += 10

				# Game difficulty
				enemy_spawn_interval = max(1.0, enemy_spawn_interval - hg.time_to_sec_f(dt) * 0.025)

				# Cleanup debris
				if len(debris_list) > max_debris:
					tmp_debris = debris_list[0]
					debris_list.remove(debris_list[0])
					tmp_debris.RemoveComponent(tmp_debris.GetRigidBody())
					# scn.RemoveNode(tmp_debris)

			render_aim_cursor(plus, scn, target_angle)
			display_hud(plus, player_life / max_player_life, max(0, turret_cool_down) / turret_cool_down_duration, score)

		# Game over screen
		elif game_state == "GAME_OVER":
			display_game_over(plus, scn, score)
			if plus.KeyReleased(hg.KeySpace):
				game_state = "SCENE_RESET"

		# Reset the playfield for a new game
		elif game_state == "SCENE_RESET":
			for enemy in enemy_list:
				destroy_enemy(plus, scn, enemy[0])

			for debris in debris_list:
				debris.RemoveComponent(debris.GetRigidBody())

			game_state = "GAME_INIT"

		plus.UpdateScene(scn, dt)
		plus.Flip()
		plus.EndFrame()
コード例 #35
0
)  # don't bother with a very fine grid given the low resolution heightmap in use
terrain.SetSurfaceShader("@data/terrain/island.isl")

terrain_node = hg.Node()
terrain_node.AddComponent(hg.Transform())
terrain_node.AddComponent(terrain)
scn.AddNode(terrain_node)

#
fps = hg.FPSController(0, 3000, -30000, 100, 400)

while not plus.IsAppEnded():
    dt = plus.UpdateClock()

    old_pos = fps.GetPos()
    fps.UpdateAndApplyToNode(cam, dt)
    speed = hg.Dist(fps.GetPos(),
                    old_pos) / hg.time_to_sec_f(dt) if dt > 0 else 0

    plus.UpdateScene(scn, dt)

    plus.Text2D(5, 25, "Current speed: %d m/s" % int(speed))
    plus.Text2D(
        5, 5,
        "Move around with QSZD, left mouse button to look around (hold shift to go faster)"
    )
    plus.Flip()
    plus.EndFrame()

plus.RenderUninit()