This commit is contained in:
Merlar 2020-02-01 11:31:07 +00:00
commit 3bcadd69ef
19 changed files with 469 additions and 222 deletions

View File

@ -1,10 +1,15 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=3 format=2]
[ext_resource path="res://BodyConfig/BodyParts/Tesso.tscn" type="PackedScene" id=1] [ext_resource path="res://BodyParts/Tesso.tscn" type="PackedScene" id=1]
[ext_resource path="res://BodyConfig/bodyBuildingScript.gd" type="Script" id=2] [ext_resource path="res://BodyConfig/bodyBuildingScript.gd" type="Script" id=2]
[node name="Body Builder Menu" type="Spatial"] [node name="Body Builder Menu" type="Spatial"]
script = ExtResource( 2 ) script = ExtResource( 2 )
torsoPath = NodePath("Torso")
cameraPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport/Camera")
rayCastPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport/MouseLook")
viewPortPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport")
[node name="GUI" type="MarginContainer" parent="."] [node name="GUI" type="MarginContainer" parent="."]
anchor_right = 1.0 anchor_right = 1.0
@ -66,4 +71,7 @@ render_target_update_mode = 3
[node name="Camera" type="Camera" parent="GUI/HBoxC/ViewportContainer/Viewport"] [node name="Camera" type="Camera" parent="GUI/HBoxC/ViewportContainer/Viewport"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3 )
[node name="MouseLook" type="RayCast" parent="GUI/HBoxC/ViewportContainer/Viewport"]
enabled = true
[node name="Torso" parent="." instance=ExtResource( 1 )] [node name="Torso" parent="." instance=ExtResource( 1 )]

View File

@ -1,55 +1,76 @@
extends Spatial extends Spatial
const ROT_MOD = 10 export(NodePath) var torsoPath
export(NodePath) var cameraPath
export(NodePath) var rayCastPath
export(NodePath) var viewPortPath
const ROT_MOD = 500
const ROT_DECLINE = 0.1
var _viewRot = false var _viewRot = false
var _prev_mouse_pos var _prev_mouse_pos
var _camera : Camera
var _rayCast : RayCast
var _torso : RigidBody
var _viewport : Viewport
var _velx = 0
var _vely = 0
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
PhysicsServer.area_set_param(get_viewport().find_world().get_space(), PhysicsServer.AREA_PARAM_GRAVITY, 0) PhysicsServer.area_set_param(get_viewport().find_world().get_space(), PhysicsServer.AREA_PARAM_GRAVITY, 0)
_torso = get_node(torsoPath) as RigidBody
_camera = get_node(cameraPath) as Camera
_rayCast = get_node(rayCastPath) as RayCast
_viewport = get_node(viewPortPath) as Viewport
func _process(delta):
if _viewRot:
var mouse_pos = get_viewport().get_mouse_position()
_velx = (mouse_pos.x - _prev_mouse_pos.x) * delta
_vely = (mouse_pos.y - _prev_mouse_pos.y) * delta
_prev_mouse_pos = mouse_pos
if not(_velx < 0.001 and _velx > -0.001) or not(_vely < 0.001 and _vely > -0.001) or _viewRot:
_torso.rotate_x(_vely * ROT_MOD * delta * PI/180 - global_transform.basis.get_euler().x)
_torso.rotate_y(_velx * ROT_MOD * delta * PI/180 - global_transform.basis.get_euler().y)
var decline = (1 - ROT_DECLINE * (delta*100))
if decline > 1:
decline = 1
elif decline < 0:
decline = 0
_velx *= decline
_vely *= decline
func _physics_process(delta): func _physics_process(delta):
if _viewRot: if _viewRot:
var mouse_pos = get_viewport().get_mouse_position() var mouse_pos = _viewport.get_viewport().get_mouse_position()
var x_dif = mouse_pos.x - _prev_mouse_pos.x #set origin of rayCast
var y_dif = mouse_pos.y - _prev_mouse_pos.y var orig = _camera.project_ray_origin(mouse_pos)
print (x_dif) #set cast_to of rayCast
print (y_dif) _rayCast.translation = orig
_rayCast.cast_to = orig + _camera.project_ray_normal(mouse_pos) * 1000.0
rotate_x(x_dif * ROT_MOD * delta * PI/180 - global_transform.basis.get_euler().y) if _rayCast.is_colliding():
rotate_y(y_dif * ROT_MOD * delta * PI/180 - global_transform.basis.get_euler().y) # collider will be the node hit
print(_rayCast.get_collider())
_prev_mouse_pos = mouse_pos
# Get the camera
#var camera = get_node("GUI/HBoxC/ViewportContainer/Viewport/Camera")
#var mouse_pos = get_viewport().get_mouse_position()
# Project mouse into a 3D ray
#var ray_origin = camera.project_ray_origin(mouse_pos)
#var ray_direction = camera.project_ray_normal(mouse_pos)
# Cast a ray
#var from = ray_origin
#var to = ray_origin + ray_direction * 1000.0
#var space_state = get_world().get_direct_space_state()
#var hit = space_state.intersect_ray(from, to)
#print("test")
#if hit.size() != 0:
# collider will be the node you hit
#print(hit.collider)
#pass
func _input(event): func _input(event):
if _viewport.get_viewport().get_mouse_position().x >= 0:
if event is InputEventMouseButton: if event is InputEventMouseButton:
if event.pressed: if event.pressed:
print("Mouse Click at: ", event.position) print("Mouse Click at: ", event.position)

