Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified invaders.app/Contents/MacOS/invaders
Binary file not shown.
3 changes: 2 additions & 1 deletion invaders.app/Contents/MacOS/public/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
body {
background-image: url("/public/images/start.png");
background-repeat: no-repeat;
background-size: 100%;
}
</style>
<script src="/public/js/jquery-3.3.1.min.js"></script>
Expand All @@ -19,4 +20,4 @@
});
</script>
</head>
</html>
</html>
5 changes: 3 additions & 2 deletions invaders.app/Contents/MacOS/public/html/invaders.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
body {
background-image: url("/public/images/background.jpg");
background-repeat: no-repeat;
background-size: 100%;
margin: 0;
}
</style>
Expand All @@ -25,6 +26,6 @@
</script>
</head>
<body>
<img id="image" src="" style="display: block;"/>
<img id="image" src="" style="display: block; width: 100%; height: 100%"/>
</body>
</html>
</html>
6 changes: 4 additions & 2 deletions invaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var bombSpeed = 10
// sprites
var sprites image.Image
var background image.Image
var backgroundWidth int
var backgroundHeight int
var cannonSprite = image.Rect(20, 47, 38, 59)
var cannonExplode = image.Rect(0, 47, 16, 57)
var alien1Sprite = image.Rect(0, 0, 20, 14)
Expand Down Expand Up @@ -123,7 +125,7 @@ func generateFrames() {
}

// create background
dst := image.NewRGBA(image.Rect(0, 0, windowWidth, windowHeight))
dst := image.NewRGBA(image.Rect(0, 0, backgroundWidth, backgroundHeight))
gift.New().Draw(dst, background)

// process aliens
Expand Down Expand Up @@ -170,7 +172,7 @@ func generateFrames() {
}

// move the aliens back and forth
if aliens[0].Position.X < alienSize || aliens[aliensPerRow-1].Position.X > windowWidth-(2*alienSize) {
if aliens[0].Position.X < alienSize || aliens[aliensPerRow-1].Position.X > backgroundWidth-(2*alienSize) {
alienDirection = alienDirection * -1
for i := 0; i < len(aliens); i++ {
aliens[i].Position.Y = aliens[i].Position.Y + 10
Expand Down
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"encoding/base64"
"flag"
"fmt"
"html/template"
"image"
Expand Down Expand Up @@ -46,18 +47,25 @@ func init() {
gameDelay = 20 // 20 ms delay
sprites = getImage(dir + "/public/images/sprites.png") // spritesheet
background = getImage(dir + "/public/images/bg.png") // background image
backgroundWidth = background.Bounds().Size().X
backgroundHeight = background.Bounds().Size().Y
}

// main function
func main() {
flag.IntVar(&windowWidth, "width", windowWidth, "Window width")
flag.IntVar(&windowHeight, "height", windowHeight, "Window height")
resize := flag.Bool("resize", true, "resizable")
flag.Parse()

// channel to get the web prefix
prefixChannel := make(chan string)
// run the web server in a separate goroutine
go app(prefixChannel)
prefix := <- prefixChannel
prefix := <-prefixChannel
// create a web view
err := webview.Open("Space Invaders", prefix + "/public/html/index.html",
windowWidth, windowHeight, false)
err := webview.Open("Space Invaders", prefix+"/public/html/index.html",
windowWidth, windowHeight, *resize)
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion public/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
body {
background-image: url("/public/images/start.png");
background-repeat: no-repeat;
background-size: 100%;
}
</style>
<script src="/public/js/jquery-3.3.1.min.js"></script>
Expand All @@ -19,4 +20,4 @@
});
</script>
</head>
</html>
</html>
5 changes: 3 additions & 2 deletions public/html/invaders.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
body {
background-image: url("/public/images/background.jpg");
background-repeat: no-repeat;
background-size: 100%;
margin: 0;
}
</style>
Expand All @@ -25,6 +26,6 @@
</script>
</head>
<body>
<img id="image" src="" style="display: block;"/>
<img id="image" src="" style="display: block; width: 100%; height: 100%"/>
</body>
</html>
</html>