pong bats working with css tailwind updates
This commit is contained in:
parent
1da4ae9c4c
commit
7571927097
5 changed files with 141 additions and 84 deletions
|
|
@ -76,8 +76,11 @@ declare module 'fastify' {
|
|||
io: Server<{
|
||||
inviteGame: (data: ClientProfil) => void;
|
||||
message: (msg: string) => void;
|
||||
pong_bat_left: (direction: "up" | "down") => void;
|
||||
|
||||
batmove_Left: (direction: "up" | "down") => void;
|
||||
batmove_Right: (direction: "up" | "down") => void;
|
||||
batLeft_update: (y:number) => void;
|
||||
batRight_update: (y:number) => void;
|
||||
MsgObjectServer: (data: { message: ClientMessage }) => void;
|
||||
}>;
|
||||
}
|
||||
}
|
||||
|
|
@ -92,30 +95,60 @@ async function onReady(fastify: FastifyInstance) {
|
|||
console.log(color.yellow, 'Connect at : https://' + machineName + ':8888/app/login');
|
||||
}
|
||||
|
||||
let batY = 185; // shared bat position
|
||||
const SPEED = 10;
|
||||
|
||||
const SPEED = 20; // bat speed
|
||||
const BOTTOM_EDGE = 370; // bottom edge of the field;
|
||||
const TOP_EDGE = 0; // top edge of the field
|
||||
const START_POS_Y = 178; // bat y in the middle of the field
|
||||
let batLeft = START_POS_Y; //shared bat position
|
||||
let batRight = START_POS_Y; //shared bat position
|
||||
|
||||
fastify.io.on('connection', (socket: Socket) => {
|
||||
|
||||
socket.emit("batLeft_update", batLeft);
|
||||
socket.emit("batRight_update", batRight);
|
||||
|
||||
socket.emit("bat:update", batY);
|
||||
|
||||
socket.on('bat:move', (direction: "up" | "down") => {
|
||||
socket.on('batmove_Left', (direction: "up" | "down") => {
|
||||
if (direction === "up") {
|
||||
batY -= SPEED;
|
||||
batLeft -= SPEED;
|
||||
console.log('w pressed UP');
|
||||
}
|
||||
if (direction === "down") {
|
||||
console.log('s pressed DOWN');
|
||||
|
||||
batY += SPEED;
|
||||
batLeft += SPEED;
|
||||
}
|
||||
// clamp inside field
|
||||
batY = Math.max(0, Math.min(370, batY));
|
||||
// position of bat leftplokoplpl
|
||||
batLeft = Math.max(TOP_EDGE, Math.min(BOTTOM_EDGE, batLeft));
|
||||
|
||||
socket.emit("bat:update", batY);
|
||||
console.log('batLeft_update is called y:',batLeft);
|
||||
|
||||
socket.emit("batLeft_update", batLeft);
|
||||
});
|
||||
|
||||
socket.on('batmove_Right', (direction: "up" | "down") => {
|
||||
if (direction === "up") {
|
||||
batRight -= SPEED;
|
||||
console.log('p pressed UP');
|
||||
}
|
||||
if (direction === "down") {
|
||||
console.log('l pressed DOWN');
|
||||
|
||||
batRight += SPEED;
|
||||
}
|
||||
// position of bat left
|
||||
batRight = Math.max(TOP_EDGE, Math.min(BOTTOM_EDGE, batRight));
|
||||
|
||||
console.log('batRight_update is called y:',batRight);
|
||||
|
||||
socket.emit("batRight_update", batRight);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
socket.on('message', (message: string) => {
|
||||
const obj: ClientMessage = JSON.parse(message) as ClientMessage;
|
||||
clientChat.set(socket.id, { user: obj.user, lastSeen: Date.now() });
|
||||
|
|
|
|||
|
|
@ -22,13 +22,24 @@ const route: FastifyPluginAsync = async (fastify): Promise<void> => {
|
|||
config: { requireAuth: false },
|
||||
},
|
||||
async function(req, res) {
|
||||
broadcast(this, { command: '', destination: '', user: 'CMwaLeSever!!', text: req.body.message, SenderWindowID: 'server' });
|
||||
broadcast(this, { command: '', destination: 'system-info', user: 'CMwaLeSever!!', text: req.body.message, SenderWindowID: 'server' });
|
||||
void res;
|
||||
},
|
||||
);
|
||||
};
|
||||
export default route;
|
||||
|
||||
/**
|
||||
*
|
||||
* try this in a terminal
|
||||
*
|
||||
* curl -k --data-raw '{"message": "Message SENT from the terminal en REMOTE"}' 'https://local.maix.me:8888/api/pong/broadcast' -H "Content-Type: application/json"
|
||||
*
|
||||
* send message info to the fronatend via the route '/api/pong/broadcast'
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
// const route: FastifyPluginAsync = async (fastify): Promise<void> => {
|
||||
// fastify.post('/api/chat/broadcast', {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue