diff options
| -rw-r--r-- | data/recipes.ts | 8 | ||||
| -rw-r--r-- | test-client/main.ts | 11 | ||||
| -rw-r--r-- | test-client/protocol.ts | 2 | ||||
| -rw-r--r-- | test-client/visual.ts | 6 | 
4 files changed, 17 insertions, 10 deletions
| diff --git a/data/recipes.ts b/data/recipes.ts index 534f1e6d..1c384f14 100644 --- a/data/recipes.ts +++ b/data/recipes.ts @@ -40,13 +40,13 @@ function cook(from: string, to?: string) {      const i = from + "-pot"      const o = (to ?? ("cooked-" + from)) + "-pot"      out({ action: "instant", inputs: ["pot", from], outputs: [i] }) -    out({ action: "passive", duration: 10, tile: "stove", inputs: [i], outputs: [o] }) -    out({ action: "passive", duration: 10, tile: "stove", inputs: [o], outputs: ["burned-pot"], warn: true }) +    out({ action: "passive", duration: 20, tile: "stove", inputs: [i], outputs: [o] }) +    out({ action: "passive", duration: 5, tile: "stove", inputs: [o], outputs: ["burned-pot"], warn: true })  }  function bake(from: string, to?: string) {      const o = (to ?? ("cooked-" + from)) -    out({ action: "passive", duration: 20, tile: "oven", inputs: [from], outputs: [o] }) -    out({ action: "passive", duration: 20, tile: "oven", inputs: [o], outputs: ["burned"], warn: true }) +    out({ action: "passive", duration: 25, tile: "oven", inputs: [from], outputs: [o] }) +    out({ action: "passive", duration: 15, tile: "oven", inputs: [o], outputs: ["burned"], warn: true })  }  function crate(item: string) {      out({ action: "instant", tile: item + "-crate", inputs: [], outputs: [item], }) diff --git a/test-client/main.ts b/test-client/main.ts index a3d5d2f2..eeb9d9c0 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -1,7 +1,7 @@  /// <reference lib="dom" />  import { Gamedata, ItemIndex, Message, PacketC, PacketS, PlayerID, TileIndex } from "./protocol.ts"; -import { V2, add_v2, length, lerp_exp_v2_mut, normalize, aabb_circle_distance, sub_v2 } from "./util.ts"; +import { V2, add_v2, length, lerp_exp_v2_mut, normalize, aabb_circle_distance, sub_v2, lerp_exp } from "./util.ts";  import { draw_ingame, draw_wait } from "./visual.ts";  export const PLAYER_SIZE = 0.4; @@ -67,12 +67,13 @@ export const players = new Map<PlayerID, PlayerData>()  export const tiles = new Map<string, TileData>()  export const items_removed = new Set<ItemData>() -export let data: Gamedata = { item_names: [], tile_names: [], spawn: [0, 0] } +export let data: Gamedata = { item_names: [], tile_names: [], spawn: [0, 0], tile_collide: [], tile_interact: [] }  let my_id: PlayerID = -1  export const camera: V2 = { x: 0, y: 0 }  export const interact_target_anim: V2 = { x: 0, y: 0 } +export let interact_possible_anim: number = 0  let interacting: V2 | undefined;  function send(p: PacketS) { ws.send(JSON.stringify(p)) } @@ -227,8 +228,12 @@ function frame_update(dt: number) {      }      remove.forEach(i => items_removed.delete(i)) -    lerp_exp_v2_mut(interact_target_anim, get_interact_target() ?? { x: 0, y: 0 }, dt * 15.)      lerp_exp_v2_mut(camera, p, dt * 10.) + +    const it = get_interact_target() ?? { x: 0, y: 0 }; +    const possible = data.tile_interact[tiles.get([it.x, it.y].toString())?.kind ?? 0] ?? false +    lerp_exp_v2_mut(interact_target_anim, it, dt * 15.) +    interact_possible_anim = lerp_exp(interact_possible_anim, +possible, dt * 18.)  }  function resize() { diff --git a/test-client/protocol.ts b/test-client/protocol.ts index 746a83e8..f075852e 100644 --- a/test-client/protocol.ts +++ b/test-client/protocol.ts @@ -6,6 +6,8 @@ export type TileIndex = number  export interface Gamedata {      item_names: string[], // Look-up table for ItemIndex      tile_names: string[], // Look-up table for TileIndex +    tile_collide: boolean[], // Look-up table for TileIndex to check tile collision with players +    tile_interact: boolean[], // Look-up table for TileIndex to check if a tile is interactable      spawn: Vec2, // Where players spawn when they join.  } diff --git a/test-client/visual.ts b/test-client/visual.ts index 37ae732d..4d7468eb 100644 --- a/test-client/visual.ts +++ b/test-client/visual.ts @@ -1,4 +1,4 @@ -import { ItemData, PLAYER_SIZE, camera, canvas, ctx, data, get_interact_target, interact_target_anim, items_removed, keys_down, players, tiles } from "./main.ts"; +import { ItemData, PLAYER_SIZE, camera, canvas, ctx, data, get_interact_target, interact_possible_anim, interact_target_anim, items_removed, keys_down, players, tiles } from "./main.ts";  import { Message } from "./protocol.ts";  import { FALLBACK_TILE, ITEMS, TILES, FALLBACK_ITEM } from "./tiles.ts";  import { V2, ceil_v2, floor_v2 } from "./util.ts"; @@ -103,8 +103,8 @@ function draw_interact_target() {      ctx.lineCap = "round"      ctx.lineJoin = "round" -    ctx.lineWidth = 0.06 + 0.03 * Math.sin(Date.now() / 100) -    ctx.strokeStyle = "rgb(84, 122, 236)" +    ctx.lineWidth = 0.06 + 0.03 * Math.sin(Date.now() / 100) * interact_possible_anim +    ctx.strokeStyle = `hsla(225, ${interact_possible_anim * 100}%, 62.70%, ${interact_possible_anim * 0.7 + 0.3})`      ctx.strokeRect(0, 0, 1, 1)      ctx.restore() | 
