khanat-client/scenes/game/game.gd

97 lines
3.2 KiB
GDScript

extends Spatial
var player_speed = 1.0
var player_rotation_speed = 0.1
var mouse_old_position = null
var mouse_delta = Vector2( 0.0, 0.0 )
var camera_zoom_speed = 0.5
var camera_zoom = 0.0
var heightmap = null
func _input( event ):
var movment = Vector3( 0.0, 0.0, 0.0 )
var rotation = Vector3( 0.0, 0.0, 0.0 )
$creatures/player.is_moving = false
if event.is_action( "move_forward" ) and event.is_pressed():
movment.z += self.player_speed * Input.get_action_strength("move_forward")
$creatures/player.is_moving = true
elif event.is_action( "move_backward" ) and event.is_pressed():
movment.z -= self.player_speed * Input.get_action_strength("move_backward")
$creatures/player.is_moving = true
elif event.is_action( "move_left" ) and event.is_pressed():
movment.x += self.player_speed
elif event.is_action( "move_right" ) and event.is_pressed():
movment.x -= self.player_speed
if event.is_action( "turn_left" ) and event.is_pressed():
rotation.y += self.player_rotation_speed
elif event.is_action( "turn_right" ) and event.is_pressed():
rotation.y -= self.player_rotation_speed
# $creatures/player.turn( rotation )
# $creatures/player.move( movment )
if event.is_action( "zoom_in" ):
self.camera_zoom -= self.camera_zoom_speed
elif event.is_action( "zoom_out" ):
self.camera_zoom += self.camera_zoom_speed
if event.is_action_pressed( "free_look" ):
self.mouse_old_position = event.position
elif event.is_action_released( "free_look" ):
self.mouse_old_position = null
if event.is_action( "reset_camera" ):
$creatures/player.reset_camera()
if event is InputEventMouseMotion:
if not mouse_old_position == null:
self.mouse_delta = self.mouse_old_position - event.position
self.mouse_old_position = event.position
func _process( delta ):
$creatures/player.rotate_camera_arm( Vector3( 0.0, 1.0, 0.0 ), deg2rad( self.mouse_delta.x ) )
$creatures/player.move_camera( Vector3( 0.0, 0.0, camera_zoom ) )
$creatures/player.rotate_camera( Vector3( 1.0, 0.0, 0.0 ), deg2rad( self.mouse_delta.y ) )
self.camera_zoom = 0.0
self.mouse_delta = Vector2( 0.0, 0.0 )
# Water fx.
if $creatures/player/model/ra.translation.y <= ($level/demo/water.translation.y-2.5):
$water_fx.get_surface_material( 0 ).set_shader_param( "mist_level", 1.0 )
else:
$water_fx.get_surface_material( 0 ).set_shader_param( "mist_level", 0.0 )
func load_player( filename ):
$creatures/player.load_creature( filename )
func _on_debug_window_time_of_day_changed(value):
$sky/viewport/sky.set_day_time_hours(( value ))
func _on_debug_window_mist_level_changed(value):
$mist_fx.get_surface_material( 0 ).set_shader_param( "mist_level", value )
func _on_debug_window_douleur_minus_pressed():
$game_ui.change_douleur( -1 )
func _on_debug_window_douleur_plus_pressed():
$game_ui.change_douleur( 1 )
func _on_debug_window_oubli_minus_pressed():
$game_ui.change_oubli( -1 )
func _on_debug_window_oubli_plus_pressed():
$game_ui.change_oubli( 1 )