Compare commits
2 Commits
52602364f3
...
58553d00b6
Author | SHA1 | Date |
---|---|---|
Luna Brovchuk | 58553d00b6 | |
Luna Brovchuk | 4417e48192 |
|
@ -0,0 +1,19 @@
|
|||
[gd_resource type="ShaderMaterial" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="Shader" id=3]
|
||||
code = "shader_type canvas_item;
|
||||
|
||||
uniform bool active = false;
|
||||
uniform vec4 color: hint_color = vec4(1, 1, 1, 1);
|
||||
|
||||
void fragment(){
|
||||
COLOR = texture(TEXTURE, UV);
|
||||
if (active) {
|
||||
COLOR = vec4(COLOR.rgb + color.rgb * color.a, COLOR.a)
|
||||
}
|
||||
}"
|
||||
|
||||
[resource]
|
||||
shader = SubResource( 3 )
|
||||
shader_param/active = false
|
||||
shader_param/color = Color( 1, 1, 1, 1 )
|
|
@ -0,0 +1,11 @@
|
|||
[gd_resource type="ShaderMaterial" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://res/shaders/outline.tres" type="Shader" id=1]
|
||||
|
||||
[resource]
|
||||
shader = ExtResource( 1 )
|
||||
shader_param/color = Color( 1, 0.870588, 0, 1 )
|
||||
shader_param/width = 1.0
|
||||
shader_param/pattern = 0
|
||||
shader_param/inside = false
|
||||
shader_param/add_margins = true
|
|
@ -9,7 +9,7 @@ extents = Vector2( 4, 3 )
|
|||
[sub_resource type="RectangleShape2D" id=2]
|
||||
extents = Vector2( 6, 4 )
|
||||
|
||||
[node name="Bat" type="KinematicBody2D" groups=["enemy"]]
|
||||
[node name="Bat" type="KinematicBody2D" groups=["bat", "enemy"]]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
script = ExtResource( 2 )
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://src/models/player/sprite.png" type="Texture" id=1]
|
||||
[ext_resource path="res://src/models/player/player.gd" type="Script" id=2]
|
||||
[ext_resource path="res://res/shaders/colorize.tres" type="Material" id=3]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 4, 5.5 )
|
||||
|
@ -9,10 +10,67 @@ extents = Vector2( 4, 5.5 )
|
|||
[sub_resource type="RectangleShape2D" id=2]
|
||||
extents = Vector2( 7, 11 )
|
||||
|
||||
[sub_resource type="Animation" id=4]
|
||||
resource_name = "RESET"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Sprite:material:shader_param/color")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 0,
|
||||
"values": [ Color( 1, 1, 1, 1 ) ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Sprite:material:shader_param/active")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ false ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=3]
|
||||
resource_name = "damage"
|
||||
length = 0.9
|
||||
step = 0.05
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Sprite:material:shader_param/active")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0, 2 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ true, false ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Sprite:material:shader_param/color")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0, 0.15, 0.3, 0.45, 0.6, 0.75, 0.9 ),
|
||||
"transitions": PoolRealArray( 8, 8, 8, 8, 8, 8, 8 ),
|
||||
"update": 0,
|
||||
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
|
||||
}
|
||||
|
||||
[node name="Player" type="KinematicBody2D" groups=["player"]]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
material = ExtResource( 3 )
|
||||
texture = ExtResource( 1 )
|
||||
centered = false
|
||||
|
||||
|
@ -25,3 +83,10 @@ shape = SubResource( 1 )
|
|||
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyCollision"]
|
||||
position = Vector2( 12, 12 )
|
||||
shape = SubResource( 2 )
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
autoplay = "RESET"
|
||||
anims/RESET = SubResource( 4 )
|
||||
anims/damage = SubResource( 3 )
|
||||
|
||||
[connection signal="area_entered" from="EnemyCollision" to="." method="area_entered"]
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
extends KinematicBody2D
|
||||
|
||||
var velocity = Vector2.ZERO
|
||||
var outline_material = load("res://res/shaders/outline_material.tres")
|
||||
var speed_multiplier: float = 1.0
|
||||
var invincibility_timer = .0
|
||||
var velocity = Vector2.ZERO
|
||||
var invincible = false
|
||||
var target: EnemyClass
|
||||
var slowed = false
|
||||
var target
|
||||
var speed = 100
|
||||
|
||||
onready var bullet = preload("res://src/models/bullet/Bullet.tscn")
|
||||
|
@ -13,13 +16,35 @@ func _process(_delta):
|
|||
if Input.is_action_just_pressed("shoot"):
|
||||
_shoot()
|
||||
|
||||
|
||||
func get_input():
|
||||
var input_direction = Input.get_vector("left", "right", "up", "down")
|
||||
velocity = input_direction * speed
|
||||
|
||||
func _physics_process(_delta):
|
||||
func choose_target():
|
||||
var least_dist = 4000
|
||||
var enemy_dist
|
||||
var enemies = get_tree().get_nodes_in_group("enemy")
|
||||
for enemy in enemies:
|
||||
enemy.material = null
|
||||
enemy_dist = global_position.distance_to(enemy.global_position)
|
||||
if enemy_dist < least_dist:
|
||||
least_dist = enemy_dist
|
||||
target = enemy
|
||||
|
||||
func area_entered(area):
|
||||
var parent = area.get_parent()
|
||||
if parent.is_in_group("enemy") and not parent.is_in_group("bat") and not invincible:
|
||||
$AnimationPlayer.play("damage")
|
||||
Global.add_health(-1)
|
||||
invincible = true
|
||||
invincibility_timer = .0
|
||||
|
||||
func _physics_process(delta):
|
||||
get_input()
|
||||
|
||||
invincibility_timer += delta
|
||||
|
||||
var areas = $EnemyCollision.get_overlapping_areas()
|
||||
slowed = false
|
||||
for area in areas:
|
||||
|
@ -27,6 +52,9 @@ func _physics_process(_delta):
|
|||
slowed = true
|
||||
break
|
||||
|
||||
if invincible and invincibility_timer >= 0.9:
|
||||
invincible = false
|
||||
|
||||
if slowed:
|
||||
speed_multiplier = 0.5
|
||||
else:
|
||||
|
@ -34,19 +62,7 @@ func _physics_process(_delta):
|
|||
|
||||
velocity = move_and_slide(velocity * speed_multiplier)
|
||||
choose_target()
|
||||
|
||||
const SHADER = preload("res://res/shaders/outline.tres")
|
||||
|
||||
func choose_target():
|
||||
var least_dist = 4000
|
||||
var enemy_dist
|
||||
var enemies = get_tree().get_nodes_in_group("enemy")
|
||||
for enemy in enemies:
|
||||
enemy_dist = global_position.distance_to(enemy.global_position)
|
||||
if enemy_dist < least_dist:
|
||||
least_dist = enemy_dist
|
||||
target = enemy
|
||||
#enemy.set_shader_param("width", 0)
|
||||
target.material = outline_material
|
||||
|
||||
func _shoot():
|
||||
bullet_instance = bullet.instance()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=24 format=2]
|
||||
[gd_scene load_steps=20 format=2]
|
||||
|
||||
[ext_resource path="res://src/scenes/menu/background/background.png" type="Texture" id=1]
|
||||
[ext_resource path="res://src/scenes/game/sprites/background_houses.png" type="Texture" id=2]
|
||||
|
@ -15,7 +15,6 @@
|
|||
[ext_resource path="res://src/models/enemies/trash_can/TrashCan.tscn" type="PackedScene" id=13]
|
||||
[ext_resource path="res://src/models/enemies/bat/Bat.tscn" type="PackedScene" id=14]
|
||||
[ext_resource path="res://src/models/enemies/ghost/Ghost.tscn" type="PackedScene" id=15]
|
||||
[ext_resource path="res://res/shaders/outline.tres" type="Shader" id=16]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=2]
|
||||
extents = Vector2( 10, 60 )
|
||||
|
@ -23,30 +22,6 @@ extents = Vector2( 10, 60 )
|
|||
[sub_resource type="RectangleShape2D" id=3]
|
||||
extents = Vector2( 140, 10.125 )
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=5]
|
||||
shader = ExtResource( 16 )
|
||||
shader_param/color = Color( 1, 0.870588, 0, 1 )
|
||||
shader_param/width = 1.0
|
||||
shader_param/pattern = 0
|
||||
shader_param/inside = false
|
||||
shader_param/add_margins = true
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=6]
|
||||
shader = ExtResource( 16 )
|
||||
shader_param/color = Color( 1, 0.870588, 0, 1 )
|
||||
shader_param/width = 1.0
|
||||
shader_param/pattern = 0
|
||||
shader_param/inside = false
|
||||
shader_param/add_margins = true
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=7]
|
||||
shader = ExtResource( 16 )
|
||||
shader_param/color = Color( 1, 0.870588, 0, 1 )
|
||||
shader_param/width = 1.0
|
||||
shader_param/pattern = 0
|
||||
shader_param/inside = true
|
||||
shader_param/add_margins = true
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 8
|
||||
font_data = ExtResource( 4 )
|
||||
|
@ -101,16 +76,13 @@ shape = SubResource( 3 )
|
|||
[node name="TrashCan" parent="View/Enemies" instance=ExtResource( 13 )]
|
||||
|
||||
[node name="Bat" parent="View/Enemies" instance=ExtResource( 14 )]
|
||||
material = SubResource( 5 )
|
||||
z_index = 1
|
||||
|
||||
[node name="Bat2" parent="View/Enemies" instance=ExtResource( 14 )]
|
||||
material = SubResource( 6 )
|
||||
position = Vector2( 142, 54 )
|
||||
z_index = 1
|
||||
|
||||
[node name="Ghost" parent="View/Enemies" instance=ExtResource( 15 )]
|
||||
material = SubResource( 7 )
|
||||
position = Vector2( 509, 100 )
|
||||
|
||||
[node name="Player" parent="View" instance=ExtResource( 5 )]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
extends Node
|
||||
|
||||
func _ready():
|
||||
Global.add_health(1)
|
||||
Global.health = 3
|
||||
Global.add_health(0)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
extends Node
|
||||
|
||||
func game_start():
|
||||
get_tree().change_scene_to(Global.GAME_SCENE)
|
||||
Global.game_start()
|
||||
|
||||
func game_exit():
|
||||
get_tree().quit(0)
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
extends Node
|
||||
|
||||
var GAME_SCENE = preload("res://src/scenes/game/Game.tscn")
|
||||
var MENU_SCENE = preload("res://src/scenes/menu/Menu.tscn")
|
||||
|
||||
var playing = true
|
||||
var health = 2
|
||||
|
||||
func game_start():
|
||||
playing = true
|
||||
get_tree().change_scene_to(GAME_SCENE)
|
||||
|
||||
func return_to_menu():
|
||||
playing = false
|
||||
get_tree().change_scene_to(MENU_SCENE)
|
||||
|
||||
func add_health(amount):
|
||||
health = clamp(health + amount, 0, 3)
|
||||
get_tree().get_root().get_node("Game/UIWrapper/UI/Health/HealthSprite").frame = health
|
||||
if health == 0:
|
||||
pass # TODO endgame
|
||||
return_to_menu() # TODO endgame
|
||||
|
|
Loading…
Reference in New Issue