22
BodyParts/Arm.gd Normal file
View File

@ -0,0 +1,22 @@
extends PushingBodyPart
onready var anim = get_node("Mesh/AnimationPlayer")
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
func action():
anim.play("ArmatureAction001")
func push(body):
# TODO: Hardcoded values - maybe try to generalize
base.apply_impulse(transform.basis.xform(Vector3(0.0, 0.0, -3.0)), base.transform.basis.y * 10.0)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass

36
BodyParts/Arm.tscn Normal file
View File

@ -0,0 +1,36 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://BodyParts/PushingBodyPart.tscn" type="PackedScene" id=1]
[ext_resource path="res://3D Input/untitled.glb" type="PackedScene" id=2]
[ext_resource path="res://BodyParts/Arm.gd" type="Script" id=3]
[sub_resource type="SphereShape" id=1]
[sub_resource type="SphereShape" id=2]
radius = 0.591769
[node name="Arm" instance=ExtResource( 1 )]
script = ExtResource( 3 )
[node name="PartCollider" parent="." index="0"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -8 )
shape = SubResource( 1 )
[node name="Mesh" parent="." index="1" instance=ExtResource( 2 )]
[node name="BoneAttachment" type="BoneAttachment" parent="Mesh/Armature/Skeleton" index="1"]
transform = Transform( 1, -1.98292e-23, -3.18966e-24, 6.71348e-24, -9.49949e-08, 1, -2.07636e-23, -1, -9.49949e-08, -2.23781e-16, -0.0078205, -5.05441 )
bone_name = "bone_2"
[node name="RemoteTransform" type="RemoteTransform" parent="Mesh/Armature/Skeleton/BoneAttachment" index="0"]
remote_path = NodePath("../../../../../TouchArea")
[node name="TouchArea" parent="." index="2"]
transform = Transform( 1, -1.98292e-23, -3.18966e-24, 6.71348e-24, -9.49949e-08, 1, -2.07636e-23, -1, -9.49949e-08, -2.23781e-16, -0.0078205, -7.60024 )
[node name="CollisionShape" type="CollisionShape" parent="TouchArea" index="0"]
transform = Transform( 1, 2.98291e-24, -1.98247e-23, -2.07684e-23, -9.49949e-08, -1, -6.50669e-24, 1, -9.49949e-08, 2.23781e-16, 0.399765, 0.00782054 )
shape = SubResource( 2 )
[editable path="Mesh"]

View File

@ -0,0 +1,14 @@
extends Spatial
class_name BodyBase
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View File

