Skip to content

Commit

Permalink
Merge pull request #2 from dusk125/update-pixel
Browse files Browse the repository at this point in the history
Update pixel, beep to v2
  • Loading branch information
dusk125 authored Aug 13, 2024
2 parents cb527ea + 24d34f2 commit a6e31f9
Show file tree
Hide file tree
Showing 55 changed files with 380 additions and 395 deletions.
2 changes: 1 addition & 1 deletion community/amidakuji/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ $ make

#### Library
- [Pixel](https://github.com/gopxl/pixel/v2/tree/7cff3ce3aed80129b7b1dd57e63439426e11b6ee)
- [Beep](https://github.com/gopxl/beep/tree/63cc6fbbac46dba1a03e55f0ebc965d6c82ca8e1)
- [Beep](https://github.com/gopxl/beep/v2/tree/63cc6fbbac46dba1a03e55f0ebc965d6c82ca8e1)
- [GLFW 3.2](https://github.com/go-gl/glfw/tree/513e4f2bf85c31fba0fc4907abd7895242ccbe50/v3.2/glfw)
- [dialog](https://github.com/sqweek/dialog/tree/2f9d9e5dd848a3bad4bdd0210c73bb90c13a3791)

Expand Down
46 changes: 23 additions & 23 deletions community/amidakuji/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
"time"
"unsafe"

glfw "github.com/go-gl/glfw/v3.2/glfw"
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"
"github.com/gopxl/pixel-examples/community/amidakuji/glossary/jukebox"
glfw "github.com/go-gl/glfw/v3.2/glfw"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/pixelgl"
"github.com/gopxl/pixel/v2/text"
"github.com/gopxl/pixel/v2/backends/opengl"
"github.com/gopxl/pixel/v2/ext/text"
"github.com/sqweek/dialog"
"golang.org/x/image/colornames"
)
Expand Down Expand Up @@ -49,7 +49,7 @@ type Updater interface {
// Also it manages and draws everything about...
type game struct {
// something system, somthing runtime
window *pixelgl.Window // lazy init
window *opengl.Window // lazy init
bg pixel.RGBA
camera *gg.Camera // lazy init
fpsw *gg.FPSWatch
Expand Down Expand Up @@ -429,7 +429,7 @@ func (g *game) Resume() {

func (g *game) SetFullScreenMode(on bool) {
if on {
monitor := pixelgl.PrimaryMonitor()
monitor := opengl.PrimaryMonitor()
width, height := monitor.Size()
// log.Println(monitor.VideoModes()) //
g.window.SetMonitor(monitor)
Expand All @@ -447,7 +447,7 @@ func (g *game) SetFullScreenMode(on bool) {
// Read only methods

// WindowDeep is a hacky way to access a window in deep.
// It returns (window *glfw.Window) which is an unexported member inside a (*pixelgl.Window).
// It returns (window *glfw.Window) which is an unexported member inside a (*opengl.Window).
// Read only argument game ignores the pass lock by value warning.
func (g game) WindowDeep() (baseWindow *glfw.Window) {
return *(**glfw.Window)(unsafe.Pointer(reflect.Indirect(reflect.ValueOf(g.window)).FieldByName("window").UnsafeAddr()))
Expand All @@ -470,15 +470,15 @@ func (g game) BridgesCount() (sum int) {

// Run the game window and its event loop on main thread.
func (g *game) Run() {
pixelgl.Run(func() {
opengl.Run(func() {
g.RunLazyInit()
g.RunEventLoop()
})
}

func (g *game) RunLazyInit() {
// This window will show up as soon as it is created.
win, err := pixelgl.NewWindow(pixelgl.WindowConfig{
win, err := opengl.NewWindow(opengl.WindowConfig{
Title: title + " (" + version + ")",
Icon: nil,
Bounds: pixel.R(0, 0, g.winWidth, g.winHeight),
Expand All @@ -492,8 +492,8 @@ func (g *game) RunLazyInit() {
}
win.SetSmooth(true)

MoveWindowToCenterOfPrimaryMonitor := func(win *pixelgl.Window) {
vmodes := pixelgl.PrimaryMonitor().VideoModes()
MoveWindowToCenterOfPrimaryMonitor := func(win *opengl.Window) {
vmodes := opengl.PrimaryMonitor().VideoModes()
vmodesLast := vmodes[len(vmodes)-1]
biggestResolution := pixel.R(0, 0, float64(vmodesLast.Width), float64(vmodesLast.Height))
win.SetPos(biggestResolution.Center().Sub(win.Bounds().Center()))
Expand Down Expand Up @@ -558,15 +558,15 @@ func (g *game) HandlingEvents(dt float64) {
// Notice that all function calls as go routine are non-blocking, but the others will block the main thread.

// system
if g.window.JustReleased(pixelgl.KeyEscape) {
if g.window.JustReleased(pixel.KeyEscape) {
g.window.SetClosed(true)
}
if g.window.JustReleased(pixelgl.KeySpace) {
if g.window.JustReleased(pixel.KeySpace) {
g.Pause()
dialog.Message("%s", "Pause").Title("PPAP").Info()
g.Resume()
}
if g.window.JustReleased(pixelgl.KeyTab) {
if g.window.JustReleased(pixel.KeyTab) {
if g.window.Monitor() == nil {
g.SetFullScreenMode(true)
} else {
Expand All @@ -575,12 +575,12 @@ func (g *game) HandlingEvents(dt float64) {
}

// scalpel mode
if g.window.JustReleased(pixelgl.MouseButtonRight) {
if g.window.JustReleased(pixel.MouseButtonRight) {
go func() {
g.isScalpelMode = !g.isScalpelMode
}()
}
if g.window.JustReleased(pixelgl.MouseButtonLeft) {
if g.window.JustReleased(pixel.MouseButtonLeft) {
// ---------------------------------------------------
if !jukebox.IsPlaying() {
jukebox.Play()
Expand Down Expand Up @@ -613,18 +613,18 @@ func (g *game) HandlingEvents(dt float64) {
}

// game ctrl
if g.window.JustReleased(pixelgl.Key1) { // shuffle
if g.window.JustReleased(pixel.Key1) { // shuffle
go func() {
g.Shuffle(10, 750)
}()
}
if g.window.JustReleased(pixelgl.Key2) { // find path slow
if g.window.JustReleased(pixel.Key2) { // find path slow
go func() {
g.ResetPaths()
g.AnimatePaths(g.AnimatePath)
}()
}
if g.window.JustReleased(pixelgl.Key3) { // find path fast
if g.window.JustReleased(pixel.Key3) { // find path fast
go func() {
g.ResetPaths()
g.AnimatePaths(func(participant int) {
Expand All @@ -634,27 +634,27 @@ func (g *game) HandlingEvents(dt float64) {
}

// camera
if g.window.JustReleased(pixelgl.KeyEnter) {
if g.window.JustReleased(pixel.KeyEnter) {
go func() {
g.camera.Rotate(-90)
}()
}
if g.window.Pressed(pixelgl.KeyRight) {
if g.window.Pressed(pixel.KeyRight) {
go func(dt float64) { // This camera will go diagonal while the case is in middle of rotating the camera.
g.camera.Move(pixel.V(1000*dt, 0).Rotated(-g.camera.Angle()))
}(dt)
}
if g.window.Pressed(pixelgl.KeyLeft) {
if g.window.Pressed(pixel.KeyLeft) {
go func(dt float64) {
g.camera.Move(pixel.V(-1000*dt, 0).Rotated(-g.camera.Angle()))
}(dt)
}
if g.window.Pressed(pixelgl.KeyUp) {
if g.window.Pressed(pixel.KeyUp) {
go func(dt float64) {
g.camera.Move(pixel.V(0, 1000*dt).Rotated(-g.camera.Angle()))
}(dt)
}
if g.window.Pressed(pixelgl.KeyDown) {
if g.window.Pressed(pixel.KeyDown) {
go func(dt float64) {
g.camera.Move(pixel.V(0, -1000*dt).Rotated(-g.camera.Angle()))
}(dt)
Expand Down
2 changes: 1 addition & 1 deletion community/amidakuji/glossary/cam.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/ext/imdraw"
"golang.org/x/image/colornames"
)

Expand Down
2 changes: 1 addition & 1 deletion community/amidakuji/glossary/explosive.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/ext/imdraw"
)

// -------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions community/amidakuji/glossary/fpschk.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/text"
"github.com/gopxl/pixel/v2/ext/imdraw"
"github.com/gopxl/pixel/v2/ext/text"
"golang.org/x/image/colornames"
)

Expand Down
6 changes: 3 additions & 3 deletions community/amidakuji/glossary/jukebox/music.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"

"github.com/gopxl/beep"
"github.com/gopxl/beep/speaker"
"github.com/gopxl/beep/vorbis"
"github.com/gopxl/beep/v2"
"github.com/gopxl/beep/v2/speaker"
"github.com/gopxl/beep/v2/vorbis"
)

// -------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion community/amidakuji/glossary/starfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/ext/imdraw"
)

// -------------------------------------------------------------------------
Expand Down
17 changes: 15 additions & 2 deletions community/amidakuji/glossary/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
_ "image/gif"
_ "image/png"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/text"
"github.com/golang/freetype/truetype"
"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/ext/text"
"golang.org/x/image/font"
"golang.org/x/image/font/basicfont"
)
Expand All @@ -32,6 +32,19 @@ func AtlasASCII() *text.Atlas {
return atlasASCII
}

func Asset(name string) ([]byte, error) {
return ioutil.ReadFile(name)
}

func AssetDir(name string) ([]string, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
defer f.Close()
return f.Readdirnames(-1)
}

// NewAtlas newly loads and prepares a set of images of characters or symbols to be drawn.
// Arg runeSet would be set to nil if non-ASCII characters are not in use.
func NewAtlas(nameAssetTTF string, size float64, runeSet []rune) *text.Atlas {
Expand Down
2 changes: 1 addition & 1 deletion community/amidakuji/ladder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/ext/imdraw"
"golang.org/x/image/colornames"
)

Expand Down
4 changes: 2 additions & 2 deletions community/amidakuji/nametag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/text"
"github.com/gopxl/pixel/v2/ext/imdraw"
"github.com/gopxl/pixel/v2/ext/text"
"golang.org/x/image/colornames"
)

Expand Down
2 changes: 1 addition & 1 deletion community/amidakuji/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/ext/imdraw"
)

// Path is for animating a path to the prize in a ladder.
Expand Down
2 changes: 1 addition & 1 deletion community/amidakuji/scalpel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/ext/imdraw"
"golang.org/x/image/colornames"
)

Expand Down
2 changes: 1 addition & 1 deletion community/bouncing/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bouncing

Bouncing particles using the [imdraw](https://godoc.org/github.com/gopxl/pixel/v2/imdraw) package.
Bouncing particles using the [imdraw](https://godoc.org/github.com/gopxl/pixel/v2/ext/imdraw) package.

Made by [Peter Hellberg](https://github.com/peterhellberg/) as part of his [pixel-experiments](https://github.com/peterhellberg/pixel-experiments)

Expand Down
14 changes: 7 additions & 7 deletions community/bouncing/bouncing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/pixelgl"
"github.com/gopxl/pixel/v2/backends/opengl"
"github.com/gopxl/pixel/v2/ext/imdraw"
)

var (
Expand All @@ -23,7 +23,7 @@ var (
)

func run() {
win, err := pixelgl.NewWindow(pixelgl.WindowConfig{
win, err := opengl.NewWindow(opengl.WindowConfig{
Bounds: pixel.R(0, 0, w, h),
VSync: true,
Undecorated: true,
Expand All @@ -49,15 +49,15 @@ func run() {
}()

for !win.Closed() {
win.SetClosed(win.JustPressed(pixelgl.KeyEscape) || win.JustPressed(pixelgl.KeyQ))
win.SetClosed(win.JustPressed(pixel.KeyEscape) || win.JustPressed(pixel.KeyQ))

if win.JustPressed(pixelgl.KeySpace) {
if win.JustPressed(pixel.KeySpace) {
for _, ball := range balls {
ball.color = ball.palette.next()
}
}

if win.JustPressed(pixelgl.KeyEnter) {
if win.JustPressed(pixel.KeyEnter) {
for _, ball := range balls {
ball.pos = center()
ball.vel = randomVelocity()
Expand Down Expand Up @@ -117,7 +117,7 @@ func main() {
}
}()

pixelgl.Run(run)
opengl.Run(run)
}

func newParticleAt(pos, vel pixel.Vec) *particle {
Expand Down
2 changes: 1 addition & 1 deletion community/game_of_life/life/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package life

import (
"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/ext/imdraw"
"golang.org/x/image/colornames"
)

Expand Down
12 changes: 6 additions & 6 deletions community/game_of_life/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (

"golang.org/x/image/colornames"

"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel-examples/community/game_of_life/life"
"github.com/gopxl/pixel/v2/imdraw"
"github.com/gopxl/pixel/v2/pixelgl"
"github.com/gopxl/pixel/v2"
"github.com/gopxl/pixel/v2/backends/opengl"
"github.com/gopxl/pixel/v2/ext/imdraw"
)

var (
Expand All @@ -28,17 +28,17 @@ func init() {
}

func main() {
pixelgl.Run(run)
opengl.Run(run)
}

func run() {

cfg := pixelgl.WindowConfig{
cfg := opengl.WindowConfig{
Title: "Pixel Rocks!",
Bounds: pixel.R(0, 0, *windowSize, *windowSize),
VSync: true,
}
win, err := pixelgl.NewWindow(cfg)
win, err := opengl.NewWindow(cfg)
if err != nil {
panic(err)
}
Expand Down
Loading

0 comments on commit a6e31f9

Please sign in to comment.