Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ | |
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Mac | ||
.DS_Store |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//go:generate file2byteslice -package=images -input=./images/skin.png -output=./images/skin.go -var=SkinPng | ||
//go:generate file2byteslice -package=images -input=./images/characters.png -output=./images/characters.go -var=CharactersPng | ||
//go:generate file2byteslice -package=images -input=./images/powers.png -output=./images/powers.go -var=PowersPng | ||
//go:generate file2byteslice -package=images -input=./images/walls.png -output=./images/walls.go -var=WallsPng | ||
//go:generate file2byteslice -package=fonts -input=./fonts/arcade-n.ttf -output=./fonts/arcade-n.go -var=ArcadeTTF | ||
|
||
package assets |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/skatiyar/pacman" | ||
) | ||
|
||
func main() { | ||
game, gameErr := pacman.NewGame() | ||
if gameErr != nil { | ||
panic(gameErr) | ||
} | ||
|
||
if runErr := game.Run(); runErr != nil { | ||
panic(runErr) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package pacman | ||
|
||
import ( | ||
"bytes" | ||
"image" | ||
"image/png" | ||
|
||
"github.com/hajimehoshi/ebiten" | ||
"github.com/skatiyar/pacman/assets/images" | ||
) | ||
|
||
type Characters struct { | ||
Pacman *ebiten.Image | ||
Ghost1 *ebiten.Image | ||
Ghost2 *ebiten.Image | ||
Ghost3 *ebiten.Image | ||
Ghost4 *ebiten.Image | ||
} | ||
|
||
func LoadCharacters() (*Characters, error) { | ||
cImage, cImageErr := png.Decode(bytes.NewReader(images.CharactersPng)) | ||
if cImageErr != nil { | ||
return nil, cImageErr | ||
} | ||
|
||
characters, charactersErr := ebiten.NewImageFromImage(cImage, ebiten.FilterDefault) | ||
if charactersErr != nil { | ||
return nil, charactersErr | ||
} | ||
|
||
pacman, pacmanErr := GetSprite(61, 64, 0, 0, characters) | ||
if pacmanErr != nil { | ||
return nil, pacmanErr | ||
} | ||
|
||
ghost1, ghost1Err := GetSprite(56, 64, 66, 0, characters) | ||
if ghost1Err != nil { | ||
return nil, ghost1Err | ||
} | ||
|
||
ghost2, ghost2Err := GetSprite(56, 64, 125, 0, characters) | ||
if ghost2Err != nil { | ||
return nil, ghost2Err | ||
} | ||
|
||
ghost3, ghost3Err := GetSprite(56, 64, 185, 0, characters) | ||
if ghost3Err != nil { | ||
return nil, ghost3Err | ||
} | ||
|
||
ghost4, ghost4Err := GetSprite(56, 64, 244, 0, characters) | ||
if ghost4Err != nil { | ||
return nil, ghost4Err | ||
} | ||
|
||
return &Characters{ | ||
Pacman: pacman, | ||
Ghost1: ghost1, | ||
Ghost2: ghost2, | ||
Ghost3: ghost3, | ||
Ghost4: ghost4, | ||
}, nil | ||
} | ||
|
||
// Offset is from top left corner | ||
func GetSprite( | ||
width, height int, | ||
xoffset, yoffset int, | ||
src *ebiten.Image, | ||
) (*ebiten.Image, error) { | ||
sprite, spriteErr := ebiten.NewImage(width, height, ebiten.FilterDefault) | ||
if spriteErr != nil { | ||
return nil, spriteErr | ||
} | ||
|
||
rect := image.Rect(xoffset, yoffset, xoffset+width, yoffset+height) | ||
|
||
ops := &ebiten.DrawImageOptions{} | ||
ops.SourceRect = &rect | ||
if drawErr := sprite.DrawImage(src, ops); drawErr != nil { | ||
return nil, drawErr | ||
} | ||
|
||
return sprite, nil | ||
} |
Oops, something went wrong.