From 789bf1e33d090f79a92dc299bfe6abd2b23a8ec1 Mon Sep 17 00:00:00 2001 From: Diego Date: Sat, 18 Jul 2020 02:27:01 -0500 Subject: [PATCH] Too much stuff --- KinematicBody2D.gd | 16 ++++++++++ Skeleton Enemy.gd | 27 +++++++++++++++++ Skeleton.gd | 32 ++++++++++++++++++++ ai/Skeleton Enemy.tscn | 28 ++++++++++++++++++ art/unknown.png | Bin 0 -> 220 bytes art/unknown.png.import | 34 +++++++++++++++++++++ characters/Player.tscn | 16 ++++------ levels/World.tscn | 39 +++++++++++++++---------- magic/projectiles/WhiteProjectile.tscn | 14 ++++++++- project.godot | 6 ---- script/PlayerStateMachine.gd | 2 +- script/Skeleton Enemy.gd | 20 +++++++++++++ script/player.gd | 4 ++- 13 files changed, 203 insertions(+), 35 deletions(-) create mode 100644 KinematicBody2D.gd create mode 100644 Skeleton Enemy.gd create mode 100644 Skeleton.gd create mode 100644 ai/Skeleton Enemy.tscn create mode 100644 art/unknown.png create mode 100644 art/unknown.png.import create mode 100644 script/Skeleton Enemy.gd diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd new file mode 100644 index 0000000..7e84473 --- /dev/null +++ b/KinematicBody2D.gd @@ -0,0 +1,16 @@ +extends KinematicBody2D + + +# 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 diff --git a/Skeleton Enemy.gd b/Skeleton Enemy.gd new file mode 100644 index 0000000..2b0de64 --- /dev/null +++ b/Skeleton Enemy.gd @@ -0,0 +1,27 @@ +extends KinematicBody2D + +var speed = 60 +var gravity =500 +const UP = Vector2(0, -1) + +var velocity = Vector2() + +func apply_gravity(delta, modifier = 1): + velocity.y += gravity * delta * modifier + +func _physics_process(_delta): + if Globals.player != null: + if $RayCast2D.get_collider() != null && $RayCast2D.get_collider().has_method("get_type") and $RayCast2D.get_collider().get_type() == "player": + velocity = Vector2(0, 0) + elif $RayCast2D2.get_collider() != null && $RayCast2D2.get_collider().has_method("get_type") and $RayCast2D2.get_collider().get_type() == "player": + velocity = Vector2(0, 0) + else: + velocity.x = position.direction_to(Globals.player).normalized().x + apply_gravity(_delta) + velocity.x *= speed + velocity = move_and_slide(velocity, UP) + + if is_on_wall() and is_on_floor(): + velocity.y = -150 + + diff --git a/Skeleton.gd b/Skeleton.gd new file mode 100644 index 0000000..3e8348f --- /dev/null +++ b/Skeleton.gd @@ -0,0 +1,32 @@ +extends RigidBody2D + +var speed = 45 +var gravity = 500 +const UP = Vector2(0, -1) +var is_grounded +var touching_wall = 0 + +var velocity = Vector2() + +func apply_gravity(delta, modifier = 1): + velocity.y += gravity * delta * modifier + +func _physics_process(_delta): + if Globals.player != null: + velocity.x = position.direction_to(Globals.player).normalized().x + apply_gravity(_delta) + velocity = move_and_slide(velocity * speed) + + if is_on_wall(): + if velocity.x > -1 and velocity.x < 1: + velocity.x = 0 + var was_on_floor = is_on_floor() + velocity = move_and_slide(velocity, Vector2.UP) + if !was_on_floor and is_on_floor(): + emit_signal("grounded_updated", is_on_floor()) + var was_grounded = is_grounded + is_grounded = is_on_floor() + + if Vector2.ZERO == velocity: + velocity.y = -10 + diff --git a/ai/Skeleton Enemy.tscn b/ai/Skeleton Enemy.tscn new file mode 100644 index 0000000..7ab1596 --- /dev/null +++ b/ai/Skeleton Enemy.tscn @@ -0,0 +1,28 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://Skeleton Enemy.gd" type="Script" id=1] +[ext_resource path="res://art/unknown.png" type="Texture" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 5, 7 ) + +[node name="Skeleton Enemy" type="KinematicBody2D"] +collision_layer = 4 +collision_mask = 3 +script = ExtResource( 1 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 2 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) + +[node name="RayCast2D" type="RayCast2D" parent="."] +enabled = true +cast_to = Vector2( -80, 0 ) +collision_mask = 3 + +[node name="RayCast2D2" type="RayCast2D" parent="."] +enabled = true +cast_to = Vector2( 80, 0 ) +collision_mask = 3 diff --git a/art/unknown.png b/art/unknown.png new file mode 100644 index 0000000000000000000000000000000000000000..2a90cd325ae26fb7ed61f51def79681db60dc5b4 GIT binary patch literal 220 zcmeAS@N?(olHy`uVBq!ia0vp^AT}Qd8;}%R+`Ae`E%tPA4ABrx4hahSb>4v`fpO(c zi|unAPak4kUKE-e%%(PHQ-+WRm!p-VgyexA8e9`a7islgN7XDXeoUm;F{rgRZ9lbmc<^_g@xtTULHZn%? ztPxOS_{`wJ-oraNnL(0&)3Z>>>>>> master [rendering] -quality/driver/fallback_to_gles2=true environment/default_environment="res://default_env.tres" diff --git a/script/PlayerStateMachine.gd b/script/PlayerStateMachine.gd index 10a86c1..b6dddc0 100644 --- a/script/PlayerStateMachine.gd +++ b/script/PlayerStateMachine.gd @@ -67,4 +67,4 @@ func enter_state(new_state, old_state): func exit_state(old_state, new_state): - pass \ No newline at end of file + pass diff --git a/script/Skeleton Enemy.gd b/script/Skeleton Enemy.gd new file mode 100644 index 0000000..3f25b2b --- /dev/null +++ b/script/Skeleton Enemy.gd @@ -0,0 +1,20 @@ +extends KinematicBody2D + +var speed = 75 +var gravity = 500 +const UP = Vector2(0, -1) + +var velocity = Vector2() + +func apply_gravity(delta, modifier = 1): + velocity.y += gravity * delta * modifier + +func _physics_process(_delta): + if Globals.player != null: + velocity.x = position.direction_to(Globals.player).normalized().x + apply_gravity(_delta) + velocity = move_and_slide(velocity * speed) + + if is_on_wall(): + velocity.y = -50 + velocity = move_and_slide(velocity, UP) diff --git a/script/player.gd b/script/player.gd index b3b71b9..3111655 100644 --- a/script/player.gd +++ b/script/player.gd @@ -32,6 +32,9 @@ onready var Stats = $Stats onready var health = Stats.health setget set_health, get_health onready var energy = Stats.energy setget set_energy, get_energy +func get_type(): + return "player" + func set_health(value): Stats.set_health(value) @@ -56,7 +59,6 @@ func _physics_process(delta): Globals.player = position emit_signal("grounded_updated", is_on_floor()) - func handle_move_input(): input_direction = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left")) velocity.x = lerp(velocity.x, speed * input_direction, get_movement_weight())