New features and plenty of code still in testing. This includes a level select, basic inventory, and a basic HUD.
This commit is contained in:
45
Player/Inventory.gd
Normal file
45
Player/Inventory.gd
Normal file
@@ -0,0 +1,45 @@
|
||||
extends Node
|
||||
|
||||
signal update_currency(amount)
|
||||
|
||||
var __currency: int
|
||||
|
||||
var __weapons: Array
|
||||
var __accessories: Array
|
||||
var __categories: Dictionary
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
self.__currency = 100
|
||||
|
||||
self.__weapons = []
|
||||
self.__accessories = []
|
||||
self.__categories = {
|
||||
'Weapon': self.__weapons,
|
||||
'Accessory': self.__accessories}
|
||||
return
|
||||
|
||||
|
||||
func get_currency() -> int:
|
||||
return self.__currency
|
||||
|
||||
|
||||
func add_currency(amount: int) -> void:
|
||||
self.__currency += amount
|
||||
emit_signal('update_currency', self.__currency)
|
||||
return
|
||||
|
||||
|
||||
func add(item) -> void:
|
||||
self.__categories[item.type].append(item)
|
||||
return
|
||||
|
||||
|
||||
func discard(item) -> void:
|
||||
var index: int = 0
|
||||
for itr in self.__categories[item.type]:
|
||||
if itr.equals(item):
|
||||
self.__categories[item.type].remove(index)
|
||||
break
|
||||
index += 1
|
||||
return
|
6
Player/Inventory.tscn
Normal file
6
Player/Inventory.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://Player/Inventory.gd" type="Script" id=1]
|
||||
|
||||
[node name="Inventory" type="Node"]
|
||||
script = ExtResource( 1 )
|
59
Player/Player.gd
Normal file
59
Player/Player.gd
Normal file
@@ -0,0 +1,59 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
const ACCELERATION: int = 1000
|
||||
const MAX_SPEED: int = 120
|
||||
const FRICTION: int = 1000
|
||||
const HEALTH_SLICES: Array = [0, 20, 35, 50, 65, 80, 100]
|
||||
|
||||
var health_index: int = 6
|
||||
var hud: CanvasLayer = null
|
||||
var velocity: Vector2 = Vector2.ZERO
|
||||
|
||||
|
||||
func _physics_process(delta) -> void:
|
||||
var input_vector: Vector2 = Vector2.ZERO
|
||||
|
||||
input_vector.x = Input.get_action_strength('player_right') \
|
||||
- Input.get_action_strength('player_left')
|
||||
input_vector.y = Input.get_action_strength('player_down') \
|
||||
- Input.get_action_strength('player_up')
|
||||
input_vector = input_vector.normalized()
|
||||
|
||||
if input_vector != Vector2.ZERO:
|
||||
$AnimationTree.set('parameters/Idle/blend_position', input_vector)
|
||||
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
|
||||
else:
|
||||
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
|
||||
|
||||
velocity = move_and_slide(velocity)
|
||||
return
|
||||
|
||||
|
||||
func load_hud(node: CanvasLayer) -> void:
|
||||
hud = node
|
||||
if hud.connect('add_currency', self, 'add_currency') != OK:
|
||||
print('ERROR: HUD "add_currency" signal already connected.')
|
||||
|
||||
hud.update_health(HEALTH_SLICES[health_index])
|
||||
hud.update_currency($Inventory.get_currency())
|
||||
return
|
||||
|
||||
|
||||
func add_currency(amount: int) -> void:
|
||||
$Inventory.add_currency(amount)
|
||||
return
|
||||
|
||||
|
||||
func _on_Inventory_update_currency(amount: int) -> void:
|
||||
hud.update_currency(amount)
|
||||
return
|
||||
|
||||
|
||||
func _on_Hitbox_body_entered(body: Node) -> void:
|
||||
if not 'enemies' in body.get_groups():
|
||||
return
|
||||
|
||||
if health_index != 0:
|
||||
health_index -= 1
|
||||
hud.update_health(HEALTH_SLICES[health_index])
|
||||
return
|
BIN
Player/Player.png
Normal file
BIN
Player/Player.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 173 B |
35
Player/Player.png.import
Normal file
35
Player/Player.png.import
Normal file
@@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/Player.png-3d0801c65bdfc563657cfa304115f1c7.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Player/Player.png"
|
||||
dest_files=[ "res://.import/Player.png-3d0801c65bdfc563657cfa304115f1c7.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=3
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=2
|
||||
flags/repeat=0
|
||||
flags/filter=false
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=0
|
||||
process/fix_alpha_border=false
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=false
|
||||
svg/scale=1.0
|
220
Player/Player.tscn
Normal file
220
Player/Player.tscn
Normal file
@@ -0,0 +1,220 @@
|
||||
[gd_scene load_steps=20 format=2]
|
||||
|
||||
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Player/Player.png" type="Texture" id=2]
|
||||
[ext_resource path="res://Player/Player_Down.png" type="Texture" id=3]
|
||||
[ext_resource path="res://Player/Player_Up.png" type="Texture" id=4]
|
||||
[ext_resource path="res://Player/Inventory.tscn" type="PackedScene" id=5]
|
||||
|
||||
[sub_resource type="SpriteFrames" id=1]
|
||||
animations = [ {
|
||||
"frames": [ ExtResource( 4 ) ],
|
||||
"loop": false,
|
||||
"name": "look_up",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ ExtResource( 2 ) ],
|
||||
"loop": false,
|
||||
"name": "look_left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ ExtResource( 2 ) ],
|
||||
"loop": false,
|
||||
"name": "look_right",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ ExtResource( 3 ) ],
|
||||
"loop": false,
|
||||
"name": "look_down",
|
||||
"speed": 5.0
|
||||
} ]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=2]
|
||||
radius = 3.0
|
||||
height = 5.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=3]
|
||||
radius = 5.5
|
||||
height = 3.75
|
||||
|
||||
[sub_resource type="Animation" id=4]
|
||||
resource_name = "Look Down"
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Sprite:animation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ "look_down" ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Sprite:flip_h")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ false ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=5]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Sprite:animation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ "look_right" ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Sprite:flip_h")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ true ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=6]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Sprite:animation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ "look_right" ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Sprite:flip_h")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ false ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=7]
|
||||
resource_name = "Look Up"
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Sprite:animation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ "look_up" ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Sprite:flip_h")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ false ]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id=8]
|
||||
animation = "Look Left"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id=9]
|
||||
animation = "Look Down"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id=10]
|
||||
animation = "Look Right"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id=11]
|
||||
animation = "Look Up"
|
||||
|
||||
[sub_resource type="AnimationNodeBlendSpace2D" id=12]
|
||||
blend_point_0/node = SubResource( 8 )
|
||||
blend_point_0/pos = Vector2( -1.01, 0 )
|
||||
blend_point_1/node = SubResource( 9 )
|
||||
blend_point_1/pos = Vector2( 0, 1.1 )
|
||||
blend_point_2/node = SubResource( 10 )
|
||||
blend_point_2/pos = Vector2( 1, 0 )
|
||||
blend_point_3/node = SubResource( 11 )
|
||||
blend_point_3/pos = Vector2( 0, -1.1 )
|
||||
min_space = Vector2( -1.01, -1.1 )
|
||||
max_space = Vector2( 1, 1.1 )
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachine" id=13]
|
||||
states/Idle/node = SubResource( 12 )
|
||||
states/Idle/position = Vector2( -2901.63, -177 )
|
||||
start_node = "Idle"
|
||||
graph_offset = Vector2( -3591.37, -302.6 )
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachinePlayback" id=14]
|
||||
|
||||
[node name="Player" type="KinematicBody2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Sprite" type="AnimatedSprite" parent="."]
|
||||
position = Vector2( 0, -5 )
|
||||
frames = SubResource( 1 )
|
||||
animation = "look_right"
|
||||
|
||||
[node name="Collision" type="CollisionShape2D" parent="."]
|
||||
visible = false
|
||||
rotation = 1.5708
|
||||
shape = SubResource( 2 )
|
||||
|
||||
[node name="Hitbox" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
|
||||
visible = false
|
||||
position = Vector2( 0, -5 )
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
autoplay = "Look Right"
|
||||
"anims/Look Down" = SubResource( 4 )
|
||||
"anims/Look Left" = SubResource( 5 )
|
||||
"anims/Look Right" = SubResource( 6 )
|
||||
"anims/Look Up" = SubResource( 7 )
|
||||
|
||||
[node name="AnimationTree" type="AnimationTree" parent="."]
|
||||
tree_root = SubResource( 13 )
|
||||
anim_player = NodePath("../AnimationPlayer")
|
||||
active = true
|
||||
parameters/playback = SubResource( 14 )
|
||||
parameters/Idle/blend_position = Vector2( 0.993787, 0.0189655 )
|
||||
|
||||
[node name="Inventory" parent="." instance=ExtResource( 5 )]
|
||||
|
||||
[connection signal="body_entered" from="Hitbox" to="." method="_on_Hitbox_body_entered"]
|
||||
[connection signal="update_currency" from="Inventory" to="." method="_on_Inventory_update_currency"]
|
BIN
Player/Player_Down.png
Normal file
BIN
Player/Player_Down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 183 B |
35
Player/Player_Down.png.import
Normal file
35
Player/Player_Down.png.import
Normal file
@@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/Player_Down.png-0720a85ec5e36101f691c750d323946c.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Player/Player_Down.png"
|
||||
dest_files=[ "res://.import/Player_Down.png-0720a85ec5e36101f691c750d323946c.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=3
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=2
|
||||
flags/repeat=0
|
||||
flags/filter=false
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=0
|
||||
process/fix_alpha_border=false
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=false
|
||||
svg/scale=1.0
|
BIN
Player/Player_Up.png
Normal file
BIN
Player/Player_Up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 175 B |
35
Player/Player_Up.png.import
Normal file
35
Player/Player_Up.png.import
Normal file
@@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/Player_Up.png-889a827868f4dc454da2bef028bdec76.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Player/Player_Up.png"
|
||||
dest_files=[ "res://.import/Player_Up.png-889a827868f4dc454da2bef028bdec76.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=3
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=2
|
||||
flags/repeat=0
|
||||
flags/filter=false
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=0
|
||||
process/fix_alpha_border=false
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=false
|
||||
svg/scale=1.0
|
Reference in New Issue
Block a user