diff --git a/src/actors/player/FireBall.gd b/src/actors/player/FireBall.gd index ad7d77a41cabb65f4b504d82bb00b24405575ee8..e88a9e8544dd11475eaf29ee29c604f7f4ca1dde 100644 --- a/src/actors/player/FireBall.gd +++ b/src/actors/player/FireBall.gd @@ -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 + diff --git a/src/actors/player/FireBall.tscn b/src/actors/player/FireBall.tscn index 4ff2f203a45e924401d9bf77c84bf4db979e5585..3d887615c84be9117fb946805f6241c9df82c185 100644 --- a/src/actors/player/FireBall.tscn +++ b/src/actors/player/FireBall.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=2] [ext_resource path="res://src/actors/player/FireBall.gd" type="Script" id=1] -[ext_resource path="res://src/assets/actors/Enemy1/dead/enemy-death-1.png" type="Texture" id=2] +[ext_resource path="res://src/assets/actors/Player/ectoplasma.png" type="Texture" id=2] [sub_resource type="RectangleShape2D" id=2] extents = Vector2( 10, 7.01674 ) @@ -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"] diff --git a/src/actors/player/Player.gd b/src/actors/player/Player.gd index bb028d8682462922addbc28e82f4595b0a4201bf..91a75c97fe9c62ed75258e4e3e0e2324ea9fbc6d 100644 --- a/src/actors/player/Player.gd +++ b/src/actors/player/Player.gd @@ -5,9 +5,12 @@ const TYPE = "player" """ SECTION VARIABLE DEFINITIONS """ -enum ANIMATION_STATES { IDLE, RUN, HURT, JUMP, DEATH, ATTACK } +enum ANIMATION_STATES { IDLE, RUN, HURT, JUMP, DEATH, ATTACK_MELEE, ATTACK_RANGED } var animation_state = ANIMATION_STATES.IDLE +enum ATTACK_STATES { MELEE, RANGED } +var attack_state = null + var is_jumping : bool var is_attacking : bool var is_moving : bool @@ -25,6 +28,7 @@ var last_look_direction : Vector2 const move_speed : float = 32*7/.8 const jump_speed : int = -720 const gravity : int = 1800 +export var velocity_cap_v : int = 1000 # keep these values between 0-1 const friction : float = 0.25 @@ -40,7 +44,7 @@ var time_since_last_air_jump : float var terminate_jump : bool var double_jump : bool -const attack_cooldown : float = .4 +const attack_cooldown : float = .7 var attack : bool = false var attack_timer : Timer @@ -97,14 +101,22 @@ func _physics_process(delta): # update vertical velocity velocity.y += gravity * delta + if velocity.y > velocity_cap_v: + print("velocity cap") + velocity.y = velocity_cap_v update_animation() - - animation_state = ANIMATION_STATES.IDLE if direction.x == 0 else ANIMATION_STATES.RUN - animation_state = animation_state if is_on_floor() else ANIMATION_STATES.JUMP + if !is_hurt and !is_attacking: + animation_state = ANIMATION_STATES.IDLE if direction.x == 0 else ANIMATION_STATES.RUN + animation_state = animation_state if is_on_floor() else ANIMATION_STATES.JUMP if attack: - animation_state = ANIMATION_STATES.ATTACK + if attack_state == ATTACK_STATES.MELEE: + print("set state melee") + animation_state = ANIMATION_STATES.ATTACK_MELEE + elif attack_state == ATTACK_STATES.RANGED: + print("set state ranged") + animation_state = ANIMATION_STATES.ATTACK_RANGED is_jumping = false if is_on_floor() else true is_moving = direction.length() != 0 @@ -134,8 +146,14 @@ func input_process(delta): if Input.is_action_just_released("jump"): terminate_jump = true if Input.is_action_just_pressed("attack"): - if not is_attacking: + if !is_attacking: attack = true + attack_state = ATTACK_STATES.RANGED + if Input.is_action_just_pressed("melee"): + if !is_attacking: + attack = true + attack_state = ATTACK_STATES.MELEE + if Input.is_action_just_pressed("hit_self"): print("ow") take_damage(1) @@ -178,6 +196,9 @@ func jump_process(): velocity.y = 0 func attack_process(): + if is_attacking: + return + if attack: is_attacking = true attack_timer = Timer.new() @@ -200,6 +221,17 @@ func die(): queue_free() func take_damage(n : int): + if is_hurt: + return + + is_hurt = true + hurt_timer = Timer.new() + hurt_timer.one_shot = true + hurt_timer.wait_time = invincible_cooldown + hurt_timer.connect("timeout", self, "hurt_timer_timeout") + add_child(hurt_timer) + hurt_timer.start() + animation_state = ANIMATION_STATES.HURT hitpoints -= n if hitpoints >= 7: @@ -223,9 +255,6 @@ func on_stomp(): pass func update_animation(): - if is_attacking or is_hurt: - return - match animation_state: ANIMATION_STATES.IDLE: $AnimatedSprite.play("idle") @@ -233,24 +262,12 @@ func update_animation(): $AnimatedSprite.play("move") ANIMATION_STATES.JUMP: $AnimatedSprite.play("jump") - ANIMATION_STATES.ATTACK: - is_attacking = true + ANIMATION_STATES.ATTACK_RANGED: $AnimatedSprite.play("attack1") - attack_timer = Timer.new() - attack_timer.one_shot = true - attack_timer.wait_time = attack_cooldown - attack_timer.connect("timeout", self, "attack_timer_timeout") - add_child(attack_timer) - attack_timer.start() + ANIMATION_STATES.ATTACK_MELEE: + $AnimatedSprite.play("melee") ANIMATION_STATES.HURT: - is_hurt = true $AnimatedSprite.play("hurt") - hurt_timer = Timer.new() - hurt_timer.one_shot = true - hurt_timer.wait_time = invincible_cooldown - hurt_timer.connect("timeout", self, "hurt_timer_timeout") - add_child(hurt_timer) - hurt_timer.start() ANIMATION_STATES.DEATH: print("play death animation") $AnimatedSprite.play("death") @@ -258,9 +275,11 @@ func update_animation(): if direction.x == -1: $AnimatedSprite.flip_h = true $AnimatedSprite.offset.x = -20 + $MeleeDetector/CollisionShape2D.position.x = -1 * abs($MeleeDetector/CollisionShape2D.position.x) if direction.x == 1: $AnimatedSprite.flip_h = false $AnimatedSprite.offset.x = 0 + $MeleeDetector/CollisionShape2D.position.x = abs($MeleeDetector/CollisionShape2D.position.x) $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) @@ -274,6 +293,7 @@ func set_black_white(boolean: bool): func attack_timer_timeout(): is_attacking = false + $MeleeDetector.monitoring = false func hurt_timer_timeout(): print("hurt finished") @@ -283,14 +303,6 @@ func _on_EnemyDetector_body_entered(body): print(body.name, " entered player body") # die() -func _on_StompDetector_area_entered(area): - print("stomping ", area.name) - - # velocity.y = stomp_velocity - - - - func _on_EnemyDetector_area_entered(area): print(area.name, " area entered") @@ -302,6 +314,7 @@ func _on_AnimatedSprite_animation_finished(): func _on_StompDetector_body_entered(body): if body.is_in_group("enemy"): + print(body.name) if body.is_stompable: body.on_stomp() velocity.y = stomp_velocity diff --git a/src/actors/player/Player.tscn b/src/actors/player/Player.tscn index 1a1130f3097cbfebba2aa0dfddd97ba8a17a7b11..3bb2911e2fde883ac1a250a07b75e2936b12beac 100755 --- a/src/actors/player/Player.tscn +++ b/src/actors/player/Player.tscn @@ -55,74 +55,34 @@ region = Rect2( 144, 0, 48, 48 ) [sub_resource type="AtlasTexture" id=23] flags = 4 -atlas = ExtResource( 8 ) +atlas = ExtResource( 3 ) region = Rect2( 0, 0, 48, 48 ) -[sub_resource type="AtlasTexture" id=18] +[sub_resource type="AtlasTexture" id=24] flags = 4 -atlas = ExtResource( 8 ) +atlas = ExtResource( 3 ) region = Rect2( 48, 0, 48, 48 ) -[sub_resource type="AtlasTexture" id=19] +[sub_resource type="AtlasTexture" id=25] flags = 4 -atlas = ExtResource( 8 ) +atlas = ExtResource( 3 ) region = Rect2( 96, 0, 48, 48 ) -[sub_resource type="AtlasTexture" id=20] +[sub_resource type="AtlasTexture" id=26] flags = 4 -atlas = ExtResource( 8 ) +atlas = ExtResource( 3 ) region = Rect2( 144, 0, 48, 48 ) -[sub_resource type="AtlasTexture" id=21] +[sub_resource type="AtlasTexture" id=27] flags = 4 -atlas = ExtResource( 8 ) +atlas = ExtResource( 3 ) region = Rect2( 192, 0, 48, 48 ) -[sub_resource type="AtlasTexture" id=22] +[sub_resource type="AtlasTexture" id=28] flags = 4 -atlas = ExtResource( 8 ) +atlas = ExtResource( 3 ) region = Rect2( 240, 0, 48, 48 ) -[sub_resource type="AtlasTexture" id=43] -flags = 4 -atlas = ExtResource( 1 ) -region = Rect2( 0, 0, 48, 48 ) - -[sub_resource type="AtlasTexture" id=44] -flags = 4 -atlas = ExtResource( 1 ) -region = Rect2( 48, 0, 48, 48 ) - -[sub_resource type="AtlasTexture" id=45] -flags = 4 -atlas = ExtResource( 1 ) -region = Rect2( 96, 0, 48, 48 ) - -[sub_resource type="AtlasTexture" id=46] -flags = 4 -atlas = ExtResource( 1 ) -region = Rect2( 144, 0, 48, 48 ) - -[sub_resource type="AtlasTexture" id=47] -flags = 4 -atlas = ExtResource( 1 ) -region = Rect2( 192, 0, 48, 48 ) - -[sub_resource type="AtlasTexture" id=48] -flags = 4 -atlas = ExtResource( 1 ) -region = Rect2( 240, 0, 48, 48 ) - -[sub_resource type="AtlasTexture" id=49] -flags = 4 -atlas = ExtResource( 1 ) -region = Rect2( 288, 0, 48, 48 ) - -[sub_resource type="AtlasTexture" id=50] -flags = 4 -atlas = ExtResource( 1 ) -region = Rect2( 336, 0, 48, 48 ) - [sub_resource type="AtlasTexture" id=5] flags = 4 atlas = ExtResource( 6 ) @@ -163,16 +123,6 @@ flags = 4 atlas = ExtResource( 6 ) region = Rect2( 336, 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=17] flags = 4 atlas = ExtResource( 8 ) @@ -203,6 +153,56 @@ 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 ) +region = Rect2( 0, 0, 48, 48 ) + +[sub_resource type="AtlasTexture" id=44] +flags = 4 +atlas = ExtResource( 1 ) +region = Rect2( 48, 0, 48, 48 ) + +[sub_resource type="AtlasTexture" id=45] +flags = 4 +atlas = ExtResource( 1 ) +region = Rect2( 96, 0, 48, 48 ) + +[sub_resource type="AtlasTexture" id=46] +flags = 4 +atlas = ExtResource( 1 ) +region = Rect2( 144, 0, 48, 48 ) + +[sub_resource type="AtlasTexture" id=47] +flags = 4 +atlas = ExtResource( 1 ) +region = Rect2( 192, 0, 48, 48 ) + +[sub_resource type="AtlasTexture" id=48] +flags = 4 +atlas = ExtResource( 1 ) +region = Rect2( 240, 0, 48, 48 ) + +[sub_resource type="AtlasTexture" id=49] +flags = 4 +atlas = ExtResource( 1 ) +region = Rect2( 288, 0, 48, 48 ) + +[sub_resource type="AtlasTexture" id=50] +flags = 4 +atlas = ExtResource( 1 ) +region = Rect2( 336, 0, 48, 48 ) + [sub_resource type="SpriteFrames" id=38] animations = [ { "frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ) ], @@ -217,28 +217,28 @@ animations = [ { }, { "frames": [ SubResource( 23 ), SubResource( 24 ), SubResource( 25 ), SubResource( 26 ), SubResource( 27 ), SubResource( 28 ) ], "loop": true, -"name": "punch", +"name": "move", "speed": 5.0 }, { -"frames": [ SubResource( 43 ), SubResource( 44 ), SubResource( 45 ), SubResource( 46 ), SubResource( 47 ), SubResource( 48 ), SubResource( 49 ), SubResource( 50 ) ], -"loop": true, -"name": "melee", -"speed": 17.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( 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( 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( 43 ), SubResource( 44 ), SubResource( 45 ), SubResource( 46 ), SubResource( 47 ), SubResource( 48 ), SubResource( 49 ), SubResource( 50 ) ], +"loop": true, +"name": "melee", +"speed": 17.0 } ] [sub_resource type="RectangleShape2D" id=39] @@ -248,10 +248,12 @@ extents = Vector2( 9.5, 15.5 ) extents = Vector2( 14.4844, 15.5 ) [sub_resource type="RectangleShape2D" id=41] -extents = Vector2( 9.11914, 2.37328 ) +extents = Vector2( 9.11914, 2.77663 ) + +[sub_resource type="RectangleShape2D" id=51] +extents = Vector2( 12.751, 6.23259 ) [node name="Player" type="KinematicBody2D" groups=["player"]] -scale = Vector2( 1.35, 1.35 ) collision_layer = 3 collision_mask = 249 collision/safe_margin = 0.01 @@ -262,7 +264,7 @@ material = ExtResource( 12 ) position = Vector2( 10, -24 ) frames = SubResource( 38 ) animation = "melee" -frame = 7 +frame = 5 playing = true [node name="Camera2D" type="Camera2D" parent="."] @@ -277,7 +279,7 @@ smoothing_speed = 10.0 [node name="InfoLabel" type="Label" parent="."] margin_left = -18.3265 -margin_top = -83.0373 +margin_top = -144.037 margin_right = 21.6735 margin_bottom = -113.037 text = "test @@ -303,7 +305,7 @@ shape = SubResource( 40 ) position = Vector2( 0, -19 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="StompDetector"] -position = Vector2( 0, 16.8304 ) +position = Vector2( 0, 17.2338 ) shape = SubResource( 41 ) [node name="MeleeDetector" type="Area2D" parent="."] @@ -341,3 +343,4 @@ __meta__ = { [connection signal="body_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_body_entered"] [connection signal="area_entered" from="StompDetector" to="." method="_on_StompDetector_area_entered"] [connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"] +[connection signal="body_entered" from="MeleeDetector" to="." method="_on_MeleeDetector_body_entered"]