Implement level 1
Level 1 is now playable; more to be added
This commit is contained in:
65
Enemies/Dark Matter.gd
Normal file
65
Enemies/Dark Matter.gd
Normal file
@@ -0,0 +1,65 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
#onready var label = get_node("Label")
|
||||
onready var timer = get_node("Timer")
|
||||
var speed : = 0.5
|
||||
var position_tracker = 0.0
|
||||
var player = null
|
||||
var obstacle = null
|
||||
var DisplayValue = 10
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
func _physics_process(_delta):
|
||||
if player == null:
|
||||
translate(Vector2(speed, 0))
|
||||
position_tracker += speed
|
||||
if position_tracker >= 50 or position_tracker <=0:#enemy move back and forth
|
||||
speed *= -1
|
||||
if player:
|
||||
translate(Vector2(position.direction_to(player.position) * abs(speed))) #enemy follow player
|
||||
|
||||
if obstacle == null:
|
||||
$Sprite.texture = load("res://Sprites/Enemies/DarkMatter_barrier.png")
|
||||
|
||||
if obstacle:
|
||||
$Sprite.texture = load("res://Sprites/Enemies/DarkMatter.png")
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
|
||||
func _on_Player_detect_body_entered(body):
|
||||
#print("player entered") # Replace with function body.
|
||||
#print(body.name)#"Player"
|
||||
if body.name == 'Player': #sometimes map_boundary is detected
|
||||
#if body.get_parent().name == 'Player':
|
||||
player = body
|
||||
|
||||
func _on_Player_detect_body_exited(_body):
|
||||
#print("player exit")
|
||||
if _body.name == 'Player':
|
||||
player = null
|
||||
|
||||
func _on_Star_detect_body_entered(body_star):
|
||||
#print("obstacle entered")
|
||||
#print(body_star.name)#Obstacle
|
||||
if body_star.name == 'Star':
|
||||
obstacle = body_star
|
||||
timer.set_wait_time(DisplayValue)
|
||||
timer.start()
|
||||
#print("timer start")
|
||||
|
||||
func _on_Star_detect_body_exited(_body):
|
||||
#if _body.name == 'Star':
|
||||
#print("obstacle exited")
|
||||
#if _body.name == 'Obstacle':
|
||||
#obstacle = null
|
||||
null
|
||||
|
||||
func _on_Timer_timeout():
|
||||
#print("time out")
|
||||
obstacle = null # Replace with function body.
|
46
Enemies/Dark Matter.tscn
Normal file
46
Enemies/Dark Matter.tscn
Normal file
@@ -0,0 +1,46 @@
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://Sprites/Enemies/DarkMatter_barrier.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Enemies/Dark Matter.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 5.55527, 4.93821 )
|
||||
|
||||
[sub_resource type="CircleShape2D" id=2]
|
||||
radius = 55.4916
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=3]
|
||||
extents = Vector2( 5.48996, 5.06427 )
|
||||
|
||||
[node name="Dark Matter" type="KinematicBody2D"]
|
||||
collision_layer = 2
|
||||
collision_mask = 6
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Enemy_body" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="Player_detect" type="Area2D" parent="."]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player_detect"]
|
||||
shape = SubResource( 2 )
|
||||
|
||||
[node name="Star_detect" type="Area2D" parent="."]
|
||||
collision_layer = 4
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Star_detect"]
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
|
||||
[connection signal="body_entered" from="Player_detect" to="." method="_on_Player_detect_body_entered"]
|
||||
[connection signal="body_exited" from="Player_detect" to="." method="_on_Player_detect_body_exited"]
|
||||
[connection signal="body_entered" from="Star_detect" to="." method="_on_Star_detect_body_entered"]
|
||||
[connection signal="body_exited" from="Star_detect" to="." method="_on_Star_detect_body_exited"]
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
|
@@ -8,43 +8,43 @@ var velocity: Vector2 = Vector2.ZERO
|
||||
var status = "walk"
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
velocity = Vector2.ZERO
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
if player:
|
||||
velocity = position.direction_to(player.position).normalized() * SPEED
|
||||
var angle = position.angle_to_point(player.position)
|
||||
if abs(angle) > PI/2:
|
||||
$AnimatedSprite1.scale.x = -0.563
|
||||
else:
|
||||
$AnimatedSprite1.scale.x = 0.563
|
||||
if player:
|
||||
velocity = position.direction_to(player.position).normalized() * SPEED
|
||||
var angle = position.angle_to_point(player.position)
|
||||
if abs(angle) > PI/2:
|
||||
$AnimatedSprite1.scale.x = -0.563
|
||||
else:
|
||||
$AnimatedSprite1.scale.x = 0.563
|
||||
|
||||
velocity = move_and_slide(velocity)
|
||||
return
|
||||
velocity = move_and_slide(velocity)
|
||||
return
|
||||
|
||||
|
||||
func _on_player_detector_area_entered(area: Area2D) -> void:
|
||||
if area.get_parent().name == 'Player':
|
||||
player = area.get_parent()
|
||||
$AnimatedSprite1.animation = "Walk"
|
||||
return
|
||||
if area.get_parent().name == 'Player':
|
||||
player = area.get_parent()
|
||||
$AnimatedSprite1.animation = "Walk"
|
||||
return
|
||||
|
||||
|
||||
func _on_player_detector_area_exited(_area: Area2D):
|
||||
player = null
|
||||
$AnimatedSprite1.animation = "Idle"
|
||||
return
|
||||
player = null
|
||||
$AnimatedSprite1.animation = "Idle"
|
||||
return
|
||||
|
||||
|
||||
func _on_Player_Attack_area_entered(area: Area2D) -> void:
|
||||
if area.get_parent().name == 'Player':
|
||||
player = area.get_parent()
|
||||
$AnimatedSprite1.animation = "Attack"
|
||||
status = "attack"
|
||||
return
|
||||
if area.get_parent().name == 'Player':
|
||||
player = area.get_parent()
|
||||
$AnimatedSprite1.animation = "Attack"
|
||||
status = "attack"
|
||||
return
|
||||
|
||||
|
||||
func _on_Player_Attack_area_exited(area: Area2D) -> void:
|
||||
player = null
|
||||
if not status == "attack":
|
||||
$AnimatedSprite1.animation = "Walk"
|
||||
return
|
||||
player = null
|
||||
if not status == "attack":
|
||||
$AnimatedSprite1.animation = "Walk"
|
||||
return
|
||||
|
Reference in New Issue
Block a user