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 @@
server.* server.*
.env .env
./tmp/

2
internal/handlers/auth.go

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

21
main.go

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

54
static/script.js

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

2
tmp/build-errors.log

@ -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 @@
- fix sending empty messages - fix sending empty messages
- hit points
- death - death
- weapons from channel point - weapons from channel point
- - https://dev.twitch.tv/docs/eventsub/ - - https://dev.twitch.tv/docs/eventsub/
- jetpack - jetpack
- remap wasd
- allow users to set their own keybindings
- map attack to mouse click as well

Loading…
Cancel
Save