Merge branch 'main' into tiff

This commit is contained in:
tiffanyfrias10
2021-12-05 20:05:14 -06:00
115 changed files with 3371 additions and 107 deletions

View File

@@ -3,43 +3,38 @@ extends Node
signal update_currency(amount)
var __currency: int
var __weapons: Array
var __accessories: Array
var __categories: Dictionary
var __items: Array
func _ready() -> void:
self.__currency = 100
self.__weapons = []
self.__accessories = []
self.__categories = {
'Weapon': self.__weapons,
'Accessory': self.__accessories}
__currency = 100
__items = []
return
func get_currency() -> int:
return self.__currency
return __currency
func add_currency(amount: int) -> void:
self.__currency += amount
emit_signal('update_currency', self.__currency)
__currency += amount
emit_signal('update_currency', __currency)
return
func add(item) -> void:
self.__categories[item.type].append(item)
func contains(item: String) -> bool:
if item in __items:
return true
return false
func add(item: String) -> void:
__items.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
func remove(item: String) -> void:
for k in range(len(__items)):
if __items[k] == item:
__items.remove(k)
return

View File

@@ -7,10 +7,17 @@ export var FRICTION: int = 1000
const HEALTH_SLICES: Array = [0, 18, 35, 50, 65, 82, 100]
var health_index: int = 6
var l5_gems: int = 0
var hud: CanvasLayer = null
var velocity: Vector2 = Vector2.ZERO
func _ready() -> void:
set_weapon_position(Vector2(1, 0))
return
func _physics_process(delta: float) -> void:
var input_vector: Vector2 = Vector2.ZERO
@@ -23,6 +30,7 @@ func _physics_process(delta: float) -> void:
if input_vector != Vector2.ZERO:
$AnimationTree.set('parameters/Idle/blend_position', input_vector)
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
set_weapon_position(input_vector)
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
@@ -40,29 +48,77 @@ func load_hud(node: CanvasLayer) -> void:
return
func set_weapon_position(pos: Vector2) -> void:
# facing left
if pos[0] < 0:
$Sword.rotation_degrees = -90
$Javelin.rotation_degrees = -90
# facing right
elif pos[0] > 0:
$Sword.rotation_degrees = 90
$Javelin.rotation_degrees = 90
# facing up
elif pos[1] < 0:
$Sword.rotation_degrees = 0
$Javelin.rotation_degrees = 0
# facing down
elif pos[1] > 0:
$Sword.rotation_degrees = 180
$Javelin.rotation_degrees = 180
return
func add_currency(amount: int) -> void:
$Inventory.add_currency(amount)
return
func has_item(item: String) -> bool:
return $Inventory.contains(item)
func add_item(item: String) -> void:
$Inventory.add(item)
return
func remove_item(item: String) -> void:
$Inventory.remove(item)
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():
func _on_hitbox_area_entered(area: Area2D) -> void:
var hit: int = 0
if area.is_in_group('enemy_hitbox_1') or area.is_in_group('enemy_projectile_1'):
hit = 1
elif area.is_in_group('enemy_hitbox_2') or area.is_in_group('enemy_projectile_2'):
hit = 2
elif area.is_in_group('enemy_hitbox_3') or area.is_in_group('enemy_projectile_3'):
hit = 3
else:
return
#var timer = Timer.new()
elif body.name.begins_with("blue_snowman"):
MAX_SPEED = 20
yield(get_tree().create_timer(3.0), "timeout")
MAX_SPEED = 120
elif health_index != 0:
health_index != 0
health_index -= 1
if health_index != 0:
health_index -= hit
if health_index < 0:
health_index = 0
hud.update_health(HEALTH_SLICES[health_index])
else:
get_tree().change_scene('res://Levels/Hub World.tscn')
@@ -71,10 +127,16 @@ func _on_Hitbox_body_entered(body: Node) -> void:
func _input(event: InputEvent) -> void:
if event.is_action_pressed('player_attack'):
if hud.weapon == 'sword':
$'Sword/Sword Animation'.play('swing')
elif hud.weapon == 'javelin':
$'Javelin/Javelin Animation'.play('swing')
if event.is_action_pressed('screenshot'):
var img: Image = get_viewport().get_texture().get_data()
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
yield(get_tree(), 'idle_frame')
yield(get_tree(), 'idle_frame')
img.flip_y()

View File

