Skip to content

Commit

Permalink
sword weapon included and PlayerSight limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ricargoes committed Feb 18, 2024
1 parent 2e9311a commit 163f721
Show file tree
Hide file tree
Showing 19 changed files with 271 additions and 55 deletions.
2 changes: 0 additions & 2 deletions scenes/bullet.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func _enter_tree():
velocity = Vector2.from_angle(orientation)*bullet_speed
rotation = orientation
time_left = bullet_lifetime

OnScreenTerminal.log(time_left)

func _process(delta: float) -> void:
var collision = move_and_collide(velocity*delta)
Expand Down
13 changes: 13 additions & 0 deletions scenes/enemies/basic_enemy.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends Enemy

@export
var speed: int = 200

func _on_reasses_dir_cooldown_timeout() -> void:
randomize()
var dir = (randi() % 2 - 0.5)*2
velocity.x = speed*dir
$Sprite2D.scale.x = 1 if dir < 0 else -1

func _custom_entry_behaviour():
_on_reasses_dir_cooldown_timeout()
12 changes: 11 additions & 1 deletion scenes/enemies/basic_enemy.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=6 format=3 uid="uid://cv5x51jwgqxsq"]
[gd_scene load_steps=7 format=3 uid="uid://cv5x51jwgqxsq"]

[ext_resource type="PackedScene" uid="uid://csfarad5ilhw6" path="res://scenes/enemies/enermy.tscn" id="1_8tfco"]
[ext_resource type="Texture2D" uid="uid://booq2ffceqwgc" path="res://resources/sprites/enemies/baseEnemy1.png" id="2_2smkd"]
[ext_resource type="Script" path="res://scenes/enemies/basic_enemy.gd" id="2_cxugm"]
[ext_resource type="Texture2D" uid="uid://cfyok2k0wo6r7" path="res://resources/sprites/enemies/baseEnemy2.png" id="3_cuomi"]

