Skip to content

Commit

Permalink
Start work on research system
Browse files Browse the repository at this point in the history
  • Loading branch information
outfrost committed Apr 26, 2021
1 parent b42055c commit fcbe708
Show file tree
Hide file tree
Showing 26 changed files with 477 additions and 10 deletions.
24 changes: 20 additions & 4 deletions character/PlayerCharacter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var inventory: Dictionary = {}

var game_controller: Game = null
var current_lootable: Lootable = null
var current_interactive: Node2D = null
var last_movement_dir: Vector2 = Vector2.DOWN
onready var home = self.position

Expand Down Expand Up @@ -82,6 +83,8 @@ func _input(event: InputEvent) -> void:
if event.is_action_pressed("use"):
get_tree().set_input_as_handled()
if current_lootable:
if !is_instance_valid(current_lootable):
return
if !inventory.has(current_lootable.loot1):
inventory[current_lootable.loot1] = 0
inventory[current_lootable.loot1] += current_lootable.loot1_amount
Expand All @@ -95,6 +98,11 @@ func _input(event: InputEvent) -> void:
# print("%s (%d)" % [Item.type_str(current_lootable.loot2), current_lootable.loot2_amount])
current_lootable.queue_free()
print_inventory()
elif current_interactive:
if !is_instance_valid(current_interactive):
return
if current_interactive.has_method("interact"):
current_interactive.interact()
elif event.is_action_pressed("attack"):
get_tree().set_input_as_handled()
play_attack_anim(last_movement_dir)
Expand Down Expand Up @@ -140,10 +148,6 @@ func play_attack_anim(direction: Vector2):
playing_action = false
$FxSprite.play("idle")

func entered_lootable_range(lootable):
print_debug(lootable)
current_lootable = lootable

func take_damage(dmg: float, fire_dmg: float, ice_dmg: float, wind_dmg: float):

health -= (1.0 - resist_base) * dmg
Expand All @@ -155,10 +159,22 @@ func take_damage(dmg: float, fire_dmg: float, ice_dmg: float, wind_dmg: float):
self.position = home
self.health = 75.0

func entered_lootable_range(lootable):
print_debug(lootable)
current_lootable = lootable

func exited_lootable_range(lootable):
if lootable == current_lootable:
current_lootable = null

func entered_interactive_range(interactive):
print_debug(interactive)
current_interactive = interactive

func exited_interactive_range(interactive):
if interactive == current_interactive:
current_interactive = null

func print_inventory():
print("Inventory:")
for entry in inventory:
Expand Down
Binary file added environment/inventorybottles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions environment/inventorybottles.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/inventorybottles.png-298d746d7f28f9cc2b955e3f3924a5ae.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://environment/inventorybottles.png"
dest_files=[ "res://.import/inventorybottles.png-298d746d7f28f9cc2b955e3f3924a5ae.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
36 changes: 36 additions & 0 deletions environment/props/ResearchTable.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
extends Area2D

onready var panel: Panel = $CanvasLayer/ResearchPanel

var character: Node2D = null

func _ready() -> void:
connect("body_entered", self, "on_body_entered")
connect("body_exited", self, "on_body_exited")

func on_body_entered(body):
if body.has_method("entered_interactive_range"):
character = body
body.entered_interactive_range(self)

func on_body_exited(body):
if body.has_method("exited_interactive_range"):
if body == character:
character = null
body.exited_interactive_range(self)

func interact():
if !character || !is_instance_valid(character):
character = null
return
character.set_process_input(false)
character.set_physics_process(false)
panel.show()

func done_interacting():
panel.hide()
if !character || !is_instance_valid(character):
character = null
return
character.set_process_input(true)
character.set_physics_process(true)
150 changes: 144 additions & 6 deletions environment/props/TableWide2.tscn
Original file line number Diff line number Diff line change
@@ -1,15 +1,153 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=7 format=2]

[ext_resource path="res://environment/props/table.png" type="Texture" id=1]
[ext_resource path="res://environment/props/ResearchTable.gd" type="Script" id=2]
[ext_resource path="res://game/ui-theme/ui_theme.tres" type="Theme" id=3]
[ext_resource path="res://game/menu/InventoryButton.tscn" type="PackedScene" id=4]

[sub_resource type="RectangleShape2D" id=1]
[sub_resource type="CircleShape2D" id=1]
radius = 40.0

[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 30, 5 )

[node name="StaticBody2D" type="StaticBody2D"]
[node name="ResearchTable" type="Area2D"]
script = ExtResource( 2 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, 8 )
shape = SubResource( 1 )

[node name="Sprite" type="Sprite" parent="."]
[node name="StaticBody2D" type="StaticBody2D" parent="."]

