Add FPS; Add turning that properly clips
This commit is contained in:
parent
fd504632d1
commit
94f88d9010
58
main.go
58
main.go
@ -2,8 +2,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
_ "image/png"
|
||||
"math"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
@ -58,7 +60,18 @@ func run() {
|
||||
|
||||
player := pixel.NewSprite(spritesheet, shipFrames[0])
|
||||
|
||||
angle := 0.0
|
||||
var angle float64 = 0.0
|
||||
var angleInDegrees float64 = 0
|
||||
|
||||
var (
|
||||
frames = 0
|
||||
second = time.Tick(time.Second)
|
||||
)
|
||||
|
||||
playerX := win.Bounds().Max.X / 2
|
||||
playerY := win.Bounds().Max.Y / 8
|
||||
|
||||
var myVec = pixel.Vec{playerX, playerY}
|
||||
|
||||
last := time.Now()
|
||||
for !win.Closed() {
|
||||
@ -67,21 +80,62 @@ func run() {
|
||||
|
||||
win.Clear(colornames.Whitesmoke)
|
||||
|
||||
myVec = pixel.Vec{playerX, playerY}
|
||||
|
||||
mat := pixel.IM
|
||||
mat = mat.Rotated(pixel.ZV, angle)
|
||||
mat = mat.Scaled(pixel.ZV, 0.25).Moved(win.Bounds().Center())
|
||||
mat = mat.Scaled(pixel.ZV, 0.25)
|
||||
//mat = mat.Moved(win.Bounds().Center())
|
||||
mat = mat.Moved(myVec)
|
||||
|
||||
player.Draw(win, mat)
|
||||
|
||||
if win.Pressed(pixelgl.KeyLeft) {
|
||||
|
||||
//angle += 3 * dt
|
||||
angle += 3 * dt
|
||||
}
|
||||
if win.Pressed(pixelgl.KeyRight) {
|
||||
angle -= 3 * dt
|
||||
|
||||
}
|
||||
if win.Pressed(pixelgl.KeyUp) {
|
||||
playerY += 3 * dt
|
||||
|
||||
}
|
||||
if win.Pressed(pixelgl.KeyDown) {
|
||||
|
||||
}
|
||||
|
||||
if angle == 0 {
|
||||
angleInDegrees = 0
|
||||
} else {
|
||||
|
||||
angleInDegrees = (angle) * 180 / math.Pi
|
||||
}
|
||||
|
||||
if angleInDegrees == 360 || angleInDegrees == -360 {
|
||||
angle = 0
|
||||
}
|
||||
|
||||
if angleInDegrees > 360 {
|
||||
angle = angle - (360*math.Pi)/180
|
||||
}
|
||||
if angleInDegrees < -360 {
|
||||
angle = angle + (360*math.Pi)/180
|
||||
}
|
||||
|
||||
win.Update()
|
||||
|
||||
frames++
|
||||
select {
|
||||
case <-second:
|
||||
win.SetTitle(fmt.Sprintf("%s | FPS: %d | Degrees: %f %f", cfgMain.Title,
|
||||
frames, angleInDegrees, angle))
|
||||
frames = 0
|
||||
default:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user