New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create examples/2048 #181
Comments
@hajimehoshi I'd be happy to create this example if you haven't started on it already. 😄 |
I've not created yet. I'd be glad if you could help it! |
@hajimehoshi awesome, I will give it a go and share what I end up with. |
What's going on? |
@hajimehoshi I worked on it for a couple of days but ended up hitting a wall and getting stuck. I haven't made much progress with this. Someone else is welcome to take over if they want to. |
OK. I was wondering if you could share your code, I'm not sure I have enough time to help this though. |
@hajimehoshi For sure, I would be happy to share what I have so far.
package main
import (
"log"
"github.com/brettchalupa/ebiten-experiments/2048/twenty48"
"github.com/hajimehoshi/ebiten"
)
func main() {
game := twenty48.NewGame()
update := game.Update
if err := ebiten.Run(update, twenty48.ScreenWidth, twenty48.ScreenHeight, 1, "2048 (Ebiten Demo)"); err != nil {
log.Fatal(err)
}
}
package twenty48
import (
"strconv"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
)
type Board struct {
size int
tiles [][]*Tile
}
func NewBoard(size int) *Board {
return &Board{
size: size,
}
}
func (board *Board) Update() error {
return nil
}
func (board *Board) Draw(r *ebiten.Image) error {
ebitenutil.DebugPrint(r, "Board Size: "+strconv.Itoa(board.size))
return nil
}
package twenty48
import (
"github.com/hajimehoshi/ebiten"
)
const ScreenWidth = 420
const ScreenHeight = 600
const DefaultBoardSize = 4
type Game struct {
board *Board
}
func NewGame() *Game {
return &Game{
board: NewBoard(DefaultBoardSize),
}
}
func (game *Game) Update(r *ebiten.Image) error {
if err := game.board.Update(); err != nil {
return err
}
if !ebiten.IsRunningSlowly() {
game.Draw(r)
}
return nil
}
func (game *Game) Draw(r *ebiten.Image) error {
if err := game.board.Draw(r); err != nil {
return err
}
return nil
}
package twenty48
const TileSize = 100
type Tile struct {
value int
x int
y int
color string
} Feel free to use this or adapt it if it is of any help. My apologies for not completing it. |
Thanks! I'll look into it later. |
Based on your files, I've started implementing the game. |
I've not implemented "Game Start", "Game Over", or "Game Clear" messages, but most of 2048 features have been implemented. Let me close this issue. Thank you for your contribution again. |
No description provided.
The text was updated successfully, but these errors were encountered: