Initial commit
This commit is contained in:
15
scripts/killzone.gd
Normal file
15
scripts/killzone.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
extends Area2D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
get_tree().reload_current_scene()
|
||||
1
scripts/killzone.gd.uid
Normal file
1
scripts/killzone.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dlx37dl8br661
|
||||
49
scripts/platform_handler.gd
Normal file
49
scripts/platform_handler.gd
Normal file
@@ -0,0 +1,49 @@
|
||||
extends Node
|
||||
|
||||
var rng = RandomNumberGenerator.new()
|
||||
var PlatformScene := preload("res://scenes/platform.tscn")
|
||||
var platforms := []
|
||||
var dead = false
|
||||
@onready var height: float = get_viewport().size.y
|
||||
@onready var width: float = get_viewport().size.x
|
||||
@onready var player: CharacterBody2D = %Player
|
||||
const N = 10
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
for i in range(N):
|
||||
var y = i * height / N
|
||||
# TODO: don't place platforms where others exist already
|
||||
place_platform(y)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var move = 0
|
||||
if player.position.y < height/2 and not dead:
|
||||
move = height/2 - player.position.y
|
||||
player.position.y = height/2
|
||||
elif player.position.y > height or dead:
|
||||
dead = true
|
||||
move = -40
|
||||
player.position.y -= 100/2.87
|
||||
|
||||
|
||||
|
||||
for platform in platforms:
|
||||
platform.position.y += move
|
||||
if platform.position.y > height + platform.get_node("Sprite2D").texture.get_height():
|
||||
platform.position = Vector2(rng.randf_range(0, width), 0)
|
||||
|
||||
|
||||
|
||||
|
||||
func place_platform(y: float = 0) -> void:
|
||||
var platform_instance = PlatformScene.instantiate()
|
||||
var x = rng.randf_range(0, width)
|
||||
platform_instance.position = Vector2(x, y)
|
||||
add_child(platform_instance)
|
||||
platforms.append(platform_instance)
|
||||
1
scripts/platform_handler.gd.uid
Normal file
1
scripts/platform_handler.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bpuudy2mj7fjd
|
||||
33
scripts/player.gd
Normal file
33
scripts/player.gd
Normal file
@@ -0,0 +1,33 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -800.0
|
||||
|
||||
var width
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
width = get_viewport().size.x
|
||||
velocity.y = JUMP_VELOCITY * 2
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
else:
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var direction := Input.get_axis("ui_left", "ui_right")
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
if position.x > width:
|
||||
position.x -= width
|
||||
elif position.x < 0:
|
||||
position.x += width
|
||||
move_and_slide()
|
||||
1
scripts/player.gd.uid
Normal file
1
scripts/player.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bgahsyy7gxau4
|
||||
Reference in New Issue
Block a user