From 7d9f54c0133536ca808d9a104c5fbdd5c59f298f Mon Sep 17 00:00:00 2001 From: mollusk Date: Wed, 24 Jan 2018 02:14:19 -0700 Subject: [PATCH] format and remove unused pointer --- gameobjects/player.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/gameobjects/player.go b/gameobjects/player.go index c906b7d..bf6d40b 100644 --- a/gameobjects/player.go +++ b/gameobjects/player.go @@ -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 -} \ No newline at end of file +}