Character script cleanup, parameter adjustments, etc
This commit is contained in:
parent
6432ac8b13
commit
9a23e5c8df
4 changed files with 127 additions and 24 deletions
61
player.gd
61
player.gd
|
|
@ -1,47 +1,69 @@
|
|||
extends Node2D
|
||||
var body : CharacterBody2D;
|
||||
extends CharacterBody2D
|
||||
# Child Nodes
|
||||
var camera : Camera2D;
|
||||
var anim_sprite : AnimatedSprite2D
|
||||
|
||||
# Gravity
|
||||
var earth_center = Vector2.ZERO;
|
||||
var max_fall_speed = 700;
|
||||
var jump_strength = 900;
|
||||
var gravity = 100;
|
||||
var hspeed = 150;
|
||||
var angle = 0;
|
||||
|
||||
var bonus_velocity = Vector2.ZERO
|
||||
|
||||
# Movement
|
||||
var hspeed = 150;
|
||||
var jump_strength = 900;
|
||||
var air_jumps_max = 1;
|
||||
var air_jumps_current = 1;
|
||||
|
||||
# HP and Iframes
|
||||
var current_hp = 5;
|
||||
var max_hp = 5;
|
||||
|
||||
var inv_time = 0;
|
||||
var hit_invulnerability = 0.5
|
||||
var inv_time = 0;
|
||||
|
||||
# Received Knockback
|
||||
var bonus_velocity = Vector2.ZERO
|
||||
var knockback_strength = 1200
|
||||
var damage_knockup = 200
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
body = get_parent().get_node("Player")
|
||||
camera = get_node("Camera2D")
|
||||
camera = $Camera2D
|
||||
anim_sprite = $AnimatedSprite2D
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if(inv_time > 0):
|
||||
inv_time = max(0, inv_time-delta)
|
||||
|
||||
angle = -(self.position - earth_center).angle_to(Vector2.UP)
|
||||
body.rotation = angle;
|
||||
body.up_direction = (self.position - earth_center).normalized();
|
||||
angle = -(position - earth_center).angle_to(Vector2.UP)
|
||||
rotation = angle;
|
||||
up_direction = (position - earth_center).normalized();
|
||||
|
||||
if(body.is_on_floor()):
|
||||
if(is_on_floor()):
|
||||
air_jumps_current = air_jumps_max
|
||||
|
||||
manage_animation()
|
||||
manage_velocity()
|
||||
body.move_and_slide()
|
||||
move_and_slide()
|
||||
|
||||
func manage_animation() -> void:
|
||||
var walk_dir = 0
|
||||
if(Input.is_action_pressed("move_right")):
|
||||
walk_dir += 1
|
||||
if(Input.is_action_pressed("move_left")):
|
||||
walk_dir -= 1
|
||||
|
||||
if(walk_dir != 0):
|
||||
anim_sprite.scale.x = - abs(anim_sprite.scale.x) * walk_dir
|
||||
if(is_on_floor()):
|
||||
anim_sprite.play("walk")
|
||||
else:
|
||||
anim_sprite.stop() # Later: Jump Animation?
|
||||
else :
|
||||
anim_sprite.stop()
|
||||
|
||||
func manage_velocity() -> void:
|
||||
var old_local_velocity = local_from_global(body.velocity)
|
||||
var old_local_velocity = local_from_global(velocity)
|
||||
var local_velocity = Vector2(old_local_velocity.x/1.7, old_local_velocity.y);
|
||||
local_velocity += Vector2(0, gravity)
|
||||
|
||||
|
|
@ -49,8 +71,9 @@ func manage_velocity() -> void:
|
|||
local_velocity += Vector2(hspeed, 0)
|
||||
if(Input.is_action_pressed("move_left")):
|
||||
local_velocity += Vector2(-hspeed, 0)
|
||||
if(Input.is_action_just_pressed("jump") and (body.is_on_floor() or air_jumps_current > 0)):
|
||||
if(not body.is_on_floor()):
|
||||
|
||||
if(Input.is_action_just_pressed("jump") and (is_on_floor() or air_jumps_current > 0)):
|
||||
if(not is_on_floor()):
|
||||
air_jumps_current -= 1;
|
||||
local_velocity.y = -jump_strength
|
||||
|
||||
|
|
@ -59,7 +82,7 @@ func manage_velocity() -> void:
|
|||
|
||||
local_velocity += bonus_velocity
|
||||
bonus_velocity = Vector2.ZERO
|
||||
body.velocity = global_from_local(local_velocity)
|
||||
velocity = global_from_local(local_velocity)
|
||||
|
||||
|
||||
func global_from_local (_velocity: Vector2) -> Vector2:
|
||||
|
|
|
|||
56
player.tscn
56
player.tscn
|
|
@ -1,20 +1,66 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://cmaovvr15b3qk"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://cmaovvr15b3qk"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ddidj1uau28ck" path="res://player.gd" id="1_4flbx"]
|
||||
[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="2_onrkg"]
|
||||
[ext_resource type="Texture2D" uid="uid://cyvxm1hf1rc12" path="res://player_walk.png" id="2_onrkg"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_onrkg"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_i3pqv"]
|
||||
atlas = ExtResource("2_onrkg")
|
||||
region = Rect2(0, 0, 240, 240)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_hqtel"]
|
||||
atlas = ExtResource("2_onrkg")
|
||||
region = Rect2(240, 0, 240, 240)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_sweqy"]
|
||||
atlas = ExtResource("2_onrkg")
|
||||
region = Rect2(480, 0, 240, 240)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_2hs0m"]
|
||||
atlas = ExtResource("2_onrkg")
|
||||
region = Rect2(720, 0, 240, 240)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_1jxqw"]
|
||||
atlas = ExtResource("2_onrkg")
|
||||
region = Rect2(960, 0, 240, 240)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_dw050"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_i3pqv")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_hqtel")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_sweqy")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_2hs0m")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_1jxqw")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"walk",
|
||||
"speed": 10.0
|
||||
}]
|
||||
|
||||
[node name="Player" type="CharacterBody2D"]
|
||||
script = ExtResource("1_4flbx")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 5.6)
|
||||
scale = Vector2(0.7, 0.72)
|
||||
shape = SubResource("CapsuleShape2D_onrkg")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
position = Vector2(5.96046e-08, 0)
|
||||
scale = Vector2(0.15625, 0.234375)
|
||||
texture = ExtResource("2_onrkg")
|
||||
scale = Vector2(0.2, 0.2)
|
||||
sprite_frames = SubResource("SpriteFrames_dw050")
|
||||
animation = &"walk"
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position = Vector2(0, -50)
|
||||
|
|
|
|||
BIN
player_walk.png
Normal file
BIN
player_walk.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
34
player_walk.png.import
Normal file
34
player_walk.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cyvxm1hf1rc12"
|
||||
path="res://.godot/imported/player_walk.png-dd7b13f797aca66ef3a8a41ed9897826.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://player_walk.png"
|
||||
dest_files=["res://.godot/imported/player_walk.png-dd7b13f797aca66ef3a8a41ed9897826.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
Loading…
Add table
Reference in a new issue