format and remove unused pointer
This commit is contained in:
parent
93fd0c714d
commit
7d9f54c013
@ -7,37 +7,35 @@ import (
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
X, Y float64
|
||||
PlayerVec pixel.Vec
|
||||
sprFrame int
|
||||
X, Y float64
|
||||
PlayerVec pixel.Vec
|
||||
sprFrame int
|
||||
spriteSheet pixel.Picture
|
||||
sprFrames []pixel.Rect
|
||||
sprite *pixel.Sprite
|
||||
speed float64
|
||||
sprFrames []pixel.Rect
|
||||
sprite *pixel.Sprite
|
||||
speed float64
|
||||
}
|
||||
|
||||
func NewPlayer(win *pixelgl.Window, spriteSheet pixel.Picture) (*Player){
|
||||
func NewPlayer(win *pixelgl.Window, spriteSheet pixel.Picture) Player {
|
||||
var p Player
|
||||
p.X = win.Bounds().Max.X/2
|
||||
p.Y = win.Bounds().Max.Y/2
|
||||
p.X = win.Bounds().Max.X / 2
|
||||
p.Y = win.Bounds().Max.Y / 2
|
||||
p.PlayerVec = pixel.Vec{
|
||||
X:win.Bounds().Max.X/2,
|
||||
Y:win.Bounds().Max.Y/2,
|
||||
X: win.Bounds().Max.X / 2,
|
||||
Y: win.Bounds().Max.Y / 2,
|
||||
}
|
||||
p.sprFrame = 9
|
||||
p.spriteSheet = spriteSheet
|
||||
p.sprFrames = createSpriteFrames(spriteSheet)
|
||||
p.sprite = pixel.NewSprite(spriteSheet, p.sprFrames[p.sprFrame])
|
||||
p.speed = 10.0
|
||||
return &p
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Player) Update(win *pixelgl.Window, dt int64) {
|
||||
var vecX, vecY float64 = 0, 0
|
||||
speed := p.speed
|
||||
|
||||
|
||||
|
||||
if win.Pressed(pixelgl.KeyA) { //left
|
||||
p.sprFrame = 6
|
||||
vecX -= speed
|
||||
@ -64,7 +62,7 @@ func (p *Player) Render(win *pixelgl.Window) { //include batch later
|
||||
p.sprite.Draw(win, pixel.IM.Scaled(pixel.ZV, 4).Moved(p.PlayerVec))
|
||||
}
|
||||
|
||||
func createSpriteFrames(spriteSheet pixel.Picture) ([]pixel.Rect) {
|
||||
func createSpriteFrames(spriteSheet pixel.Picture) []pixel.Rect {
|
||||
var sprFrames []pixel.Rect
|
||||
var frameHeight, frameWidth float64 = 96, 96
|
||||
for y := spriteSheet.Bounds().Min.Y; y < frameHeight*4; y += 96 {
|
||||
@ -73,4 +71,4 @@ func createSpriteFrames(spriteSheet pixel.Picture) ([]pixel.Rect) {
|
||||
}
|
||||
}
|
||||
return sprFrames
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user