Add Ebiten VN files

This commit is contained in:
David Alasow 2017-12-22 16:52:21 +01:00
parent d4e3f9df8a
commit a6673a855b
3 changed files with 113 additions and 0 deletions

BIN
Ebiten/VN/bg.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

113
Ebiten/VN/main.go Normal file
View File

@ -0,0 +1,113 @@
package main
import (
_ "image/jpeg"
"fmt"
"image/color"
"io/ioutil"
"log"
"github.com/golang/freetype/truetype"
"golang.org/x/image/font"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/text"
)
const (
screenWidth = 640
screenHeight = 480
)
type dialogue struct {
Speaker character
Text string
}
type character struct {
Name string
Color color.RGBA
}
var (
m = character{`Me`, color.RGBA{255, 0, 0, 255}}
s = character{`Sylvie`, color.RGBA{0, 255, 0, 255}}
d = character{``, color.RGBA{0, 255, 0, 0}}
messages = []dialogue{
{s, `Hi there! How was class?`},
{m, `Good...`},
{d, `I can't bring myself to admit that it all went in one ear and out the other.`},
}
mplusNormalFont font.Face
line = 0
bg *ebiten.Image
)
func init() {
f, err := ebitenutil.OpenFile("./mplus-1p-regular.ttf")
if err != nil {
log.Fatal(err)
}
defer f.Close()
b, err := ioutil.ReadAll(f)
if err != nil {
log.Fatal(err)
}
tt, err := truetype.Parse(b)
if err != nil {
log.Fatal(err)
}
const dpi = 72
mplusNormalFont = truetype.NewFace(tt, &truetype.Options{
Size: 24,
DPI: dpi,
Hinting: font.HintingFull,
})
}
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
for _, v := range ebiten.InputChars() {
if v == 32 {
if line+1 != len(messages) {
line++
}
}
}
msg := fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS())
const x = 20
op := &ebiten.DrawImageOptions{}
screen.DrawImage(bg, op)
ebitenutil.DrawRect(screen, 30, 350, screenWidth-60, 100, color.RGBA{128, 128, 128, 200})
text.Draw(screen, msg, mplusNormalFont, x, 40, color.White)
text.Draw(screen, messages[line].Speaker.Name, mplusNormalFont, 50, 370, messages[line].Speaker.Color)
text.Draw(screen, messages[line].Text, mplusNormalFont, 50, 400, color.White)
return nil
}
func main() {
var err error
bg, _, err = ebitenutil.NewImageFromFile("./bg.jpg", ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Font (Ebiten Demo)"); err != nil {
log.Fatal(err)
}
}

Binary file not shown.