Browse Source

creeping, crouching, hit points

main
Stephanie Gredell 5 months ago
parent
commit
af57b63337
  1. 1
      .gitignore
  2. 2
      internal/handlers/auth.go
  3. 21
      main.go
  4. 54
      static/script.js
  5. 2
      tmp/build-errors.log
  6. BIN
      tmp/main
  7. 4
      todo.md

1
.gitignore vendored

@ -1,2 +1,3 @@ @@ -1,2 +1,3 @@
server.*
.env
./tmp/

2
internal/handlers/auth.go

@ -34,7 +34,7 @@ func (h *Handler) Callback(w http.ResponseWriter, r *http.Request) { @@ -34,7 +34,7 @@ func (h *Handler) Callback(w http.ResponseWriter, r *http.Request) {
store := sessions.NewCookieStore([]byte(key))
store.MaxAge(maxAge)
store.Options.Path = "/"
store.Options.HttpOnly = true // HttpOnly should always be enabled
store.Options.HttpOnly = true
store.Options.Secure = isProd
gothic.Store = store

21
main.go

@ -2,7 +2,6 @@ package main @@ -2,7 +2,6 @@ package main
import (
"context"
"flag"
"fmt"
"net/http"
"os"
@ -19,9 +18,6 @@ import ( @@ -19,9 +18,6 @@ import (
)
func main() {
dev := flag.Bool("dev", true, "is this a dev env?")
flag.Parse()
err := godotenv.Load()
if err != nil {
fmt.Printf("error loading .env file: %v", err)
@ -38,6 +34,8 @@ func main() { @@ -38,6 +34,8 @@ func main() {
os.Getenv("TWITCH_CLIENT_ID"),
os.Getenv("TWITCH_SECRET"),
os.Getenv("TWITCH_CALLBACK"),
"channel:read:redemptions",
"channel:manage:redemptions",
),
)
@ -61,16 +59,11 @@ func main() { @@ -61,16 +59,11 @@ func main() {
}
go func() {
if *dev {
fmt.Println("Dev server started...")
if err := server.ListenAndServe(); err != http.ErrServerClosed {
fmt.Printf("Serve error: %v\n", err)
}
} else {
fmt.Println("Server started...")
if err := server.ListenAndServeTLS("server.crt", "server.key"); err != http.ErrServerClosed {
fmt.Printf("Serve error: %v\n", err)
}
fmt.Println("Server started...")
fmt.Println(os.Getenv("TWITCH_CALLBACK"))
if err := server.ListenAndServe(); err != http.ErrServerClosed {
fmt.Printf("Serve error: %v\n", err)
}
}()

54
static/script.js

@ -25,6 +25,8 @@ window.addEventListener("DOMContentLoaded", function() { @@ -25,6 +25,8 @@ window.addEventListener("DOMContentLoaded", function() {
this.isPunching = false;
this.punchHasHit = false;
this.sentJoin = false;
this.hp = 10;
this.isAlive = true;
}
@ -36,6 +38,15 @@ window.addEventListener("DOMContentLoaded", function() { @@ -36,6 +38,15 @@ window.addEventListener("DOMContentLoaded", function() {
this.facing = -1;
}
if (this.crouching && this.keys.l) {
this.speed = 0.5;
this.vx = this.speed;
}
if (this.crouching && this.keys.h) {
this.speed = 0.5;
this.vx = -this.speed;
}
if (this.keys.l) {
this.vx = this.speed;
this.facing = 1;
@ -146,7 +157,7 @@ window.addEventListener("DOMContentLoaded", function() { @@ -146,7 +157,7 @@ window.addEventListener("DOMContentLoaded", function() {
// speech bubble
if (this.talking) {
const padding = 12;
const maxMessageWidth = 150;
const maxMessageWidth = 100;
// set font BEFORE measuring
ctx.font = "12px sans-serif";
@ -155,11 +166,11 @@ window.addEventListener("DOMContentLoaded", function() { @@ -155,11 +166,11 @@ window.addEventListener("DOMContentLoaded", function() {
const textWidth = ctx.measureText(this.message).width;
const widths = lines.map(line => ctx.measureText(line).width);
const contentWidth = Math.max(...widths, textWidth);
const bubbleWidth = Math.min(contentWidth + padding * 2, maxMessageWidth + padding * 2);
const lineHeight = 18;
const bubbleWidth = Math.min(contentWidth + padding + 10, maxMessageWidth + padding + 10);
const lineHeight = 14;
const bubbleHeight = lines.length * lineHeight + padding;
const bubbleX = x - bubbleWidth;
const bubbleY = y - 30;
const bubbleX = x - bubbleWidth - 15;
const bubbleY = y - 20;
ctx.beginPath();
ctx.fillStyle = "white";
@ -180,11 +191,11 @@ window.addEventListener("DOMContentLoaded", function() { @@ -180,11 +191,11 @@ window.addEventListener("DOMContentLoaded", function() {
// name tag
ctx.save();
ctx.font = "14px sans-serif";
ctx.font = "10px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "bottom";
ctx.fillStyle = "black";
ctx.fillText(this.id, x, y - 12);
ctx.fillText(this.id, x, y - 19);
ctx.restore();
}
@ -272,7 +283,11 @@ window.addEventListener("DOMContentLoaded", function() { @@ -272,7 +283,11 @@ window.addEventListener("DOMContentLoaded", function() {
this.leaveBtn = document.getElementById(leaveBtnId);
this.time = 0;
this.players = {};
this.players = {
"player": new StickFigure(10, 1, "player", this.canvas),
"player1": new StickFigure(100, 1, "player1", this.canvas)
};
this.pageData = this._getPageData();
this.ws = null;
@ -362,11 +377,21 @@ window.addEventListener("DOMContentLoaded", function() { @@ -362,11 +377,21 @@ window.addEventListener("DOMContentLoaded", function() {
if (playerAPunch && !playerA.punchHasHit && rectangleOverlap(playerAPunch, playerBBody)) {
playerA.punchHasHit = true;
console.log("Player A hits player B");
playerB.hp -= 1;
if (playerB.hp == 0) {
playerB.isAlive = false;
delete this.players[playerB.id]
}
}
if (playerBPunch && !playerB.punchHasHit && rectangleOverlap(playerBPunch, playerABody)) {
playerB.punchHasHit = true;
console.log("Player B hits player A")
playerA.hp -= 1;
if (playerA.hp == 0) {
playerA.isAlive = false;
delete this.players[playerA.id]
}
}
}
}
@ -400,16 +425,16 @@ window.addEventListener("DOMContentLoaded", function() { @@ -400,16 +425,16 @@ window.addEventListener("DOMContentLoaded", function() {
me.punch()
this._sendAction('e', "keyDown")
break;
case 'w':
case 'k':
me.jump();
this._sendAction('k', "keyDown")
break;
case 's':
case 'j':
me.crouching = true;
this._sendAction('j', 'keyDown')
break;
case 'a':
case 'd':
case 'h':
case 'l':
if (!me.keys) me.keys = {};
if (!me.keys[e.key]) me.keys[e.key] = true;
this._sendAction(e.key, 'keyDown')
@ -431,12 +456,13 @@ window.addEventListener("DOMContentLoaded", function() { @@ -431,12 +456,13 @@ window.addEventListener("DOMContentLoaded", function() {
this.chatInput.focus();
}
if (e.key === 's') {
if (e.key === 'j') {
me.crouching = false;
me.speed = 2;
this._sendAction('j', 'keyUp')
}
if (e.key === 'a' || e.key === 'd') {
if (e.key === 'h' || e.key === 'l') {
if (!me.keys) me.keys = {};
me.keys[e.key] = false;
this._sendAction(e.key, 'keyUp')

2
tmp/build-errors.log

@ -1 +1 @@ @@ -1 +1 @@
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1

BIN
tmp/main

Binary file not shown.

4
todo.md

@ -1,9 +1,5 @@ @@ -1,9 +1,5 @@
- fix sending empty messages
- hit points
- death
- weapons from channel point
- - https://dev.twitch.tv/docs/eventsub/
- jetpack
- remap wasd
- allow users to set their own keybindings
- map attack to mouse click as well

Loading…
Cancel
Save