Commit 3516fc7d authored by Chunchi Che's avatar Chunchi Che

simpleDuelPlate 10%

parent a91c4476
...@@ -5,10 +5,35 @@ ...@@ -5,10 +5,35 @@
import * as BABYLON from "@babylonjs/core"; import * as BABYLON from "@babylonjs/core";
export const GroundShape = { width: 6, height: 6 }; export const GroundShape = () => {
export const CardSlotShape = { width: 0.5, height: 0.75, depth: 0.05 }; return { width: 6, height: 6 };
export const CardSlotRotation = new BABYLON.Vector3(1.5, 0, 0); };
export const CardSlotShape = () => {
return { width: 0.5, height: 0.75, depth: 0.05 };
};
export const CardSlotRotation = () => {
return new BABYLON.Vector3(1.5, 0, 0);
};
// 手牌 // 手牌
export const HandShape = { width: 0.5, height: 0.75 }; export const HandShape = () => {
export const HandColor = BABYLON.Color3.White(); return { width: 0.5, height: 0.75 };
};
export const HandColor = () => {
return BABYLON.Color3.White();
};
// 怪兽区
export const MonsterColor = () => {
return BABYLON.Color3.Red();
};
// 额外怪兽区
export const extraMonsterColor = () => {
return BABYLON.Color3.Yellow();
};
// 魔法陷阱区
export const MagicColor = () => {
return BABYLON.Color3.Blue();
};
import * as BABYLON from "@babylonjs/core";
import * as CONFIG from "./config";
export default (scene: BABYLON.Scene) => {
const xs = [-1, 1];
for (let i in xs) {
const slot = BABYLON.MeshBuilder.CreateBox(
`extraMonster${i}`,
CONFIG.CardSlotShape(),
scene
);
// 位置
slot.position = new BABYLON.Vector3(xs[i], 0.5, -1);
// 旋转
slot.rotation = CONFIG.CardSlotRotation();
// 材质
const extraMonsterMaterial = new BABYLON.StandardMaterial(
"extraMonsterMaterial",
scene
);
extraMonsterMaterial.diffuseColor = CONFIG.extraMonsterColor();
slot.material = extraMonsterMaterial;
}
};
...@@ -3,24 +3,26 @@ import * as BABYLON from "@babylonjs/core"; ...@@ -3,24 +3,26 @@ import * as BABYLON from "@babylonjs/core";
import * as CONFIG from "./config"; import * as CONFIG from "./config";
export default (hands: Card[], scene: BABYLON.Scene) => { export default (hands: Card[], scene: BABYLON.Scene) => {
const gap = CONFIG.GroundShape.width / hands.length; const groundShape = CONFIG.GroundShape();
const left = -(CONFIG.GroundShape.width / 2); const handShape = CONFIG.HandShape();
const gap = groundShape.width / hands.length;
const left = -(groundShape.width / 2);
hands.forEach((item, idx, _) => { hands.forEach((item, idx, _) => {
const hand = BABYLON.MeshBuilder.CreatePlane( const hand = BABYLON.MeshBuilder.CreatePlane(
`hand${idx}`, `hand${idx}`,
CONFIG.HandShape, handShape,
scene scene
); );
// 位置 // 位置
hand.position = new BABYLON.Vector3( hand.position = new BABYLON.Vector3(
left + gap * idx, left + gap * idx,
CONFIG.HandShape.height / 2, handShape.height / 2,
-(CONFIG.GroundShape.height / 2) - 1 -(groundShape.height / 2) - 1
); );
// 材质 // 材质
const handMaterial = new BABYLON.StandardMaterial("handMaterial", scene); const handMaterial = new BABYLON.StandardMaterial("handMaterial", scene);
// 材质颜色 // 材质颜色
handMaterial.diffuseColor = CONFIG.HandColor; handMaterial.diffuseColor = CONFIG.HandColor();
hand.material = handMaterial; hand.material = handMaterial;
// 事件管理 // 事件管理
hand.actionManager = new BABYLON.ActionManager(scene); hand.actionManager = new BABYLON.ActionManager(scene);
......
import * as BABYLON from "@babylonjs/core";
import * as CONFIG from "./config";
export default (scene: BABYLON.Scene) => {
const left = -2;
const gap = 1;
for (let i = 0; i < 5; i++) {
const slot = BABYLON.MeshBuilder.CreateBox(
`magic${i}`,
CONFIG.CardSlotShape(),
scene
);
// 位置
slot.position = new BABYLON.Vector3(left + gap * i, 0.5, -3);
// 旋转
slot.rotation = CONFIG.CardSlotRotation();
// 材质
const magicMaterial = new BABYLON.StandardMaterial("magicMaterial", scene);
magicMaterial.diffuseColor = CONFIG.MagicColor();
slot.material = magicMaterial;
}
};
...@@ -10,12 +10,12 @@ import React, { useEffect, useRef } from "react"; ...@@ -10,12 +10,12 @@ import React, { useEffect, useRef } from "react";
import type { RootState } from "../../../store"; import type { RootState } from "../../../store";
import * as BABYLON from "@babylonjs/core"; import * as BABYLON from "@babylonjs/core";
import renderHands from "./hands"; import renderHands from "./hands";
import renderMonsters from "./monsters";
import renderExtraMonsters from "./extraMonsters";
import renderMagics from "./magics";
import * as CONFIG from "./config";
// CONFIG // CONFIG
const GroundShape = { width: 6, height: 6 };
const CardSlotShape = { width: 0.5, height: 0.75, depth: 0.05 };
const CardSlotRotation = new BABYLON.Vector3(1.5, 0, 0);
const HandSlotShape = { width: 0.5, height: 0.75 };
export default class SimpleDuelPlateImpl implements IDuelPlate { export default class SimpleDuelPlateImpl implements IDuelPlate {
handsSelector?: TypeSelector<DuelData.Card[]>; handsSelector?: TypeSelector<DuelData.Card[]>;
...@@ -34,26 +34,6 @@ export default class SimpleDuelPlateImpl implements IDuelPlate { ...@@ -34,26 +34,6 @@ export default class SimpleDuelPlateImpl implements IDuelPlate {
// ----- WebGL渲染 ----- // ----- WebGL渲染 -----
const canvasRef = useRef<HTMLCanvasElement>(null); const canvasRef = useRef<HTMLCanvasElement>(null);
const createCardSlot = (
name: string,
position: BABYLON.Vector3,
color: BABYLON.Color3,
scene: BABYLON.Scene
) => {
const cardSlot = BABYLON.MeshBuilder.CreateBox(
name,
CardSlotShape,
scene
);
cardSlot.position = position;
cardSlot.rotation = CardSlotRotation;
const boxMaterail = new BABYLON.StandardMaterial("boxMaterail", scene);
boxMaterail.diffuseColor = color;
cardSlot.material = boxMaterail;
return cardSlot;
};
useEffect(() => { useEffect(() => {
// 初始化Scene // 初始化Scene
const canvasCurrent = canvasRef.current; const canvasCurrent = canvasRef.current;
...@@ -77,83 +57,13 @@ export default class SimpleDuelPlateImpl implements IDuelPlate { ...@@ -77,83 +57,13 @@ export default class SimpleDuelPlateImpl implements IDuelPlate {
); );
light.intensity = 0.7; light.intensity = 0.7;
// 创建魔法陷阱区 // 魔法陷阱区
createCardSlot( renderMagics(scene);
"cardSlot0", // 怪兽区
new BABYLON.Vector3(-2, 0.5, -3), renderMonsters(scene);
BABYLON.Color3.Blue(),
scene
);
createCardSlot(
"cardSlot1",
new BABYLON.Vector3(-1, 0.5, -3),
BABYLON.Color3.Blue(),
scene
);
createCardSlot(
"cardSlot2",
new BABYLON.Vector3(0, 0.5, -3),
BABYLON.Color3.Blue(),
scene
);
createCardSlot(
"cardSlot3",
new BABYLON.Vector3(1, 0.5, -3),
BABYLON.Color3.Blue(),
scene
);
createCardSlot(
"cardSlot4",
new BABYLON.Vector3(2, 0.5, -3),
BABYLON.Color3.Blue(),
scene
);
// 创建怪兽区
createCardSlot(
"cardSlot5",
new BABYLON.Vector3(-2, 0.5, -2),
BABYLON.Color3.Red(),
scene
);
createCardSlot(
"cardSlot6",
new BABYLON.Vector3(-1, 0.5, -2),
BABYLON.Color3.Red(),
scene
);
createCardSlot(
"cardSlot7",
new BABYLON.Vector3(0, 0.5, -2),
BABYLON.Color3.Red(),
scene
);
createCardSlot(
"cardSlot8",
new BABYLON.Vector3(1, 0.5, -2),
BABYLON.Color3.Red(),
scene
);
createCardSlot(
"cardSlot9",
new BABYLON.Vector3(2, 0.5, -2),
BABYLON.Color3.Red(),
scene
);
// 创建额外怪兽区 // 创建额外怪兽区
createCardSlot( renderExtraMonsters(scene);
"cardSlot10",
new BABYLON.Vector3(-1, 0.5, -1),
BABYLON.Color3.Yellow(),
scene
);
createCardSlot(
"cardSlot11",
new BABYLON.Vector3(1, 0.5, -1),
BABYLON.Color3.Yellow(),
scene
);
// 创建手牌 // 创建手牌
renderHands(hands, scene); renderHands(hands, scene);
...@@ -161,7 +71,7 @@ export default class SimpleDuelPlateImpl implements IDuelPlate { ...@@ -161,7 +71,7 @@ export default class SimpleDuelPlateImpl implements IDuelPlate {
// 创建地板 // 创建地板
const ground = BABYLON.MeshBuilder.CreateGround( const ground = BABYLON.MeshBuilder.CreateGround(
"ground", "ground",
GroundShape, CONFIG.GroundShape(),
scene scene
); );
......
import * as BABYLON from "@babylonjs/core";
import * as CONFIG from "./config";
export default (scene: BABYLON.Scene) => {
const left = -2;
const gap = 1;
for (let i = 0; i < 5; i++) {
const slot = BABYLON.MeshBuilder.CreateBox(
`monster${i}`,
CONFIG.CardSlotShape(),
scene
);
// 位置
slot.position = new BABYLON.Vector3(left + gap * i, 0.5, -2);
// 旋转
slot.rotation = CONFIG.CardSlotRotation();
// 材质
const monsterMaterial = new BABYLON.StandardMaterial(
"monsterMaterial",
scene
);
monsterMaterial.diffuseColor = CONFIG.MonsterColor();
slot.material = monsterMaterial;
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment