khanat-client/scenes/game/game.gd
2020-04-01 21:02:49 +02:00

120 lines
3.9 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 _ready():
var player_ra = Ra.new()
var file = File.new()
if file.open("res://ressources/files/creatures/test.creature", File.READ) == OK:
player_ra.from_dict( JSON.parse( file.get_as_text() ).result )
$game_ui/inventory_window.get_content_child( "content_box/inventory_box" ).set_inventory( player_ra.inventory )
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
if event.is_action_released( "inventory_window" ):
if not $inventory_window.visible:
$inventory_window.show()
else:
$inventory_window.hide()
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.global_transform.origin.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 )
var trauma_value = ($game_ui/stats_window.get_content_child( "trauma" ).value / 6.0)
$trauma_fx.get_surface_material( 0 ).set_shader_param( "mist_level", trauma_value )
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 )