[sub_resource type="SpriteFrames" id="SpriteFrames_wio7a"]
Expand All @@ -22,6 +23,8 @@ animations = [{
size = Vector2(131, 186)

[node name="BasicEnemy" instance=ExtResource("1_8tfco")]
script = ExtResource("2_cxugm")
speed = 200

[node name="Sprite2D" parent="." index="0"]
sprite_frames = SubResource("SpriteFrames_wio7a")
Expand All @@ -30,3 +33,10 @@ autoplay = "default"
[node name="CollisionShape2D" parent="." index="1"]
position = Vector2(-1.5, 0)
shape = SubResource("RectangleShape2D_tj310")

[node name="ReassesDirCooldown" type="Timer" parent="." index="3"]
wait_time = 0.5
one_shot = true
autostart = true

[connection signal="timeout" from="ReassesDirCooldown" to="." method="_on_reasses_dir_cooldown_timeout"]
11 changes: 9 additions & 2 deletions scenes/enemies/enermy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var xp_value: int = 200
@export
var max_life_points: float = 20.0
@export
var contact_dps: float = 50.0
var contact_dps: float = 5.0

var dead: bool = true

Expand All @@ -22,6 +22,10 @@ func _ready() -> void:
func _enter_tree():
life_points = max_life_points
dead = false
_custom_entry_behaviour()

func _custom_entry_behaviour():
pass

func _process(delta: float) -> void:
if not is_on_floor():
Expand All @@ -33,7 +37,7 @@ func _process(delta: float) -> void:

func fall_check():
if global_position.y > GameConstants.DEATH_GLOBAL_Y_POSITION:
die()
shelf()

func contact_attack(delta: float):
for body in $ContactDamageArea.get_overlapping_bodies():
Expand All @@ -49,5 +53,8 @@ func hurt(damage: float):

func die():
defeated.emit(self)
shelf()

func shelf():
dead = true
PoolManager.shelf_instance(self)
3 changes: 2 additions & 1 deletion scenes/enemies/flying_enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var wander_lower_limit: float = 500
@export
var wander_speed := Vector2(-300, 200)
@export
var attack_speed: float = 300
var attack_speed: float = 600
@export
var attack_range: int = 500

Expand All @@ -16,6 +16,7 @@ func _process(delta: float) -> void:
var distance_to_hero = hero.global_position - global_position
if distance_to_hero.length() < attack_range:
velocity = distance_to_hero.normalized()* attack_speed
$Sprite2D.scale.x = 1 if velocity.x < 0 else -1
else:
wander_speed.y *= -1 if (global_position.y < wander_upper_limit and wander_speed.y < 0) or (global_position.y > wander_lower_limit and wander_speed.y > 0) else 1
velocity = wander_speed
Expand Down
3 changes: 2 additions & 1 deletion scenes/enemies/flying_enemy.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ script = ExtResource("2_vyr0w")
wander_upper_limit = 200.0
wander_lower_limit = 500.0
wander_speed = Vector2(-300, 200)
attack_speed = 300.0
attack_speed = 600.0
attack_range = 500
resource_type = 2

[node name="Sprite2D" parent="." index="0"]
self_modulate = Color(1, 0.541176, 0, 1)
Expand Down
11 changes: 7 additions & 4 deletions scenes/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends Node2D
var run_time: float = 300.0

const ANIMATION_BASE_RUNTIME: float = 300.0
const TERRAIN_CHUNK_LENGTH: int = 6*1920
const TERRAINS_SCENES = [
preload("res://scenes/terrain/terrain_chunk_1.tscn"),
preload("res://scenes/terrain/terrain_chunk_2.tscn"),
Expand All @@ -17,17 +18,19 @@ func _ready() -> void:
func _process(_delta: float) -> void:
if $Hero.position > last_terrain_position:
var terrain = TERRAINS_SCENES[randi() % TERRAINS_SCENES.size()].instantiate()
last_terrain_position += Vector2(6*1920, 0)
last_terrain_position += Vector2(TERRAIN_CHUNK_LENGTH, 0)
terrain.position = last_terrain_position
$Terrain.add_child(terrain)
OnScreenTerminal.log(last_terrain_position)
for terrain_chunk: Node2D in $Terrain.get_children():
if $Hero.position.x - terrain_chunk.position.x > 2*TERRAIN_CHUNK_LENGTH:
terrain_chunk.queue_free()


func spawn_bullet(starting_position: Vector2, orientation: float, is_player: bool):
func spawn_bullet(starting_position: Vector2, orientation: float, is_player: bool, lifetime: float = 1):
var bullet = PoolManager.get_instance(PoolManager.PoolResource.BULLET)
bullet.global_position = starting_position
bullet.orientation = orientation
bullet.is_player = is_player
bullet.bullet_lifetime = lifetime
$Bullets.add_child(bullet)

func win() -> void:
Expand Down
57 changes: 56 additions & 1 deletion scenes/game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,62 @@ _data = {

[node name="Game" type="Node2D"]
script = ExtResource("1_17qkh")
run_time = 30.0

[node name="Lore" type="Label" parent="."]
offset_left = -251.0
offset_top = 121.0
offset_right = 1680.0
offset_bottom = 398.0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 100
text = "Daylight plant vampires
want you death!"
horizontal_alignment = 1

[node name="Tutorial" type="Label" parent="."]
offset_left = 1928.0
offset_top = 65.0
offset_right = 3859.0
offset_bottom = 202.0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 100
text = "Press Space to jump"

[node name="Cheer1" type="Label" parent="."]
offset_left = 2799.0
offset_top = 235.0
offset_right = 4730.0
offset_bottom = 372.0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 50
text = "Escape them!"

[node name="Tutorial2" type="Label" parent="."]
offset_left = 2721.0
offset_top = 343.0
offset_right = 4652.0
offset_bottom = 480.0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 100
text = "Pick your build carefully"

[node name="Cheer2" type="Label" parent="."]
offset_left = 3269.0
offset_top = 507.0
offset_right = 5200.0
offset_bottom = 644.0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 50
text = "Slaughter them!"

[node name="Tutorial3" type="Label" parent="."]
offset_left = 4404.0
offset_top = 127.0
offset_right = 6335.0
offset_bottom = 264.0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 100
text = "And survive till dusk.."

[node name="Terrain" type="Node2D" parent="."]

Expand Down
8 changes: 4 additions & 4 deletions scenes/global/game_library.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const POWERUPS = {
'icon': preload("res://resources/ui/icons/pistol.png"),
'scene': preload("res://scenes/powerups/pistol.tscn")
},
'Sword and shield': {
'Sword': {
'type': PowerUpType.Weapon,
'description': 'Slash nearby enermies while an orbiting shield protects you',
'description': 'Slash nearby enermies with a mighty sword.',
'icon': preload("res://resources/ui/icons/sword.png"),
'scene': preload("res://scenes/powerups/boomerang.tscn")
},
Expand Down Expand Up @@ -52,7 +52,7 @@ const POWERUPS = {
'type': PowerUpType.Passive,
'description': 'Make yourself harder to kill: HP boost.',
'icon': preload("res://resources/ui/icons/armour.png"),
'levels': {1: 20, 2: 20, 3: 30, 4: 30, 5: 50}
'levels': {1: 20, 2: 40, 3: 70, 4: 100, 5: 150}
},
"Invisibility cloak": {
'type': PowerUpType.Passive,
Expand All @@ -64,7 +64,7 @@ const POWERUPS = {
'type': PowerUpType.Passive,
'description': 'Your are getting nervous rather than alert. Well, everything helps. Reduces cooldowns.',
'icon': preload("res://resources/ui/icons/badCoffee.png"),
'levels': {1: 10, 2: 30, 3: 60, 4: 100, 5: 150}
'levels': {1: 110, 2: 130, 3: 160, 4: 200, 5: 250}
},
'Dark Necrogrimoire': {
'type': PowerUpType.Passive,
Expand Down
6 changes: 5 additions & 1 deletion scenes/hero.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var life_points: float = 50.0
var level: int = 0
var xp: int = 0
var xp_threshold: int = 100
var powerups = { "Pistol": 1 }
var powerups = { "Pistol": 1, "Sword": 1 }
var enemies_slain: int = 0

var jump_impulse_time: float = 0.0
Expand Down Expand Up @@ -124,3 +124,7 @@ func steal_life(damage: float):
func on_enermy_defeated(enermy: Enemy) -> void:
get_xp(enermy.xp_value)
enemies_slain += 1
$UI.update_deathcount(enemies_slain)

func get_enemies_on_sight() -> Array:
return $PlayerSight.get_overlapping_bodies()
42 changes: 34 additions & 8 deletions scenes/hero.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=22 format=3 uid="uid://f31q7ameb6hm"]
[gd_scene load_steps=23 format=3 uid="uid://f31q7ameb6hm"]

[ext_resource type="Script" path="res://scenes/hero.gd" id="1_omy4t"]
[ext_resource type="Texture2D" uid="uid://cipplrmttgmy4" path="res://resources/sprites/pj/pjHead.png" id="2_3f0u1"]
Expand All @@ -11,7 +11,7 @@
[ext_resource type="Texture2D" uid="uid://ciownt0dopb4i" path="res://resources/sprites/pj/pjRunningLegs1.png" id="6_ejbq7"]
[ext_resource type="Texture2D" uid="uid://ced1gvm3ejp8b" path="res://resources/sprites/pj/pjRunningLegs2.png" id="7_34yky"]
[ext_resource type="PackedScene" uid="uid://cdxbhwtpcrqwx" path="res://scenes/level_up_screen.tscn" id="7_y4fjo"]
[ext_resource type="Texture2D" uid="uid://e7iq4rrlcxb8" path="res://resources/sprites/pj/pjArmSword.png" id="8_8jdhp"]
[ext_resource type="PackedScene" uid="uid://be7qt3ldbvjxr" path="res://scenes/powerups/sword.tscn" id="9_hr181"]
[ext_resource type="PackedScene" uid="uid://c8qbjfx63idyx" path="res://scenes/powerups/pistol.tscn" id="9_jqixl"]
[ext_resource type="Texture2D" uid="uid://bdexcucrlyfrt" path="res://resources/ui/full_life_bar.png" id="13_axndc"]
[ext_resource type="Texture2D" uid="uid://cuxvaqlgqpm2c" path="res://resources/ui/full_xp_bar.png" id="14_glpkk"]
Expand Down Expand Up @@ -58,14 +58,18 @@ animations = [{
"speed": 5.0
}]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_8yq1y"]
size = Vector2(76, 168)
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_itkei"]
radius = 24.0
height = 172.0

[sub_resource type="RectangleShape2D" id="RectangleShape2D_lk7si"]
size = Vector2(53, 137)

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_er8d3"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_33dn5"]
size = Vector2(1800, 1000)

[node name="Hero" type="CharacterBody2D" groups=["hero"]]
collision_mask = 4
floor_stop_on_slope = false
Expand All @@ -83,13 +87,13 @@ sprite_frames = SubResource("SpriteFrames_rcvp2")
animation = &"run"
autoplay = "run"

[node name="SwordArm" type="Sprite2D" parent="."]
texture = ExtResource("8_8jdhp")

[node name="Pistol" parent="." instance=ExtResource("9_jqixl")]

[node name="Sword" parent="." instance=ExtResource("9_hr181")]

[node name="RunningShape" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_8yq1y")
position = Vector2(0, 7)
shape = SubResource("CapsuleShape2D_itkei")

[node name="JumpingShape" type="CollisionShape2D" parent="."]
visible = false
Expand Down Expand Up @@ -159,3 +163,25 @@ offset_right = 40.0
grow_vertical = 0
auto_height = true
script = ExtResource("15_1qfb5")

[node name="DeathCount" type="Label" parent="UI"]
unique_name_in_owner = true
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -40.0
offset_top = -23.0
grow_horizontal = 0
grow_vertical = 0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 20
text = "0 enemies slain"

[node name="PlayerSight" type="Area2D" parent="."]
collision_layer = 0
collision_mask = 2

[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerSight"]
shape = SubResource("RectangleShape2D_33dn5")
21 changes: 9 additions & 12 deletions scenes/pistol.gd
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
extends Node2D

const PISTOL_RANGE = 1000

@export
var shooting_cooldown: float = 0.3
@export
var arm_rotation_speed: float = 4*PI
var arm_rotation_speed: float = PI

var target: Enemy = null

func _ready() -> void:
$ShootingCooldown.wait_time = shooting_cooldown

func _process(delta: float) -> void:
if target == null or target.dead:
if target == null or target.dead or target.global_position.distance_to(target.global_position) > PISTOL_RANGE:
select_target()

var target_orientation = global_position.angle_to_point(target.global_position) if target != null else 0.0
aim_to(target_orientation, delta)
rotation = rotate_toward(rotation, target_orientation, arm_rotation_speed*delta)


func shoot():
Expand All @@ -27,18 +29,13 @@ func set_level(level: int):
match level:
1:
shooting_cooldown = 0.3
arm_rotation_speed = 4*PI
arm_rotation_speed = PI

func cooldown_boost(boost: float):
$ShootingCooldown.wait_time = shooting_cooldown/boost

func select_target():
target = null
var pistol_range = 1000
for enemy: Node2D in get_tree().get_nodes_in_group("enemies"):
if (enemy.global_position - global_position).length() < pistol_range:
target = enemy

func aim_to(target_orientation: float, delta: float):
var rotation_strength = fmod(target_orientation-rotation, PI)/PI
rotation += rotation_strength*arm_rotation_speed*delta
var hero: Node2D = get_tree().get_first_node_in_group("hero")
var enemies: Array = hero.get_enemies_on_sight()
target = null if enemies.is_empty() else enemies[randi() % enemies.size()]
Loading

0 comments on commit 163f721

Please sign in to comment.