2019-01-14 11:22:46 +01:00
|
|
|
// 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"
|
2024-09-11 18:03:53 +02:00
|
|
|
"math/rand/v2"
|
2019-01-14 11:22:46 +01:00
|
|
|
|
2020-10-03 19:35:13 +02:00
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
2019-01-14 11:22:46 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
screenWidth = 320
|
|
|
|
screenHeight = 240
|
|
|
|
)
|
|
|
|
|
2020-05-30 14:14:10 +02:00
|
|
|
type Game struct {
|
2021-07-21 17:15:30 +02:00
|
|
|
offscreen *ebiten.Image
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGame() *Game {
|
|
|
|
return &Game{
|
|
|
|
offscreen: ebiten.NewImage(screenWidth, screenHeight),
|
|
|
|
}
|
2020-05-30 14:14:10 +02:00
|
|
|
}
|
|
|
|
|
2020-10-04 10:42:54 +02:00
|
|
|
func (g *Game) Update() error {
|
2023-01-19 15:42:35 +01:00
|
|
|
s := g.offscreen.Bounds().Size()
|
2024-09-11 18:03:53 +02:00
|
|
|
x := rand.IntN(s.X)
|
|
|
|
y := rand.IntN(s.Y)
|
2019-01-14 12:04:58 +01:00
|
|
|
c := color.RGBA{
|
2024-09-11 18:03:53 +02:00
|
|
|
byte(rand.IntN(256)),
|
|
|
|
byte(rand.IntN(256)),
|
|
|
|
byte(rand.IntN(256)),
|
2019-01-14 11:22:46 +01:00
|
|
|
byte(0xff),
|
|
|
|
}
|
2021-07-21 17:15:30 +02:00
|
|
|
g.offscreen.Set(x, y, c)
|
2020-05-30 14:14:10 +02:00
|
|
|
return nil
|
|
|
|
}
|
2019-01-14 11:22:46 +01:00
|
|
|
|
2020-05-30 14:14:10 +02:00
|
|
|
func (g *Game) Draw(screen *ebiten.Image) {
|
2021-07-21 17:15:30 +02:00
|
|
|
screen.DrawImage(g.offscreen, nil)
|
2022-07-17 04:25:45 +02:00
|
|
|
ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f\nFPS: %0.2f", ebiten.ActualTPS(), ebiten.ActualFPS()))
|
2020-05-30 14:14:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
|
|
|
return screenWidth, screenHeight
|
2019-01-14 11:22:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2020-05-30 14:14:10 +02:00
|
|
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
2022-08-29 04:16:39 +02:00
|
|
|
ebiten.SetWindowTitle("Set (Ebitengine Demo)")
|
2021-07-21 17:15:30 +02:00
|
|
|
if err := ebiten.RunGame(NewGame()); err != nil {
|
2019-01-14 11:22:46 +01:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|