Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daniel/upgrade inventory #5

Merged
merged 5 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ config/icon="res://icon.svg"
[autoload]

SignalBus="*res://scripts/SignalBus.gd"
Globals="*res://scenes/Globals.tscn"

[display]

Expand Down
8 changes: 8 additions & 0 deletions scenes/Globals.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://rqxrfrjtp106"]

[ext_resource type="Script" path="res://scripts/Globals.gd" id="1_dd7n5"]

[node name="Globals" type="Node2D"]
script = ExtResource("1_dd7n5")

[node name="BulletContainer" type="Node2D" parent="."]
10 changes: 8 additions & 2 deletions scenes/Player.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[gd_scene load_steps=6 format=3 uid="uid://cwre7pomfe73u"]
[gd_scene load_steps=8 format=3 uid="uid://cwre7pomfe73u"]

[ext_resource type="Script" path="res://scripts/Player.gd" id="1_e2y74"]
[ext_resource type="Texture2D" uid="uid://5jnm0t5m0wyr" path="res://sprites/03.png" id="2_tpg8j"]
[ext_resource type="PackedScene" uid="uid://cfx5cdofitgxf" path="res://scenes/PickerUpper.tscn" id="3_dc2ih"]
[ext_resource type="Script" path="res://scripts/Inventory.gd" id="4_py77w"]
[ext_resource type="Script" path="res://scripts/Shooter.gd" id="5_372h2"]
[ext_resource type="Resource" uid="uid://gk7qypk05u23" path="res://resources/items/sauce/ketcup.tres" id="6_8uwjp"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_w7vev"]
size = Vector2(6, 7)
Expand All @@ -27,6 +29,10 @@ region_rect = Rect2(2.08165e-12, 2.08165e-12, 35, 35)

[node name="PickerUpper" parent="." instance=ExtResource("3_dc2ih")]

[node name="Inventory" type="Node" parent="."]
[node name="Inventory" type="Node2D" parent="."]
script = ExtResource("4_py77w")
items = Array[Resource("res://scripts/BurgerItem.gd")]([null])

[node name="Shooter" type="Node2D" parent="."]
script = ExtResource("5_372h2")
ammunition = Array[Resource("res://scripts/SauceItem.gd")]([ExtResource("6_8uwjp"), ExtResource("6_8uwjp"), ExtResource("6_8uwjp"), ExtResource("6_8uwjp"), ExtResource("6_8uwjp")])
4 changes: 2 additions & 2 deletions scenes/PlayerBullet.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=4 format=3 uid="uid://c6k4os3sbxelr"]

