func drawGameNextPiece(screen *image.Image, world *World, engine *mygameengine.MyGameEngine) { piece := world.GetNextPiece() pieceBlocks := piece.GetBlocks() pieceSize := piece.GetSize() marginLeft := uint(15) marginTop := uint(8) width := uint(6) // border for y := uint(0); y < width; y++ { for x := uint(0); x < width; x++ { if x == 0 || y == 0 || x == 5 || y == 5 { screen.BlitAt( engine.Assets().Get(IMG_BLOCK_05), int(BLOCK_SIZE*marginLeft+uint(x)*BLOCK_SIZE), int(BLOCK_SIZE*marginTop+uint(y)*BLOCK_SIZE), ) } } } // piece for y := uint(0); y < pieceSize; y++ { for x := uint(0); x < pieceSize; x++ { if pieceBlocks[y][x] != nil { image := blockToImage(pieceBlocks[y][x], engine) screen.BlitAt( image, int(BLOCK_SIZE*(marginLeft+1)+uint(x)*BLOCK_SIZE), int(BLOCK_SIZE*(marginTop+1)+uint(y)*BLOCK_SIZE), ) } } } }
func drawGameGridBorders(screen *image.Image, world *World, engine *mygameengine.MyGameEngine) { gridWidth := world.GetGridWidth() gridHeight := world.GetGridHeight() for y := uint(0); y < gridHeight; y++ { screen.BlitAt(engine.Assets().Get(IMG_BLOCK_05), 0, int(y*BLOCK_SIZE)) screen.BlitAt(engine.Assets().Get(IMG_BLOCK_06), int(gridWidth*BLOCK_SIZE+BLOCK_SIZE), int(y*BLOCK_SIZE)) } for x := uint(0); x < gridWidth+2; x++ { screen.BlitAt(engine.Assets().Get(IMG_BLOCK_06), int(x*BLOCK_SIZE), int(gridHeight*BLOCK_SIZE)) } }
func Game(engine *mygameengine.MyGameEngine) *mygameengine.Board { loadAssets(engine) gameBoard := mygameengine.NewBoard() world := NewWorld() world.OnGameOver(func() { world.Stop() engine.Boards().SetCurrent(engine.Boards().Get("intro")) }) gameBoard.OnStart(world.Start) gameBoard.OnKeyDown(keyHandler(world)) gameBoard.OnRepaint(repaintHandler(engine, world)) return gameBoard }
func blockToImage(block *Block, engine *mygameengine.MyGameEngine) *image.Image { switch block.GetShape() { case 1: return engine.Assets().Get(IMG_BLOCK_01) case 2: return engine.Assets().Get(IMG_BLOCK_02) case 3: return engine.Assets().Get(IMG_BLOCK_03) case 4: return engine.Assets().Get(IMG_BLOCK_04) } return nil }
func loadAssets(engine *mygameengine.MyGameEngine) { engine.Assets().Png(IMG_BLOCK_01) engine.Assets().Png(IMG_BLOCK_02) engine.Assets().Png(IMG_BLOCK_03) engine.Assets().Png(IMG_BLOCK_04) engine.Assets().Png(IMG_BLOCK_05) engine.Assets().Png(IMG_BLOCK_06) }
func Intro(engine *mygameengine.MyGameEngine) *mygameengine.Board { engine.Assets().Png(IMG_ROTATING_BG) engine.Assets().Png(IMG_TITLE) engine.Assets().Png(IMG_PRESS_SPACE) intro := mygameengine.NewBoard() intro.OnKeyDown(func(key int) { fmt.Println("intro: KEY DOWN", key) if key == mygameengine.KEY_SPACE { engine.Boards().SetCurrent(engine.Boards().Get("game")) } }) intro.OnRepaint(func(screen *image.Image) { frame := intro.GetFrame() drawIntroBackground(screen, frame, engine.Assets().Get(IMG_ROTATING_BG)) screen.BlitAt(engine.Assets().Get(IMG_TITLE), 130, 140) drawIntroText(screen, frame, engine.Assets().Get(IMG_PRESS_SPACE)) drawIntroMask(screen, frame, engine.GetFps()) }) return intro }