From e49e8b57f2c4d5de72d5a4dfe7458425046599e4 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Wed, 4 Nov 2020 21:13:24 -0500 Subject: [PATCH] Added Spring scene --- assets/Items/Spring.png | Bin 0 -> 469 bytes assets/Items/Spring.png.import | 34 ++++++++++++++++ src/Actors/Player.gd | 13 +++++- src/CutScenes/ChallengeCutscene.gd | 10 ++--- src/GameWorld/Levels/PreGame.tscn | 6 ++- src/Hazards/SpikeTrap.gd | 10 ++++- src/Hazards/SpikeTrap.tscn | 13 +++--- src/Items/Spring.gd | 9 +++++ src/Items/Spring.tscn | 63 +++++++++++++++++++++++++++++ 9 files changed, 141 insertions(+), 17 deletions(-) create mode 100644 assets/Items/Spring.png create mode 100644 assets/Items/Spring.png.import create mode 100644 src/Items/Spring.gd create mode 100644 src/Items/Spring.tscn diff --git a/assets/Items/Spring.png b/assets/Items/Spring.png new file mode 100644 index 0000000000000000000000000000000000000000..80b56ce5d7b5d2510e523d59306fedd6c1dcf395 GIT binary patch literal 469 zcmV;`0V@89P)fUJWR0SjH;G$)E_+osrFyXt!novOT{-Ug!SQ>W zZ-DJW02qt}=z)QwDCWXA&ktamZ-z^tVrL&?A@gmVNVH9)tk!Ob50#ure6G$_rjl=S( z`^WIzCP#q$&+`LF@&hP}xm*nP5po{4&oiGbc$zVId;d@xZ^EbUAIo<{5&(NgV4FKk zH&>{si6(sN{xN(jcYvx1A&hxKCMLGwQ}=JeFC=|@c;c7gl{P_DF}i|P void: _update_state() _input_check() _velocity = calculate_move_velocity(_direction,_is_jump_canceled, delta) + _velocity = _boost_velocity if _boost_velocity != Vector2.ZERO else _velocity _velocity = move_and_slide(_velocity, Vector2.UP) + _boost_velocity = Vector2.ZERO _check_collisions() update_sprite(_direction) func _input_check() -> void: if self._alive and (GameState.get_state() == GameState.States.GAME or GameState.get_state() == GameState.States.NEW_GAME): - _is_jump_canceled = Input.is_action_just_released("jump") and !_is_wall_jumping and _velocity.y < 0.0; + _is_jump_canceled = Input.is_action_just_released("jump") and !_is_wall_jumping and _velocity.y < 0.0 and _velocity.y >= -jump_power; + if _boost_velocity != Vector2.ZERO: + _is_jump_canceled = false _get_direction() _check_dash() if Input.is_action_just_pressed("attack") and abilities.attack: @@ -93,7 +98,7 @@ func _update_state(new_state:int = -1): if _state == States.DASHING: return if _state == States.ATTACKING: return if _state == States.IDLE: - if _velocity.y > 0 and not is_on_floor(): + if _velocity.y > 0 and not is_on_floor(): # Falling from ground new_state = States.IN_AIR elif _state == States.IN_AIR: @@ -109,6 +114,7 @@ func _update_state(new_state:int = -1): if is_on_floor() or not is_on_wall(): new_state = States.IDLE else: new_state = States.IDLE + _transition_state(_state, new_state, auto_update) func _transition_state(old_state, new_state, auto_update): @@ -313,3 +319,6 @@ func face_player(right:bool = true): 1 if right else -1, 1 ) + +func boost(velocity:Vector2): + _boost_velocity = velocity diff --git a/src/CutScenes/ChallengeCutscene.gd b/src/CutScenes/ChallengeCutscene.gd index 44fc1d7..31f1b20 100644 --- a/src/CutScenes/ChallengeCutscene.gd +++ b/src/CutScenes/ChallengeCutscene.gd @@ -69,7 +69,7 @@ func start_scene(camera:CameraGame = null): $Tween.interpolate_property(_camera, "position", _camera.position, _camera.get_parent().position, 2, Tween.TRANS_BOUNCE, Tween.EASE_OUT) $Tween.start() yield($Tween, "tween_completed") - camera.get_parent()._velocity.y = -100 + camera.get_parent().boost(Vector2(0,-100)) # Dialog 2 $AnimationPlayer.play("old_dude_slide_in") yield($AnimationPlayer, "animation_finished") @@ -89,10 +89,10 @@ func start_scene(camera:CameraGame = null): _on_scene_exited() pass -func _input(event: InputEvent) -> void: - if not _started: return - if Input.is_action_just_pressed("jump"): - if allow_skip: _on_scene_exited() +# func _input(event: InputEvent) -> void: +# if not _started: return +# if Input.is_action_just_pressed("jump"): +# if allow_skip: _on_scene_exited() func _on_scene_exited(): diff --git a/src/GameWorld/Levels/PreGame.tscn b/src/GameWorld/Levels/PreGame.tscn index b0693e5..3a63172 100644 --- a/src/GameWorld/Levels/PreGame.tscn +++ b/src/GameWorld/Levels/PreGame.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=25 format=2] +[gd_scene load_steps=26 format=2] [ext_resource path="res://src/GameWorld/Levels/PreGame.gd" type="Script" id=1] [ext_resource path="res://assets/Tiles/background_0.png" type="Texture" id=2] @@ -16,6 +16,7 @@ [ext_resource path="res://src/GameWorld/AmbiantLighting.tscn" type="PackedScene" id=14] [ext_resource path="res://src/Scripts/WarpZone.tscn" type="PackedScene" id=15] [ext_resource path="res://src/Hazards/SpikeTrap.tscn" type="PackedScene" id=16] +[ext_resource path="res://src/Items/Spring.tscn" type="PackedScene" id=17] [sub_resource type="TileSet" id=1] 0/name = "tileset.png 0" @@ -269,4 +270,7 @@ to_level_coord = Vector2( 0, 1 ) [node name="SpikeTrap" parent="." instance=ExtResource( 16 )] position = Vector2( 352, 208 ) + +[node name="Spring" parent="." instance=ExtResource( 17 )] +position = Vector2( 98, 240 ) [connection signal="body_entered" from="CutsceneAreas/OldDudeIntroArea" to="." method="_on_OldDudeIntroArea_body_entered"] diff --git a/src/Hazards/SpikeTrap.gd b/src/Hazards/SpikeTrap.gd index 11f8d1f..72ee109 100644 --- a/src/Hazards/SpikeTrap.gd +++ b/src/Hazards/SpikeTrap.gd @@ -1,7 +1,11 @@ +tool extends Node2D - var triggerd = false +export(int, -360, 360) var direction = 1 setget set_direction + + + func _on_DamageArea_body_entered(body: Node) -> void: if body.name == "Player": body.die() @@ -13,4 +17,6 @@ func _on_TriggerArea_body_entered(body: Node) -> void: yield($AnimationPlayer, "animation_finished") yield(get_tree().create_timer(.3), "timeout") $AnimationPlayer.play_backwards("emit") - triggerd = false \ No newline at end of file + triggerd = false +func set_direction(new_direction): + self.rotation_degrees = new_direction diff --git a/src/Hazards/SpikeTrap.tscn b/src/Hazards/SpikeTrap.tscn index 8a9a2d1..ddfc661 100644 --- a/src/Hazards/SpikeTrap.tscn +++ b/src/Hazards/SpikeTrap.tscn @@ -6,10 +6,10 @@ [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 5, 8 ) -[sub_resource type="RectangleShape2D" id=3] +[sub_resource type="RectangleShape2D" id=2] extents = Vector2( 10, 8 ) -[sub_resource type="Animation" id=4] +[sub_resource type="Animation" id=3] resource_name = "emit" length = 0.5 tracks/0/type = "value" @@ -37,8 +37,7 @@ tracks/1/keys = { "values": [ Vector2( -11, -8 ), Vector2( -9, -8 ), Vector2( -3, -8 ), Vector2( 5, -8 ), Vector2( 5, -8 ) ] } -[sub_resource type="Animation" id=2] -resource_name = "idle" +[sub_resource type="Animation" id=4] length = 0.1 tracks/0/type = "value" tracks/0/path = NodePath("Sprite:frame") @@ -87,11 +86,11 @@ collision_layer = 0 [node name="CollisionShape2D" type="CollisionShape2D" parent="TriggerArea"] position = Vector2( 4, -8 ) -shape = SubResource( 3 ) +shape = SubResource( 2 ) [node name="AnimationPlayer" type="AnimationPlayer" parent="."] playback_speed = 2.5 -anims/emit = SubResource( 4 ) -anims/idle = SubResource( 2 ) +anims/emit = SubResource( 3 ) +anims/idle = SubResource( 4 ) [connection signal="body_entered" from="DamageArea" to="." method="_on_DamageArea_body_entered"] [connection signal="body_entered" from="TriggerArea" to="." method="_on_TriggerArea_body_entered"] diff --git a/src/Items/Spring.gd b/src/Items/Spring.gd new file mode 100644 index 0000000..2c77c1a --- /dev/null +++ b/src/Items/Spring.gd @@ -0,0 +1,9 @@ +extends Node2D + +export var thrust:float = 250 + + +func _on_Area2D_body_entered(body: Node) -> void: + if body.name == "Player": + body.boost(Vector2(body._velocity.x, -thrust)) + $AnimationPlayer.play("activated") diff --git a/src/Items/Spring.tscn b/src/Items/Spring.tscn new file mode 100644 index 0000000..b301bdc --- /dev/null +++ b/src/Items/Spring.tscn @@ -0,0 +1,63 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://assets/Items/Spring.png" type="Texture" id=1] +[ext_resource path="res://src/Items/Spring.gd" type="Script" id=2] + +[sub_resource type="Animation" id=1] +resource_name = "activated" +length = 0.6 +tracks/0/type = "value" +tracks/0/path = NodePath("Sprite:frame") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 ), +"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1, 1 ), +"update": 1, +"values": [ 0, 1, 2, 3, 4, 5, 6 ] +} + +[sub_resource type="Animation" id=2] +resource_name = "idle" +length = 0.1 +tracks/0/type = "value" +tracks/0/path = NodePath("Sprite:frame") +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": [ 0 ] +} + +[sub_resource type="RectangleShape2D" id=3] +extents = Vector2( 7, 3 ) + +[node name="Spring" type="Node2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +position = Vector2( 0, -8 ) +texture = ExtResource( 1 ) +hframes = 7 +frame = 6 + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +autoplay = "idle" +playback_speed = 2.0 +anims/activated = SubResource( 1 ) +anims/idle = SubResource( 2 ) + +[node name="Area2D" type="Area2D" parent="."] +collision_layer = 0 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +position = Vector2( 0, -3 ) +shape = SubResource( 3 ) +one_way_collision = true +[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]