63 lines
1.8 KiB
C
63 lines
1.8 KiB
C
// nooncraft.game: Most game data randomly thrown in a structure
|
|
|
|
#pragma once
|
|
#include "world.h"
|
|
#include "camera.h"
|
|
#include "item.h"
|
|
|
|
struct Game
|
|
{
|
|
World *world;
|
|
Camera *camera;
|
|
|
|
/* Current player/cursor positions (they are linked) */
|
|
WorldCoord playerPos;
|
|
WorldCoord cursorPos;
|
|
|
|
/* Info on the pointed block */
|
|
BlockInfo *pointedBlockInfo() const;
|
|
/* Info on the selected item */
|
|
Item handItem() const;
|
|
|
|
/* Place the hand block at the cursor position, if possible */
|
|
void place();
|
|
|
|
/* Current ticks spent damaging the pointed block, ≥ 0 when breaking */
|
|
int damageTicks;
|
|
|
|
/* Whether we are currently breaking a block */
|
|
bool isBreakingBlock() const {
|
|
return this->damageTicks >= 0;
|
|
}
|
|
/* Whether we are breaking a block with a suitable tool */
|
|
bool isBreakingBlockWithSuitableTool(bool require_best) const;
|
|
/* Time required to break currently selected block */
|
|
int blockBreakingDuration() const;
|
|
/* Block breaking progress as a range 0-3 */
|
|
int8_t blockBreakingProgress() const;
|
|
|
|
/* Move the player by specified amount. */
|
|
bool movePlayerBy(WorldCoord dir, bool camera_follow=true);
|
|
/* Move the cursor by the specified amount. */
|
|
bool moveCursorBy(WorldCoord dir);
|
|
|
|
/* Find an empty inventory slot */
|
|
int findEmptyInventorySlot() const;
|
|
/* Find an inventory slot where `i` can be dropped */
|
|
int findInventorySlotForItem(Item i) const;
|
|
/* Put an item in a slot, __assuming a compatible/non-full stack__ */
|
|
void addItemInSlot(Item i, int slot);
|
|
|
|
/* Function called whenever a block is broken, to drop it */
|
|
bool collectBrokenBlock(WorldCoord dir);
|
|
|
|
/* Player inventory */
|
|
ItemStack inventory[36];
|
|
/* Hotbar cursor (0-8) */
|
|
int hotbarCursor;
|
|
|
|
// --== Tick update functions ==--
|
|
|
|
void updateBlockBreaking();
|
|
};
|