mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-15 07:27:32 +01:00
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
// Copyright 2019 The Ebiten Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"image/color"
|
|
"log"
|
|
"math/rand/v2"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
|
)
|
|
|
|
const (
|
|
screenWidth = 320
|
|
screenHeight = 240
|
|
)
|
|
|
|
type Game struct {
|
|
offscreen *ebiten.Image
|
|
}
|
|
|
|
func NewGame() *Game {
|
|
return &Game{
|
|
offscreen: ebiten.NewImage(screenWidth, screenHeight),
|
|
}
|
|
}
|
|
|
|
func (g *Game) Update() error {
|
|
s := g.offscreen.Bounds().Size()
|
|
x := rand.IntN(s.X)
|
|
y := rand.IntN(s.Y)
|
|
c := color.RGBA{
|
|
byte(rand.IntN(256)),
|
|
byte(rand.IntN(256)),
|
|
byte(rand.IntN(256)),
|
|
byte(0xff),
|
|
}
|
|
g.offscreen.Set(x, y, c)
|
|
return nil
|
|
}
|
|
|
|
func (g *Game) Draw(screen *ebiten.Image) {
|
|
screen.DrawImage(g.offscreen, nil)
|
|
ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f\nFPS: %0.2f", ebiten.ActualTPS(), ebiten.ActualFPS()))
|
|
}
|
|
|
|
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
|
return screenWidth, screenHeight
|
|
}
|
|
|
|
func main() {
|
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
|
ebiten.SetWindowTitle("Set (Ebitengine Demo)")
|
|
if err := ebiten.RunGame(NewGame()); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|