@ -0,0 +1,52 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://BodyParts/BodyBase/BodyBase.gd" type="Script" id=1]
[sub_resource type="CapsuleMesh" id=1]
[sub_resource type="CapsuleShape" id=2]
[sub_resource type="SphereMesh" id=3]
[sub_resource type="SphereShape" id=4]
[sub_resource type="SphereShape" id=5]
[node name="Torso" type="RigidBody"]
script = ExtResource( 1 )
[node name="TorsoMesh" type="MeshInstance" parent="."]
mesh = SubResource( 1 )
material/0 = null
[node name="TorsoCollider" type="CollisionShape" parent="."]
shape = SubResource( 2 )
[node name="FrontLeft" type="Spatial" parent="."]
transform = Transform( 1.62921e-07, -5.30863e-14, -1, -3.25841e-07, -1, 0, -1, 3.25841e-07, -1.62921e-07, 0.6, 0, 1 )
[node name="FrontLeftAttachMent" type="MeshInstance" parent="FrontLeft"]
transform = Transform( 0.3, 0, 0, 0, 0.3, 0, 0, 0, 0.3, 0, 0, 0 )
mesh = SubResource( 3 )
material/0 = null
[node name="Area" type="Area" parent="FrontLeft"]
[node name="CollisionShape" type="CollisionShape" parent="FrontLeft/Area"]
transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0 )
shape = SubResource( 4 )
[node name="FrontRight" type="Spatial" parent="."]
transform = Transform( 1.62921e-07, -5.30863e-14, 1, -3.25841e-07, -1, 0, 1, -3.25841e-07, -1.62921e-07, -0.6, 0, 1 )
[node name="FrontRightAttachMent" type="MeshInstance" parent="FrontRight"]
transform = Transform( 0.3, 0, 0, 0, 0.3, 0, 0, 0, 0.3, 0, 0, 0 )
mesh = SubResource( 3 )
material/0 = null
[node name="Area" type="Area" parent="FrontRight"]
[node name="CollisionShape" type="CollisionShape" parent="FrontRight/Area"]
transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0 )
shape = SubResource( 5 )

43
BodyParts/BodyPart.gd Normal file
View File

@ -0,0 +1,43 @@
extends Spatial
class_name BodyPart
# Must be the direct child of an AttachmentPoint of the BodyBase
onready var base = get_parent().get_parent()
onready var physics_shape = get_node("PartCollider")
export(int) var key
var setup_done = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
assert(base is BodyBase)
func _process(delta: float) -> void:
# We do this here because we want the whole tree to really be done instancing
if not setup_done:
var translation = physics_shape.global_transform.basis * physics_shape.translation
remove_child(physics_shape)
base.add_child(physics_shape)
physics_shape.translation = translation
setup_done = true
func _unhandled_input(event):
if event is InputEventKey:
if event.pressed and event.scancode == key:
action()
# Do something with the base
func action():
pass

9
BodyParts/BodyPart.tscn Normal file
View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://BodyParts/BodyPart.gd" type="Script" id=1]
[node name="BodyPart" type="Spatial"]
script = ExtResource( 1 )
[node name="PartCollider" type="CollisionShape" parent="."]

View File

@ -0,0 +1,18 @@
extends BodyPart
class_name PushingBodyPart
onready var touch_area = get_node("TouchArea")
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
touch_area.connect("body_entered", self, "_on_touch_area_entered")
func _on_touch_area_entered(body):
if body.name != base.name:
push(body)
func push(body):
pass

View File

@ -0,0 +1,10 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://BodyParts/BodyPart.tscn" type="PackedScene" id=1]
[ext_resource path="res://BodyParts/PushingBodyPart.gd" type="Script" id=2]
[node name="PushingBodyPart" index="0" instance=ExtResource( 1 )]
script = ExtResource( 2 )
[node name="TouchArea" type="Area" parent="." index="1"]

39
Global/InGameState.gd Normal file
View File