@@ -1,10 +1,12 @@
[gd_scene load_steps=20 format=2]
[gd_scene load_steps=22 format=2]
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
[ext_resource path="res://Sprites/Player/Player.png" type="Texture" id=2]
[ext_resource path="res://Sprites/Player/Player_Down.png" type="Texture" id=3]
[ext_resource path="res://Sprites/Player/Player_Up.png" type="Texture" id=4]
[ext_resource path="res://Player/Inventory.tscn" type="PackedScene" id=5]
[ext_resource path="res://Player/Weapons/Javelin.tscn" type="PackedScene" id=6]
[ext_resource path="res://Player/Weapons/Sword.tscn" type="PackedScene" id=7]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
@@ -180,24 +182,26 @@ graph_offset = Vector2( -3591.37, -302.6 )
[sub_resource type="AnimationNodeStateMachinePlayback" id=14]
[node name="Player" type="KinematicBody2D"]
[node name="Player" type="KinematicBody2D" groups=["player"]]
collision_layer = 2
script = ExtResource( 1 )
[node name="Sprite" type="AnimatedSprite" parent="."]
light_mask = 2
z_index = 1
frames = SubResource( 1 )
animation = "look_right"
offset = Vector2( 0, -5 )
offset = Vector2( 0, -4 )
[node name="Collision" type="CollisionShape2D" parent="."]
visible = false
rotation = 1.5708
shape = SubResource( 2 )
[node name="Hitbox" type="Area2D" parent="."]
[node name="Hitbox" type="Area2D" parent="." groups=["player_hitbox"]]
collision_layer = 2
collision_mask = 2
collision_mask = 4
input_pickable = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
visible = false
@@ -220,6 +224,11 @@ parameters/Idle/blend_position = Vector2( 0.0760697, 0 )
[node name="Inventory" parent="." instance=ExtResource( 5 )]
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]
[connection signal="body_entered" from="Hitbox" to="." method="_on_Hitbox_body_entered"]
[node name="Sword" parent="." instance=ExtResource( 7 )]
position = Vector2( 0, -4 )
[node name="Javelin" parent="." instance=ExtResource( 6 )]
position = Vector2( 0, -4 )
[connection signal="area_entered" from="Hitbox" to="." method="_on_hitbox_area_entered"]
[connection signal="update_currency" from="Inventory" to="." method="_on_Inventory_update_currency"]

11
Player/Weapons/Javelin.gd Normal file
View File

@@ -0,0 +1,11 @@
extends Node2D
func _on_javelin_animation_animation_started(anim_name: String) -> void:
$Animation/CollisionShape2D.set_deferred('monitorable', true)
return
func _on_javelin_animation_animation_finished(anim_name: String) -> void:
$Animation/CollisionShape2D.set_deferred('monitorable', false)
return

View File

@@ -0,0 +1,75 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Sprites/Items/Javelin.png" type="Texture" id=1]
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 2.2, 3 )
[sub_resource type="Animation" id=2]
resource_name = "swing"
length = 0.4
tracks/0/type = "value"
tracks/0/path = NodePath("Animation:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0.01, 0.21 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Vector2( 0, 0 ), Vector2( 0, -7 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Animation/Javelin:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.01, 0.4 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 1,
"values": [ false, true, false ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("Animation:monitorable")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0.02, 0.22 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ true, false ]
}
[node name="Javelin" type="Node2D"]
light_mask = 0
[node name="Animation" type="Area2D" parent="." groups=["player_weapon_2"]]
light_mask = 0
position = Vector2( 0, -7 )
collision_layer = 0
collision_mask = 4
input_pickable = false
monitoring = false
monitorable = false
[node name="Javelin" type="Sprite" parent="Animation"]
visible = false
light_mask = 8
position = Vector2( 0, -7 )
rotation = 0.785398
scale = Vector2( 0.65, 0.65 )
texture = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Animation"]
visible = false
light_mask = 0
position = Vector2( 0, -11.5 )
shape = SubResource( 3 )
[node name="Javelin Animation" type="AnimationPlayer" parent="."]
anims/swing = SubResource( 2 )

26
Player/Weapons/Sword.gd Normal file
View File

@@ -0,0 +1,26 @@
extends Node2D
# 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:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass
func _on_SwordAttack_animation_started(anim_name: String) -> void:
$Sword.visible = true
return
func _on_SwordAttack_animation_finished(anim_name: String) -> void:
$Sword.visible = false
return

75
Player/Weapons/Sword.tscn Normal file
View File

@@ -0,0 +1,75 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Sprites/Items/Sword.png" type="Texture" id=1]
[sub_resource type="RectangleShape2D" id=6]
extents = Vector2( 1.5, 4.2 )
[sub_resource type="Animation" id=5]
resource_name = "swing"
length = 0.2
tracks/0/type = "value"
tracks/0/path = NodePath("Animation/Sword:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.01, 0.2 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 1,
"values": [ false, true, false ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Animation:rotation_degrees")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.01, 0.19 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ -45.0, 45.0 ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("Animation:monitorable")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0.02, 0.2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ true, false ]
}
[node name="Sword" type="Node2D"]
light_mask = 0
[node name="Animation" type="Area2D" parent="." groups=["player_weapon_1"]]
light_mask = 0
rotation = 0.785398
collision_layer = 0
collision_mask = 4
input_pickable = false
monitoring = false
monitorable = false
[node name="Sword" type="Sprite" parent="Animation"]
visible = false
light_mask = 8
rotation = 0.785398
scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 1 )
offset = Vector2( -16, -16 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Animation"]
visible = false
light_mask = 0
position = Vector2( 0, -13 )
shape = SubResource( 6 )
[node name="Sword Animation" type="AnimationPlayer" parent="."]
anims/swing = SubResource( 5 )