mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Finale image in car-race
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 298 KiB |
@@ -24,6 +24,12 @@ module.exports = class CarRaceCommand extends Command {
|
|||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
reasonURL: 'https://www.istockphoto.com/vector/side-view-of-a-road-with-a-crash-barrier-roadside-green-meadow-and-clear-blue-sky-gm1081596948-290039955'
|
reasonURL: 'https://www.istockphoto.com/vector/side-view-of-a-road-with-a-crash-barrier-roadside-green-meadow-and-clear-blue-sky-gm1081596948-290039955'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Currituck County',
|
||||||
|
url: 'https://co.currituck.nc.us/',
|
||||||
|
reason: 'Fireworks Image',
|
||||||
|
reasonURL: 'https://co.currituck.nc.us/fireworks/'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'PNGkit',
|
name: 'PNGkit',
|
||||||
url: 'https://www.pngkit.com/',
|
url: 'https://www.pngkit.com/',
|
||||||
@@ -90,6 +96,12 @@ module.exports = class CarRaceCommand extends Command {
|
|||||||
url: 'https://codepen.io/natefr0st',
|
url: 'https://codepen.io/natefr0st',
|
||||||
reason: 'Mario Car Image',
|
reason: 'Mario Car Image',
|
||||||
reasonURL: 'https://codepen.io/natefr0st/pen/GrMrZV'
|
reasonURL: 'https://codepen.io/natefr0st/pen/GrMrZV'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'zekewhipper',
|
||||||
|
url: 'https://www.deviantart.com/zekewhipper',
|
||||||
|
reason: 'Mach 5 Car Image',
|
||||||
|
reasonURL: 'https://www.deviantart.com/zekewhipper/art/Mach-5-My-Version-112814534'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
args: [
|
args: [
|
||||||
@@ -137,16 +149,13 @@ module.exports = class CarRaceCommand extends Command {
|
|||||||
max: 1,
|
max: 1,
|
||||||
time: 30000
|
time: 30000
|
||||||
});
|
});
|
||||||
let car2;
|
|
||||||
if (p2Car.size) {
|
if (p2Car.size) {
|
||||||
const choice = p2Car.first().content.toLowerCase();
|
const choice = p2Car.first().content.toLowerCase();
|
||||||
car2 = choice;
|
|
||||||
oppoCar = await loadImage(
|
oppoCar = await loadImage(
|
||||||
path.join(__dirname, '..', '..', 'assets', 'images', 'car-race', 'cars', `${choice}.png`)
|
path.join(__dirname, '..', '..', 'assets', 'images', 'car-race', 'cars', `${choice}.png`)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const chosen = cars[Math.floor(Math.random() * cars.length)];
|
const chosen = cars[Math.floor(Math.random() * cars.length)];
|
||||||
car2 = chosen;
|
|
||||||
oppoCar = await loadImage(
|
oppoCar = await loadImage(
|
||||||
path.join(__dirname, '..', '..', 'assets', 'images', 'car-race', 'cars', `${chosen}.png`)
|
path.join(__dirname, '..', '..', 'assets', 'images', 'car-race', 'cars', `${chosen}.png`)
|
||||||
);
|
);
|
||||||
@@ -156,10 +165,14 @@ module.exports = class CarRaceCommand extends Command {
|
|||||||
let lastRoundWinner;
|
let lastRoundWinner;
|
||||||
let lastTurnTimeout = false;
|
let lastTurnTimeout = false;
|
||||||
while (userCarSpaces < 7 && oppoCarSpaces < 7) {
|
while (userCarSpaces < 7 && oppoCarSpaces < 7) {
|
||||||
const board = this.generateBoard(bg, userCar, oppoCar, userCarSpaces, oppoCarSpaces);
|
const board = await this.generateBoard(bg, userCar, oppoCar, userCarSpaces, oppoCarSpaces);
|
||||||
let text;
|
let text;
|
||||||
if (lastRoundWinner) {
|
if (lastRoundWinner) {
|
||||||
text = `${lastRoundWinner} pulls ahead!`;
|
if (userCarSpaces > oppoCarSpaces || oppoCarSpaces > userCarSpaces) {
|
||||||
|
text = `${lastRoundWinner} pulls ahead!`;
|
||||||
|
} else if (userCarSpaces === oppoCarSpaces) {
|
||||||
|
text = `${lastRoundWinner} ties it up!`;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
text = stripIndents`
|
text = stripIndents`
|
||||||
Welcome to \`car-race\`! Whenever a message pops up, type the word provided.
|
Welcome to \`car-race\`! Whenever a message pops up, type the word provided.
|
||||||
@@ -215,9 +228,10 @@ module.exports = class CarRaceCommand extends Command {
|
|||||||
}
|
}
|
||||||
this.client.games.delete(msg.channel.id);
|
this.client.games.delete(msg.channel.id);
|
||||||
const winner = userCarSpaces > oppoCarSpaces ? msg.author : opponent;
|
const winner = userCarSpaces > oppoCarSpaces ? msg.author : opponent;
|
||||||
const winnerCar = winner.id === msg.author.id ? car : car2;
|
const winnerCar = winner.id === msg.author.id ? userCar : oppoCar;
|
||||||
|
const board = await this.generateBoard(bg, userCar, oppoCar, userCarSpaces, oppoCarSpaces, true, winnerCar);
|
||||||
return msg.say(`Congrats, ${winner}!`, {
|
return msg.say(`Congrats, ${winner}!`, {
|
||||||
files: [path.join(__dirname, '..', '..', 'assets', 'images', 'car-race', 'cars', `${winnerCar}.png`)]
|
files: [{ attachment: board, name: 'car-race-win.png' }]
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.client.games.delete(msg.channel.id);
|
this.client.games.delete(msg.channel.id);
|
||||||
@@ -225,7 +239,7 @@ module.exports = class CarRaceCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateBoard(bg, userCar, oppoCar, userCarSpaces, oppoCarSpaces) {
|
async generateBoard(bg, userCar, oppoCar, userCarSpaces, oppoCarSpaces, win, winnerCar) {
|
||||||
const canvas = createCanvas(bg.width, bg.height);
|
const canvas = createCanvas(bg.width, bg.height);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.drawImage(bg, 0, 0);
|
ctx.drawImage(bg, 0, 0);
|
||||||
@@ -233,6 +247,17 @@ module.exports = class CarRaceCommand extends Command {
|
|||||||
ctx.drawImage(oppoCar, oppoCarX, 208);
|
ctx.drawImage(oppoCar, oppoCarX, 208);
|
||||||
const userCarX = -155 + (92 * userCarSpaces);
|
const userCarX = -155 + (92 * userCarSpaces);
|
||||||
ctx.drawImage(userCar, userCarX, 254);
|
ctx.drawImage(userCar, userCarX, 254);
|
||||||
|
if (win) {
|
||||||
|
const fireworks = await loadImage(
|
||||||
|
path.join(__dirname, '..', '..', 'assets', 'images', 'car-race', 'fireworks.png')
|
||||||
|
);
|
||||||
|
const congrats = await loadImage(
|
||||||
|
path.join(__dirname, '..', '..', 'assets', 'images', 'car-race', 'congrats.png')
|
||||||
|
);
|
||||||
|
ctx.drawImage(fireworks, 106, -48, 400, 283);
|
||||||
|
ctx.drawImage(congrats, 182, 21, 250, 62);
|
||||||
|
ctx.drawImage(winnerCar, 152, 84);
|
||||||
|
}
|
||||||
return canvas.toBuffer();
|
return canvas.toBuffer();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "127.1.0",
|
"version": "127.1.1",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user