Implement key map and unlockable abilities

master
NaiJi ✨ 3 years ago
parent 7e12cfd408
commit a4f3361048

@ -1,7 +0,0 @@
extends Node
class_name Action
var action_id = -1
func process(actor, delta):
actor.setState(action_id)

@ -3,8 +3,6 @@ class_name Actor
var state = 0
var health = 100
var state_map = {} # {STATE, Action Node}
export var speed = 200 # How fast the actor will move (pixels/sec).
var speed = 200 # How fast the actor will move (pixels/sec).
func setState(new_state):
state = new_state
var state_map = {} # {STATE, Action Node}

@ -1,16 +0,0 @@
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

@ -0,0 +1,9 @@
extends Node
class_name AttackKey
func register(actor):
actor.state_map[actor.PlayerState.ATTACKING] = PlayerAttack.new()
return self
func trigger(actor):
actor.state = actor.PlayerState.ATTACKING

@ -0,0 +1,11 @@
extends Node
class_name DashKey
func register(actor):
actor.state_map[actor.PlayerState.DASHING] = PlayerDash.new()
actor.state_map[actor.PlayerState.STANDING] = PlayerStanding.new()
return self
func trigger(actor):
actor.state = actor.PlayerState.DASHING

@ -4,4 +4,14 @@ func _ready():
newGame()
func newGame():
$Player.start($StartPosition.position)
var player = preload("res://Player.tscn").instance()
player.name = "Player"
player.start($StartPosition.position)
add_child(player)
var orb = preload("res://OrbItem.tscn").instance()
orb.position.x = player.position.x
orb.position.y = player.position.y - 250
orb.scale = Vector2(0.4, 0.4)
add_child(orb)

@ -1,6 +1,5 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://test-scene.tscn" type="PackedScene" id=1]
[ext_resource path="res://Main.gd" type="Script" id=2]
[ext_resource path="res://Actor.gd" type="Script" id=3]
[ext_resource path="res://Ground.tscn" type="PackedScene" id=4]
@ -12,11 +11,6 @@ script = ExtResource( 2 )
collision_layer = 2
collision_mask = 0
[node name="Player" parent="." instance=ExtResource( 1 )]
position = Vector2( 65.481, 38.7541 )
scale = Vector2( 1.5, 1.5 )
collision_mask = 0
[node name="StartPosition" type="Position2D" parent="."]
position = Vector2( 240, 450 )

@ -1,12 +0,0 @@
extends RigidBody2D
export var min_speed = 150 # Minimum speed range.
export var max_speed = 250 # Maximum speed range.
func _ready():
var mob_types = $AnimatedSprite.frames.get_animation_names()
$AnimatedSprite.animation = mob_types[randi() % mob_types.size()]
func _on_VisibilityNotifier2D_screen_exited():
#queue_free()
pass

@ -1,51 +0,0 @@
[gd_scene load_steps=10 format=2]
[ext_resource path="res://dodge_assets/art/enemySwimming_1.png" type="Texture" id=1]
[ext_resource path="res://dodge_assets/art/enemyWalking_1.png" type="Texture" id=2]
[ext_resource path="res://dodge_assets/art/enemySwimming_2.png" type="Texture" id=3]
[ext_resource path="res://dodge_assets/art/enemyFlyingAlt_2.png" type="Texture" id=4]
[ext_resource path="res://dodge_assets/art/enemyFlyingAlt_1.png" type="Texture" id=5]
[ext_resource path="res://dodge_assets/art/enemyWalking_2.png" type="Texture" id=6]
[ext_resource path="res://Mob.gd" type="Script" id=7]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 5 ), ExtResource( 4 ) ],
"loop": true,
"name": "fly",
"speed": 5.0
}, {
"frames": [ ExtResource( 2 ), ExtResource( 6 ) ],
"loop": true,
"name": "walk",
"speed": 3.0
}, {
"frames": [ ExtResource( 1 ), ExtResource( 3 ) ],
"loop": true,
"name": "swim",
"speed": 5.0
} ]
[sub_resource type="CapsuleShape2D" id=2]
radius = 34.9916
height = 29.2442
[node name="Mob" type="RigidBody2D"]
collision_mask = 0
gravity_scale = 0.0
script = ExtResource( 7 )
__meta__ = {
"_edit_group_": true
}
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
scale = Vector2( 0.75, 0.75 )
frames = SubResource( 1 )
animation = "walk"
playing = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 1.5708
shape = SubResource( 2 )
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]

