Esempio n. 1
0
func loadTextures() []sprite.SubTex {
	a, err := asset.Open("cards.jpeg")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(img)
	if err != nil {
		log.Fatal(err)
	}

	a2, err := asset.Open("dropTarget.jpeg")
	if err != nil {
		log.Fatal(err)
	}
	defer a2.Close()

	img2, _, err := image.Decode(a2)
	if err != nil {
		log.Fatal(err)
	}
	t2, err := eng.LoadTexture(img2)
	if err != nil {
		log.Fatal(err)
	}

	a3, err := asset.Open("deck.jpeg")
	if err != nil {
		log.Fatal(err)
	}
	defer a3.Close()

	img3, _, err := image.Decode(a3)
	if err != nil {
		log.Fatal(err)
	}
	t3, err := eng.LoadTexture(img3)
	if err != nil {
		log.Fatal(err)
	}

	return []sprite.SubTex{
		card1:      sprite.SubTex{t, image.Rect(15, 15, 190, 260)},
		card2:      sprite.SubTex{t, image.Rect(195, 60, 370, 305)},
		card3:      sprite.SubTex{t, image.Rect(375, 107, 550, 350)},
		card4:      sprite.SubTex{t, image.Rect(555, 135, 730, 377)},
		dropTarget: sprite.SubTex{t2, image.Rect(0, 0, 766, 620)},
		draw:       sprite.SubTex{t3, image.Rect(0, 0, 1506/2, 1052)},
		discard:    sprite.SubTex{t3, image.Rect(1506/2, 0, 1506, 1052)},
	}
}
Esempio n. 2
0
func MustOpen(name string) asset.File {
	f, err := asset.Open(name)
	if err != nil {
		log.Fatal(err)
	}
	return f
}
Esempio n. 3
0
func loadTexture(glctx gl.Context) {
	a, err := asset.Open("key.jpeg")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}

	rect := img.Bounds()
	rgba := image.NewRGBA(rect)
	draw.Draw(rgba, rect, img, rect.Min, draw.Src)
	tex := glctx.CreateTexture()

	glctx.ActiveTexture(gl.TEXTURE0)
	glctx.BindTexture(gl.TEXTURE_2D, tex)

	glctx.TexImage2D(gl.TEXTURE_2D, 0, 859, 610, gl.RGBA, gl.UNSIGNED_BYTE, rgba.Pix)

	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)

	glctx.ActiveTexture(gl.TEXTURE0)
	glctx.BindTexture(gl.TEXTURE_2D, tex)
	glctx.TexImage2D(
		gl.TEXTURE_2D, 0,
		rect.Max.X-rect.Min.X, rect.Max.Y-rect.Min.Y,
		gl.RGBA, gl.UNSIGNED_BYTE, rgba.Pix)
}
Esempio n. 4
0
func loadTextures() map[string]sprite.SubTex {
	a, err := asset.Open("tx_letters.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(img)
	if err != nil {
		log.Fatal(err)
	}

	return map[string]sprite.SubTex{
		":":     sprite.SubTex{t, image.Rect(0, 0, 200, 200)},
		"0":     sprite.SubTex{t, image.Rect(200, 0, 400, 200)},
		"1":     sprite.SubTex{t, image.Rect(400, 0, 600, 200)},
		"2":     sprite.SubTex{t, image.Rect(0, 200, 200, 400)},
		"3":     sprite.SubTex{t, image.Rect(200, 200, 400, 400)},
		"4":     sprite.SubTex{t, image.Rect(400, 200, 600, 400)},
		"5":     sprite.SubTex{t, image.Rect(0, 400, 200, 600)},
		"6":     sprite.SubTex{t, image.Rect(200, 400, 400, 600)},
		"7":     sprite.SubTex{t, image.Rect(400, 400, 600, 600)},
		"8":     sprite.SubTex{t, image.Rect(0, 600, 200, 800)},
		"9":     sprite.SubTex{t, image.Rect(200, 600, 400, 800)},
		"GO":    sprite.SubTex{t, image.Rect(0, 800, 600, 1000)},
		"gooon": sprite.SubTex{t, image.Rect(0, 1000, 600, 1200)},
	}
}
Esempio n. 5
0
func loadTextures(eng sprite.Engine) []sprite.SubTex {
	a, err := asset.Open("placeholder-sprites.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close() // 処理が終わったらCloseする

	m, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}

	t, err := eng.LoadTexture(m)
	if err != nil {
		log.Fatal(err)
	}

	const n = 128
	return []sprite.SubTex{
		texGopher: sprite.SubTex{t, image.Rect(1+0, 0, n-1, n)},     //splite画像の一番左の青色のテクスチャを切り出す
		texGround: sprite.SubTex{t, image.Rect(1+n*2, 0, n*3-1, n)}, //splite画像の左からn-1番目のテクスチャを切り出す
		texEarth:  sprite.SubTex{t, image.Rect(1+n*5, 0, n*6-1, n)}, //splite画像の左からn-1番目のテクスチャを切り出す
	}

}
Esempio n. 6
0
func loadAsset(name string) ([]byte, error) {
	f, err := asset.Open(name)
	if err != nil {
		return nil, err
	}
	return ioutil.ReadAll(f)
}
Esempio n. 7
0
func loadTextures(eng sprite.Engine) []sprite.SubTex {
	a, err := asset.Open("sprite.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	m, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(m)
	if err != nil {
		log.Fatal(err)
	}

	const n = 128
	return []sprite.SubTex{
		texGopherRun1:  sprite.SubTex{t, image.Rect(n*0, 0, n*1, n)},
		texGopherRun2:  sprite.SubTex{t, image.Rect(n*1, 0, n*2, n)},
		texGopherFlap1: sprite.SubTex{t, image.Rect(n*2, 0, n*3, n)},
		texGopherFlap2: sprite.SubTex{t, image.Rect(n*3, 0, n*4, n)},
		texGopherDead1: sprite.SubTex{t, image.Rect(n*4, 0, n*5, n)},
		texGopherDead2: sprite.SubTex{t, image.Rect(n*5, 0, n*6-1, n)},
		texGround1:     sprite.SubTex{t, image.Rect(n*6+1, 0, n*7-1, n)},
		texGround2:     sprite.SubTex{t, image.Rect(n*7+1, 0, n*8-1, n)},
		texGround3:     sprite.SubTex{t, image.Rect(n*8+1, 0, n*9-1, n)},
		texGround4:     sprite.SubTex{t, image.Rect(n*9+1, 0, n*10-1, n)},
		texEarth:       sprite.SubTex{t, image.Rect(n*10+1, 0, n*11-1, n)},
	}
}
Esempio n. 8
0
func LoadTexture(name string) (tex gl.Texture, err error) {
	imgFile, err := asset.Open(name)
	if err != nil {
		return
	}
	img, _, err := image.Decode(imgFile)
	if err != nil {
		return
	}

	rgba := image.NewRGBA(img.Bounds())
	image_draw.Draw(rgba, rgba.Bounds(), img, image.Point{0, 0}, image_draw.Src)

	tex = gl.CreateTexture()
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, tex)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
	gl.TexImage2D(
		gl.TEXTURE_2D,
		0,
		rgba.Rect.Size().X,
		rgba.Rect.Size().Y,
		gl.RGBA,
		gl.UNSIGNED_BYTE,
		rgba.Pix)

	return
}
Esempio n. 9
0
File: game.go Progetto: 2722/lantern
func loadTextures(eng sprite.Engine) []sprite.SubTex {
	a, err := asset.Open("sprite.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	m, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(m)
	if err != nil {
		log.Fatal(err)
	}

	const n = 128
	// The +1's and -1's in the rectangles below are to prevent colors from
	// adjacent textures leaking into a given texture.
	// See: http://stackoverflow.com/questions/19611745/opengl-black-lines-in-between-tiles
	return []sprite.SubTex{
		texGopherRun1:  sprite.SubTex{t, image.Rect(n*0+1, 0, n*1-1, n)},
		texGopherRun2:  sprite.SubTex{t, image.Rect(n*1+1, 0, n*2-1, n)},
		texGopherFlap1: sprite.SubTex{t, image.Rect(n*2+1, 0, n*3-1, n)},
		texGopherFlap2: sprite.SubTex{t, image.Rect(n*3+1, 0, n*4-1, n)},
		texGopherDead1: sprite.SubTex{t, image.Rect(n*4+1, 0, n*5-1, n)},
		texGopherDead2: sprite.SubTex{t, image.Rect(n*5+1, 0, n*6-1, n)},
		texGround1:     sprite.SubTex{t, image.Rect(n*6+1, 0, n*7-1, n)},
		texGround2:     sprite.SubTex{t, image.Rect(n*7+1, 0, n*8-1, n)},
		texGround3:     sprite.SubTex{t, image.Rect(n*8+1, 0, n*9-1, n)},
		texGround4:     sprite.SubTex{t, image.Rect(n*9+1, 0, n*10-1, n)},
		texEarth:       sprite.SubTex{t, image.Rect(n*10+1, 0, n*11-1, n)},
	}
}
Esempio n. 10
0
func Load(filename string) {

	file, _ := asset.Open(filename)

	scanner := bufio.NewReader(file)

	var maxSize int = 300000

	var fileData []byte = make([]byte, maxSize)

	size, _ := scanner.Read(fileData)

	fileData = fileData[:size]

	var buf bytes.Buffer = *bytes.NewBuffer(fileData)

	dec := gob.NewDecoder(&buf)

	err := dec.Decode(&dict)
	if err == nil {
		isLoaded = true
	}
	pos = make(map[int]int)
	end = make(map[int]bool)
	rewind()
}
Esempio n. 11
0
func loadTextures(eng sprite.Engine) []sprite.SubTex {
	a, err := asset.Open("assets.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	m, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(m)
	if err != nil {
		log.Fatal(err)
	}

	const n = 128
	// The +1's and -1's in the rectangles below are to prevent colors from
	// adjacent textures leaking into a given texture.
	// See: http://stackoverflow.com/questions/19611745/opengl-black-lines-in-between-tiles
	return []sprite.SubTex{
		texCtrl:         {T: t, R: image.Rect(0, 0, 320, 320)},
		texStick:        {T: t, R: image.Rect(320, 0, 440, 120)},
		texBot:          {T: t, R: image.Rect(0, 320, 300, 610)},
		texProxSmGrey:   {T: t, R: image.Rect(300, 320, 300+50, 320+15)},
		texProxSmGreen:  {T: t, R: image.Rect(300, 320+15, 300+50, 320+30)},
		texProxSmOrange: {T: t, R: image.Rect(300, 320+30, 300+50, 320+45)},
		texProxSmRed:    {T: t, R: image.Rect(300, 320+45, 300+50, 320+60)},
		texProxMdGrey:   {T: t, R: image.Rect(300, 320+60, 300+78, 320+80)},
		texProxMdOrange: {T: t, R: image.Rect(300, 320+80, 300+78, 320+100)},
		texProxMdRed:    {T: t, R: image.Rect(300, 320+100, 300+78, 320+120)},
		texProxLgGrey:   {T: t, R: image.Rect(300, 320+120, 300+110, 320+147)},
		texProxLgRed:    {T: t, R: image.Rect(300, 320+147, 300+110, 320+174)},
	}
}
Esempio n. 12
0
func loadSprite(fileName string) Sprite {
	a, err := asset.Open(fileName)
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(img)
	if err != nil {
		log.Fatal(err)
	}

	bounds := img.Bounds()

	imgWidth := bounds.Max.X - bounds.Min.X
	imgHeight := bounds.Max.Y - bounds.Min.Y
	log.Printf("sprite %v size: %vx%v\n", fileName, imgWidth, imgHeight)

	subTex := sprite.SubTex{t, image.Rect(0, 0, imgWidth, imgHeight)}

	return Sprite{
		SubTex: subTex,
		Width:  imgWidth,
		Height: imgHeight,
	}
}
Esempio n. 13
0
func onStart() {
	rc, err := asset.Open("boing.wav")
	if err != nil {
		log.Fatal(err)
	}
	player, err = audio.NewPlayer(rc, 0, 0)
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 14
0
func PlaySound(name string) {
	println("Playing Sound: " + name)
	rc, err := asset.Open("sound/" + name + ".wav")
	if err != nil {
		panic(err)
	}
	soundsPlayer, err = audio.NewPlayer(rc, 0, 0)
	if err != nil {
		panic(err)
	}
	soundsPlayer.Play()
	// player.Close()
}
Esempio n. 15
0
func onStart() {
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	rc, err := asset.Open("hello.wav")
	if err != nil {
		log.Fatal(err)
	}
	player, err = audio.NewPlayer(rc, 0, 0)
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 16
0
func loadSE() {
	rc, err := asset.Open("gooon.wav")
	if err != nil {
		log.Fatal(err)
	}
	player, err = audio.NewPlayer(rc, 0, 0)
	if err != nil {
		log.Fatal(err)
	}

	player.SetVolume(1)
	//log.Println("SE open")
}
Esempio n. 17
0
func InitPlayers(u *uistate.UIState) {
	for i, _ := range u.Audio.Players {
		rc, err := asset.Open(u.Audio.Sounds[i])
		if err != nil {
			fmt.Println("FIRST ERR")
			log.Fatal(err)
		}
		u.Audio.Players[i], err = audio.NewPlayer(rc, 0, 0)
		if err != nil {
			fmt.Println("SECOND ERR")
			log.Fatal(err)
		}
	}
}
Esempio n. 18
0
func onStart(glctx gl.Context) {
	images = glutil.NewImages(glctx)
	eng = glsprite.Engine(images)
	loadScene()

	rc, err := asset.Open("boing.wav")
	if err != nil {
		log.Fatal(err)
	}
	player, err = audio.NewPlayer(rc, 0, 0)
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 19
0
func (loader *textureLoader) loadAsset(name string) (*image.RGBA, error) {
	imgFile, err := asset.Open(name)
	if err != nil {
		return nil, err
	}
	defer imgFile.Close()
	img, _, err := image.Decode(imgFile)
	if err != nil {
		return nil, err
	}

	rgba := image.NewRGBA(img.Bounds())
	image_draw.Draw(rgba, rgba.Bounds(), img, image.Point{0, 0}, image_draw.Src)
	return rgba, nil
}
Esempio n. 20
0
func loadFont() *truetype.Font {
	ttf, err := asset.Open("luximr.ttf")
	if err != nil {
		log.Fatal(err)
	}
	b, err := ioutil.ReadAll(ttf)
	if err != nil {
		log.Fatal(err)
	}
	f, err := truetype.Parse(b)
	if err != nil {
		log.Fatal(err)
	}

	return f
}
Esempio n. 21
0
func NewTexture(path string, eng *Engine) *spr.Texture {
	ass, err := asset.Open(path)
	if err != nil {
		log.Fatal(err)
	}
	defer ass.Close()
	i, _, err := image.Decode(ass)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(i)
	if err != nil {
		log.Fatal(err)
	}

	return &t
}
Esempio n. 22
0
// LoadAsset loads the asset at path and interprets it as a font for rendering
// with golang.org/x/image/font using opt to create the font.Face object.
func LoadAsset(path string, opt *truetype.Options) (*truetype.Font, font.Face, error) {
	f, err := asset.Open(path)
	if err != nil {
		return nil, nil, err
	}
	defer f.Close()
	raw, err := ioutil.ReadAll(f)
	if err != nil {
		return nil, nil, err
	}
	ttf, err := freetype.ParseFont(raw)
	if err != nil {
		return nil, nil, err
	}
	face := truetype.NewFace(ttf, opt)
	return ttf, face, nil
}
Esempio n. 23
0
func loadGopher() sprite.SubTex {
	a, err := asset.Open("gopher.jpeg")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(img)
	if err != nil {
		log.Fatal(err)
	}
	return sprite.SubTex{t, image.Rect(0, 0, 360, 300)}
}
Esempio n. 24
0
func loadImages(path string) *image.RGBA {
	// allocating image holder
	var img image.Image

	imgFile, e := asset.Open(path)
	def_check(e)
	defer imgFile.Close()

	// decoding image
	img, _, e = image.Decode(imgFile)
	def_check(e)
	// pure rgbaing
	rgba := image.NewRGBA(img.Bounds())
	draw.Draw(rgba, rgba.Bounds(), img, image.Point{0, 0}, draw.Src)

	return rgba
}
Esempio n. 25
0
func loadFont(r Resource) (*truetype.Font, error) {
	if strings.HasPrefix(r.url, "assets/") {
		r.url = r.url[7:]
	}

	file, err := asset.Open(r.url)
	if err != nil {
		return nil, err
	}

	ttfBytes, err := ioutil.ReadAll(file)
	if err != nil {
		return nil, err
	}

	return freetype.ParseFont(ttfBytes)
}
Esempio n. 26
0
func loadKeyboard() sprite.SubTex {
	a, err := asset.Open("piano-octave.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(img)
	if err != nil {
		log.Fatal(err)
	}
	return sprite.SubTex{t, image.Rect(0, 0, 500, 249)}
}
Esempio n. 27
0
func loadTextures(assetName string, rect image.Rectangle) sprite.SubTex {

	a, err := asset.Open(assetName)
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(img)
	if err != nil {
		log.Fatal(err)
	}

	return sprite.SubTex{t, rect}
}
Esempio n. 28
0
func loadTexture(name string) sprite.SubTex {
	f, err := asset.Open(name)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	img, _, err := image.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	t, err := eng.LoadTexture(img)
	if err != nil {
		log.Fatal(err)
	}

	return sprite.SubTex{t, image.Rect(0, 0, 16, 16)}
}
Esempio n. 29
0
func loadKid() sprite.SubTex {
	file := picForDay(time.Now())

	a, err := asset.Open(file)
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(img)
	if err != nil {
		log.Fatal(err)
	}

	return sprite.SubTex{T: t, R: image.Rect(0, 0, 466, 466)}
}
Esempio n. 30
0
func (self *GLPeer) LoadTexture(assetName string, rect image.Rectangle) sprite.SubTex {
	LogDebug("IN")
	a, err := asset.Open(assetName)
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := self.eng.LoadTexture(img)
	if err != nil {
		log.Fatal(err)
	}

	LogDebug("OUT")
	return sprite.SubTex{t, rect}
}