예제 #1
0
파일: main.go 프로젝트: hajimehoshi/ebiten
func main() {
	var err error
	bgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/tile.png", ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	w, h := bgImage.Size()
	const repeat = 5
	repeatedBgImage, err = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	for j := 0; j < repeat; j++ {
		for i := 0; i < repeat; i++ {
			op := &ebiten.DrawImageOptions{}
			op.GeoM.Translate(float64(w*i), float64(h*j))
			if err := repeatedBgImage.DrawImage(bgImage, op); err != nil {
				log.Fatal(err)
			}
		}
	}
	groundImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}

	if err := ebiten.Run(update, screenWidth, screenHeight, 2, "infinite scroll"); err != nil {
		log.Fatal(err)
	}
}
예제 #2
0
func init() {
	var err error
	// Background
	imageGameBG, _, err = ebitenutil.NewImageFromFile("images/gophers.jpg", ebiten.FilterLinear)
	if err != nil {
		panic(err)
	}

	// Windows
	imageWindows, err = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterNearest)
	if err != nil {
		panic(err)
	}
	// Windows: Field
	x, y := fieldWindowPosition()
	if err := drawWindow(imageWindows, x, y, fieldWidth, fieldHeight); err != nil {
		panic(err)
	}
	// Windows: Next
	x, y = nextWindowLabelPosition()
	if err := common.ArcadeFont.DrawTextWithShadow(imageWindows, "NEXT", x, y, 1, fontColor); err != nil {
		panic(err)
	}
	x, y = nextWindowPosition()
	if err := drawWindow(imageWindows, x, y, 5*blockWidth, 5*blockHeight); err != nil {
		panic(err)
	}
	// Windows: Score
	x, y = scoreTextBoxPosition()
	if err := drawTextBox(imageWindows, "SCORE", x, y, textBoxWidth()); err != nil {
		panic(err)
	}
	// Windows: Level
	x, y = levelTextBoxPosition()
	if err := drawTextBox(imageWindows, "LEVEL", x, y, textBoxWidth()); err != nil {
		panic(err)
	}
	// Windows: Lines
	x, y = linesTextBoxPosition()
	if err := drawTextBox(imageWindows, "LINES", x, y, textBoxWidth()); err != nil {
		panic(err)
	}

	// Gameover
	imageGameover, err = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterNearest)
	if err != nil {
		panic(err)
	}
	imageGameover.Fill(color.NRGBA{0x00, 0x00, 0x00, 0x80})
	y = (ScreenHeight - blockHeight) / 2
	if err := drawTextWithShadowCenter(imageGameover, "GAME OVER", 0, y, 1, color.White, ScreenWidth); err != nil {
		panic(err)
	}
}
예제 #3
0
func init() {
	var err error
	transitionFrom, err = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterNearest)
	if err != nil {
		panic(err)
	}
	transitionTo, err = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterNearest)
	if err != nil {
		panic(err)
	}
}
예제 #4
0
파일: main.go 프로젝트: carriercomm/ebiten
func init() {
	var err error
	playerBarImage, err = ebiten.NewImage(300, 4, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	playerBarImage.Fill(&color.RGBA{0x80, 0x80, 0x80, 0xff})

	playerCurrentImage, err = ebiten.NewImage(4, 10, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	playerCurrentImage.Fill(&color.RGBA{0xff, 0xff, 0xff, 0xff})
}
예제 #5
0
파일: main.go 프로젝트: hajimehoshi/ebiten
func main() {
	var err error
	gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	w, h := gophersImage.Size()
	const repeat = 5
	repeatedGophersImage, err = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	for j := 0; j < repeat; j++ {
		for i := 0; i < repeat; i++ {
			op := &ebiten.DrawImageOptions{}
			op.GeoM.Translate(float64(w*i), float64(h*j))
			if err := repeatedGophersImage.DrawImage(gophersImage, op); err != nil {
				log.Fatal(err)
			}
		}
	}
	groundWidth := screenWidth + 70
	groundImage, err = ebiten.NewImage(groundWidth, screenHeight*2/3+50, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	const fogHeight = 8
	fogRGBA := image.NewRGBA(image.Rect(0, 0, groundWidth, fogHeight))
	for j := 0; j < fogHeight; j++ {
		a := uint32(float64(fogHeight-1-j) * 0xff / (fogHeight - 1))
		clr := skyColor
		r, g, b, oa := uint32(clr.R), uint32(clr.G), uint32(clr.B), uint32(clr.A)
		clr.R = uint8(r * a / oa)
		clr.G = uint8(g * a / oa)
		clr.B = uint8(b * a / oa)
		clr.A = uint8(a)
		for i := 0; i < groundWidth; i++ {
			fogRGBA.SetRGBA(i, j, clr)
		}
	}
	fogImage, err = ebiten.NewImageFromImage(fogRGBA, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Air Ship (Ebiten Demo)"); err != nil {
		log.Fatal(err)
	}
}
예제 #6
0
파일: main.go 프로젝트: DrJosh9000/ebiten
func main() {
	var err error
	const a0, a1, a2 = 0x40, 0xc0, 0xff
	pixels := []uint8{
		a0, a1, a1, a0,
		a1, a2, a2, a1,
		a1, a2, a2, a1,
		a0, a1, a1, a0,
	}
	brushImage, err = ebiten.NewImageFromImage(&image.Alpha{
		Pix:    pixels,
		Stride: 4,
		Rect:   image.Rect(0, 0, 4, 4),
	}, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}

	canvasImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	canvasImage.Fill(color.White)

	if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Paint (Ebiten Demo)"); err != nil {
		log.Fatal(err)
	}
}
예제 #7
0
파일: main.go 프로젝트: DrJosh9000/ebiten
func init() {
	var err error
	pianoImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
	if err != nil {
		panic(err)
	}
	whiteKeys := []string{"A", "S", "D", "F", "G", "H", "J", "K", "L"}
	width := 24
	y := 48
	for i, k := range whiteKeys {
		x := i*width + 36
		height := 112
		pianoImage.DrawFilledRect(x, y, width-1, height, color.White)
		common.ArcadeFont.DrawText(pianoImage, k, x+8, y+height-16, 1, color.Black)
	}

	blackKeys := []string{"Q", "W", "", "R", "T", "", "U", "I", "O"}
	for i, k := range blackKeys {
		if k == "" {
			continue
		}
		x := i*width + 24
		height := 64
		pianoImage.DrawFilledRect(x, y, width-1, height, color.Black)
		common.ArcadeFont.DrawText(pianoImage, k, x+8, y+height-16, 1, color.White)
	}
}
예제 #8
0
파일: main.go 프로젝트: carriercomm/ebiten
func main() {
	var err error
	gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	fiveyearsImage, _, err = common.AssetImage("fiveyears.jpg", ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	maskImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}

	as := image.Point{128, 128}
	a := image.NewAlpha(image.Rectangle{image.ZP, as})
	for j := 0; j < as.Y; j++ {
		for i := 0; i < as.X; i++ {
			r := as.X / 2
			d := math.Sqrt(float64((i-r)*(i-r) + (j-r)*(j-r)))
			b := uint8(max(0, min(0xff, 3*0xff-int(d*3*0xff)/r)))
			a.SetAlpha(i, j, color.Alpha{b})
		}
	}
	spotLightImage, err = ebiten.NewImageFromImage(a, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Masking (Ebiten Demo)"); err != nil {
		log.Fatal(err)
	}
}
예제 #9
0
// DebugPrint prints the given text str on the given image r.
func (d *debugPrintState) DebugPrint(r *ebiten.Image, str string) error {
	if d.textImage == nil {
		img, err := assets.TextImage()
		if err != nil {
			return err
		}
		d.textImage, err = ebiten.NewImageFromImage(img, ebiten.FilterNearest)
		if err != nil {
			return err
		}
	}
	if d.debugPrintRenderTarget == nil {
		width, height := 256, 256
		var err error
		d.debugPrintRenderTarget, err = ebiten.NewImage(width, height, ebiten.FilterNearest)
		if err != nil {
			return err
		}
	}
	if err := d.drawText(r, str, 1, 1, color.NRGBA{0x00, 0x00, 0x00, 0x80}); err != nil {
		return err
	}
	if err := d.drawText(r, str, 0, 0, color.NRGBA{0xff, 0xff, 0xff, 0xff}); err != nil {
		return err
	}
	return nil
}
예제 #10
0
파일: game.go 프로젝트: hajimehoshi/ebiten
func (g *Game) Draw(screen *ebiten.Image) error {
	if g.boardImage == nil {
		var err error
		w, h := g.board.Size()
		g.boardImage, err = ebiten.NewImage(w, h, ebiten.FilterNearest)
		if err != nil {
			return err
		}
	}
	if err := screen.Fill(backgroundColor); err != nil {
		return err
	}
	if err := g.board.Draw(g.boardImage); err != nil {
		return err
	}
	op := &ebiten.DrawImageOptions{}
	sw, sh := screen.Size()
	bw, bh := g.boardImage.Size()
	x := (sw - bw) / 2
	y := (sh - bh) / 2
	op.GeoM.Translate(float64(x), float64(y))
	if err := screen.DrawImage(g.boardImage, op); err != nil {
		return err
	}
	return nil
}
예제 #11
0
파일: tile.go 프로젝트: hajimehoshi/ebiten
func init() {
	var err error
	tileImage, err = ebiten.NewImage(tileSize, tileSize, ebiten.FilterNearest)
	if err != nil {
		panic(err)
	}
	if err := tileImage.Fill(color.White); err != nil {
		panic(err)
	}
}
예제 #12
0
파일: main.go 프로젝트: hajimehoshi/ebiten
func main() {
	var err error
	textImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	if err := parseFont(); err != nil {
		log.Fatal(err)
	}
	if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Font (Ebiten Demo)"); err != nil {
		log.Fatal(err)
	}
}
예제 #13
0
파일: main.go 프로젝트: hajimehoshi/ebiten
func main() {
	var err error
	gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	w, h := gophersImage.Size()
	gophersRenderTarget, err = ebiten.NewImage(w/mosaicRatio, h/mosaicRatio, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Mosaic (Ebiten Demo)"); err != nil {
		log.Fatal(err)
	}
}
예제 #14
0
func main() {
	var err error
	if cursorImage, err = ebiten.NewImage(4, 4, ebiten.FilterNearest); err != nil {
		log.Fatal(err)
	}
	cursorImage.Fill(color.White)
	var speed, scale, width, height int
	flag.IntVar(&speed, "speed", 15, "simulation steps per second")
	flag.IntVar(&scale, "scale", 16, "pixel scale factor")
	flag.IntVar(&width, "width", 64, "width of the simulation")
	flag.IntVar(&height, "height", 64, "height of the simulation")
	flag.Parse()
	flag.Args()

	cursorPosition = image.Point{width / 2, height / 2}
	simulationTimer = time.Tick(time.Second / time.Duration(speed))
	if flag.NArg() == 1 {
		inputFileName := flag.Arg(0)
		in, err := os.Open(inputFileName)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		gifImage, err := gif.DecodeAll(in)
		if err != nil {
			log.Fatal(err)
		}
		simulationImage = gifImage.Image[0]
		simulationImage.Palette[0] = color.Transparent
	} else {
		p := color.Palette{
			color.Black,
			color.RGBA{0x88, 0, 0, 0xFF},
			color.RGBA{0xFF, 0, 0, 0xFF},
			color.RGBA{0xFF, 0x22, 0, 0xFF},
			color.RGBA{0xFF, 0x44, 0, 0xFF},
			color.RGBA{0xFF, 0x66, 0, 0xFF},
			color.RGBA{0xFF, 0x88, 0, 0xFF},
			color.RGBA{0xFF, 0xAA, 0, 0xFF},
		}
		simulationImage = image.NewPaletted(image.Rect(0, 0, width, height), p)
	}
	reloadSimulation()
	if err := ebiten.Run(update, simulationImage.Bounds().Dx(), simulationImage.Bounds().Dy(), scale, "Wired Logic"); err != nil {
		log.Fatal(err)
	}
}
예제 #15
0
파일: main.go 프로젝트: DrJosh9000/ebiten
func main() {
	var err error
	ebitenImage, _, err = ebitenutil.NewImageFromFile("images/ebiten.png", ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	tmpRenderTarget, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	//update := update
	//f, _ := os.Create("out.gif")
	//update = ebitenutil.RecordScreenAsGIF(update, f, 100)
	if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Alpha Blending (Ebiten Demo)"); err != nil {
		log.Fatal(err)
	}
}
예제 #16
0
파일: gen.go 프로젝트: DrJosh9000/ebiten
func outputKeyboardImage() (map[string]image.Rectangle, error) {
	keyMap := map[string]image.Rectangle{}
	img, err := ebiten.NewImage(320, 240, ebiten.FilterNearest)
	if err != nil {
		return nil, err
	}
	x, y := 0, 0
	for j, line := range keyboardKeys {
		x = 0
		const height = 18
		for i, key := range line {
			width := 16
			switch j {
			default:
				switch i {
				case 0:
					width = 16 + 8*(j+2)
				case len(line) - 1:
					width = 16 + 8*(j+2)
				}
			case 4:
				switch i {
				case 0:
					width = 16 + 8*(j+2)
				case 1:
					width = 16 * 2
				case 2:
					width = 16 * 5
				case 3:
					width = 16 * 2
				case 4:
					width = 16 + 8*(j+2)
				}
			case 6, 7:
				width = 16 * 3
			}
			if key != "" {
				drawKey(img, key, x, y, width)
				if key != " " {
					keyMap[key] = image.Rect(x, y, x+width, y+height)
				}
			}
			x += width
		}
		y += height
	}

	palette := color.Palette([]color.Color{
		color.Transparent, color.Opaque,
	})
	palettedImg := image.NewPaletted(img.Bounds(), palette)
	draw.Draw(palettedImg, palettedImg.Bounds(), img, image.ZP, draw.Src)

	f, err := os.Create("images/keyboard/keyboard.png")
	if err != nil {
		return nil, err
	}
	defer f.Close()
	if err := png.Encode(f, palettedImg); err != nil {
		return nil, err
	}
	return keyMap, nil
}