ebiten/examples/shapes/main.go

68 lines
1.9 KiB
Go
Raw Normal View History

// Copyright 2017 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.
2021-06-24 14:49:37 +02:00
//go:build example
2020-10-06 17:45:54 +02:00
// +build example
package main
import (
"fmt"
"image/color"
"log"
2020-10-03 19:35:13 +02:00
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/vector"
)
const (
screenWidth = 640
screenHeight = 480
)
2020-05-30 14:14:10 +02:00
type Game struct {
count int
}
func (g *Game) Update() error {
2020-05-30 14:14:10 +02:00
g.count++
g.count %= 240
return nil
}
2020-05-30 14:14:10 +02:00
func (g *Game) Draw(screen *ebiten.Image) {
cf := float32(g.count)
vector.StrokeLine(screen, 100, 100, 300, 100, 1, color.RGBA{0xff, 0xff, 0xff, 0xff})
vector.StrokeLine(screen, 50, 150, 50, 350, 1, color.RGBA{0xff, 0xff, 0x00, 0xff})
vector.StrokeLine(screen, 50, 100+float32(cf), 200+float32(cf), 250, 4, color.RGBA{0x00, 0xff, 0xff, 0xff})
vector.FillRect(screen, 50+float32(cf), 50+float32(cf), 100+float32(cf), 100+float32(cf), color.RGBA{0x80, 0x80, 0x80, 0xff})
vector.StrokeRect(screen, 300-float32(cf), 50, 120, 120, 10, color.RGBA{0x00, 0x80, 0x00, 0xff})
ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f", ebiten.ActualTPS()))
2020-05-30 14:14:10 +02:00
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return screenWidth, screenHeight
}
func main() {
2020-05-30 14:14:10 +02:00
ebiten.SetWindowSize(screenWidth, screenHeight)
ebiten.SetWindowTitle("Shapes (Ebitengine Demo)")
2020-05-30 14:14:10 +02:00
if err := ebiten.RunGame(&Game{}); err != nil {
log.Fatal(err)
}
}