diff --git a/invaders.app/Contents/MacOS/invaders b/invaders.app/Contents/MacOS/invaders index bf5dbce..65f8515 100755 Binary files a/invaders.app/Contents/MacOS/invaders and b/invaders.app/Contents/MacOS/invaders differ diff --git a/invaders.app/Contents/MacOS/public/html/index.html b/invaders.app/Contents/MacOS/public/html/index.html index 15b9f86..847d513 100644 --- a/invaders.app/Contents/MacOS/public/html/index.html +++ b/invaders.app/Contents/MacOS/public/html/index.html @@ -5,6 +5,7 @@ body { background-image: url("/public/images/start.png"); background-repeat: no-repeat; + background-size: 100%; } @@ -19,4 +20,4 @@ }); - \ No newline at end of file + diff --git a/invaders.app/Contents/MacOS/public/html/invaders.html b/invaders.app/Contents/MacOS/public/html/invaders.html index 08426fb..f3dbb88 100644 --- a/invaders.app/Contents/MacOS/public/html/invaders.html +++ b/invaders.app/Contents/MacOS/public/html/invaders.html @@ -5,6 +5,7 @@ body { background-image: url("/public/images/background.jpg"); background-repeat: no-repeat; + background-size: 100%; margin: 0; } @@ -25,6 +26,6 @@ - + - \ No newline at end of file + diff --git a/invaders.go b/invaders.go index 7ff30b4..f165ac8 100644 --- a/invaders.go +++ b/invaders.go @@ -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) @@ -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 @@ -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 diff --git a/main.go b/main.go index 31226c9..6832fae 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/base64" + "flag" "fmt" "html/template" "image" @@ -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) } diff --git a/public/html/index.html b/public/html/index.html index 15b9f86..847d513 100644 --- a/public/html/index.html +++ b/public/html/index.html @@ -5,6 +5,7 @@ body { background-image: url("/public/images/start.png"); background-repeat: no-repeat; + background-size: 100%; } @@ -19,4 +20,4 @@ }); - \ No newline at end of file + diff --git a/public/html/invaders.html b/public/html/invaders.html index 08426fb..f3dbb88 100644 --- a/public/html/invaders.html +++ b/public/html/invaders.html @@ -5,6 +5,7 @@ body { background-image: url("/public/images/background.jpg"); background-repeat: no-repeat; + background-size: 100%; margin: 0; } @@ -25,6 +26,6 @@ - + - \ No newline at end of file +