urinal goes zoom
This commit is contained in:
		| @@ -4,7 +4,7 @@ extends CharacterBody2D | ||||
| @export var ACCELERATION = 1000.0; | ||||
| @export var FRICTION = 1500.0; | ||||
| @export var HP = 100; | ||||
| @export var DAMAGE = 34; | ||||
| @export var DAMAGE = 10; | ||||
| @export var COOLDOWN = 2; | ||||
|  | ||||
| @onready var raycast = $RayCast2D; | ||||
|   | ||||
| @@ -31,6 +31,7 @@ shape = SubResource("RectangleShape2D_47nt3") | ||||
| target_position = Vector2(35, 0) | ||||
|  | ||||
| [node name="Line2D" type="Line2D" parent="RayCast2D"] | ||||
| visible = false | ||||
| points = PackedVector2Array(0, 0, 35, 0) | ||||
| width = 5.0 | ||||
| default_color = Color(1, 0, 0, 0.392157) | ||||
|   | ||||
							
								
								
									
										59
									
								
								Enemies/urinal_mimic.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								Enemies/urinal_mimic.gd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,59 @@ | ||||
| extends CharacterBody2D | ||||
|  | ||||
| @export var MAX_SPEED = 500.0; | ||||
| @export var ACCELERATION = 1000.0; | ||||
| @export var FRICTION = 1500.0; | ||||
| @export var HP = 1; | ||||
| @export var DAMAGE = 25; | ||||
| @export var COOLDOWN = 10; | ||||
|  | ||||
| @onready var raycast = $RayCast2D; | ||||
| @onready var cooldown_timer = $CooldownTimer; | ||||
| @onready var sprite = $AnimatedSprite2D; | ||||
|  | ||||
| var player = null; | ||||
| var is_on_cooldown = false; | ||||
| var attacking = false; | ||||
|  | ||||
| func _ready(): | ||||
| 	add_to_group("enemies"); | ||||
|  | ||||
| func _physics_process(delta): | ||||
| 	if player == null || !attacking: | ||||
| 		return | ||||
| 	 | ||||
| 	var vec_to_player = player.global_position - global_position; | ||||
| 	vec_to_player = vec_to_player.normalized(); | ||||
| 	raycast.rotation = atan2(vec_to_player.y,vec_to_player.x); | ||||
| 	velocity = velocity.move_toward(vec_to_player * MAX_SPEED,ACCELERATION*delta); | ||||
| 	move_and_slide(); | ||||
| 	 | ||||
| 	if raycast.is_colliding(): | ||||
| 		var coll = raycast.get_collider(); | ||||
| 		if coll.name == "Player": | ||||
| 			attack(coll); | ||||
|  | ||||
| func attack(collider): | ||||
| 	collider.take_damage(DAMAGE); | ||||
| 	kill() | ||||
|  | ||||
| func take_damage(damage): | ||||
| 	HP = HP - damage; | ||||
| 	if HP <= 0: | ||||
| 		kill(); | ||||
|  | ||||
| func kill(): | ||||
| 	queue_free(); | ||||
|  | ||||
| func set_player(p): | ||||
| 	player = p; | ||||
|  | ||||
| func _on_cooldown_timer_timeout(): | ||||
| 	is_on_cooldown = false; | ||||
|  | ||||
| func _on_area_2d_body_entered(body): | ||||
| 	if body.name == "Player": | ||||
| 		sprite.play("default"); | ||||
|  | ||||
| func _on_animated_sprite_2d_animation_finished(): | ||||
| 	attacking = true; | ||||
							
								
								
									
										103
									
								
								Enemies/urinal_mimic.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								Enemies/urinal_mimic.tscn
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,103 @@ | ||||
| [gd_scene load_steps=14 format=3 uid="uid://p7aa6t787b3d"] | ||||
|  | ||||
| [ext_resource type="Script" path="res://Enemies/urinal_mimic.gd" id="1_2ga4k"] | ||||
| [ext_resource type="Texture2D" uid="uid://clw15m8cxj22p" path="res://Sprites/Urinol.png" id="2_3n7wy"] | ||||
| [ext_resource type="Texture2D" uid="uid://t2d8ft40y5c0" path="res://Sprites/Urinol_MIMIC.png" id="3_fjxqr"] | ||||
|  | ||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_rqcqj"] | ||||
| atlas = ExtResource("3_fjxqr") | ||||
| region = Rect2(0, 0, 64, 64) | ||||
|  | ||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_hcf1j"] | ||||
| atlas = ExtResource("3_fjxqr") | ||||
| region = Rect2(64, 0, 64, 64) | ||||
|  | ||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_smam5"] | ||||
| atlas = ExtResource("3_fjxqr") | ||||
| region = Rect2(128, 0, 64, 64) | ||||
|  | ||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_mvcd5"] | ||||
| atlas = ExtResource("3_fjxqr") | ||||
| region = Rect2(192, 0, 64, 64) | ||||
|  | ||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_uyisr"] | ||||
| atlas = ExtResource("3_fjxqr") | ||||
| region = Rect2(256, 0, 64, 64) | ||||
|  | ||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_r27p5"] | ||||
| atlas = ExtResource("3_fjxqr") | ||||
| region = Rect2(320, 0, 64, 64) | ||||
|  | ||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_qbor8"] | ||||
| atlas = ExtResource("3_fjxqr") | ||||
| region = Rect2(384, 0, 64, 64) | ||||
|  | ||||
| [sub_resource type="SpriteFrames" id="SpriteFrames_e70cb"] | ||||
| animations = [{ | ||||
| "frames": [{ | ||||
| "duration": 1.0, | ||||
| "texture": ExtResource("2_3n7wy") | ||||
| }, { | ||||
| "duration": 1.0, | ||||
| "texture": SubResource("AtlasTexture_rqcqj") | ||||
| }, { | ||||
| "duration": 1.0, | ||||
| "texture": SubResource("AtlasTexture_hcf1j") | ||||
| }, { | ||||
| "duration": 1.0, | ||||
| "texture": SubResource("AtlasTexture_smam5") | ||||
| }, { | ||||
| "duration": 1.0, | ||||
| "texture": SubResource("AtlasTexture_mvcd5") | ||||
| }, { | ||||
| "duration": 1.0, | ||||
| "texture": SubResource("AtlasTexture_uyisr") | ||||
| }, { | ||||
| "duration": 1.0, | ||||
| "texture": SubResource("AtlasTexture_r27p5") | ||||
| }, { | ||||
| "duration": 1.0, | ||||
| "texture": SubResource("AtlasTexture_qbor8") | ||||
| }], | ||||
| "loop": true, | ||||
| "name": &"default", | ||||
| "speed": 5.0 | ||||
| }] | ||||
|  | ||||
| [sub_resource type="RectangleShape2D" id="RectangleShape2D_jn4wv"] | ||||
| size = Vector2(23, 21) | ||||
|  | ||||
| [sub_resource type="CircleShape2D" id="CircleShape2D_0y76e"] | ||||
| radius = 120.037 | ||||
|  | ||||
| [node name="urinal_mimic" type="CharacterBody2D"] | ||||
| script = ExtResource("1_2ga4k") | ||||
|  | ||||
| [node name="RayCast2D" type="RayCast2D" parent="."] | ||||
| target_position = Vector2(30, 0) | ||||
|  | ||||
| [node name="Line2D" type="Line2D" parent="RayCast2D"] | ||||
| visible = false | ||||
| points = PackedVector2Array(0, 0, 30, 0) | ||||
| width = 4.0 | ||||
| default_color = Color(0.752941, 0, 0, 1) | ||||
|  | ||||
| [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] | ||||
| position = Vector2(0, 21) | ||||
| frames = SubResource("SpriteFrames_e70cb") | ||||
|  | ||||
| [node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||||
| position = Vector2(0.5, -0.5) | ||||
| shape = SubResource("RectangleShape2D_jn4wv") | ||||
|  | ||||
| [node name="Area2D" type="Area2D" parent="."] | ||||
| collision_layer = 2 | ||||
| collision_mask = 2 | ||||
|  | ||||
| [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] | ||||
| shape = SubResource("CircleShape2D_0y76e") | ||||
|  | ||||
| [node name="CooldownTimer" type="Timer" parent="."] | ||||
|  | ||||
| [connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"] | ||||
| [connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"] | ||||
		Reference in New Issue
	
	Block a user