main.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2017 The Ebiten Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "fmt"
  17. "image/color"
  18. "log"
  19. "github.com/hajimehoshi/ebiten/v2"
  20. "github.com/hajimehoshi/ebiten/v2/ebitenutil"
  21. "github.com/hajimehoshi/ebiten/v2/vector"
  22. )
  23. const (
  24. screenWidth = 640
  25. screenHeight = 480
  26. )
  27. type Game struct {
  28. count int
  29. }
  30. func (g *Game) Update() error {
  31. g.count++
  32. g.count %= 240
  33. return nil
  34. }
  35. func (g *Game) Draw(screen *ebiten.Image) {
  36. cf := float32(g.count)
  37. vector.StrokeLine(screen, 100, 100, 300, 100, 1, color.RGBA{0xff, 0xff, 0xff, 0xff}, true)
  38. vector.StrokeLine(screen, 50, 150, 50, 350, 1, color.RGBA{0xff, 0xff, 0x00, 0xff}, true)
  39. vector.StrokeLine(screen, 50, 100+cf, 200+cf, 250, 4, color.RGBA{0x00, 0xff, 0xff, 0xff}, true)
  40. vector.DrawFilledRect(screen, 50+cf, 50+cf, 100+cf, 100+cf, color.RGBA{0x80, 0x80, 0x80, 0xc0}, true)
  41. vector.StrokeRect(screen, 300-cf, 50, 120, 120, 10+cf/4, color.RGBA{0x00, 0x80, 0x00, 0xff}, true)
  42. vector.DrawFilledCircle(screen, 400, 400, 100, color.RGBA{0x80, 0x00, 0x80, 0x80}, true)
  43. vector.StrokeCircle(screen, 400, 400, 10+cf, 10+cf/2, color.RGBA{0xff, 0x80, 0xff, 0xff}, true)
  44. ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f", ebiten.ActualTPS()))
  45. }
  46. func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
  47. return screenWidth, screenHeight
  48. }
  49. func main() {
  50. ebiten.SetWindowSize(screenWidth, screenHeight)
  51. ebiten.SetWindowTitle("Shapes (Ebitengine Demo)")
  52. if err := ebiten.RunGame(&Game{}); err != nil {
  53. log.Fatal(err)
  54. }
  55. }