[ext_resource type="Script" path="res://scripts/Bullet.gd" id="1_tip0v"]
[ext_resource type="Script" path="res://scripts/Bullet.gd" id="1_vaw3o"]
[ext_resource type="Texture2D" uid="uid://bdtdj0ci7pivl" path="res://sprites/spritesheet.png" id="2_2bmwt"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_hdek1"]
Expand All @@ -9,7 +9,7 @@ size = Vector2(2, 2)
[node name="PlayerBullet" type="Area2D"]
collision_layer = 8
collision_mask = 4
script = ExtResource("1_tip0v")
script = ExtResource("1_vaw3o")

[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_2bmwt")
Expand Down
8 changes: 1 addition & 7 deletions scenes/levels/Daniel.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[gd_scene load_steps=11 format=3 uid="uid://ctbe15r3nw1ey"]
[gd_scene load_steps=10 format=3 uid="uid://ctbe15r3nw1ey"]

[ext_resource type="Script" path="res://scripts/GameManager.gd" id="1_p5wqo"]
[ext_resource type="Texture2D" uid="uid://tpf23uytvwei" path="res://sprites/tileset.png" id="2_4uj7p"]
[ext_resource type="PackedScene" uid="uid://cwre7pomfe73u" path="res://scenes/Player.tscn" id="3_wbqv4"]
[ext_resource type="PackedScene" uid="uid://c0ujo7raol74o" path="res://scenes/Enemy.tscn" id="4_vfbub"]
[ext_resource type="Script" path="res://scripts/Camera.gd" id="5_r3lwe"]
[ext_resource type="PackedScene" uid="uid://ckeuy4n7lbry5" path="res://scenes/PickupItem.tscn" id="6_n4xlb"]
[ext_resource type="Resource" uid="uid://gk7qypk05u23" path="res://resources/items/sauce/ketcup.tres" id="7_yr2jp"]
Expand Down Expand Up @@ -287,11 +286,6 @@ layer_1/tile_data = PackedInt32Array(262142, 0, 19, 262143, 65536, 19, 196608, 1
[node name="Player" parent="." instance=ExtResource("3_wbqv4")]
position = Vector2(-41, 6)

[node name="Enemy" parent="." instance=ExtResource("4_vfbub")]
position = Vector2(-37, -8)

[node name="BulletContainer" type="Node" parent="."]

[node name="Camera2D" type="Camera2D" parent="."]
zoom = Vector2(3, 3)
script = ExtResource("5_r3lwe")
Expand Down
2 changes: 0 additions & 2 deletions scripts/Bullet.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ class_name PlayerBullet extends Area2D
@export var speed: int = 200
@export var dir: Vector2 = Vector2(0, -1)

@onready var shooter = load("res://scripts/Shooter.gd").new()

func set_dir(dir):
self.dir = dir

Expand Down
17 changes: 9 additions & 8 deletions scripts/GameManager.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends Node2D

@onready var player = $Player
@onready var bullet_container = $BulletContainer
#@onready var bullet_container = $BulletContainer

@onready var signal_bus = get_node("/root/SignalBus")
@onready var shooter = load("res://scripts/Shooter.gd").new()
Expand All @@ -21,13 +21,14 @@ func _on_bullet_shoot(bullet_scene, location, rotation):
var bullet = bullet_scene.instantiate()
bullet.global_position = location
bullet.rotation = rotation
bullet_container.add_child(bullet)
#bullet_container.add_child(bullet)

func _on_bullet_shoot_player(bullet_scene, location, rotation):
var bullet = bullet_scene.instantiate()
bullet.global_position = location
bullet.rotation = rotation
bullet_container.add_child(bullet)
var curr_bullet_type = shooter.shoot_bullet(shooter.shooting_queue)
bullet.modulate = shooter.bullet_type[curr_bullet_type]
# var bullet = bullet_scene.instantiate()
# bullet.global_position = location
# bullet.rotation = rotation
# bullet_container.add_child(bullet)
# var curr_bullet_type = shooter.shoot_bullet(shooter.shooting_queue)
# bullet.modulate = shooter.bullet_type[curr_bullet_type]

pass
3 changes: 3 additions & 0 deletions scripts/Globals.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extends Node2D

@onready var bullet_container = $BulletContainer
3 changes: 2 additions & 1 deletion scripts/Inventory.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extends Node

extends Node2D

@export var items : Array[BurgerItem]

Expand Down
1 change: 1 addition & 0 deletions scripts/PickerUpper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ func _physics_process(delta):
$"../Inventory".add_item(body.item)
elif body.item is SauceItem:
print("sauce item", body.item)
$"../Shooter".add_bullet(body.item)

body.queue_free()
12 changes: 10 additions & 2 deletions scripts/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ extends CharacterBody2D
@onready var bullet_spawn = $Marker2D

@onready var signal_bus = get_node("/root/SignalBus")
@onready var globals = get_node("/root/Globals")

func _process(delta):
look_at(get_global_mouse_position())
# handle shooting
if Input.is_action_just_pressed('shoot'):
signal_bus.bullet_shoot_player.emit(bullet_scene, bullet_spawn.global_position, rotation)

var bullet = $Shooter.use_bullet()
print("shooting bullet", bullet)
if bullet != null:
var inst = bullet_scene.instantiate()
print("instantiate bullet", inst)
inst.global_position = bullet_spawn.global_position
inst.rotation = rotation
inst.modulate = Color.RED
globals.bullet_container.add_child(inst)

func _physics_process(delta):

Expand Down
25 changes: 8 additions & 17 deletions scripts/Shooter.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
extends Node

@export var ammunition: Array[SauceItem]

@export var shooting_queue: Array = ["lettuce", "shoe", "ketchup", "lettuce", "lettuce", "ketchup"]

var max_queue_size = 10

@export var bullet_type: Dictionary = {
ketchup = Color.RED,
lettuce = Color.LIGHT_GREEN,
Expand All @@ -10,23 +14,10 @@ var max_queue_size = 10
}

func add_bullet(item):
if len(shooting_queue) < max_queue_size:
shooting_queue.push_back(item)
if len(ammunition) < max_queue_size:
ammunition.push_back(item)

func shoot_bullet(shooting_queue):
if len(shooting_queue) != 0:
var shoot_item = shooting_queue[0]
shooting_queue.pop_front()
return shoot_item
else:
return "nothing"
func use_bullet():
return ammunition.pop_front()


# Called when the node enters the scene tree for the first time.
func _ready():
pass


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass