Skip to content

Commit

Permalink
add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmcallister committed Aug 21, 2021
1 parent 23b7c7f commit ae5f86c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.17-alpine AS build
WORKDIR /go/conway
COPY . .
RUN cp $(go env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
RUN GOOS=js GOARCH=wasm go build -o ./html/main.wasm .

FROM nginx:1.21-alpine
COPY html/nginx /etc/nginx
COPY --from=build /go/conway/html/index.html /go/conway/html/main.wasm /go/conway/html/wasm_exec.js var/www/code.sknk.ws/public/
RUN adduser -u 82 -D -S -G www-data www-data
EXPOSE 80
16 changes: 16 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<script src="wasm_exec.js"></script>
<script>
// Polyfill
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}

const go = new Go();
WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then(result => {
go.run(result.instance);
});
</script>
1 change: 1 addition & 0 deletions html/nginx
Submodule nginx added at f1ee74
36 changes: 35 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ var (
heightFlag = flag.Int("height", 400, "height (in pixels)")
)

type direction int

const (
left direction = iota
right
)

// Doom implements the ebiten.Game interface.
type Doom struct {
width, height int
Expand Down Expand Up @@ -100,6 +107,26 @@ func (d *Doom) spreadFire(src int) {
}
}

func (d *Doom) addWind(dir direction) {
switch dir {
case left:
for x := d.width - 50; x < d.width; x++ {
for y := d.height; y > d.height/4; y-- {
fmt.Println("y: ", y)
dst := y*d.width + x
if dst > len(d.firePixels) {
continue
}
if d.firePixels[dst] != 0 {
d.firePixels[y*d.width+x] = 3
}
}
}
case right:
fmt.Println("right")
}
}

// Update applies the fire spread on each frame.
func (d *Doom) Update() error {
for x := 0; x < d.width; x++ {
Expand All @@ -125,6 +152,13 @@ func (d *Doom) Update() error {
os.Exit(0)
}

if ebiten.IsKeyPressed(ebiten.KeyLeft) {
d.addWind(left)
}
if ebiten.IsKeyPressed(ebiten.KeyRight) {
d.addWind(right)
}

return nil
}

Expand Down Expand Up @@ -155,7 +189,7 @@ func main() {
flag.Parse()
ebiten.SetWindowTitle("DOOM")
ebiten.SetMaxTPS(ebiten.UncappedTPS)
ebiten.SetWindowSize(*widthFlag*2, *heightFlag*2)
ebiten.SetWindowSize(*widthFlag, *heightFlag)
d := NewDoom(*widthFlag, *heightFlag)

if err := ebiten.RunGame(d); err != nil {
Expand Down

0 comments on commit ae5f86c

Please sign in to comment.