@ -0,0 +1,39 @@
extends Node
var max_health = 100.0
var player_healths = []
var player_count: int
signal player_win(player_id)
signal player_count_updated(new_player_count)
signal player_health_updated(player_id, new_player_health)
func set_player_count(new_player_count: int):
assert(new_player_count <= 4)
player_count = new_player_count
player_healths = []
for i in range(0, player_count):
player_healths.append(0.0)
set_player_health(i, max_health)
emit_signal("player_count_updated", new_player_count)
func subtract_player_health(player_id, subtractor):
set_player_health(player_id, player_healths[player_id] - subtractor)
func set_player_health(player_id, new_value):
assert(player_id < player_count)
assert(player_id >= 0)
player_healths[player_id] = new_value
if player_healths[player_id] < 0.0:
emit_signal("player_win", player_id)
else:
emit_signal("player_health_updated", player_id, player_healths[player_id])

View File

@ -1,26 +0,0 @@
extends RigidBody
onready var anim = get_node("AnimationPlayer")
onready var skeleton = get_node("Armature/Skeleton")
onready var area = get_node("Armature/Skeleton/BoneAttachment/TouchArea")
func _ready():
area.connect("body_entered", self, "arm_collided")
func arm_collided(body):
if body.name != "Arm":
print("Entered")
apply_impulse(area.transform.origin, Vector3.UP * 10.0)
func _unhandled_input(event):
if event is InputEventKey:
if event.pressed and event.scancode == KEY_A:
play()
func play():
anim.play("ArmatureAction001")

File diff suppressed because one or more lines are too long

16
Ingame/Ingame.gd Normal file
View File

@ -0,0 +1,16 @@
extends Spatial
# Declare member variables here. Examples:
# var a: int = 2
# var b: String = "text"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
InGameState.set_player_count(2)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass

View File

@ -1,6 +1,9 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=7 format=2]
[ext_resource path="res://Ingame/BodyParts/Arm.tscn" type="PackedScene" id=1] [ext_resource path="res://BodyParts/Arm.tscn" type="PackedScene" id=1]
[ext_resource path="res://UI/UI.tscn" type="PackedScene" id=2]
[ext_resource path="res://BodyParts/BodyBase/BodyBase.tscn" type="PackedScene" id=3]
[ext_resource path="res://Ingame/Ingame.gd" type="Script" id=4]
[sub_resource type="PlaneMesh" id=1] [sub_resource type="PlaneMesh" id=1]
size = Vector2( 10, 10 ) size = Vector2( 10, 10 )
@ -8,7 +11,8 @@ size = Vector2( 10, 10 )
[sub_resource type="BoxShape" id=2] [sub_resource type="BoxShape" id=2]
extents = Vector3( 5, 1, 5 ) extents = Vector3( 5, 1, 5 )
[node name="Spatial" type="Spatial"] [node name="InGame" type="Spatial"]
script = ExtResource( 4 )
[node name="MeshInstance" type="MeshInstance" parent="."] [node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0 ) transform = Transform( 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0 )
@ -22,11 +26,21 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
shape = SubResource( 2 ) shape = SubResource( 2 )
[node name="Camera" type="Camera" parent="."] [node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 0.866025, 0.5, 0, -0.5, 0.866025, 0, 9, 18 ) transform = Transform( -4.37114e-08, -0.5, 0.866025, 0, 0.866025, 0.5, -1, 2.18557e-08, -3.78552e-08, 17, 9, -2 )
[node name="DirectionalLight" type="DirectionalLight" parent="."] [node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 0.999532, 0.0126075, 0.027872, -0.0305909, 0.411942, 0.910697, 0, -0.911123, 0.412135, 0, 0, 0 ) transform = Transform( 0.999532, 0.0126075, 0.027872, -0.0305909, 0.411942, 0.910697, 0, -0.911123, 0.412135, 0, 0, 0 )
shadow_enabled = true shadow_enabled = true
[node name="Arm" parent="." instance=ExtResource( 1 )] [node name="Torso" parent="." instance=ExtResource( 3 )]
transform = Transform( 0.652297, -0.343448, 0.675686, 0, 0.89145, 0.453119, -0.757964, -0.295568, 0.58149, 0, 11.9276, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.02111, 0 )
[node name="Arm" parent="Torso/FrontLeft" index="1" instance=ExtResource( 1 )]
key = 83
[node name="Arm" parent="Torso/FrontRight" index="1" instance=ExtResource( 1 )]
key = 65
[node name="UI" parent="." instance=ExtResource( 2 )]
[editable path="Torso"]

