WIP: Metroidvania

This commit is contained in:
Felipe M 2021-01-26 23:04:34 +01:00
parent 4e3b2e4ac9
commit f456725cf2
Signed by: fmartingr
GPG key ID: 716BC147715E716F
116 changed files with 1998 additions and 0 deletions

View file

@ -0,0 +1,16 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Assets/World/Brick.png" type="Texture" id=1]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 8, 8 )
[node name="Brick" type="StaticBody2D"]
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
centered = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 8, 8 )
shape = SubResource( 1 )

View file

@ -0,0 +1,70 @@
extends KinematicBody2D
export (int) var acceleration = 512
export (int) var max_speed = 64
export (float) var friction = 0.25
export (int) var gravity = 200
export (int) var jump_force = 128
export (int) var max_slope = 46
var motion = Vector2.ZERO
var snap_vector = Vector2.ZERO
onready var sprite = $Sprite
onready var animation = $Animation
func _physics_process(delta):
var input_vector = get_input_vector()
apply_horizontal_force(input_vector, delta)
apply_friction(input_vector)
update_snap_vector()
jump_check()
apply_gravity(delta)
update_animations(input_vector)
move()
func get_input_vector():
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
return input_vector
func apply_horizontal_force(input_vector, delta):
if input_vector.x != 0:
motion.x += input_vector.x * acceleration * delta
motion.x = clamp(motion.x, -max_speed, max_speed) # Set the max motion
func apply_friction(input_vector):
if input_vector.x == 0 and is_on_floor():
motion.x = lerp(motion.x, 0, friction)
func update_snap_vector():
if is_on_floor():
snap_vector = Vector2.DOWN
func jump_check():
if is_on_floor():
if Input.is_action_just_pressed("ui_select"):
motion.y = -jump_force
snap_vector = Vector2.ZERO
else:
if Input.is_action_just_released("ui_select"):# and motion.y < -jump_force/2:
motion.y = motion.y/2
func apply_gravity(delta):
motion.y += gravity * delta
motion.y = min(motion.y, jump_force)
func update_animations(input_vector):
if input_vector.x != 0:
# Reverses the sprite if the direction is -x ?
sprite.scale.x = sign(input_vector.x)
animation.play("Run")
else:
animation.play("Idle")
if not is_on_floor():
animation.play("Jump")
func move():
motion = move_and_slide_with_snap(motion, snap_vector * 4, Vector2.UP, true, 4, deg2rad(max_slope), false)

View file

@ -0,0 +1,83 @@
[gd_scene load_steps=8 format=2]
[ext_resource path="res://Assets/Player/Player.png" type="Texture" id=1]
[ext_resource path="res://Scenes/Player.gd" type="Script" id=2]
[ext_resource path="res://DebugKinematicBody2D.tscn" type="PackedScene" id=3]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 4, 7 )
[sub_resource type="Animation" id=2]
resource_name = "Idle"
length = 1.2
loop = true
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.3, 0.6, 0.9 ),
"transitions": PoolRealArray( 1, 1, 1, 1 ),
"update": 1,
"values": [ 0, 1, 2, 3 ]
}
[sub_resource type="Animation" id=3]
resource_name = "Jump"
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": [ 11 ]
}
[sub_resource type="Animation" id=4]
resource_name = "Run"
length = 0.6
loop = true
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": [ 4, 5, 6, 7, 8, 9, 7 ]
}
[node name="Player" type="KinematicBody2D"]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 0, -12 )
texture = ExtResource( 1 )
hframes = 12
[node name="Collision" type="CollisionShape2D" parent="."]
position = Vector2( 0, -7 )
shape = SubResource( 1 )
[node name="Animation" type="AnimationPlayer" parent="."]
anims/Idle = SubResource( 2 )
anims/Jump = SubResource( 3 )
anims/Run = SubResource( 4 )
[node name="Debug" parent="." instance=ExtResource( 3 )]
visible = false
[node name="CameraFollow" type="RemoteTransform2D" parent="."]
position = Vector2( 0, -8 )
update_rotation = false
update_scale = false

View file

@ -0,0 +1,52 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Scenes/Brick.tscn" type="PackedScene" id=1]
[ext_resource path="res://Scenes/Player.tscn" type="PackedScene" id=2]
[node name="World" type="Node"]
[node name="Brick" parent="." instance=ExtResource( 1 )]
position = Vector2( 0, 160 )
[node name="Brick2" parent="." instance=ExtResource( 1 )]
position = Vector2( 16, 160 )
[node name="Brick3" parent="." instance=ExtResource( 1 )]
position = Vector2( 32, 160 )
[node name="Brick4" parent="." instance=ExtResource( 1 )]
position = Vector2( 48, 160 )
[node name="Brick5" parent="." instance=ExtResource( 1 )]
position = Vector2( 64, 160 )
[node name="Brick6" parent="." instance=ExtResource( 1 )]
position = Vector2( 80, 160 )
[node name="Brick7" parent="." instance=ExtResource( 1 )]
position = Vector2( 96, 160 )
[node name="Brick8" parent="." instance=ExtResource( 1 )]
position = Vector2( 48, 144 )
[node name="Brick9" parent="." instance=ExtResource( 1 )]
position = Vector2( 64, 144 )
[node name="Player" parent="." instance=ExtResource( 2 )]
position = Vector2( 32, 96 )
[node name="CameraFollow" parent="Player" index="4"]
remote_path = NodePath("../../Camera")
[node name="Camera" type="Camera2D" parent="."]
position = Vector2( 32, 88 )
current = true
smoothing_enabled = true
[node name="Terrain" type="StaticBody2D" parent="."]
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Terrain"]
position = Vector2( -16, -32 )
polygon = PoolVector2Array( 0, 112, 0, 144, 48, 144, 64, 128, 96, 128, 128, 96, 160, 96, 160, 112, 224, 112, 224, 80, 240, 112, 160, 176, -32, 176, -32, 112 )
[editable path="Player"]