Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
update calculate target aim
Browse files Browse the repository at this point in the history
  • Loading branch information
claustra01 committed Aug 11, 2024
1 parent 258dbdf commit 35adec0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/pages/yatai/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
} from "three";
import { randFloat } from "three/src/math/MathUtils.js";
import { useSocketRefStore } from "../../store";
import type { ActionSchema, PointerSchema, Target } from "../../type/shooting";
import { MessageType, type ActionSchema, type PointerSchema, type Target } from "../../type/shooting";
import styles from "./index.module.css";

function Yatai() {
Expand All @@ -20,10 +20,10 @@ function Yatai() {
const onMessage = (event: MessageEvent) => {
const data = JSON.parse(event.data);
// サーバーから受け取ったデータを使った処理
if (data.event_type === "pointer") {
if (data.message_type === MessageType.Pointer) {
aimTarget(data);
}
if (data.event_type === "action") {
if (data.message_type === MessageType.Action) {
shotTarget(data);
}
};
Expand All @@ -37,7 +37,9 @@ function Yatai() {
// TODO: これらは一人用,いつかマルチプレイヤー対応する
const [aim, setAim] = useState<Target | undefined>(undefined);
const aimTarget = (data: PointerSchema) => {
setAim(data.target);
let x = window.innerWidth / 2 * data.target.x - window.innerWidth / 2;
let y = window.innerHeight / 2 * data.target.y - window.innerHeight / 2;
setAim({ x, y });
};

const [target, setTarget] = useState<Target | undefined>(undefined);
Expand Down
6 changes: 3 additions & 3 deletions src/type/shooting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum EventType {
export enum MessageType {
Pointer = "pointer",
Action = "action",
}
Expand All @@ -16,13 +16,13 @@ export interface Vector {

export interface PointerSchema {
id: string;
event_type: EventType.Pointer;
message_type: MessageType.Pointer;
target: Target;
}

export interface ActionSchema {
id: string;
event_type: EventType.Action;
message_type: MessageType.Action;
target: Target;
vector: Vector;
}

0 comments on commit 35adec0

Please sign in to comment.