Dinhero21 / game-engine

Fully Open Source Game and Game Engine
0 stars 0 forks source link

"Survival Elements" #10

Open Dinhero21 opened 11 months ago

Dinhero21 commented 11 months ago

TODO: Find a better name for this.

"Survival Elements", basically health, hunger, mana, limited (non-instant, ranged) world manipulation

Dinhero21 commented 11 months ago

I feel like the simplest one to implement is range.

Terraria has an INSANE range with 18 tiles horizontally, 17 up, and 14 down (with the character's feet as the center (1 tile above red)). Terraria Screenshot The distance function seems to be a maximum absolute axial difference. (max(|a.x - b.x|, |a.y - b.y|))

When outside the range, any attempt at breaking a tile will fail with the animation still playing. The tooltip will disappear (if the current tile is outside the range), this will not however happen with other "illegal" states (such as placing a tile inside a furniture).

Some items have range modifiers which, as the name implies, modifies the range. -1 range +3 range +4 range The range gets linearly shifted by the value present in the modifier.

Dinhero21 commented 11 months ago

The way block placement works currently is kind of awkward since you can place infinitely far floating blocks, might want to work on this first

Dinhero21 commented 11 months ago

(me when accidentally closed issue)

Dinhero21 commented 11 months ago

Terraria, and many other games (such as Minecraft), use a "selected slot"-like system which is what I've been thinking about implementing.

You can use the Number Keys (except the Numeric Keypad (even with NumLock) (for whatever reason)) or the mouse scroll wheel to change which item is selected.

The set of selectable slots, usually a row of the grid inventory, is called the Hotbar. Terraria has a grid inventory with a size of 10 (x) by 5 (y) (overkill imo) with the first row being the Hotbar.

This is much better than what is currently in the game which is an awkward cursor-slot system requiring a complicated set of actions to do anything. Pseudo-code below.

--- on Slot.ClickHandler@Event<left.down> ---
// Clicked -> Clicked Slot
// Cursor  -> Cursor  Slot

// Type    -> Stack Type
// Amount  -> Stack Amount

// Swap(A, B) -> Sets A to B and B to A

if (Type<Clicked> === Type<Cursor>)
{
  Amount<Clicked> += Amount<Cursor>
  Amount<Cursor> = 0
}

Swap(Clicked, Cursor)
---------------------------------------------

--- on World.ClickHandler@Event<left.down> ---
// Cursor    -> Cursor Slot
// World     -> World     Helper
// Inventory -> Inventory Helper
// Position  -> Clicked Tile Position
// Tile      -> Clicked Tile Instance

// Type      -> [Tile|Stack] Type
// Amount    ->       Stack  Amount

// A is B    -> Type<A> === B

if (Tile is air)
{
  World.setTile(
    Type<Cursor>,
    Position
  )

  Amount<Cursor> -= 1
}
else
{
  Inventory.add(
    Type<Cursor>,
    1
  )

  World.setTile(
    air,
    Position
  )
}
----------------------------------------------