[node name="Sprite" type="Sprite" parent="StaticBody2D"]
texture = ExtResource( 1 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
position = Vector2( 0.0883942, 10.0342 )
shape = SubResource( 1 )
shape = SubResource( 2 )

[node name="CanvasLayer" type="CanvasLayer" parent="."]
layer = 2

[node name="ResearchPanel" type="Panel" parent="CanvasLayer"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -280.0
margin_top = -200.0
margin_right = 280.0
margin_bottom = 200.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="InventoryButtons" type="Control" parent="CanvasLayer/ResearchPanel"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="InventoryButton1" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 60.0
margin_top = 100.0
margin_right = 100.0
margin_bottom = 140.0

[node name="InventoryButton2" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 110.0
margin_top = 100.0
margin_right = 150.0
margin_bottom = 140.0

[node name="InventoryButton3" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 160.0
margin_top = 100.0
margin_right = 200.0
margin_bottom = 140.0

[node name="InventoryButton4" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 210.0
margin_top = 100.0
margin_right = 250.0
margin_bottom = 140.0

[node name="InventoryButton5" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 60.0
margin_top = 150.0
margin_right = 100.0
margin_bottom = 190.0

[node name="InventoryButton6" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 110.0
margin_top = 150.0
margin_right = 150.0
margin_bottom = 190.0

[node name="InventoryButton7" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 160.0
margin_top = 150.0
margin_right = 200.0
margin_bottom = 190.0

[node name="InventoryButton8" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 210.0
margin_top = 150.0
margin_right = 250.0
margin_bottom = 190.0

[node name="InventoryButton9" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 60.0
margin_top = 200.0
margin_right = 100.0
margin_bottom = 240.0

[node name="InventoryButton10" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 110.0
margin_top = 200.0
margin_right = 150.0
margin_bottom = 240.0

[node name="InventoryButton11" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 160.0
margin_top = 200.0
margin_right = 200.0
margin_bottom = 240.0

[node name="InventoryButton12" parent="CanvasLayer/ResearchPanel/InventoryButtons" instance=ExtResource( 4 )]
margin_left = 210.0
margin_top = 200.0
margin_right = 250.0
margin_bottom = 240.0

[node name="ChosenItemIconRect" type="TextureRect" parent="CanvasLayer/ResearchPanel"]
margin_left = 390.0
margin_top = 90.0
margin_right = 422.0
margin_bottom = 122.0
expand = true

[node name="ConfirmButton" type="Button" parent="CanvasLayer/ResearchPanel"]
margin_left = 200.0
margin_top = 300.0
margin_right = 360.0
margin_bottom = 334.0
text = "Research"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="ConfirmButton2" type="Button" parent="CanvasLayer/ResearchPanel"]
margin_left = 200.0
margin_top = 350.0
margin_right = 360.0
margin_bottom = 384.0
text = "Done"
__meta__ = {
"_edit_use_anchors_": false
}
1 change: 1 addition & 0 deletions game/Game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ player_character = ExtResource( 7 )
[node name="MenuBackground" parent="." instance=ExtResource( 9 )]

[node name="LevelContainer" type="Node" parent="."]
pause_mode = 1

[node name="MainCamera" type="Camera2D" parent="."]
position = Vector2( 640, 360 )
Expand Down
17 changes: 17 additions & 0 deletions game/menu/InventoryButton.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://game/ui-theme/button_inventory_empty.tres" type="StyleBox" id=1]
[ext_resource path="res://game/ui-theme/button_inventory_base.tres" type="StyleBox" id=2]
[ext_resource path="res://game/ui-theme/button_inventory_pressed.tres" type="StyleBox" id=3]

[node name="InventoryButton" type="Button"]
margin_right = 40.0
margin_bottom = 40.0
custom_styles/hover = ExtResource( 2 )
custom_styles/pressed = ExtResource( 3 )
custom_styles/focus = ExtResource( 1 )
custom_styles/disabled = ExtResource( 2 )
custom_styles/normal = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
15 changes: 15 additions & 0 deletions game/ui-theme/button_inventory_base.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[gd_resource type="StyleBoxTexture" load_steps=2 format=2]

[ext_resource path="res://game/ui-theme/oinventoryitembackground.png" type="Texture" id=1]

[resource]
content_margin_left = 12.0
content_margin_right = 12.0
content_margin_top = 12.0
content_margin_bottom = 12.0
texture = ExtResource( 1 )
region_rect = Rect2( 0, 0, 32, 32 )
margin_left = 12.0
margin_right = 12.0
margin_top = 12.0
margin_bottom = 12.0
12 changes: 12 additions & 0 deletions game/ui-theme/button_inventory_empty.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_resource type="StyleBoxTexture" format=2]

[resource]
content_margin_left = 12.0
content_margin_right = 12.0
content_margin_top = 12.0
content_margin_bottom = 12.0
margin_left = 12.0
margin_right = 12.0
margin_top = 12.0
margin_bottom = 12.0
draw_center = false
16 changes: 16 additions & 0 deletions game/ui-theme/button_inventory_pressed.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[gd_resource type="StyleBoxTexture" load_steps=2 format=2]

[ext_resource path="res://game/ui-theme/oinventoryitembackground.png" type="Texture" id=1]

[resource]
content_margin_left = 12.0
content_margin_right = 12.0
content_margin_top = 12.0
content_margin_bottom = 12.0
texture = ExtResource( 1 )
region_rect = Rect2( 0, 0, 32, 32 )
margin_left = 12.0
margin_right = 12.0
margin_top = 12.0
margin_bottom = 12.0
modulate_color = Color( 0.866667, 0.607843, 0.717647, 1 )
Loading

0 comments on commit fcbe708

Please sign in to comment.