Skip to content

Instantly share code, notes, and snippets.

@pegasusearl
Created October 18, 2019 05:37
Show Gist options
  • Select an option

  • Save pegasusearl/211df0e3ba710e0bb69445f3a710b677 to your computer and use it in GitHub Desktop.

Select an option

Save pegasusearl/211df0e3ba710e0bb69445f3a710b677 to your computer and use it in GitHub Desktop.
Welcome file
<title>Welcome file</title>

Todo

  • Resolve ItemAdder with inventory full notification along with item receiver. Similiar to PickableItem.
  • [ ]

Docs

Game System

ResourceManager.objectList

{
Inventory : $Game/interface/interface/td/roomNav/cente/inventory/margin/items,
Used to manage item inside inventory and show it to player.

grabber : $Game/interface/floating/grab,
Used to drag and drop item.

losing_notification, winning_notification, get_item_notification, notify_full
All in $Game/interface/popups, self explanatory.

level_node
$Game/Level
The currently loaded level.
}

Game system

Inventory

Access function via ResourceManager.objectList["Inventory"]

Method

  • void addItem( String name , Texture icon )

Accessed by PickableItem and ItemAdder class.
name is what the item is called to help the game identify.
icon is item’s thumbnail shown in inventory.

  • bool useItem( String name )

Accessed by ItemReceiver class. Used to check if inventory had certain item. If yes return true, then item will be used. If no, return false and nothing else will happened.

  • void removeItem( String name )

Force remove an item. Only called by the node itself (not from outside).

Item drag and drop

Start from Inventory’s each item’s button. It’s item.tscn.

Inventory : $Game/interface/interface/td/roomNav/cente/inventory/margin/items,

item.tscn Control/Button

properties:

grabber = ResourceManager.objectList["grabber"]
call grab() from grabber when item.tscn (which is Button) is pushed down.
<<

grabber Control

a.k.aResourceManager.objectList["grabber"] / interface/floating/grab / Mouse.gd

  • void grab( Texture texture, String item_name )

Called when item.tscn(button) is pushed down.
Show item icon’s texture. Then it will spawn item_hover.tscn inside $Game/Level. Which will follow mouse global position as long as it’s remain on scene.

  • void drop()

Called when player just released the touch.

if (event is InputEventScreenTouch and !event.is_pressed())and isGrabbing:
	drop()

This will delete item_hover.tscn and spawn item_dropper.tscn inside $Game/Level. item_dropper.tscn will check wether it touching ItemReceiver that will receive the item that just dropped or not. If yes it will call trigger() on the said ItemReceiver. Then freed from the scene.

  • void hide_item()
item_hover.tscn : Node2D/Area2D

Item hover will follow mouse global position in each frame. At this state, player is dragging the mouse/touch.

item_dropper.tscn : Node2D/Area2D

Will check if item dropped into ItemReceiver or not then got freed.

Classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment