Skip to content
Snippets Groups Projects
Commit d0c16df9 authored by Jannik Rosendahl's avatar Jannik Rosendahl
Browse files

Merge branch 'player' into main

parents 2c943d09 9199cd7a
No related branches found
No related tags found
No related merge requests found
......@@ -22,3 +22,15 @@ func _on_Area2D_body_entered(body : Node):
if body.is_in_group("enemyweapon"):
print("blocked")
queue_free()
if body.is_class("TileMap"):
queue_free()
#print("collided with " + str(body.name) + " - " + str(body.get_class()) + " - " + str(body.get_groups()))
func set_direction(dir: Vector2):
direction = dir
print(dir)
if dir.x < 0:
print("flip")
$Sprite.flip_v = true
$Sprite.offset.y = 25
......@@ -12,7 +12,7 @@ collision_mask = 24
script = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 0, -18 )
position = Vector2( -12, -18 )
rotation = -1.57079
texture = ExtResource( 2 )
......@@ -21,7 +21,7 @@ collision_layer = 5
collision_mask = 24
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2( 12, -18 )
position = Vector2( 0, -18 )
shape = SubResource( 2 )
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
......@@ -63,9 +63,15 @@ func _ready():
hitpoints = 10
is_alive = true
$Control/HealthBar.max_value = hitpoints
$Control/HealthBar.value = hitpoints
$Control/HealthBar.tint_progress = Color.green
$MeleeDetector.monitoring = false
print("ready")
set_black_white(false)
func _process(delta):
if not is_alive:
......@@ -205,7 +211,7 @@ func attack_process():
if attack_state == ATTACK_STATES.RANGED:
var b = FireBall.instance()
b.position = self.position
b.direction = self.last_look_direction
b.set_direction(self.last_look_direction)
get_tree().current_scene.add_child(b)
if attack_state == ATTACK_STATES.MELEE:
print("melee")
......@@ -228,13 +234,20 @@ func take_damage(n : int):
animation_state = ANIMATION_STATES.HURT
hitpoints -= n
if hitpoints >= 7:
$Control/HealthBar.tint_progress = Color.green
elif hitpoints >= 3:
$Control/HealthBar.tint_progress = Color.orange
else:
$Control/HealthBar.tint_progress = Color.red
$Control/HealthBar.value = hitpoints
if hitpoints <= 0:
print("dying")
animation_state = ANIMATION_STATES.DEATH
is_alive = false
update_animation()
func take_damage_player(n : int):
take_damage(n)
......@@ -268,9 +281,13 @@ func update_animation():
$AnimatedSprite.offset.x = 0
$MeleeDetector/CollisionShape2D.position.x = abs($MeleeDetector/CollisionShape2D.position.x)
$Camera2D/InfoLabel.text = "is_moving: " + str(is_moving) + "\nis_jumping: " + str(is_jumping) + "\nis_attacking: " + str(is_attacking) + "\nvh: " + str(velocity.x) + "\nvv" + str(velocity.y) + "\nhp: " + str(hitpoints)
$InfoLabel.text = "is_moving: " + str(is_moving) + "\nis_jumping: " + str(is_jumping) + "\nis_attacking: " + str(is_attacking) + "\nvh: " + str(velocity.x) + "\nvv" + str(velocity.y) + "\nhp: " + str(hitpoints)
func set_black_white(boolean: bool):
if boolean:
$AnimatedSprite.material = load("res://src/actors/player/PlayerShader.tres")
else:
$AnimatedSprite.material = null
""" SECTION SIGNAL FUNCTIONS """
......
[gd_scene load_steps=52 format=2]
[gd_scene load_steps=56 format=2]
[ext_resource path="res://src/assets/actors/Player/player_attack_melee.png" type="Texture" id=1]
[ext_resource path="res://src/actors/player/Player.gd" type="Script" id=2]
......@@ -8,6 +8,10 @@
[ext_resource path="res://src/assets/actors/Player/player_attack3.png" type="Texture" id=6]
[ext_resource path="res://src/assets/actors/Player/player_hurt.png" type="Texture" id=7]
[ext_resource path="res://src/assets/actors/Player/player_death.png" type="Texture" id=8]
[ext_resource path="res://src/assets/actors/Player/health-bar-under.png" type="Texture" id=9]
[ext_resource path="res://src/assets/actors/Player/health-bar-over.png" type="Texture" id=10]
[ext_resource path="res://src/assets/actors/Player/health_bar_health.png" type="Texture" id=11]
[ext_resource path="res://src/actors/player/PlayerShader.tres" type="Material" id=12]
[sub_resource type="AtlasTexture" id=1]
flags = 4
......@@ -49,85 +53,75 @@ flags = 4
atlas = ExtResource( 5 )
region = Rect2( 144, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=5]
[sub_resource type="AtlasTexture" id=23]
flags = 4
atlas = ExtResource( 6 )
atlas = ExtResource( 3 )
region = Rect2( 0, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=6]
[sub_resource type="AtlasTexture" id=24]
flags = 4
atlas = ExtResource( 6 )
atlas = ExtResource( 3 )
region = Rect2( 48, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=7]
[sub_resource type="AtlasTexture" id=25]
flags = 4
atlas = ExtResource( 6 )
atlas = ExtResource( 3 )
region = Rect2( 96, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=8]
[sub_resource type="AtlasTexture" id=26]
flags = 4
atlas = ExtResource( 6 )
atlas = ExtResource( 3 )
region = Rect2( 144, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=9]
[sub_resource type="AtlasTexture" id=27]
flags = 4
atlas = ExtResource( 6 )
atlas = ExtResource( 3 )
region = Rect2( 192, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=10]
[sub_resource type="AtlasTexture" id=28]
flags = 4
atlas = ExtResource( 6 )
atlas = ExtResource( 3 )
region = Rect2( 240, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=11]
flags = 4
atlas = ExtResource( 6 )
region = Rect2( 288, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=12]
[sub_resource type="AtlasTexture" id=5]
flags = 4
atlas = ExtResource( 6 )
region = Rect2( 336, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=23]
flags = 4
atlas = ExtResource( 3 )
region = Rect2( 0, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=24]
[sub_resource type="AtlasTexture" id=6]
flags = 4
atlas = ExtResource( 3 )
atlas = ExtResource( 6 )
region = Rect2( 48, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=25]
[sub_resource type="AtlasTexture" id=7]
flags = 4
atlas = ExtResource( 3 )
atlas = ExtResource( 6 )
region = Rect2( 96, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=26]
[sub_resource type="AtlasTexture" id=8]
flags = 4
atlas = ExtResource( 3 )
atlas = ExtResource( 6 )
region = Rect2( 144, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=27]
[sub_resource type="AtlasTexture" id=9]
flags = 4
atlas = ExtResource( 3 )
atlas = ExtResource( 6 )
region = Rect2( 192, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=28]
[sub_resource type="AtlasTexture" id=10]
flags = 4
atlas = ExtResource( 3 )
atlas = ExtResource( 6 )
region = Rect2( 240, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=29]
[sub_resource type="AtlasTexture" id=11]
flags = 4
atlas = ExtResource( 7 )
region = Rect2( 48, 0, 48, 48 )
atlas = ExtResource( 6 )
region = Rect2( 288, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=42]
[sub_resource type="AtlasTexture" id=12]
flags = 4
atlas = ExtResource( 7 )
region = Rect2( 0, 0, 48, 48 )
atlas = ExtResource( 6 )
region = Rect2( 336, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=17]
flags = 4
......@@ -159,6 +153,16 @@ flags = 4
atlas = ExtResource( 8 )
region = Rect2( 240, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=29]
flags = 4
atlas = ExtResource( 7 )
region = Rect2( 48, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=42]
flags = 4
atlas = ExtResource( 7 )
region = Rect2( 0, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=43]
flags = 4
atlas = ExtResource( 1 )
......@@ -211,26 +215,26 @@ animations = [ {
"name": "jump",
"speed": 2.0
}, {
"frames": [ SubResource( 5 ), SubResource( 6 ), SubResource( 7 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ), SubResource( 11 ), SubResource( 12 ) ],
"loop": true,
"name": "attack1",
"speed": 20.0
}, {
"frames": [ SubResource( 23 ), SubResource( 24 ), SubResource( 25 ), SubResource( 26 ), SubResource( 27 ), SubResource( 28 ) ],
"loop": true,
"name": "move",
"speed": 5.0
}, {
"frames": [ SubResource( 29 ), SubResource( 42 ), SubResource( 29 ), SubResource( 42 ), SubResource( 29 ), SubResource( 29 ), SubResource( 42 ) ],
"frames": [ SubResource( 5 ), SubResource( 6 ), SubResource( 7 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ), SubResource( 11 ), SubResource( 12 ) ],
"loop": true,
"name": "hurt",
"speed": 5.0
"name": "attack1",
"speed": 20.0
}, {
"frames": [ SubResource( 17 ), SubResource( 18 ), SubResource( 19 ), SubResource( 20 ), SubResource( 21 ), SubResource( 22 ), SubResource( 22 ), SubResource( 22 ), SubResource( 22 ), SubResource( 22 ), SubResource( 22 ) ],
"loop": false,
"name": "death",
"speed": 7.0
}, {
"frames": [ SubResource( 29 ), SubResource( 42 ), SubResource( 29 ), SubResource( 42 ), SubResource( 29 ), SubResource( 29 ), SubResource( 42 ) ],
"loop": true,
"name": "hurt",
"speed": 5.0
}, {
"frames": [ SubResource( 43 ), SubResource( 44 ), SubResource( 45 ), SubResource( 46 ), SubResource( 47 ), SubResource( 48 ), SubResource( 49 ), SubResource( 50 ) ],
"loop": true,
"name": "melee",
......@@ -252,10 +256,11 @@ extents = Vector2( 12.751, 6.23259 )
[node name="Player" type="KinematicBody2D" groups=["player"]]
collision_layer = 3
collision_mask = 249
collision/safe_margin = 0.5
collision/safe_margin = 0.01
script = ExtResource( 2 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
material = ExtResource( 12 )
position = Vector2( 10, -24 )
frames = SubResource( 38 )
animation = "melee"
......@@ -272,11 +277,13 @@ drag_margin_v_enabled = true
smoothing_enabled = true
smoothing_speed = 10.0
[node name="InfoLabel" type="Label" parent="Camera2D"]
[node name="InfoLabel" type="Label" parent="."]
margin_left = -18.3265
margin_top = -144.037
margin_right = 21.6735
margin_bottom = -130.037
margin_bottom = -113.037
text = "test
"
__meta__ = {
"_edit_use_anchors_": false
}
......@@ -307,6 +314,30 @@ shape = SubResource( 41 )
position = Vector2( 22.3487, -20.622 )
shape = SubResource( 51 )
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="Control" type="Control" parent="."]
margin_left = -24.5817
margin_top = -103.502
margin_right = 15.4183
margin_bottom = -63.502
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HealthBar" type="TextureProgress" parent="Control"]
margin_left = -4.83041
margin_top = 40.0753
margin_right = 54.1696
margin_bottom = 49.0753
max_value = 10.0
texture_under = ExtResource( 9 )
texture_over = ExtResource( 10 )
texture_progress = ExtResource( 11 )
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="animation_finished" from="AnimatedSprite" to="." method="_on_AnimatedSprite_animation_finished"]
[connection signal="area_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_area_entered"]
[connection signal="body_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_body_entered"]
......
[gd_resource type="ShaderMaterial" load_steps=2 format=2]
[sub_resource type="Shader" id=52]
code = "shader_type canvas_item;
render_mode unshaded;
void fragment() {
COLOR = texture(TEXTURE, UV);
float lumi = (COLOR.r + COLOR.g + COLOR.b) / 3f;
COLOR.rgb = vec3(lumi);
}"
[resource]
shader = SubResource( 52 )
src/assets/actors/Player/health-bar-over.png

123 B

src/assets/actors/Player/health-bar-under.png

136 B

src/assets/actors/Player/health_bar_health.png

136 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment