16 Commits

Author SHA1 Message Date
a754319374 Merge pull request 'core: reorganize some pieces for the future' (#10) from reorganize into main
Reviewed-on: Trianta/trianta.dev#10
2024-11-16 19:12:30 -06:00
Trianta
4aeed537d7 core: update package to v0.2.2 2024-11-16 19:01:52 -06:00
Trianta
f725b4e922 core: propagate changes throughout files 2024-11-16 02:45:38 -06:00
Trianta
8252f38bb7 core: move home page css to root and rename 2024-11-16 02:38:15 -06:00
Trianta
e4d9afdd68 pong: remove unused css file 2024-11-16 02:32:58 -06:00
Trianta
90c868d9e9 docker: add healthcheck 2024-11-09 04:37:30 -06:00
Trianta
452c35c1b0 snake: slightly increase speed 2024-11-09 03:18:42 -06:00
Trianta
9dea6014fe snake: remove dealt with comments 2024-11-09 02:57:12 -06:00
Trianta
e37d737d3a snake: decrease speed again 2024-11-09 02:50:24 -06:00
Trianta
65c7b930e3 meta: update package.json 2024-11-09 02:38:08 -06:00
Trianta
082176d75e snake: revert speed back 2024-11-09 02:32:14 -06:00
Trianta
18673c95c4 snake: decrease speed slightly more 2024-11-09 02:25:16 -06:00
Trianta
cb52bd1561 snake: slightly decrease game speed 2024-11-09 02:09:06 -06:00
0c196e690f Merge pull request 'snake: add some misc tweaks to game and page' (#8) from snake into main
Reviewed-on: Trianta/trianta.dev#8
2024-11-09 01:42:25 -06:00
Trianta
532d8a480c snake: decrease timeout to make it faster 2024-11-09 01:39:46 -06:00
Trianta
92cfd954c1 snake: display information about game in stats 2024-11-09 01:39:16 -06:00
7 changed files with 24 additions and 43 deletions
+4 -2
View File
@@ -1,6 +1,6 @@
FROM nginx:latest FROM nginx:latest
RUN apt-get update && apt-get install -y nodejs npm RUN apt-get update && apt-get install -y nodejs npm netcat-openbsd
WORKDIR /app WORKDIR /app
@@ -14,10 +14,12 @@ RUN npm run build
WORKDIR /usr/share/nginx/html WORKDIR /usr/share/nginx/html
COPY index.html . COPY index.html .
COPY default.css .
RUN mkdir -p /usr/share/nginx/html/public RUN mkdir -p /usr/share/nginx/html/public
COPY src/*.css ./public
RUN cp /app/build/* ./public RUN cp /app/build/* ./public
HEALTHCHECK CMD nc -z 127.0.0.1 80
EXPOSE 80 EXPOSE 80
View File
+3 -2
View File
@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"/> <meta charset="utf-8"/>
<title>Trianta</title> <title>Trianta</title>
<link rel="stylesheet" href="public/home.css" /> <link rel="stylesheet" href="default.css" />
</head> </head>
<body> <body>
<div id="navigation"> <div id="navigation">
@@ -30,7 +30,8 @@
<h2 class="cardTop">Snake</h2> <h2 class="cardTop">Snake</h2>
<canvas width="625" height="375" id="snake"></canvas> <canvas width="625" height="375" id="snake"></canvas>
<script src="public/snake.js"></script> <script src="public/snake.js"></script>
<p class="cardStats">Bottom Text<span></span></p> <p class="cardStats">Snake Head Location: <span id="snakeHead"></span></p>
<p class="cardStats">Food Location: <span id="snakeFood"></span></p>
<a class="navItem" href="https://lab.trianta.dev/Trianta/trianta.dev/src/branch/main/src/snake.ts">View Code</a> <a class="navItem" href="https://lab.trianta.dev/Trianta/trianta.dev/src/branch/main/src/snake.ts">View Code</a>
</div> </div>
</div> </div>
+5 -5
View File
@@ -1,21 +1,21 @@
{ {
"name": "trianta.dev", "name": "trianta.dev",
"version": "0.1.0", "version": "0.2.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "trianta.dev", "name": "trianta.dev",
"version": "0.1.0", "version": "0.2.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"typescript": "^5.5.4" "typescript": "^5.5.4"
} }
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "5.5.4", "version": "5.6.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz",
"integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==",
"license": "Apache-2.0", "license": "Apache-2.0",
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "trianta.dev", "name": "trianta.dev",
"version": "0.1.0", "version": "0.2.2",
"description": "My personal website", "description": "My personal website",
"main": "index.html", "main": "index.html",
"scripts": { "scripts": {
-23
View File
@@ -1,23 +0,0 @@
html, body {
height: 100%;
margin: 0;
}
body {
background: black;
display: flex;
align-items: center;
justify-content: center;
}
.button {
background: blue;
color: white;
padding: 15px 20px;
font-size: 32px;
font-family: Arial, Helvetica, sans-serif;
text-transform: uppercase;
cursor: pointer;
position: relative;
}
+11 -10
View File
@@ -55,21 +55,22 @@ class SnakeCore {
height: number; height: number;
board: number[][]; board: number[][];
body: Point[]; body: Point[];
food: Point;
gameover: boolean; gameover: boolean;
foodAte: boolean; foodAte: boolean;
constructor() { constructor() {
// TODO: Add CSS stuff for page
this.canvas = document.getElementById('snake') as HTMLCanvasElement; this.canvas = document.getElementById('snake') as HTMLCanvasElement;
this.context = this.canvas.getContext('2d') as CanvasRenderingContext2D; this.context = this.canvas.getContext('2d') as CanvasRenderingContext2D;
this.grid = 25; // size of grid squares this.grid = 25; // size of grid squares
this.timeout = 100; // speed in ms this.timeout = 32; // speed in ms
this.width = 25; this.width = 25;
this.height = 15; this.height = 15;
this.board = []; this.board = [];
for (let i = 0; i < this.height; i++) for (let i = 0; i < this.height; i++)
this.board.push(new Array(this.width)); this.board.push(new Array(this.width));
this.body = []; this.body = [];
this.food = new Point();
this.gameover = false; this.gameover = false;
this.foodAte = true; this.foodAte = true;
this.body.push(new Point(12, 8)); this.body.push(new Point(12, 8));
@@ -112,6 +113,7 @@ class SnakeCore {
if (isBitSet(this.board[tmp.y][tmp.x], BoardState.SNAKE)) if (isBitSet(this.board[tmp.y][tmp.x], BoardState.SNAKE))
continue; continue;
this.board[tmp.y][tmp.x] = bitSet(this.board[tmp.y][tmp.x], BoardState.FOOD); this.board[tmp.y][tmp.x] = bitSet(this.board[tmp.y][tmp.x], BoardState.FOOD);
this.food.copy(tmp);
return; return;
} }
} }
@@ -161,6 +163,12 @@ class SnakeCore {
} }
} }
} }
// Update text on page to match game
updatePageText() {
document.getElementById("snakeHead").innerHTML = "x: " + this.body[this.body.length - 1].x + " y: " + this.body[this.body.length - 1].y;
document.getElementById("snakeFood").innerHTML = "x: " + this.food.x + " y: " + this.food.y ;
}
} }
class Bot { class Bot {
@@ -204,7 +212,6 @@ class Bot {
} }
} }
// TODO: Fix trim function
trim() { trim() {
let reachedSnake = false; let reachedSnake = false;
this.path.push(this.pathUntrimmed.pop() as Point); // Push food location this.path.push(this.pathUntrimmed.pop() as Point); // Push food location
@@ -231,13 +238,6 @@ class Bot {
} }
} }
/*
values:
0 = left
1 = up
2 = right
4 = down
*/
nextMove() { nextMove() {
// Get new path to food // Get new path to food
if (this.path.length === 0) if (this.path.length === 0)
@@ -280,6 +280,7 @@ function snakeloop() {
g_snake.foodRegen(); g_snake.foodRegen();
g_snake.draw(); g_snake.draw();
g_snake.updatePageText();
} }
// start the game // start the game