@ -0,0 +1,7 @@
extends Area2D
func _on_OrbItem_area_shape_entered(area_id, area, area_shape, self_shape):
if area.name == "Player":
var dk = DashKey.new()
area.key_map[KEY_SHIFT] = dk.register(area)
get_tree().queue_delete(self)

@ -0,0 +1,29 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://assets/art/red-orb.png" type="Texture" id=1]
[ext_resource path="res://OrbItem.gd" type="Script" id=2]
[sub_resource type="CircleShape2D" id=1]
radius = 33.9555
[node name="OrbItem" type="Area2D"]
gravity = 0.0
script = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
[node name="Label" type="Label" parent="."]
margin_left = 34.3329
margin_top = -36.8527
margin_right = 143.333
margin_bottom = -22.8527
rect_scale = Vector2( 3, 3 )
text = "PICKUP TO DASH"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="area_shape_entered" from="." to="." method="_on_OrbItem_area_shape_entered"]

@ -8,12 +8,15 @@ enum PlayerState { NORMAL = 0, # < default from Actor
var screen_size # Size of the game window.
var last_process_velocity = Vector2()
var key_map
func start(pos):
position = pos
state_map = {PlayerState.NORMAL: PlayerNormal.new(),
PlayerState.DASHING: PlayerDash.new(),
PlayerState.STANDING: PlayerStanding.new(),
PlayerState.ATTACKING: PlayerAttack.new()}
var ak = AttackKey.new()
key_map = { KEY_Z: ak.register(self) }
show()
func _process(delta):

@ -1,75 +1,77 @@
[gd_scene load_steps=33 format=2]
[ext_resource path="res://assets/art/forward-sheet.png" type="Texture" id=1]
[ext_resource path="res://assets/art/backwards-sheet.png" type="Texture" id=2]
[ext_resource path="res://assets/art/idle-sheet.png" type="Texture" id=3]
[ext_resource path="res://assets/art/dash/dash-04.png" type="Texture" id=4]
[ext_resource path="res://player.gd" type="Script" id=5]
[ext_resource path="res://assets/art/dash/dash-02.png" type="Texture" id=6]
[ext_resource path="res://assets/art/dash/dash-06.png" type="Texture" id=7]
[ext_resource path="res://assets/art/dash/dash-09.png" type="Texture" id=8]
[ext_resource path="res://assets/art/dash/dash-01.png" type="Texture" id=9]
[ext_resource path="res://assets/art/dash/dash-05.png" type="Texture" id=10]
[ext_resource path="res://assets/art/dash/dash-07.png" type="Texture" id=11]
[ext_resource path="res://assets/art/dash/dash-03.png" type="Texture" id=12]
[ext_resource path="res://assets/art/dash/dash-08.png" type="Texture" id=13]
[ext_resource path="res://assets/art/slash/slash-02.png" type="Texture" id=14]
[ext_resource path="res://assets/art/slash/slash-03.png" type="Texture" id=15]
[ext_resource path="res://assets/art/slash/slash-01.png" type="Texture" id=16]
[ext_resource path="res://PlayerNormal.gd" type="Script" id=17]
[ext_resource path="res://assets/art/slash/slash-04.png" type="Texture" id=18]
[ext_resource path="res://PlayerDash.gd" type="Script" id=19]
[ext_resource path="res://PlayerStanding.gd" type="Script" id=20]
[ext_resource path="res://PlayerAttack.gd" type="Script" id=21]
[gd_scene load_steps=36 format=2]
[ext_resource path="res://Player.gd" type="Script" id=1]
[ext_resource path="res://DashKey.gd" type="Script" id=2]
[ext_resource path="res://PlayerStanding.gd" type="Script" id=3]
[ext_resource path="res://PlayerDash.gd" type="Script" id=4]
[ext_resource path="res://PlayerAttack.gd" type="Script" id=5]
[ext_resource path="res://assets/art/backwards-sheet.png" type="Texture" id=6]
[ext_resource path="res://AttackKey.gd" type="Script" id=7]
[ext_resource path="res://assets/art/forward-sheet.png" type="Texture" id=8]
[ext_resource path="res://assets/art/dash/dash-04.png" type="Texture" id=9]
[ext_resource path="res://assets/art/idle-sheet.png" type="Texture" id=10]
[ext_resource path="res://assets/art/slash/slash-03.png" type="Texture" id=11]
[ext_resource path="res://assets/art/dash/dash-05.png" type="Texture" id=12]
[ext_resource path="res://assets/art/dash/dash-06.png" type="Texture" id=13]
[ext_resource path="res://assets/art/dash/dash-02.png" type="Texture" id=14]
[ext_resource path="res://assets/art/slash/slash-02.png" type="Texture" id=15]
[ext_resource path="res://PlayerNormal.gd" type="Script" id=16]
[ext_resource path="res://assets/art/dash/dash-08.png" type="Texture" id=17]
[ext_resource path="res://assets/art/dash/dash-03.png" type="Texture" id=18]
[ext_resource path="res://assets/art/dash/dash-07.png" type="Texture" id=19]
[ext_resource path="res://assets/art/dash/dash-09.png" type="Texture" id=20]
[ext_resource path="res://assets/art/dash/dash-01.png" type="Texture" id=21]
[ext_resource path="res://assets/art/slash/slash-01.png" type="Texture" id=22]
[ext_resource path="res://assets/art/slash/slash-04.png" type="Texture" id=23]
[sub_resource type="AtlasTexture" id=1]
flags = 4
atlas = ExtResource( 3 )
atlas = ExtResource( 10 )
region = Rect2( 0, 0, 45, 47 )
[sub_resource type="AtlasTexture" id=2]
flags = 4
atlas = ExtResource( 3 )
atlas = ExtResource( 10 )
region = Rect2( 45, 0, 45, 47 )
[sub_resource type="AtlasTexture" id=3]
flags = 4
atlas = ExtResource( 3 )
atlas = ExtResource( 10 )
region = Rect2( 90, 0, 45, 47 )
[sub_resource type="AtlasTexture" id=4]
flags = 4
atlas = ExtResource( 3 )
atlas = ExtResource( 10 )
region = Rect2( 135, 0, 45, 47 )
[sub_resource type="AtlasTexture" id=5]
flags = 4
atlas = ExtResource( 1 )
atlas = ExtResource( 8 )
region = Rect2( 0, 0, 45, 47 )
[sub_resource type="AtlasTexture" id=6]
flags = 4
atlas = ExtResource( 1 )
atlas = ExtResource( 8 )
region = Rect2( 45, 0, 45, 47 )
[sub_resource type="AtlasTexture" id=7]
flags = 4
atlas = ExtResource( 1 )
atlas = ExtResource( 8 )
region = Rect2( 90, 0, 45, 47 )
[sub_resource type="AtlasTexture" id=8]
flags = 4
atlas = ExtResource( 2 )
atlas = ExtResource( 6 )
region = Rect2( 0, 0, 44, 47 )
[sub_resource type="AtlasTexture" id=9]
flags = 4
atlas = ExtResource( 2 )
atlas = ExtResource( 6 )
region = Rect2( 44, 0, 44, 47 )
[sub_resource type="AtlasTexture" id=10]
flags = 4
atlas = ExtResource( 2 )
atlas = ExtResource( 6 )
region = Rect2( 88, 0, 44, 47 )
[sub_resource type="SpriteFrames" id=11]
@ -79,7 +81,7 @@ animations = [ {
"name": "idle",
"speed": 5.0
}, {
"frames": [ ExtResource( 16 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 18 ) ],
"frames": [ ExtResource( 22 ), ExtResource( 15 ), ExtResource( 11 ), ExtResource( 23 ) ],
"loop": true,
"name": "slash",
"speed": 5.0
@ -89,7 +91,7 @@ animations = [ {
"name": "forward",
"speed": 5.0
}, {
"frames": [ ExtResource( 9 ), ExtResource( 6 ), ExtResource( 12 ), ExtResource( 4 ), ExtResource( 4 ), ExtResource( 10 ), ExtResource( 7 ), ExtResource( 7 ), ExtResource( 11 ) ],
"frames": [ ExtResource( 21 ), ExtResource( 14 ), ExtResource( 18 ), ExtResource( 9 ), ExtResource( 9 ), ExtResource( 12 ), ExtResource( 13 ), ExtResource( 13 ), ExtResource( 19 ) ],
"loop": true,
"name": "dash",
"speed": 5.0
@ -99,34 +101,47 @@ animations = [ {
"name": "backward",
"speed": 5.0
}, {
"frames": [ ExtResource( 13 ), ExtResource( 13 ), ExtResource( 8 ) ],
"frames": [ ExtResource( 17 ), ExtResource( 17 ), ExtResource( 20 ) ],
"loop": true,
"name": "standing up",
"speed": 5.0
} ]
[sub_resource type="CapsuleShape2D" id=12]
radius = 8.82094
height = 0.0
[node name="Player" type="Area2D"]
script = ExtResource( 5 )
gravity = 0.0
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
frames = SubResource( 11 )
animation = "slash"
animation = "idle"
frame = 2
playing = true
[node name="PlayerNormal" type="Node" parent="."]
script = ExtResource( 17 )
script = ExtResource( 16 )
[node name="PlayerDash" type="Node" parent="."]
script = ExtResource( 19 )
script = ExtResource( 4 )
[node name="PlayerStanding" type="Node" parent="."]
script = ExtResource( 20 )
script = ExtResource( 3 )
[node name="PlayerAttack" type="Node" parent="."]
script = ExtResource( 21 )
[connection signal="body_entered" from="." to="." method="_on_Player_body_entered"]
script = ExtResource( 5 )
[node name="DashKey" type="Node" parent="."]
script = ExtResource( 2 )
[node name="AttackKey" type="Node" parent="."]
script = ExtResource( 7 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 12 )
[connection signal="animation_finished" from="AnimatedSprite" to="." method="_on_AnimatedSprite_animation_finished"]

@ -3,11 +3,13 @@ class_name PlayerNormal
func run(actor, delta):
var velocity = Vector2() # The player's movement vector.
if Input.is_key_pressed(KEY_SHIFT):
actor.setState(actor.PlayerState.DASHING)
if Input.is_key_pressed(KEY_Z):
actor.setState(actor.PlayerState.ATTACKING)
var velocity = Vector2() # The player's movement vector.
var keys = actor.key_map.keys()
for i in keys:
if Input.is_key_pressed(i):
actor.key_map[i].trigger(actor)
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
@ -34,4 +36,5 @@ func run(actor, delta):
actor.last_process_velocity = velocity
func spriteFinished(actor):
actor.show()
pass

@ -1,4 +0,0 @@
extends Timer
func _ready():
Timer.wait_time(2.0)

@ -9,17 +9,22 @@
config_version=4
_global_script_classes=[ {
"base": "Node",
"class": "Action",
"language": "GDScript",
"path": "res://Action.gd"
}, {
"base": "Area2D",
"class": "Actor",
"language": "GDScript",
"path": "res://Actor.gd"
}, {
"base": "Node",
"class": "AttackKey",
"language": "GDScript",
"path": "res://AttackKey.gd"
}, {
"base": "Node",
"class": "DashKey",
"language": "GDScript",
"path": "res://DashKey.gd"
}, {
"base": "Node",
"class": "PlayerAttack",
"language": "GDScript",
"path": "res://PlayerAttack.gd"
@ -40,8 +45,9 @@ _global_script_classes=[ {
"path": "res://PlayerStanding.gd"
} ]
_global_script_class_icons={
"Action": "",
"Actor": "",
"AttackKey": "",
"DashKey": "",
"PlayerAttack": "",
"PlayerDash": "",
"PlayerNormal": "",

@ -1,15 +0,0 @@
extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
$Label.text = "Press me, senpai!"
func _on_Button_pressed():
$Label.text = "HELLO!"
$Timer.stop()
$Timer.start()
func _on_Timer_timeout():
$Label.text = "Press me, senpai!"
Loading…
Cancel
Save