Compare commits

...

4 Commits

Author SHA1 Message Date
Jalen Winslow
f35e404703 slowed down the sprite 2018-01-23 06:12:38 -07:00
Jalen Winslow
748f605bff animated sprite 2018-01-23 06:06:35 -07:00
Jalen Winslow
297e33d89e added frames only concerning sprite 2018-01-23 05:52:53 -07:00
Jalen Winslow
452bd9cdc3 added frames only concerning sprite 2018-01-23 05:38:52 -07:00

43
main.go
View File

@ -52,20 +52,22 @@ func run() {
bg := pixel.NewSprite(background, background.Bounds())
//batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet)
/*
When creating the sprite, you need to know big each frame is inside the spritesheet.
If you use aseprite or some other pixel art program, you can find the number of pixels
within each frame. For our sprite sheet, each frame is 96 px wide and 96 px high. So
we increment it by 96 for both x and y so that it can get the position of the frame
at the bottom right corner.
/* setting-character-sprite
basically changed it around so the 12 frames of the character with yellow hair
are added to spritesFrames.
*/
var spritesFrames []pixel.Rect
for x := spritesheet.Bounds().Min.X; x < spritesheet.Bounds().Max.X; x += 96 {
for y := spritesheet.Bounds().Min.Y; y < spritesheet.Bounds().Max.Y; y += 96 {
var frameWidth, frameHeight float64 = 96, 96
for y := spritesheet.Bounds().Min.Y; y < frameHeight*4; y += 96 {
for x := spritesheet.Bounds().Min.X; x < frameWidth*3; x += 96 {
spritesFrames = append(spritesFrames, pixel.R(x, y, x+96, y+96)) // (x, y, width, height) of frame
}
}
Sprite := pixel.NewSprite(spritesheet, spritesFrames[3])
Sprite := pixel.NewSprite(spritesheet, spritesFrames[9])
var (
camPos = pixel.ZV
@ -94,6 +96,8 @@ func run() {
var now int64
var dt int64
frameCounter := 0
// Game Loop
for !win.Closed() {
now = time.Now().UnixNano()
@ -123,24 +127,35 @@ func run() {
*/
//mouse := cam.Unproject(win.MousePosition())
if frames%10==0 {
frameCounter += 1
}
if frameCounter >= 3 {
frameCounter = 0
}
speed := 10.0
sprFrame := 0
if win.Pressed(pixelgl.KeyA) { //left
sprFrame = 6
playerX -= speed
Sprite.Set(spritesheet, spritesFrames[2])
//Sprite.Set(spritesheet, spritesFrames[sprFrame+frameCounter])
}
if win.Pressed(pixelgl.KeyD) { //Right
sprFrame = 3
playerX += speed
Sprite.Set(spritesheet, spritesFrames[1])
//Sprite.Set(spritesheet, spritesFrames[3])
}
if win.Pressed(pixelgl.KeyS) { //Down
sprFrame = 9
playerY -= speed
Sprite.Set(spritesheet, spritesFrames[3])
//Sprite.Set(spritesheet, spritesFrames[9])
}
if win.Pressed(pixelgl.KeyW) { //up
sprFrame = 0
playerY += speed
Sprite.Set(spritesheet, spritesFrames[0])
//Sprite.Set(spritesheet, spritesFrames[0])
}
Sprite.Set(spritesheet, spritesFrames[sprFrame+frameCounter])
camPos.X = playerX
camPos.Y = playerY
camZoom *= math.Pow(camZoomSpeed, win.MouseScroll().Y)