Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c70c8a9b2f | |||
| 24cb58ca58 | |||
| e323fb8e24 |
11
gamejam/src/Actors/Camera2D.gd
Normal file
11
gamejam/src/Actors/Camera2D.gd
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
extends Camera2D
|
||||||
|
|
||||||
|
const DEAD_ZONE = 160
|
||||||
|
|
||||||
|
func _input(event: InputEvent) -> void:
|
||||||
|
if event is InputEventMouseMotion:
|
||||||
|
var _target = event.position - get_viewport().size * 0.5
|
||||||
|
if _target.length() < DEAD_ZONE:
|
||||||
|
self.position = Vector2(0,0)
|
||||||
|
else:
|
||||||
|
self.position = _target.normalized() * (_target.length() - DEAD_ZONE) * 0.5
|
||||||
@@ -1,19 +1,22 @@
|
|||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
const speed = 400
|
const speed = 400
|
||||||
const jump_power = -1400.0
|
|
||||||
|
|
||||||
const acc = 25
|
const acc = 25
|
||||||
const friction = 70
|
const friction = 70
|
||||||
|
|
||||||
const grav = 100
|
|
||||||
|
|
||||||
const max_jumps = 2
|
@export var jump_height : float = 225
|
||||||
|
@export var jump_time_to_peak : float = 0.5
|
||||||
|
@export var jump_time_to_descent : float = 0.3
|
||||||
|
|
||||||
var current_jumps = 1
|
@onready var jump_velocity : float = ((2.0 * jump_height) / jump_time_to_peak) * -1.0
|
||||||
|
@onready var jump_gravity : float = ((-2.0 * jump_height) / (jump_time_to_peak * jump_time_to_peak)) * -1.0
|
||||||
|
@onready var fall_gravity : float = ((-2.0 * jump_height) / (jump_time_to_descent * jump_time_to_descent)) * -1.0
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
|
||||||
var input_dir: Vector2 = input()
|
var input_dir: Vector2 = input()
|
||||||
|
|
||||||
if input_dir != Vector2.ZERO:
|
if input_dir != Vector2.ZERO:
|
||||||
@@ -24,7 +27,7 @@ func _physics_process(delta):
|
|||||||
#play_animation()
|
#play_animation()
|
||||||
|
|
||||||
|
|
||||||
jump()
|
jump(delta)
|
||||||
player_moviment()
|
player_moviment()
|
||||||
|
|
||||||
func input() -> Vector2:
|
func input() -> Vector2:
|
||||||
@@ -43,13 +46,11 @@ func add_friction():
|
|||||||
func player_moviment():
|
func player_moviment():
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
func jump():
|
func jump(delta):
|
||||||
if Input.is_action_just_pressed("ui_up"):
|
velocity.y += get_grav() * delta
|
||||||
if current_jumps < max_jumps:
|
|
||||||
velocity.y = jump_power
|
|
||||||
current_jumps += 1
|
|
||||||
else:
|
|
||||||
velocity.y += grav
|
|
||||||
|
|
||||||
if is_on_floor():
|
if Input.is_action_just_pressed("ui_up") and is_on_floor():
|
||||||
current_jumps = 1
|
velocity.y = jump_velocity
|
||||||
|
|
||||||
|
func get_grav() -> float:
|
||||||
|
return jump_gravity if velocity.y < 0.0 else fall_gravity
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://dp4nln7877kq3"]
|
[gd_scene load_steps=5 format=3 uid="uid://dp4nln7877kq3"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/Actors/Player.gd" id="1_qe2a3"]
|
[ext_resource type="Script" path="res://src/Actors/Player.gd" id="1_qe2a3"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bglwfp5ngk8xr" path="res://assests/placeholder.png" id="2_ctbi8"]
|
[ext_resource type="Texture2D" uid="uid://bglwfp5ngk8xr" path="res://assests/placeholder.png" id="2_ctbi8"]
|
||||||
|
[ext_resource type="Script" path="res://src/Actors/Camera2D.gd" id="3_0ej4p"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_xv46f"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_xv46f"]
|
||||||
size = Vector2(121, 149.5)
|
size = Vector2(121, 149.5)
|
||||||
@@ -19,3 +20,6 @@ texture = ExtResource("2_ctbi8")
|
|||||||
position = Vector2(0, -37.375)
|
position = Vector2(0, -37.375)
|
||||||
scale = Vector2(0.5, 0.5)
|
scale = Vector2(0.5, 0.5)
|
||||||
shape = SubResource("RectangleShape2D_xv46f")
|
shape = SubResource("RectangleShape2D_xv46f")
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
script = ExtResource("3_0ej4p")
|
||||||
|
|||||||
Reference in New Issue
Block a user