bullet,timer,scene manager, keyboard input
This commit is contained in:
parent
012b7e13d0
commit
72be1b2739
@ -23,6 +23,14 @@ folder_colors={
|
|||||||
"res://scripts/": "green"
|
"res://scripts/": "green"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[input]
|
||||||
|
|
||||||
|
shoot={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
3d/physics_engine="Jolt Physics"
|
3d/physics_engine="Jolt Physics"
|
||||||
|
|||||||
15
scenes/bullet.tscn
Normal file
15
scenes/bullet.tscn
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[gd_scene format=3 uid="uid://ium8i6770pf4"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://bfuhpow7x2xr1" path="res://scripts/bullet.gd" id="1_mkf8s"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_h1aey"]
|
||||||
|
size = Vector2(9, 2.25)
|
||||||
|
|
||||||
|
[node name="Bullet" type="Area2D" unique_id=223347173]
|
||||||
|
script = ExtResource("1_mkf8s")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=219685621]
|
||||||
|
position = Vector2(0, 0.125)
|
||||||
|
shape = SubResource("RectangleShape2D_h1aey")
|
||||||
|
debug_color = Color(0.9529412, 0.078431375, 0.019607844, 0.41960785)
|
||||||
@ -1,62 +1,73 @@
|
|||||||
[gd_scene format=3 uid="uid://cqk2rgy3m1chs"]
|
[gd_scene format=3 uid="uid://cqk2rgy3m1chs"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://rintkrku4ld1" path="res://scripts/gameController.gd" id="1_lnu2h"]
|
[ext_resource type="Script" uid="uid://rintkrku4ld1" path="res://scripts/gameController.gd" id="1_lnu2h"]
|
||||||
|
[ext_resource type="Script" uid="uid://ch2id76i14srx" path="res://scripts/scene_manager.gd" id="2_iywne"]
|
||||||
[ext_resource type="PackedScene" uid="uid://8c7u50hn4l8l" path="res://scenes/create.tscn" id="2_lbhrr"]
|
[ext_resource type="PackedScene" uid="uid://8c7u50hn4l8l" path="res://scenes/create.tscn" id="2_lbhrr"]
|
||||||
[ext_resource type="Script" uid="uid://cugku4bbar0fk" path="res://scripts/player.gd" id="2_yqjtg"]
|
[ext_resource type="PackedScene" uid="uid://s0utas3jmhjk" path="res://scenes/player.tscn" id="3_iywne"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bf50mxdma8wq4" path="res://scenes/trigger.tscn" id="3_lbhrr"]
|
[ext_resource type="PackedScene" uid="uid://bf50mxdma8wq4" path="res://scenes/trigger.tscn" id="3_lbhrr"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://ium8i6770pf4" path="res://scenes/bullet.tscn" id="6_p57ef"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"]
|
||||||
size = Vector2(71.45, 2.6500006)
|
size = Vector2(71.45, 2.6500006)
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"]
|
|
||||||
|
|
||||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_lbhrr"]
|
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_lbhrr"]
|
||||||
|
|
||||||
[node name="Game" type="Node2D" unique_id=194725900]
|
[node name="Game" type="Node2D" unique_id=194725900]
|
||||||
script = ExtResource("1_lnu2h")
|
script = ExtResource("1_lnu2h")
|
||||||
|
|
||||||
[node name="StaticBody2D" type="StaticBody2D" parent="." unique_id=1395018923]
|
[node name="SceneManager" type="Node2D" parent="." unique_id=173230898]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
script = ExtResource("2_iywne")
|
||||||
|
|
||||||
|
[node name="player" parent="." unique_id=1410007482 instance=ExtResource("3_iywne")]
|
||||||
|
position = Vector2(619, 417)
|
||||||
|
|
||||||
|
[node name="Triggers" type="Node2D" parent="." unique_id=2030156960]
|
||||||
|
|
||||||
|
[node name="trigger" parent="Triggers" unique_id=370558120 instance=ExtResource("3_lbhrr")]
|
||||||
|
position = Vector2(994, 554)
|
||||||
|
|
||||||
|
[node name="trigger2" parent="Triggers" unique_id=1589939050 instance=ExtResource("3_lbhrr")]
|
||||||
|
position = Vector2(154, 560)
|
||||||
|
effect = "teleport"
|
||||||
|
|
||||||
|
[node name="trigger3" parent="Triggers" unique_id=388511118 instance=ExtResource("3_lbhrr")]
|
||||||
|
position = Vector2(501, 270)
|
||||||
|
effect = "powerup"
|
||||||
|
|
||||||
|
[node name="Creates" type="Node2D" parent="." unique_id=2024545285]
|
||||||
|
|
||||||
|
[node name="Create" parent="Creates" unique_id=1182340047 instance=ExtResource("2_lbhrr")]
|
||||||
|
position = Vector2(326.00006, 362)
|
||||||
|
|
||||||
|
[node name="Create2" parent="Creates" unique_id=1480887512 instance=ExtResource("2_lbhrr")]
|
||||||
|
position = Vector2(773, 385)
|
||||||
|
|
||||||
|
[node name="Create3" parent="Creates" unique_id=2035400368 instance=ExtResource("2_lbhrr")]
|
||||||
|
position = Vector2(757, 324)
|
||||||
|
|
||||||
|
[node name="Create4" parent="Creates" unique_id=371721949 instance=ExtResource("2_lbhrr")]
|
||||||
|
position = Vector2(878, 331)
|
||||||
|
|
||||||
|
[node name="Level" type="Node2D" parent="." unique_id=1660227037]
|
||||||
|
position = Vector2(1, 0)
|
||||||
|
|
||||||
|
[node name="StaticBody2D" type="StaticBody2D" parent="Level" unique_id=1395018923]
|
||||||
position = Vector2(576, 457)
|
position = Vector2(576, 457)
|
||||||
metadata/_edit_group_ = true
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D" unique_id=315339386]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Level/StaticBody2D" unique_id=315339386]
|
||||||
position = Vector2(4.5776367e-05, 2)
|
position = Vector2(4.5776367e-05, 2)
|
||||||
scale = Vector2(10, 10)
|
scale = Vector2(10, 10)
|
||||||
shape = SubResource("RectangleShape2D_8cj0n")
|
shape = SubResource("RectangleShape2D_8cj0n")
|
||||||
|
|
||||||
[node name="Create" parent="." unique_id=1182340047 instance=ExtResource("2_lbhrr")]
|
[node name="StaticBody2D2" type="StaticBody2D" parent="Level" unique_id=1469811553]
|
||||||
position = Vector2(607.00006, 343.00003)
|
position = Vector2(999, 642)
|
||||||
|
|
||||||
[node name="trigger" parent="." unique_id=370558120 instance=ExtResource("3_lbhrr")]
|
|
||||||
position = Vector2(994, 554)
|
|
||||||
|
|
||||||
[node name="player" type="CharacterBody2D" parent="." unique_id=2100658411]
|
|
||||||
position = Vector2(619, 417)
|
|
||||||
script = ExtResource("2_yqjtg")
|
|
||||||
metadata/_edit_group_ = true
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="player" unique_id=116863376]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Level/StaticBody2D2" unique_id=454036517]
|
||||||
shape = SubResource("CircleShape2D_uwrxv")
|
|
||||||
debug_color = Color(0.12898415, 0.62508565, 0.4800858, 0.41960785)
|
|
||||||
|
|
||||||
[node name="trigger2" parent="." unique_id=1589939050 instance=ExtResource("3_lbhrr")]
|
|
||||||
position = Vector2(147, 558)
|
|
||||||
|
|
||||||
[node name="Create2" parent="." unique_id=1480887512 instance=ExtResource("2_lbhrr")]
|
|
||||||
position = Vector2(773, 385)
|
|
||||||
|
|
||||||
[node name="StaticBody2D2" type="StaticBody2D" parent="." unique_id=1469811553]
|
|
||||||
position = Vector2(993, 644)
|
|
||||||
metadata/_edit_group_ = true
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D2" unique_id=454036517]
|
|
||||||
position = Vector2(-2, 0)
|
position = Vector2(-2, 0)
|
||||||
shape = SubResource("WorldBoundaryShape2D_lbhrr")
|
shape = SubResource("WorldBoundaryShape2D_lbhrr")
|
||||||
|
|
||||||
[node name="Create3" parent="." unique_id=2035400368 instance=ExtResource("2_lbhrr")]
|
[node name="Bullet" parent="." unique_id=223347173 instance=ExtResource("6_p57ef")]
|
||||||
position = Vector2(757, 324)
|
position = Vector2(271, 404)
|
||||||
|
|
||||||
[node name="Create4" parent="." unique_id=371721949 instance=ExtResource("2_lbhrr")]
|
|
||||||
position = Vector2(878, 331)
|
|
||||||
|
|
||||||
[connection signal="AreaTrigger" from="trigger" to="." method="_on_trigger"]
|
|
||||||
|
|||||||
19
scenes/player.tscn
Normal file
19
scenes/player.tscn
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
[gd_scene format=3 uid="uid://s0utas3jmhjk"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://cugku4bbar0fk" path="res://scripts/player.gd" id="1_3vyb7"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"]
|
||||||
|
|
||||||
|
[node name="player" type="CharacterBody2D" unique_id=1410007482]
|
||||||
|
script = ExtResource("1_3vyb7")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=446542358]
|
||||||
|
shape = SubResource("CircleShape2D_uwrxv")
|
||||||
|
debug_color = Color(0.12898415, 0.62508565, 0.4800858, 0.41960785)
|
||||||
|
|
||||||
|
[node name="RightTarget" type="Marker2D" parent="." unique_id=1188700194]
|
||||||
|
position = Vector2(14, -5)
|
||||||
|
|
||||||
|
[node name="LeftTarget" type="Marker2D" parent="." unique_id=1940665709]
|
||||||
|
position = Vector2(-14, -5)
|
||||||
13
scripts/bullet.gd
Normal file
13
scripts/bullet.gd
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
class_name Bullet extends Area2D
|
||||||
|
|
||||||
|
var speed: float = 700
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
position +=transform.x * speed * delta
|
||||||
1
scripts/bullet.gd.uid
Normal file
1
scripts/bullet.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://bfuhpow7x2xr1
|
||||||
@ -1 +1,17 @@
|
|||||||
class_name Create extends RigidBody2D
|
class_name Create extends RigidBody2D
|
||||||
|
|
||||||
|
var teleport_target: Vector2 = Vector2.ZERO
|
||||||
|
var should_teleport: bool = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func teleport_to(position:Vector2):
|
||||||
|
teleport_target = position
|
||||||
|
should_teleport = true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
|
||||||
|
if should_teleport:
|
||||||
|
state.transform = Transform2D.IDENTITY.translated(teleport_target)
|
||||||
|
should_teleport = false
|
||||||
|
|||||||
@ -1,11 +1,29 @@
|
|||||||
extends Node2D
|
class_name GameController extends Node2D
|
||||||
|
|
||||||
var createTotal = 3
|
var createTotal = 0
|
||||||
|
signal destroySignal(body)
|
||||||
|
signal teleportSignal(body)
|
||||||
|
signal levelChangeSignal(level)
|
||||||
|
var currentScene:String = "res://scenes/game.tscn"
|
||||||
|
|
||||||
|
var timer := Timer.new()
|
||||||
|
var timeAvailable := 20
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready() -> void:
|
||||||
pass # Replace with function body.
|
add_child(timer)
|
||||||
|
timer.wait_time = 1
|
||||||
|
timer.one_shot = false
|
||||||
|
timer.connect("timeout", secondCounter)
|
||||||
|
timer.start()
|
||||||
|
|
||||||
|
func secondCounter() ->void:
|
||||||
|
timeAvailable -=1
|
||||||
|
if timeAvailable <=0:
|
||||||
|
print("You Lose")
|
||||||
|
levelChangeSignal.emit(currentScene)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
@ -13,7 +31,7 @@ func _process(delta):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _on_trigger(body, effect):
|
func _on_trigger(body, effect,trigger):
|
||||||
print("GC knows trigger...." + effect)
|
print("GC knows trigger...." + effect)
|
||||||
if body is Create:
|
if body is Create:
|
||||||
match effect:
|
match effect:
|
||||||
@ -21,5 +39,20 @@ func _on_trigger(body, effect):
|
|||||||
createTotal -= 1
|
createTotal -= 1
|
||||||
if createTotal <= 0:
|
if createTotal <= 0:
|
||||||
print("You won")
|
print("You won")
|
||||||
body.queue_free()
|
levelChangeSignal.emit(currentScene)
|
||||||
|
destroySignal.emit(body)
|
||||||
|
"teleport":
|
||||||
|
print("GM teleport an object")
|
||||||
|
teleportSignal.emit(body)
|
||||||
|
|
||||||
|
if body is Player:
|
||||||
|
match effect:
|
||||||
|
"powerup":
|
||||||
|
print("GC knows about powerup")
|
||||||
|
timeAvailable +=5
|
||||||
|
destroySignal.emit(trigger)
|
||||||
|
|
||||||
|
func createUpdate(creatsAmonut):
|
||||||
|
createTotal = creatsAmonut
|
||||||
|
print("GC updated creats:" +str(createTotal))
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,33 @@
|
|||||||
extends CharacterBody2D
|
class_name Player extends CharacterBody2D
|
||||||
|
|
||||||
|
@onready var right_target: Marker2D = $RightTarget
|
||||||
|
@onready var left_target: Marker2D = $LeftTarget
|
||||||
|
|
||||||
|
|
||||||
const SPEED = 300.0
|
const SPEED = 300.0
|
||||||
const JUMP_VELOCITY = -400.0
|
const JUMP_VELOCITY = -400.0
|
||||||
const BUMP_POWER = 50
|
const BUMP_POWER = 50
|
||||||
|
enum FaceDirection{LEFT, RIGHT}
|
||||||
|
var facing: FaceDirection = FaceDirection.RIGHT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
# Add the gravity.
|
# Add the gravity.
|
||||||
if not is_on_floor():
|
if not is_on_floor():
|
||||||
velocity += get_gravity() * delta
|
velocity += get_gravity() * delta
|
||||||
|
|
||||||
|
#Handler shoot
|
||||||
|
if Input.is_action_just_pressed("shoot"):
|
||||||
|
print("Player wants to shoot")
|
||||||
|
match facing:
|
||||||
|
FaceDirection.RIGHT:
|
||||||
|
print("Shoot to the Right")
|
||||||
|
%SceneManager.makeBullet(right_target.global_transform,700)
|
||||||
|
FaceDirection.LEFT:
|
||||||
|
print("Shoot to the Left")
|
||||||
|
%SceneManager.makeBullet(left_target.global_transform,-700)
|
||||||
|
|
||||||
# Handle jump.
|
# Handle jump.
|
||||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||||
velocity.y = JUMP_VELOCITY
|
velocity.y = JUMP_VELOCITY
|
||||||
@ -19,6 +37,10 @@ func _physics_process(delta):
|
|||||||
var direction = Input.get_axis("ui_left", "ui_right")
|
var direction = Input.get_axis("ui_left", "ui_right")
|
||||||
if direction:
|
if direction:
|
||||||
velocity.x = direction * SPEED
|
velocity.x = direction * SPEED
|
||||||
|
if direction <0:
|
||||||
|
facing = FaceDirection.LEFT
|
||||||
|
if direction >=0:
|
||||||
|
facing = FaceDirection.RIGHT
|
||||||
else:
|
else:
|
||||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||||
|
|
||||||
|
|||||||
72
scripts/scene_manager.gd
Normal file
72
scripts/scene_manager.gd
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
class_name SceneManager extends Node2D
|
||||||
|
@onready var triggers: Node2D = $"../Triggers"
|
||||||
|
@onready var creates: Node2D = $"../Creates"
|
||||||
|
@onready var level: Node2D = $"../Level"
|
||||||
|
@onready var game: GameController = $".."
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
#pass # Replace with function body.
|
||||||
|
buildLevel()
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func buildLevel() ->void:
|
||||||
|
print("building level")
|
||||||
|
updateCreates()
|
||||||
|
updateTriggers()
|
||||||
|
|
||||||
|
#wire up signals from GameCtroller
|
||||||
|
game.destroySignal.connect(destroy)
|
||||||
|
game.teleportSignal.connect(teleport)
|
||||||
|
game.levelChangeSignal.connect(loadLevel)
|
||||||
|
|
||||||
|
|
||||||
|
func updateTriggers()->void:
|
||||||
|
if triggers:
|
||||||
|
for obj in triggers.get_children():
|
||||||
|
if obj is Trigger:
|
||||||
|
if not obj.AreaTrigger.is_connected(game._on_trigger):
|
||||||
|
obj.AreaTrigger.connect(game._on_trigger)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func updateCreates() ->void:
|
||||||
|
#check that there is a create note
|
||||||
|
if creates:
|
||||||
|
var totalCreates = 0
|
||||||
|
for obj in creates.get_children():
|
||||||
|
if obj is Create:
|
||||||
|
if not obj.tree_exited.is_connected(updateCreates):
|
||||||
|
obj.tree_exited.connect(updateCreates)
|
||||||
|
totalCreates +=1
|
||||||
|
#print("Total Creates:"+ str(totalCreates))
|
||||||
|
game.createUpdate(totalCreates)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func destroy(body)->void:
|
||||||
|
body.queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
func teleport(body) ->void:
|
||||||
|
if body is Create:
|
||||||
|
var viewport_size = get_viewport().get_visible_rect().size
|
||||||
|
var random_x = randf_range(0,viewport_size.x)
|
||||||
|
var random_y = randf_range(0,viewport_size.y)
|
||||||
|
var newPosition = Vector2(random_x,random_y)
|
||||||
|
body.teleport_to(newPosition)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func loadLevel(level:String)->void:
|
||||||
|
print(level)
|
||||||
|
get_tree().call_deferred("change_scene_to_file", level)
|
||||||
|
|
||||||
|
|
||||||
|
func makeBullet(targetPosition, speed):
|
||||||
|
print("Make a bullet!")
|
||||||
1
scripts/scene_manager.gd.uid
Normal file
1
scripts/scene_manager.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://ch2id76i14srx
|
||||||
@ -1,6 +1,6 @@
|
|||||||
extends Area2D
|
class_name Trigger extends Area2D
|
||||||
|
|
||||||
signal AreaTrigger(body, effect)
|
signal AreaTrigger(body, effect, trigger)
|
||||||
@export var effect = "destroy"
|
@export var effect = "destroy"
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
@ -16,4 +16,4 @@ func _process(delta)-> void:
|
|||||||
func _on_body_entered(body: Node2D) -> void:
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
#pass # Replace with function body.
|
#pass # Replace with function body.
|
||||||
print("Trigger activated")
|
print("Trigger activated")
|
||||||
AreaTrigger.emit(body, effect)
|
AreaTrigger.emit(body, effect,self)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user