Compare commits
2 Commits
78bcdb0d6f
...
023e749833
| Author | SHA1 | Date | |
|---|---|---|---|
| 023e749833 | |||
| 41fc5de4d3 |
|
|
@ -94,6 +94,11 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://lib/classes/movement_state_receiver.gd"
|
||||
}, {
|
||||
"base": "Area2D",
|
||||
"class": "Projectile",
|
||||
"language": "GDScript",
|
||||
"path": "res://src/classes/projectile.gd"
|
||||
}, {
|
||||
"base": "Resource",
|
||||
"class": "SE_StateFrame",
|
||||
"language": "GDScript",
|
||||
|
|
@ -152,6 +157,7 @@ _global_script_class_icons={
|
|||
"Modifier_Receiver": "",
|
||||
"MovementComponent": "",
|
||||
"Movement_StateReceiver": "",
|
||||
"Projectile": "",
|
||||
"SE_StateFrame": "",
|
||||
"State": "",
|
||||
"StateAnimatedActor": "",
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ extends Interactable
|
|||
# var a = 2
|
||||
# var b = "text"
|
||||
export var item :Resource
|
||||
export var count :int = 1
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
64
src/PewMachine.gd
Normal file
64
src/PewMachine.gd
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
extends Position2D
|
||||
## Represents a weapon that spawns and shoots bullets.
|
||||
## The Cooldown timer controls the cooldown duration between shots.
|
||||
|
||||
export var scene_path :Resource
|
||||
export var pew_cooldown_time :float = 1.0
|
||||
|
||||
const BULLET_VELOCITY = 350
|
||||
var projectile :Projectile #preload("res://src/Projectile.tscn")
|
||||
|
||||
#onready var sound_shoot = $Shoot
|
||||
onready var timer = Timer.new()
|
||||
onready var offset_position = Vector2(transform.origin.x, transform.origin.y)
|
||||
|
||||
## I don't know what type this would be
|
||||
var loaded_scene
|
||||
|
||||
func _ready():
|
||||
#projectile = load(scene_path.resource_path)
|
||||
loaded_scene = load(scene_path.resource_path)
|
||||
timer.autostart = false
|
||||
timer.wait_time = pew_cooldown_time
|
||||
timer.one_shot = true
|
||||
timer.autostart = false
|
||||
add_child(timer)
|
||||
|
||||
|
||||
# This method is only called by Player.gd.
|
||||
func shoot(direction = 1):
|
||||
#self.set_position(Vector2(position.x * direction, position.y))
|
||||
#transform.x = transform.x * direction
|
||||
#Transform2D.FLIP_Y
|
||||
#transform.origin.x = transform.origin.x * direction
|
||||
# if direction < 0:
|
||||
# var t = Transform2D()
|
||||
# # Translation
|
||||
# t.origin = Vector2(position.x * -1, position.y)
|
||||
# transform = t
|
||||
# elif direction > 0:
|
||||
# var t = Transform2D()
|
||||
# # Translation
|
||||
# t.origin = Vector2(position.x, position.y)
|
||||
# transform = t
|
||||
|
||||
print("Fire Debug: ", direction, " Gun position: ", position, transform.origin)
|
||||
# position.x = position.x * direction #shifting position before fire was unreliable
|
||||
if not timer.is_stopped():
|
||||
return false
|
||||
var bullet = loaded_scene.instance()
|
||||
# if (direction > 0):
|
||||
# bullet.global_position = global_position
|
||||
# else:
|
||||
# bullet.global_position = global_position - Vector2(position.x * 2, 0)
|
||||
if bullet is Projectile:
|
||||
bullet.global_position = global_position
|
||||
|
||||
#bullet.linear_velocity = Vector2(direction * BULLET_VELOCITY, 0)
|
||||
|
||||
bullet.set_as_toplevel(true)
|
||||
add_child(bullet)
|
||||
# sound_shoot.play()
|
||||
timer.start()
|
||||
return true
|
||||
|
||||
|
|
@ -4,6 +4,8 @@ var parent_request_state_change :FuncRef
|
|||
|
||||
var player_number: int = 1
|
||||
|
||||
onready var pew_machine = $"%PewMachine"
|
||||
|
||||
func _ready():
|
||||
var state_ref :State
|
||||
var state_name :String
|
||||
|
|
@ -163,6 +165,10 @@ func attack_secondary():
|
|||
|
||||
|
||||
func _state_process_physics_attack_shoot():
|
||||
|
||||
if pew_machine.timer.time_left == 0:
|
||||
pew_machine.shoot()
|
||||
|
||||
if current_state.animation_finished == true:
|
||||
request_state_change.call_func('idle')
|
||||
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ func touch_the_thing(the_thing: Interactable) -> bool:
|
|||
movement_state_machine.change_to_known_state('enter_right')
|
||||
the_thing.trigger_interaction()
|
||||
if the_thing is ItemPickup:
|
||||
player_inventory.add_to_inventory(the_thing.item)
|
||||
player_inventory.select_secondary(the_thing.item)
|
||||
player_inventory.add_to_inventory(the_thing.item, the_thing.count)
|
||||
#player_inventory.select_secondary(the_thing.item)
|
||||
the_thing.trigger_interaction()
|
||||
return true
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=34 format=2]
|
||||
[gd_scene load_steps=36 format=2]
|
||||
|
||||
[ext_resource path="res://lib/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://assets/actors/players/playerE/PlayerE_SpriteFrames.tres" type="SpriteFrames" id=2]
|
||||
|
|
@ -27,6 +27,8 @@
|
|||
[ext_resource path="res://assets_tmp/SE/tap.wav" type="AudioStream" id=25]
|
||||
[ext_resource path="res://assets_tmp/SE/land.wav" type="AudioStream" id=26]
|
||||
[ext_resource path="res://src/actors/players/playerE/states/attack_punch.tres" type="Resource" id=27]
|
||||
[ext_resource path="res://src/PewMachine.gd" type="Script" id=28]
|
||||
[ext_resource path="res://src/projectiles/MushroomPew.tscn" type="PackedScene" id=29]
|
||||
|
||||
[sub_resource type="Resource" id=3]
|
||||
resource_local_to_scene = true
|
||||
|
|
@ -145,3 +147,9 @@ shape = SubResource( 2 )
|
|||
[node name="Interactable_Receiver" type="Node" parent="." index="10"]
|
||||
script = ExtResource( 21 )
|
||||
interactable_parent_callback = "touch_the_thing"
|
||||
|
||||
[node name="PewMachine" type="Position2D" parent="." index="11"]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2( 10, 1.36422e-12 )
|
||||
script = ExtResource( 28 )
|
||||
scene_path = ExtResource( 29 )
|
||||
|
|
|
|||
|
|
@ -87,14 +87,17 @@ func select_secondary(_item :Item) -> void:
|
|||
if _items.has(_item):
|
||||
secondary_selection = _item
|
||||
|
||||
func add_to_inventory(_item :Item) -> int:
|
||||
func add_to_inventory(_item :Item, _count :int = 1) -> int:
|
||||
if _items.has(_item):
|
||||
_items[_item] += 1
|
||||
_items[_item] += _count
|
||||
else:
|
||||
_items[_item] = 1
|
||||
_items[_item] = _count
|
||||
if primary_selection == null:
|
||||
primary_selection = _item
|
||||
elif secondary_selection == null:
|
||||
secondary_selection = _item
|
||||
return _items[_item]
|
||||
|
||||
|
||||
func remove_from_inventory (_item :Item) -> int:
|
||||
if _items.has(_item):
|
||||
if _item.consumable:
|
||||
|
|
@ -115,6 +118,10 @@ func remove_from_inventory (_item :Item) -> int:
|
|||
else:
|
||||
return 0
|
||||
|
||||
func get_item_inventory_count(_item :Item) -> int:
|
||||
if _items.has(_item):
|
||||
return _items[_item]
|
||||
return 0
|
||||
|
||||
func clear_item_from_inventory (_item :Item) -> void:
|
||||
if _items.has(_item):
|
||||
|
|
|
|||
30
src/classes/projectile.gd
Normal file
30
src/classes/projectile.gd
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
class_name Projectile
|
||||
extends Area2D
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
var velocity_pps :float = 60
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
rotate(delta * 10)
|
||||
position += Vector2(velocity_pps * delta, velocity_pps * delta)
|
||||
|
||||
|
||||
func _on_body_entered(body):
|
||||
var colliding_node = body
|
||||
if colliding_node.has_node("Projectile_Receiver"):
|
||||
colliding_node.get_node("Projectile_Receiver").register_interactable(self)
|
||||
|
||||
|
||||
func _on_area_entered(area):
|
||||
pass # Replace with function body.
|
||||
|
|
@ -123,6 +123,7 @@ tile_data = PoolIntArray( -65536, 0, 0, -65521, 0, 0, 65535, 0, 0, 16, 0, 0, 524
|
|||
position = Vector2( 203, 38 )
|
||||
type_name = "item_pickup"
|
||||
item = ExtResource( 8 )
|
||||
count = 10
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="ItemPickup" index="0"]
|
||||
shape = SubResource( 6 )
|
||||
|
|
|
|||
16
src/projectiles/MushroomPew.tscn
Normal file
16
src/projectiles/MushroomPew.tscn
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://src/templates/projectile_template.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://assets/items/mushroom_icon.png" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=1]
|
||||
radius = 6.0
|
||||
height = 2.0
|
||||
|
||||
[node name="MushroomPew" instance=ExtResource( 1 )]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="0"]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="." index="1"]
|
||||
texture = ExtResource( 2 )
|
||||
10
src/templates/projectile_template.tscn
Normal file
10
src/templates/projectile_template.tscn
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://src/classes/projectile.gd" type="Script" id=1]
|
||||
|
||||
[node name="Projectile_Template" type="Area2D"]
|
||||
monitorable = false
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
|
|
@ -112,7 +112,21 @@ script = ExtResource( 8 )
|
|||
[node name="PrimaryItem" type="TextureRect" parent="SelectedInventoryItems"]
|
||||
margin_bottom = 16.0
|
||||
|
||||
[node name="Label" type="Label" parent="SelectedInventoryItems/PrimaryItem"]
|
||||
margin_right = 20.0
|
||||
margin_bottom = 10.0
|
||||
custom_fonts/font = ExtResource( 2 )
|
||||
align = 2
|
||||
valign = 2
|
||||
|
||||
[node name="SecondaryItem" type="TextureRect" parent="SelectedInventoryItems"]
|
||||
margin_left = 4.0
|
||||
margin_right = 4.0
|
||||
margin_bottom = 16.0
|
||||
|
||||
[node name="Label" type="Label" parent="SelectedInventoryItems/SecondaryItem"]
|
||||
margin_right = 20.0
|
||||
margin_bottom = 10.0
|
||||
custom_fonts/font = ExtResource( 2 )
|
||||
align = 2
|
||||
valign = 2
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ extends HBoxContainer
|
|||
onready var primary_item = $PrimaryItem
|
||||
onready var secondary_item = $SecondaryItem
|
||||
|
||||
onready var _primary_item_count = $PrimaryItem/Label
|
||||
onready var _secondary_item_count = $SecondaryItem/Label
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
|
@ -16,10 +18,22 @@ func _ready():
|
|||
func _process(delta):
|
||||
if (PlayerInfo.player_inventory.primary_selection):
|
||||
primary_item.texture = PlayerInfo.player_inventory.primary_selection.inventory_icon
|
||||
var count = PlayerInfo.player_inventory.get_item_inventory_count(PlayerInfo.player_inventory.primary_selection)
|
||||
if count > 1:
|
||||
_primary_item_count.text = str(count)
|
||||
else:
|
||||
_primary_item_count.text = ''
|
||||
else:
|
||||
primary_item.texture = null
|
||||
_primary_item_count.text = ''
|
||||
|
||||
if (PlayerInfo.player_inventory.secondary_selection):
|
||||
secondary_item.texture = PlayerInfo.player_inventory.secondary_selection.inventory_icon
|
||||
var count = PlayerInfo.player_inventory.get_item_inventory_count(PlayerInfo.player_inventory.secondary_selection)
|
||||
if count > 1:
|
||||
_secondary_item_count.text = str(count)
|
||||
else:
|
||||
_secondary_item_count.text = ''
|
||||
else:
|
||||
secondary_item.texture = null
|
||||
_secondary_item_count.text = ''
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user