21
UI/PlayerHealth.gd Normal file
View File

@ -0,0 +1,21 @@
extends ProgressBar
export(int) var player_id
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
InGameState.connect("player_health_updated", self, "_on_player_health_updated")
max_value = InGameState.max_health
func _on_player_health_updated(updated_id, updated_health):
if player_id == updated_id:
value = updated_health
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass

80
UI/UI.tscn Normal file
View File

@ -0,0 +1,80 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://UI/PlayerHealth.gd" type="Script" id=1]
[node name="UI" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="MarginContainer" type="MarginContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 20.0
margin_top = 20.0
margin_right = -20.0
margin_bottom = -20.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="PlayerHealthController" type="Control" parent="MarginContainer"]
margin_right = 984.0
margin_bottom = 560.0
[node name="VSplitContainer" type="VSplitContainer" parent="MarginContainer/PlayerHealthController"]
margin_right = 984.0
margin_bottom = 560.0
split_offset = 902
dragger_visibility = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HSplitContainer" type="HSplitContainer" parent="MarginContainer/PlayerHealthController/VSplitContainer"]
margin_right = 984.0
margin_bottom = 560.0
split_offset = 492
dragger_visibility = 1
[node name="Player1Health" type="ProgressBar" parent="MarginContainer/PlayerHealthController/VSplitContainer/HSplitContainer"]
margin_right = 496.0
margin_bottom = 14.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player2Health" type="ProgressBar" parent="MarginContainer/PlayerHealthController/VSplitContainer/HSplitContainer"]
margin_left = 508.0
margin_right = 984.0
margin_bottom = 14.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HSplitContainer2" type="HSplitContainer" parent="MarginContainer/PlayerHealthController/VSplitContainer"]
visible = false
margin_top = 546.0
margin_right = 984.0
margin_bottom = 560.0
split_offset = 492
dragger_visibility = 1
[node name="Player3Health" type="ProgressBar" parent="MarginContainer/PlayerHealthController/VSplitContainer/HSplitContainer2"]
margin_right = 496.0
margin_bottom = 14.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player4Health" type="ProgressBar" parent="MarginContainer/PlayerHealthController/VSplitContainer/HSplitContainer2"]
margin_left = 508.0
margin_right = 984.0
margin_bottom = 14.0
__meta__ = {
"_edit_use_anchors_": false
}

View File

@ -8,9 +8,26 @@
config_version=4 config_version=4
_global_script_classes=[ ] _global_script_classes=[ {
"base": "Spatial",
"class": "BodyBase",
"language": "GDScript",
"path": "res://BodyParts/BodyBase/BodyBase.gd"
}, {
"base": "Spatial",
"class": "BodyPart",
"language": "GDScript",
"path": "res://BodyParts/BodyPart.gd"
}, {
"base": "BodyPart",
"class": "PushingBodyPart",
"language": "GDScript",
"path": "res://BodyParts/PushingBodyPart.gd"
} ]
_global_script_class_icons={ _global_script_class_icons={
"BodyBase": "",
"BodyPart": "",
"PushingBodyPart": ""
} }
[application] [application]
@ -19,6 +36,10 @@ config/name="BodyPartFighter"
run/main_scene="res://Ingame/Testing.tscn" run/main_scene="res://Ingame/Testing.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[autoload]
InGameState="*res://Global/InGameState.gd"
[rendering] [rendering]
environment/default_environment="res://default_env.tres" environment/default_environment="res://default_env.tres"