Browse Source

Use character_data.tres to store character information

master
Non0w 4 years ago
parent
commit
51a4cc6f17
13 changed files with 152 additions and 52 deletions
  1. +9
    -0
      jrpg/characters/basic_enemy.tres
  2. +9
    -0
      jrpg/characters/player.tres
  3. +12
    -19
      jrpg/scenes/TestLVL.tscn
  4. +1
    -1
      jrpg/scenes/entities/Enemy.tscn
  5. +6
    -0
      jrpg/scripts/entities/data/character_data.gd
  6. +48
    -0
      jrpg/scripts/entities/model/player_infos.gd
  7. +7
    -24
      jrpg/scripts/entities/player.gd
  8. +10
    -0
      jrpg/scripts/levels/base_level.gd
  9. +8
    -0
      jrpg/scripts/levels/spawner.gd
  10. +2
    -0
      jrpg/scripts/misc/controller.gd
  11. +2
    -7
      jrpg/scripts/misc/test_level.gd
  12. +8
    -1
      jrpg/scripts/ui/test_hud.gd
  13. +30
    -0
      project.godot

+ 9
- 0
jrpg/characters/basic_enemy.tres View File

@@ -0,0 +1,9 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://jrpg/scripts/entities/data/character_data.gd" type="Script" id=1]
[ext_resource path="res://jrpg/scenes/entities/Enemy.tscn" type="PackedScene" id=2]

[resource]
script = ExtResource( 1 )
name = "Basic Enemy"
scene = ExtResource( 2 )

+ 9
- 0
jrpg/characters/player.tres View File

@@ -0,0 +1,9 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://jrpg/scripts/entities/data/character_data.gd" type="Script" id=1]
[ext_resource path="res://jrpg/scenes/entities/Player.tscn" type="PackedScene" id=2]

[resource]
script = ExtResource( 1 )
name = "Player"
scene = ExtResource( 2 )

+ 12
- 19
jrpg/scenes/TestLVL.tscn View File

@@ -1,19 +1,17 @@
[gd_scene load_steps=30 format=2]
[gd_scene load_steps=28 format=2]

[ext_resource path="res://jrpg/scenes/entities/Enemy.tscn" type="PackedScene" id=1]
[ext_resource path="res://jrpg/scripts/levels/spawner.gd" type="Script" id=1]
[ext_resource path="res://jrpg/scenes/ui/HUD.tscn" type="PackedScene" id=2]
[ext_resource path="res://jrpg/scenes/entities/Pickup.tscn" type="PackedScene" id=3]
[ext_resource path="res://jrpg/scenes/ui/SpeechText.tscn" type="PackedScene" id=4]
[ext_resource path="res://jrpg/scenes/ui/ChoicesBox.tscn" type="PackedScene" id=5]
[ext_resource path="res://jrpg/scenes/entities/Player.tscn" type="PackedScene" id=6]
[ext_resource path="res://jrpg/characters/player.tres" type="Resource" id=6]
[ext_resource path="res://jrpg/misc/jrpg_env.tres" type="Environment" id=7]
[ext_resource path="res://jrpg/models/nature/dirt.material" type="Material" id=8]
[ext_resource path="res://jrpg/models/nature/grass.material" type="Material" id=9]
[ext_resource path="res://jrpg/models/nature/_defaultMat.material" type="Material" id=10]
[ext_resource path="res://jrpg/scripts/ui/speech_panel.gd" type="Script" id=11]
[ext_resource path="res://jrpg/scripts/entities/components/interactions/talk_interaction.gd" type="Script" id=12]
[ext_resource path="res://jrpg/scripts/entities/npc.gd" type="Script" id=13]
[ext_resource path="res://jrpg/yarn_scripts/npc_debug.yarn" type="Resource" id=14]
[ext_resource path="res://jrpg/characters/basic_enemy.tres" type="Resource" id=12]
[ext_resource path="res://jrpg/scripts/misc/test_level.gd" type="Script" id=15]

[sub_resource type="ArrayMesh" id=1]
@@ -392,18 +390,15 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 15.6138, 3.8056, 3.13732 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = ExtResource( 7 )

