diff --git a/maps/test_room.tscn b/maps/test_room.tscn index 624e32c..8389874 100644 --- a/maps/test_room.tscn +++ b/maps/test_room.tscn @@ -14,13 +14,13 @@ [ext_resource path="res://objects/environment/turniwood/turning_platform.tscn" type="PackedScene" id=12] [ext_resource path="res://objects/collectibles/arrow.tscn" type="PackedScene" id=13] [ext_resource path="res://objects/environment/hatch/hatch.tscn" type="PackedScene" id=14] +[ext_resource path="res://objects/enemy/cop.tscn" type="PackedScene" id=15] [ext_resource path="res://objects/respawn_point.tscn" type="PackedScene" id=16] [ext_resource path="res://shaders/1px_border.gdshader" type="Shader" id=17] [ext_resource path="res://objects/enemy/tin.tscn" type="PackedScene" id=20] [ext_resource path="res://graphics/enemy/sawblade.png" type="Texture" id=21] [ext_resource path="res://objects/enemy/rolling_fiend.tscn" type="PackedScene" id=22] [ext_resource path="res://objects/enemy/steam.tscn" type="PackedScene" id=23] -[ext_resource path="res://objects/enemy/roboturret.tscn" type="PackedScene" id=24] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 16, 20 ) @@ -67,10 +67,10 @@ tile_set = ExtResource( 3 ) cell_size = Vector2( 8, 8 ) collision_layer = 9 format = 1 -tile_data = PoolIntArray( 196630, 1, 0, 262166, 1, 0, 327702, 1, 0, 393238, 1, 0, 458774, 1, 0, 524310, 1, 0, 589846, 1, 0, 655382, 1, 0, 655388, 0, 196609, 851987, 0, 196609, 983062, 0, 65536, 983063, 0, 65537, 983064, 0, 65537, 983065, 0, 65537, 983066, 0, 65537, 983067, 0, 65537, 983068, 0, 65537, 983069, 0, 65537, 1048579, 0, 65537, 1048580, 0, 65537, 1048581, 0, 65537, 1048582, 0, 65537, 1048583, 0, 65537, 1114125, 0, 0, 1114126, 0, 0, 1310734, 0, 0, 1310735, 0, 0, 1310736, 0, 0, 1310738, 0, 0, 1310739, 0, 0, 1310740, 0, 0, 1310741, 0, 0, 1310742, 0, 0, 1310743, 0, 0, 1310744, 0, 0, 1441792, 0, 0, 1441793, 0, 0, 1441794, 0, 0, 1441795, 0, 0, 1441796, 0, 0, 1441797, 0, 0, 1441798, 0, 0, 1441799, 0, 0, 1441800, 0, 0, 1441801, 0, 0, 1441802, 0, 0, 1441803, 0, 0, 1441804, 0, 0, 1441805, 0, 0, 1441806, 0, 0, 1441807, 0, 0, 1441808, 0, 0, 1441809, 0, 0, 1441810, 0, 0, 1441811, 0, 0, 1441812, 0, 0, 1441813, 0, 0, 1441814, 0, 0, 1441815, 0, 0, 1441816, 0, 0, 1441817, 0, 0, 1441818, 0, 0, 1441819, 0, 0, 1441820, 0, 0, 1441821, 0, 0, 1441822, 0, 0, 1441823, 0, 0, 1507328, 0, 1, 1507329, 0, 1, 1507330, 0, 1, 1507331, 0, 1, 1507332, 0, 1, 1507333, 0, 1, 1507334, 0, 1, 1507335, 0, 1, 1507336, 0, 1, 1507337, 0, 1, 1507338, 0, 1, 1507339, 0, 1, 1507340, 0, 1, 1507341, 0, 1, 1507342, 0, 1, 1507343, 0, 1, 1507344, 0, 1, 1507345, 0, 1, 1507346, 0, 1, 1507347, 0, 1, 1507348, 0, 1, 1507349, 0, 1, 1507350, 0, 1, 1507351, 0, 1, 1507352, 0, 1, 1507353, 0, 1, 1507354, 0, 1, 1507355, 0, 1, 1507356, 0, 1, 1507357, 0, 1, 1507358, 0, 1, 1507359, 0, 1 ) +tile_data = PoolIntArray( 196630, 1, 0, 262166, 1, 0, 327702, 1, 0, 393238, 1, 0, 458774, 1, 0, 524310, 1, 0, 589846, 1, 0, 655382, 1, 0, 655388, 0, 196609, 983065, 0, 65537, 983066, 0, 65537, 983067, 0, 65537, 983068, 0, 65537, 983069, 0, 65537, 1048579, 0, 65537, 1048580, 0, 65537, 1048581, 0, 65537, 1048582, 0, 65537, 1048583, 0, 65537, 1048594, 0, 65537, 1048595, 0, 65537, 1048596, 0, 65537, 1048597, 0, 65537, 1114125, 0, 0, 1114126, 0, 0, 1114127, 0, 0, 1179663, 0, 0, 1245199, 0, 0, 1310734, 0, 0, 1310735, 0, 0, 1310736, 0, 0, 1310737, 0, 65537, 1310738, 0, 0, 1310739, 0, 0, 1310740, 0, 0, 1310741, 0, 0, 1310742, 0, 0, 1310743, 0, 0, 1310744, 0, 0, 1310745, 0, 65537, 1310746, 0, 65537, 1310747, 0, 65537, 1310748, 0, 65537, 1310749, 0, 65537, 1310750, 0, 65537, 1310751, 0, 65537, 1310752, 0, 65537, 1441792, 0, 0, 1441793, 0, 0, 1441794, 0, 0, 1441795, 0, 0, 1441796, 0, 0, 1441797, 0, 0, 1441798, 0, 0, 1441799, 0, 0, 1441800, 0, 0, 1441801, 0, 0, 1441802, 0, 0, 1441803, 0, 0, 1441804, 0, 0, 1441805, 0, 0, 1441806, 0, 0, 1441807, 0, 0, 1441808, 0, 0, 1441809, 0, 0, 1441810, 0, 0, 1441811, 0, 0, 1441812, 0, 0, 1441813, 0, 0, 1441814, 0, 0, 1441815, 0, 0, 1441816, 0, 0, 1441817, 0, 0, 1441818, 0, 0, 1441819, 0, 0, 1441820, 0, 0, 1441821, 0, 0, 1441822, 0, 0, 1441823, 0, 0, 1507328, 0, 1, 1507329, 0, 1, 1507330, 0, 1, 1507331, 0, 1, 1507332, 0, 1, 1507333, 0, 1, 1507334, 0, 1, 1507335, 0, 1, 1507336, 0, 1, 1507337, 0, 1, 1507338, 0, 1, 1507339, 0, 1, 1507340, 0, 1, 1507341, 0, 1, 1507342, 0, 1, 1507343, 0, 1, 1507344, 0, 1, 1507345, 0, 1, 1507346, 0, 1, 1507347, 0, 1, 1507348, 0, 1, 1507349, 0, 1, 1507350, 0, 1, 1507351, 0, 1, 1507352, 0, 1, 1507353, 0, 1, 1507354, 0, 1, 1507355, 0, 1, 1507356, 0, 1, 1507357, 0, 1, 1507358, 0, 1, 1507359, 0, 1 ) [node name="Rock" parent="." instance=ExtResource( 9 )] -position = Vector2( 120, 152 ) +position = Vector2( 152, 120 ) [node name="Slime" parent="." instance=ExtResource( 10 )] position = Vector2( 264, 168 ) @@ -156,6 +156,7 @@ material = SubResource( 4 ) position = Vector2( 120, 168 ) z_index = -3 frames = SubResource( 5 ) +frame = 1 playing = true [node name="SawTest4" type="AnimatedSprite" parent="."] @@ -163,7 +164,6 @@ material = SubResource( 4 ) position = Vector2( 160, 168 ) z_index = -3 frames = SubResource( 5 ) -frame = 1 playing = true [node name="SawTest5" type="AnimatedSprite" parent="."] @@ -171,7 +171,6 @@ material = SubResource( 4 ) position = Vector2( 56, 176 ) z_index = -3 frames = SubResource( 5 ) -frame = 1 playing = true [node name="RollingFiend" parent="." instance=ExtResource( 22 )] @@ -185,19 +184,20 @@ material = SubResource( 4 ) position = Vector2( 4, 4 ) z_index = -3 frames = SubResource( 5 ) +frame = 1 playing = true [node name="Steam" parent="." instance=ExtResource( 23 )] position = Vector2( 27, 128 ) -[node name="Roboturret" parent="." instance=ExtResource( 24 )] -position = Vector2( 184, 112 ) -scale = Vector2( -1, 1 ) -shoot_time = 4.0 - [node name="StaticBody2D" type="StaticBody2D" parent="."] [node name="Hatch" parent="." instance=ExtResource( 14 )] -position = Vector2( 216, 112 ) +position = Vector2( 184, 152 ) + +[node name="Cop" parent="." instance=ExtResource( 15 )] +position = Vector2( 224, 152 ) +left_boundary = 8.0 +right_boundary = 2.0 [editable path="RollingFiend"] diff --git a/objects/enemy/cop.gd b/objects/enemy/cop.gd new file mode 100644 index 0000000..155a347 --- /dev/null +++ b/objects/enemy/cop.gd @@ -0,0 +1,86 @@ +extends "res://objects/enemy/enemy.gd" + +export var walk_speed = 25.0 +export var left_boundary = 0.0 +export var right_boundary = 0.0 +export var direction = 1.0 +export var idle_turns = 4 +export var turn_time = 0.5 +export var shoot_time = 1.0 + +onready var sprite = $AnimatedSprite +onready var shoot_position = $"%ShootPosition" +onready var shoot_cast = $"%ShootCast" +onready var graphics_cast = $"%GraphicsCast" +onready var shoot_line = $"%ShootLine" +onready var sparks = $SparkParticles + +var shooting = false +var turns = 0 + +func _ready(): + # convert boundaries into actual coordinate positions + left_boundary = position.x - left_boundary * 8.0 + right_boundary = position.x + right_boundary * 8.0 + # make facing match direction + sprite.scale.x = direction + # make animation speed sync to walk speed + sprite.speed_scale = inverse_lerp(0.0, 25.0, walk_speed) + +func _physics_process(delta): + if !shooting: + # check for player in raycast + var collider = shoot_cast.get_collider() + if collider != null && collider.is_in_group("player"): + # kill player and enter shooting state temporarily + collider.get_parent().die() + shooting = true + get_tree().create_timer(0.05, false).connect("timeout", self, "_stop_shoot") + sprite.play("shoot") + # check other raycast to find collision passing through player + graphics_cast.force_raycast_update() + var hit_position = graphics_cast.to_global(Vector2(256.0, 0.0)) + if graphics_cast.is_colliding(): + hit_position = graphics_cast.get_collision_point() + # set line point to point of collision + var hit_x = shoot_line.to_local(hit_position).x + shoot_line.points[1].x = hit_x +# shoot_line.visible = true +# get_tree().create_timer(0.05, false).connect("timeout", shoot_line, "set_visible", [false], CONNECT_DEFERRED) + # move and play sparks + sparks.global_position = hit_position + sparks.emitting = true + return + + # if there aren't turns, walk around + if turns == 0: + sprite.play("walk") + position.x += direction * walk_speed * delta + if position.x <= left_boundary: + position.x = left_boundary + direction = 1.0 + _do_turn() + elif position.x >= right_boundary: + position.x = right_boundary + direction = -1.0 + _do_turn() + +func _do_turn(): + if shooting: + get_tree().create_timer(turn_time, false).connect("timeout", self, "_do_turn") + return + sprite.play("idle") + sprite.scale.x *= -1.0 + if turns < idle_turns * 2: + turns += 1 + get_tree().create_timer(turn_time, false).connect("timeout", self, "_do_turn") + else: + turns = 0 + +func _stop_shoot(): + shooting = false + shoot_line.visible = false + if turns == 0: + sprite.play("walk") + else: + sprite.play("idle") diff --git a/objects/enemy/cop.tscn b/objects/enemy/cop.tscn new file mode 100644 index 0000000..c715083 --- /dev/null +++ b/objects/enemy/cop.tscn @@ -0,0 +1,127 @@ +[gd_scene load_steps=17 format=2] + +[ext_resource path="res://objects/enemy/cop.gd" type="Script" id=1] +[ext_resource path="res://graphics/enemy/cop/cop_idle.png" type="Texture" id=2] +[ext_resource path="res://graphics/enemy/cop/cop_walk.png" type="Texture" id=3] +[ext_resource path="res://graphics/enemy/cop/cop_shoot.png" type="Texture" id=4] +[ext_resource path="res://shaders/1px_border.gdshader" type="Shader" id=5] +[ext_resource path="res://graphics/particles/dust.png" type="Texture" id=6] + +[sub_resource type="ShaderMaterial" id=7] +shader = ExtResource( 5 ) +shader_param/border_color = Color( 0, 0, 0, 1 ) +shader_param/border_corners = true + +[sub_resource type="AtlasTexture" id=1] +atlas = ExtResource( 2 ) +region = Rect2( 0, 0, 20, 21 ) + +[sub_resource type="AtlasTexture" id=2] +atlas = ExtResource( 3 ) +region = Rect2( 0, 0, 20, 21 ) + +[sub_resource type="AtlasTexture" id=3] +atlas = ExtResource( 3 ) +region = Rect2( 20, 0, 20, 21 ) + +[sub_resource type="AtlasTexture" id=4] +atlas = ExtResource( 3 ) +region = Rect2( 40, 0, 20, 21 ) + +[sub_resource type="AtlasTexture" id=5] +atlas = ExtResource( 3 ) +region = Rect2( 60, 0, 20, 21 ) + +[sub_resource type="SpriteFrames" id=6] +animations = [ { +"frames": [ SubResource( 1 ) ], +"loop": false, +"name": "idle", +"speed": 5.0 +}, { +"frames": [ ExtResource( 4 ) ], +"loop": false, +"name": "shoot", +"speed": 1.0 +}, { +"frames": [ SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ) ], +"loop": true, +"name": "walk", +"speed": 5.0 +} ] + +[sub_resource type="RectangleShape2D" id=8] +extents = Vector2( 3, 8 ) + +[sub_resource type="Curve" id=9] +_data = [ Vector2( 0, 1 ), 0.0, -1.45746, 0, 0, Vector2( 1, 0 ), 0.00323196, 0.0, 0, 0 ] + +[sub_resource type="Gradient" id=10] +offsets = PoolRealArray( 0, 0.515152 ) +colors = PoolColorArray( 1, 1, 1, 1, 1, 1, 0.290196, 1 ) + +[node name="Cop" type="Node2D"] +script = ExtResource( 1 ) +idle_turns = 2 + +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] +material = SubResource( 7 ) +position = Vector2( 5, -2 ) +frames = SubResource( 6 ) +animation = "shoot" +playing = true + +[node name="ShootPosition" type="Position2D" parent="AnimatedSprite"] +unique_name_in_owner = true +position = Vector2( 7, 0.5 ) +__meta__ = { +"_gizmo_extents_": 4.0 +} + +[node name="ShootCast" type="RayCast2D" parent="AnimatedSprite/ShootPosition"] +unique_name_in_owner = true +visible = false +enabled = true +cast_to = Vector2( 256, 0 ) +collision_mask = 8 +collide_with_areas = true + +[node name="GraphicsCast" type="RayCast2D" parent="AnimatedSprite/ShootPosition"] +unique_name_in_owner = true +visible = false +cast_to = Vector2( 256, 0 ) +collision_mask = 8 + +[node name="ShootLine" type="Line2D" parent="AnimatedSprite/ShootPosition"] +unique_name_in_owner = true +visible = false +points = PoolVector2Array( 0, 0, 8, 0 ) +width = 1.0 +default_color = Color( 1, 1, 0.290196, 1 ) + +[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"] +position = Vector2( 4, 0 ) +shape = SubResource( 8 ) + +[node name="SparkParticles" type="CPUParticles2D" parent="."] +position = Vector2( 4, 0 ) +emitting = false +amount = 16 +lifetime = 0.5 +one_shot = true +explosiveness = 1.0 +texture = ExtResource( 6 ) +spread = 180.0 +gravity = Vector2( 0, 0 ) +initial_velocity = 30.0 +initial_velocity_random = 0.5 +damping = 50.0 +angle = 720.0 +angle_random = 1.0 +scale_amount = 0.5 +scale_amount_curve = SubResource( 9 ) +color_ramp = SubResource( 10 ) + +[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]