unique block ids, better running, remove deprecated tree parts
This commit is contained in:
parent
9929d21fa1
commit
7098bffd25
6 changed files with 61 additions and 68 deletions
14
src/App.vue
14
src/App.vue
|
@ -21,9 +21,9 @@ const level = createLevel(STAGE_WIDTH + 2, STAGE_HEIGHT + 2)
|
||||||
const lightMapEl = ref<HTMLCanvasElement | undefined>(undefined)
|
const lightMapEl = ref<HTMLCanvasElement | undefined>(undefined)
|
||||||
let updateLightMap: ReturnType<typeof useLightMap>
|
let updateLightMap: ReturnType<typeof useLightMap>
|
||||||
|
|
||||||
pocket({ name: 'Wooden Shovel', type: 'tool', icon: 'shovel', quality: 'wood' })
|
pocket(getItem('tool_shovel_wood'))
|
||||||
pocket({ name: 'Wooden Sword', type: 'tool', icon: 'sword', quality: 'wood' })
|
pocket(getItem('tool_sword_wood'))
|
||||||
pocket({ name: 'Wooden Pick Axe', type: 'tool', icon: 'pick', quality: 'wood' })
|
pocket(getItem('tool_pickaxe_wood'))
|
||||||
|
|
||||||
let animationFrame = 0
|
let animationFrame = 0
|
||||||
let lastTick = 0
|
let lastTick = 0
|
||||||
|
@ -126,7 +126,7 @@ function build(blockX: number, blockY: number, block: InventoryItem) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function interactWith(blockX: number, blockY: number, block: Block) {
|
function interactWith(blockX: number, blockY: number, block: Block) {
|
||||||
console.log('interact with', blockX, blockY, block.type)
|
if (debug) console.debug('interact with', blockX, blockY, block.type)
|
||||||
// § 4 ArbZG
|
// § 4 ArbZG
|
||||||
if (paused.value) return
|
if (paused.value) return
|
||||||
|
|
||||||
|
@ -235,7 +235,11 @@ onMounted(() => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="player"
|
<div id="player"
|
||||||
:class="[direction, { walking, running, sitting: paused }]"
|
:class="[direction, {
|
||||||
|
walking,
|
||||||
|
running: walking && running,
|
||||||
|
sitting: paused
|
||||||
|
}]"
|
||||||
@click="inventory = !inventory"
|
@click="inventory = !inventory"
|
||||||
>
|
>
|
||||||
<div class="head"></div>
|
<div class="head"></div>
|
||||||
|
|
|
@ -99,6 +99,10 @@
|
||||||
background-image: url(/Tiles/brick_grey.png);
|
background-image: url(/Tiles/brick_grey.png);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#field {
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
#field .block:hover,
|
#field .block:hover,
|
||||||
#field .block.block.highlight {
|
#field .block.block.highlight {
|
||||||
filter: brightness(1.2) saturate(1.2);
|
filter: brightness(1.2) saturate(1.2);
|
||||||
|
|
|
@ -2,8 +2,6 @@ import type { NoiseFunction2D } from 'simplex-noise'
|
||||||
import { blockTypes as T, level as L, probability as P } from './def'
|
import { blockTypes as T, level as L, probability as P } from './def'
|
||||||
import type { Block } from '../types.d'
|
import type { Block } from '../types.d'
|
||||||
|
|
||||||
const TREE_ROOT = [T.treeRootLeft, T.treeRootMiddle, T.treeRootRight]
|
|
||||||
|
|
||||||
function trees(r: number, i: number, row: Block[], previousRow: Block[]) {
|
function trees(r: number, i: number, row: Block[], previousRow: Block[]) {
|
||||||
const max = row.length - 1
|
const max = row.length - 1
|
||||||
const h = i - 1
|
const h = i - 1
|
||||||
|
@ -45,7 +43,8 @@ function ground(r: number, i: number, current: Block, above: Block) {
|
||||||
return current
|
return current
|
||||||
}
|
}
|
||||||
|
|
||||||
function ground_(r: number, i: number, row: Block[], previousRow: Block[]) {
|
/*
|
||||||
|
function ground(r: number, i: number, row: Block[], previousRow: Block[]) {
|
||||||
const rootParts = [T.treeRootLeft, T.treeRootMiddle, T.treeRootRight]
|
const rootParts = [T.treeRootLeft, T.treeRootMiddle, T.treeRootRight]
|
||||||
const prevBlock = previousRow[i]
|
const prevBlock = previousRow[i]
|
||||||
|
|
||||||
|
@ -56,6 +55,7 @@ function ground_(r: number, i: number, row: Block[], previousRow: Block[]) {
|
||||||
if (row[i] === T.soil) row[i] = T.grass
|
if (row[i] === T.soil) row[i] = T.grass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
function rock(r: number, i: number, current: Block, above: Block) {
|
function rock(r: number, i: number, current: Block, above: Block) {
|
||||||
if (above === T.soil && r < P.fray) return T.soil
|
if (above === T.soil && r < P.fray) return T.soil
|
||||||
|
|
|
@ -14,22 +14,19 @@ export const blockTypes: Record<BlockType, Block> = {
|
||||||
air: { type: 'air', hp: Infinity, walkable: true, transparent: true },
|
air: { type: 'air', hp: Infinity, walkable: true, transparent: true },
|
||||||
cave: { type: 'cave', hp: Infinity, walkable: true, transparent: true },
|
cave: { type: 'cave', hp: Infinity, walkable: true, transparent: true },
|
||||||
// Tree Parts
|
// Tree Parts
|
||||||
treeCrown: { type: 'treeCrown', hp: 1, walkable: true, transparent: true, drops: 'leaves' },
|
treeCrown: { type: 'treeCrown', hp: 1, walkable: true, transparent: true, drops: 'block_leaves' },
|
||||||
treeLeaves: { type: 'treeLeaves', hp: 1, walkable: true, transparent: true, drops: 'leaves' },
|
treeLeaves: { type: 'treeLeaves', hp: 1, walkable: true, transparent: true, drops: 'block_leaves' },
|
||||||
treeTrunk: { type: 'treeTrunk', hp: 10, walkable: true, climbable: true, transparent: true, drops: 'wood' },
|
treeTrunk: { type: 'treeTrunk', hp: 10, walkable: true, climbable: true, transparent: true, drops: 'block_wood' },
|
||||||
treeRoot: { type: 'treeRoot', hp: 10, walkable: true, climbable: true, drops: 'wood' },
|
treeRoot: { type: 'treeRoot', hp: 10, walkable: true, climbable: true, drops: 'block_wood' },
|
||||||
treeRootLeft: { type: 'treeRootLeft', hp: 10, walkable: true, climbable: true, drops: 'wood' },
|
|
||||||
treeRootMiddle: { type: 'treeRootMiddle', hp: 10, walkable: true, climbable: true, drops: 'wood' },
|
|
||||||
treeRootRight: { type: 'treeRootRight', hp: 10, walkable: true, climbable: true, drops: 'wood' },
|
|
||||||
// Opaque Natural Blocks
|
// Opaque Natural Blocks
|
||||||
grass: { type: 'grass', hp: 5, walkable: false, drops: 'dirt' },
|
grass: { type: 'grass', hp: 5, walkable: false, drops: 'block_dirt' },
|
||||||
soil: { type: 'soil', hp: 5, walkable: false, drops: 'dirt' },
|
soil: { type: 'soil', hp: 5, walkable: false, drops: 'block_dirt' },
|
||||||
soilGravel: { type: 'soilGravel', hp: 5, walkable: false, drops: 'gravel' },
|
soilGravel: { type: 'soilGravel', hp: 5, walkable: false, drops: 'block_gravel' },
|
||||||
stoneGravel: { type: 'stoneGravel', hp: 10, walkable: false, drops: 'gravel' },
|
stoneGravel: { type: 'stoneGravel', hp: 10, walkable: false, drops: 'block_gravel' },
|
||||||
stone: { type: 'stone', hp: 10, walkable: false, drops: 'stone' },
|
stone: { type: 'stone', hp: 10, walkable: false, drops: 'block_stone' },
|
||||||
bedrock: { type: 'bedrock', hp: 25, walkable: false, drops: 'stone' },
|
bedrock: { type: 'bedrock', hp: 25, walkable: false, drops: 'block_stone' },
|
||||||
// Built Blocks
|
// Built Blocks
|
||||||
brickWall: { type: 'brickWall', hp: 25, walkable: false, drops: 'stone' },
|
brickWall: { type: 'brickWall', hp: 25, walkable: false, drops: 'block_gravel' },
|
||||||
}
|
}
|
||||||
|
|
||||||
export const level = {
|
export const level = {
|
||||||
|
|
|
@ -1,51 +1,43 @@
|
||||||
import type { ItemQuality, Item, InventoryItem } from '../types.d'
|
import type { ItemQuality, Item, InventoryItem } from '../types.d'
|
||||||
|
|
||||||
export const items: Item[] = [
|
export const items = {
|
||||||
{ name: 'Wooden Shovel', type: 'tool', icon: 'shovel', quality: 'wood' },
|
tool_shovel_wood: { id: 'tool_shovel_wood', name: 'Wooden Shovel', type: 'tool', icon: 'shovel', quality: 'wood' } as Item,
|
||||||
{ name: 'Wooden Pick Axe', type: 'tool', icon: 'pick', quality: 'wood' },
|
tool_pickaxe_wood: { id: 'tool_pickaxe_wood', name: 'Wooden Pick Axe', type: 'tool', icon: 'pick', quality: 'wood' } as Item,
|
||||||
{ name: 'Wooden Sword', type: 'tool', icon: 'sword', quality: 'wood' },
|
tool_sword_wood: { id: 'tool_sword_wood', name: 'Wooden Sword', type: 'tool', icon: 'sword', quality: 'wood' } as Item,
|
||||||
|
|
||||||
{ name: 'Iron Shovel', type: 'tool', icon: 'shovel', quality: 'iron' },
|
tool_shovel_iron: { id: 'tool_shovel_iron', name: 'Iron Shovel', type: 'tool', icon: 'shovel', quality: 'iron' } as Item,
|
||||||
{ name: 'Iron Pick Axe', type: 'tool', icon: 'pick', quality: 'iron' },
|
tool_pickaxe_iron: { id: 'tool_pickaxe_iron', name: 'Iron Pick Axe', type: 'tool', icon: 'pick', quality: 'iron' } as Item,
|
||||||
{ name: 'Iron Sword', type: 'tool', icon: 'sword', quality: 'iron' },
|
tool_sword_iron: { id: 'tool_sword_iron', name: 'Iron Sword', type: 'tool', icon: 'sword', quality: 'iron' } as Item,
|
||||||
|
|
||||||
{ name: 'Diamond Shovel', type: 'tool', icon: 'shovel', quality: 'diamond' },
|
tool_shovel_diamond: { id: 'tool_shovel_diamond', name: 'Diamond Shovel', type: 'tool', icon: 'shovel', quality: 'diamond' } as Item,
|
||||||
{ name: 'Diamond Pick Axe', type: 'tool', icon: 'pick', quality: 'diamond' },
|
tool_pickaxe_diamond: { id: 'tool_pickaxe_diamond', name: 'Diamond Pick Axe', type: 'tool', icon: 'pick', quality: 'diamond' } as Item,
|
||||||
{ name: 'Diamond Sword', type: 'tool', icon: 'sword', quality: 'diamond' },
|
tool_sword_diamond: { id: 'tool_sword_diamond', name: 'Diamond Sword', type: 'tool', icon: 'sword', quality: 'diamond' } as Item,
|
||||||
|
|
||||||
{ name: 'Wooden Shovel', type: 'tool', icon: 'shovel', quality: 'wood' },
|
block_leaves: { id: 'block_leaves', name: 'leaves', type: 'block', icon: 'leaves', builds: 'treeLeaves' } as Item,
|
||||||
{ name: 'Wooden Pick Axe', type: 'tool', icon: 'pick', quality: 'wood' },
|
block_dirt: { id: 'block_dirt', name: 'dirt', type: 'block', icon: 'dirt', builds: 'soil' } as Item,
|
||||||
{ name: 'Wooden Sword', type: 'tool', icon: 'sword', quality: 'wood' },
|
block_wood: { id: 'block_wood', name: 'wood', type: 'block', icon: 'wood', builds: 'treeTrunk' } as Item,
|
||||||
|
block_stone: { id: 'block_stone', name: 'stone', type: 'block', icon: 'stone', builds: 'brickWall' } as Item,
|
||||||
|
block_gravel: { id: 'block_gravel', name: 'gravel', type: 'block', icon: 'stone' /*, builds??? TODO */ } as Item,
|
||||||
|
|
||||||
{ name: 'leaves', type: 'block', icon: 'leaves', builds: 'treeLeaves' },
|
ore_coal: { id: 'ore_coal', name: 'coal', type: 'ore', icon: 'ore_coal' } as Item,
|
||||||
{ name: 'dirt', type: 'block', icon: 'dirt', builds: 'soil' },
|
ore_iron: { id: 'ore_iron', name: 'iron', type: 'ore', icon: 'ore_iron' } as Item,
|
||||||
{ name: 'wood', type: 'block', icon: 'wood', builds: 'treeTrunk' },
|
ore_silver: { id: 'ore_silver', name: 'silver', type: 'ore', icon: 'ore_silver' } as Item,
|
||||||
{ name: 'stone', type: 'block', icon: 'stone', builds: 'brickWall' },
|
ore_gold: { id: 'ore_gold', name: 'gold', type: 'ore', icon: 'ore_gold' } as Item,
|
||||||
{ name: 'gravel', type: 'block', icon: 'stone' }, // TODO
|
ore_ruby: { id: 'ore_ruby', name: 'ruby', type: 'ore', icon: 'ore_ruby' } as Item,
|
||||||
|
ore_diamond: { id: 'ore_diamond', name: 'diamond', type: 'ore', icon: 'ore_diamond' } as Item,
|
||||||
|
ore_emerald: { id: 'ore_emerald', name: 'emerald', type: 'ore', icon: 'ore_emerald' } as Item,
|
||||||
|
} as const
|
||||||
|
|
||||||
{ name: 'coal', type: 'ore', icon: 'ore_coal' },
|
export type ItemId = keyof typeof items
|
||||||
{ name: 'iron', type: 'ore', icon: 'ore_iron' },
|
|
||||||
{ name: 'silver', type: 'ore', icon: 'ore_silver' },
|
|
||||||
{ name: 'gold', type: 'ore', icon: 'ore_gold' },
|
|
||||||
{ name: 'ruby', type: 'ore', icon: 'ore_ruby' },
|
|
||||||
{ name: 'diamond', type: 'ore', icon: 'ore_diamond' },
|
|
||||||
{ name: 'emerald', type: 'ore', icon: 'ore_emerald' },
|
|
||||||
]
|
|
||||||
|
|
||||||
export const damage: Record<ItemQuality, number> = {
|
export const damage: Record<ItemQuality, number> = {
|
||||||
wood: 1,
|
wood: 1,
|
||||||
iron: 3,
|
iron: 3,
|
||||||
diamond: 5,
|
diamond: 5,
|
||||||
}
|
} as const
|
||||||
|
|
||||||
export function getItem(name: string, quality?: ItemQuality) {
|
export function getItem(id: ItemId) {
|
||||||
const item = items.find(i => i.name === name)
|
return items[id]
|
||||||
if (item) {
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
quality,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getItemClass(item: InventoryItem) {
|
export function getItemClass(item: InventoryItem) {
|
||||||
|
|
18
src/types.d.ts
vendored
18
src/types.d.ts
vendored
|
@ -1,15 +1,10 @@
|
||||||
|
import type { ItemId } from './level/items'
|
||||||
export type ItemQuality = 'wood' | 'iron' | 'diamond'
|
export type ItemQuality = 'wood' | 'iron' | 'diamond'
|
||||||
export type ItemType = 'tool' | 'block' | 'ore'
|
export type ItemType = 'tool' | 'block' | 'ore'
|
||||||
|
|
||||||
export type DropItem =
|
|
||||||
| 'Wooden Shovel' | 'Iron Shovel' | 'Diamond Shovel'
|
|
||||||
| 'Wooden Pick Axe' | 'Iron Pick Axe' | 'Diamond Pick Axe'
|
|
||||||
| 'Wooden Sword' | 'Iron Sword' | 'Diamond Sword'
|
|
||||||
| 'leaves' | 'dirt' | 'wood' | 'stone' | 'gravel'
|
|
||||||
| 'coal' | 'iron' | 'silver' | 'gold' | 'ruby' | 'diamond' | 'emerald'
|
|
||||||
|
|
||||||
export interface Item {
|
export interface Item {
|
||||||
name: DropItem
|
id: string
|
||||||
|
name: string
|
||||||
type: ItemType
|
type: ItemType
|
||||||
icon: string
|
icon: string
|
||||||
quality?: ItemQuality
|
quality?: ItemQuality
|
||||||
|
@ -28,8 +23,9 @@ export interface BlockItem extends Item {
|
||||||
|
|
||||||
export type BlockType =
|
export type BlockType =
|
||||||
| 'air' | 'grass'
|
| 'air' | 'grass'
|
||||||
| 'treeCrown' | 'treeLeaves' | 'treeTrunk' | 'treeRoot' | 'treeRootRight' | 'treeRootMiddle' | 'treeRootLeft'
|
| 'treeCrown' | 'treeLeaves' | 'treeTrunk' | 'treeRoot'
|
||||||
| 'soil' | 'soilGravel' | 'stone' | 'stoneGravel'
|
| 'soil' | 'soilGravel'
|
||||||
|
| 'stone' | 'stoneGravel'
|
||||||
| 'bedrock' | 'cave'
|
| 'bedrock' | 'cave'
|
||||||
| 'brickWall'
|
| 'brickWall'
|
||||||
|
|
||||||
|
@ -40,7 +36,7 @@ export type Block = {
|
||||||
climbable?: boolean, // can I climb it?
|
climbable?: boolean, // can I climb it?
|
||||||
transparent?: boolean, // can I see through it?
|
transparent?: boolean, // can I see through it?
|
||||||
illuminated?: boolean, // is it glowing?
|
illuminated?: boolean, // is it glowing?
|
||||||
drops?: DropItem, // what do I get, when loot it?
|
drops?: ItemId, // what do I get, when loot it?
|
||||||
}
|
}
|
||||||
|
|
||||||
// describes a changed block, eg digged or placed by the player
|
// describes a changed block, eg digged or placed by the player
|
||||||
|
|
Loading…
Add table
Reference in a new issue