[node name="Player" parent="." instance=ExtResource( 6 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.45297, 0 )
ui_path = NodePath("../../TestLVL/CanvasLayer/UI")
[node name="Enemy Spawner" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 3.42834, 0, 8.41565 )
script = ExtResource( 1 )
character_data = ExtResource( 12 )

[node name="Enemy" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.06601, 0.281974, 5.23785 )
script = ExtResource( 13 )

[node name="TalkInteraction" type="Node" parent="Enemy"]
script = ExtResource( 12 )
yarnScript = ExtResource( 14 )
speechPanel_path = NodePath("../../../TestLVL/CanvasLayer/SpeechPanel")
[node name="Player Spawner" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.218717, 0, -1.84536 )
script = ExtResource( 1 )
character_data = ExtResource( 6 )

[node name="CanvasLayer" type="CanvasLayer" parent="."]

@@ -435,5 +430,3 @@ anchor_bottom = 1.0
margin_left = 0.0319824
margin_right = -50.0
alignment = 1

[editable path="Player"]

+ 1
- 1
jrpg/scenes/entities/Enemy.tscn View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://jrpg/models/chars/Zombie_Male.glb" type="PackedScene" id=1]
[ext_resource path="res://jrpg/scripts/entities/enemy.gd" type="Script" id=2]
[ext_resource path="res://jrpg/scripts/entities/npc.gd" type="Script" id=2]

[sub_resource type="CapsuleShape" id=1]
radius = 0.5


+ 6
- 0
jrpg/scripts/entities/data/character_data.gd View File

@@ -0,0 +1,6 @@
extends Resource

class_name CharacterData

export var name : String
export var scene : PackedScene

+ 48
- 0
jrpg/scripts/entities/model/player_infos.gd View File

@@ -0,0 +1,48 @@
extends Object

class_name PlayerInfos

# curHp
var curHp : int = 10 setget curHp_set, curHp_get
signal curHp_update

func curHp_set(value):
curHp = value
emit_signal("curHp_update", value)

func curHp_get():
return curHp

# maxHp
var maxHp : int = 10 setget maxHp_set, maxHp_get
signal maxHp_update

func maxHp_set(value):
maxHp = value
emit_signal("maxHp_update", value)

func maxHp_get():
return maxHp

# damage
var damage : int = 1 setget damage_set, damage_get
signal damage_update

func damage_set(value):
damage = value
emit_signal("damage_update", value)

func damage_get():
return damage

# gold
var gold : int = 0 setget gold_set, gold_get
signal gold_update

func gold_set(value):
gold = value
emit_signal("gold_update", value)

func gold_get():
return gold


+ 7
- 24
jrpg/scripts/entities/player.gd View File

@@ -1,15 +1,10 @@
extends KinematicBody

# stats
var curHp : int = 10
var maxHp : int = 10
var damage : int = 1
var gold : int = 0
class_name Player

var attackRate : float = 0.3
var lastAttackTime : int = 0

# physics
var airborneSpeed : float = 3.0
var walkSpeed : float = 5.0
@@ -23,14 +18,6 @@ var vel := Vector3()
onready var camera = get_node("CameraOrbit")
onready var interactCast = get_node("InteractRayCast")
onready var anim = get_node("Casual2_Female/AnimationPlayer")
export var ui_path : NodePath
onready var ui = get_node(ui_path)

# called when the node is initialized
func _ready ():
# initialize the UI
ui.update_health_bar(curHp, maxHp)
ui.update_gold_text(gold)

func _process(delta):
# attack input
@@ -99,19 +86,16 @@ func _physics_process (delta):

# called when we collect a coin
func give_gold (amount):
var gold = Controller.player_infos.gold
gold += amount
# update the UI
ui.update_gold_text(gold)
Controller.player_infos.gold = gold

# called when an enemy deals damage to us
func take_damage (damageToTake):

curHp -= damageToTake
# update the UI
ui.update_health_bar(curHp, maxHp)
Controller.player_infos.curHp -= damageToTake
# if our health is 0, die
if curHp <= 0:
if Controller.player_infos.curHp <= 0:
die()

# called when our health reaches 0
@@ -142,7 +126,6 @@ func die ():

# called when we press the interact button
func try_interact():
# is the ray cast colliding with an enemy?
if interactCast.is_colliding():
# play the animation


+ 10
- 0
jrpg/scripts/levels/base_level.gd View File

@@ -0,0 +1,10 @@
extends Node

class_name BaseLevel

func _enter_tree():
Controller.player_input_enabled = true
func _exit_tree():
Controller.player_input_enabled = false
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

+ 8
- 0
jrpg/scripts/levels/spawner.gd View File

@@ -0,0 +1,8 @@
extends Node

export var character_data : Resource

func _ready():
var inst = character_data.scene.instance()
inst.name = character_data.name
add_child(inst)

+ 2
- 0
jrpg/scripts/misc/controller.gd View File

@@ -1,5 +1,7 @@
extends Node

var player_infos := PlayerInfos.new()

var player_input_enabled := true setget player_input_enabled_set
signal player_input_change



+ 2
- 7
jrpg/scripts/misc/test_level.gd View File

@@ -1,8 +1,3 @@
extends Node
extends BaseLevel

func _enter_tree():
Controller.player_input_enabled = true
func _exit_tree():
Controller.player_input_enabled = false
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
class_name TestLevel

+ 8
- 1
jrpg/scripts/ui/test_hud.gd View File

@@ -5,9 +5,16 @@ onready var healthBar = get_node(healthBar_path)
export var goldText_path : NodePath
onready var goldText = get_node(goldText_path)

func _ready():
Controller.player_infos.connect("curHp_update", self, "update_health_bar")
Controller.player_infos.connect("gold_update", self, "update_gold_text")
update_health_bar(Controller.player_infos.curHp)
update_gold_text(Controller.player_infos.gold)

# called when we take damage
func update_health_bar (curHp, maxHp):
func update_health_bar (curHp):
fetch_components()
var maxHp : int = Controller.player_infos.maxHp
healthBar.value = (100 / maxHp) * curHp
# called when our gold changes


+ 30
- 0
project.godot View File

@@ -10,20 +10,45 @@ config_version=4

_global_script_classes=[ {
"base": "Node",
"class": "BaseLevel",
"language": "GDScript",
"path": "res://jrpg/scripts/levels/base_level.gd"
}, {
"base": "Node",
"class": "BasisInteraction",
"language": "GDScript",
"path": "res://jrpg/scripts/entities/components/interactions/basis_interaction.gd"
}, {
"base": "Resource",
"class": "CharacterData",
"language": "GDScript",
"path": "res://jrpg/scripts/entities/data/character_data.gd"
}, {
"base": "VBoxContainer",
"class": "ChoicesBox",
"language": "GDScript",
"path": "res://jrpg/scripts/ui/choices_box.gd"
}, {
"base": "KinematicBody",
"class": "Player",
"language": "GDScript",
"path": "res://jrpg/scripts/entities/player.gd"
}, {
"base": "Object",
"class": "PlayerInfos",
"language": "GDScript",
"path": "res://jrpg/scripts/entities/model/player_infos.gd"
}, {
"base": "Label",
"class": "SpeechText",
"language": "GDScript",
"path": "res://jrpg/scripts/ui/speech_text.gd"
}, {
"base": "BaseLevel",
"class": "TestLevel",
"language": "GDScript",
"path": "res://jrpg/scripts/misc/test_level.gd"
}, {
"base": "Node",
"class": "YarnImporter",
"language": "GDScript",
@@ -45,9 +70,14 @@ _global_script_classes=[ {
"path": "res://addons/yarn_spinner/yarn_script.gd"
} ]
_global_script_class_icons={
"BaseLevel": "",
"BasisInteraction": "",
"CharacterData": "",
"ChoicesBox": "",
"Player": "",
"PlayerInfos": "",
"SpeechText": "",
"TestLevel": "",
"YarnImporter": "",
"YarnRunner": "",
"YarnRunnerNode": "",


Loading…
Cancel
Save