예제 #1
0
파일: engine.go 프로젝트: mccordnate/gogam
func (a *arrangerFunc) Arrange(e s.Engine, n *s.Node, t clock.Time) {
	sprite, _ := a.eng.sprites[n]
	frameTime := float32(t - a.eng.lastUpdate)
	updatePosition(sprite, frameTime)

	screenWidthScaler, screenHeightScaler := a.eng.GetScreenScalers()
	actualScaleX := screenWidthScaler * sprite.ScaleX
	actualScaleY := screenHeightScaler * sprite.ScaleY
	actualPositionX := screenWidthScaler * sprite.X
	actualPositionY := screenHeightScaler * sprite.Y

	e.SetSubTex(n, *sprite.GetCurrentFrame().Texture)

	r := sprite.Rotation * math.Pi / 180
	matrix := f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	}

	matrix.Translate(&matrix, actualPositionX, actualPositionY)
	//matrix.Translate(&matrix, sprite.X, sprite.Y)
	matrix.Rotate(&matrix, r)
	matrix.Scale(&matrix, actualScaleX, actualScaleY)
	e.SetTransform(n, matrix)

	a.eng.lastUpdate = t
}
예제 #2
0
func (g *Game) Scene(eng sprite.Engine) *sprite.Node {
	texs := loadTextures(eng)

	scene := &sprite.Node{}
	eng.Register(scene)
	eng.SetTransform(scene, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})

	newNode := func(fn arrangerFunc) {
		n := &sprite.Node{Arranger: arrangerFunc(fn)}
		eng.Register(n)
		scene.AppendChild(n)
	}

	// The gopher.
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texGopher])
		eng.SetTransform(n, f32.Affine{
			{tileWidth, 0, 0},
			{0, tileHeight, 0},
		})
	})
	return scene
}
예제 #3
0
파일: card.go 프로젝트: vanadium/croupier
// Moves c to a new position and size
func (c *Card) Move(newXY, newDimensions *coords.Vec, eng sprite.Engine) {
	eng.SetTransform(c.node, f32.Affine{
		{newDimensions.X, 0, newXY.X},
		{0, newDimensions.Y, newXY.Y},
	})
	c.current = newXY
	c.dimensions = newDimensions
}
예제 #4
0
// Moves s to a new position and size
func (s *StaticImg) Move(newXY, newDimensions *coords.Vec, eng sprite.Engine) {
	eng.SetTransform(s.node, f32.Affine{
		{newDimensions.X, 0, newXY.X},
		{0, newDimensions.Y, newXY.Y},
	})
	s.current = newXY
	s.dimensions = newDimensions
}
예제 #5
0
파일: card.go 프로젝트: vanadium/croupier
func (c *Card) Move(eng sprite.Engine, newX float32, newY float32) {
	eng.SetTransform(c.node, f32.Affine{
		{c.width, 0, newX},
		{0, c.height, newY},
	})
	c.x = newX
	c.y = newY
}
예제 #6
0
func (g *Game) Scene(eng sprite.Engine) *sprite.Node {
	texs := loadTextures(eng)

	scene = &sprite.Node{} // sceneのルートノードを生成
	eng.Register(scene)    // Engineオブジェクトにルートノードを登録
	// ルートの初期位置やスケールを設定する
	eng.SetTransform(scene, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})

	newNode := func(fn arrangerFunc) {
		n := &sprite.Node{Arranger: arrangerFunc(fn)}
		eng.Register(n)
		scene.AppendChild(n)
	}

	// The ground.
	// 地面を描画するメソッド
	for i := range g.groundY {
		i := i
		// 地表の描画
		newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
			eng.SetSubTex(n, texs[texGround]) //texGroundのテクスチャを使う
			eng.SetTransform(n, f32.Affine{
				{tileWidth, 0, float32(i)*tileWidth - g.scroll.x},
				{0, tileHeight, g.groundY[i]}, //地面を描画する
			})
		})
		// 地中の描画
		newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
			eng.SetSubTex(n, texs[texEarth])
			eng.SetTransform(n, f32.Affine{
				{tileWidth, 0, float32(i) * tileWidth},
				{0, tileHeight * tilesY, g.groundY[i] + tileHeight},
			})
		})
	}

	// The gopher.
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texGopher])
		eng.SetTransform(n, f32.Affine{
			{tileWidth, 0, tileWidth * gopherTile},
			{0, tileHeight, g.gopher.y},
		})
	})

	return scene
}
예제 #7
0
func loadScene(eng sprite.Engine, ts map[string]sprite.SubTex) *sprite.Node {
	root := &sprite.Node{}
	eng.Register(root)
	eng.SetTransform(root, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})

	n := &sprite.Node{}
	eng.Register(n)
	root.AppendChild(n)
	eng.SetTransform(n, f32.Affine{
		{200, 0, 0},
		{0, 200, 0},
	})
	n.Arranger = arrangerFunc(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		s := fmt.Sprintf("%02d", int(t))
		eng.SetSubTex(n, ts[s[0:1]])
	})

	return root
}
예제 #8
0
파일: bbot.go 프로젝트: viru/berrybot
// Scene creates and returns a new app scene.
func (a *App) Scene(eng sprite.Engine, sz size.Event) *sprite.Node {
	texs := loadTextures(eng)
	scene := &sprite.Node{}
	eng.Register(scene)
	eng.SetTransform(scene, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})

	newNode := func(fn arrangerFunc) {
		n := &sprite.Node{Arranger: arrangerFunc(fn)}
		eng.Register(n)
		scene.AppendChild(n)
	}

	// Controller boundaries.
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texCtrl])
		eng.SetTransform(n, f32.Affine{
			{ctrlSize, 0, a.ctrl.x},
			{0, ctrlSize, a.ctrl.y},
		})
	})

	// Controller stick.
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texStick])
		eng.SetTransform(n, f32.Affine{
			{ctrlStickSize, 0, a.stick.x},
			{0, ctrlStickSize, a.stick.y},
		})
	})

	// Bot.
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texBot])
		eng.SetTransform(n, f32.Affine{
			{botSize, 0, a.bot.x},
			{0, botSize, a.bot.y},
		})
	})

	// Proximity small.
	const (
		smSizeW = 15
		smSizeH = 5
	)
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texProxSmGrey+a.bot.front.sm])
		eng.SetTransform(n, f32.Affine{
			{smSizeW, 0, a.bot.x + botSize/2 - smSizeW/2},
			{0, smSizeH, a.bot.y - 2*smSizeH},
		})
	})
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texProxSmGrey+a.bot.rear.sm])
		eng.SetTransform(n, f32.Affine{
			{smSizeW, 0, a.bot.x + botSize/2 - smSizeW/2},
			{0, -smSizeH, a.bot.y + botSize + 2*smSizeH},
		})
	})

	// Proximity medium.
	const (
		mdSizeW = 25
		mdSizeH = 7
	)
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texProxMdGrey+a.bot.front.md])
		eng.SetTransform(n, f32.Affine{
			{mdSizeW, 0, a.bot.x + botSize/2 - mdSizeW/2},
			{0, mdSizeH, a.bot.y - 3*mdSizeH},
		})
	})
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texProxMdGrey+a.bot.rear.md])
		eng.SetTransform(n, f32.Affine{
			{mdSizeW, 0, a.bot.x + botSize/2 - mdSizeW/2},
			{0, -mdSizeH, a.bot.y + botSize + 3*mdSizeH},
		})
	})

	// Proximity large
	const (
		lgSizeW = 35
		lgSizeH = 10
	)
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texProxLgGrey+a.bot.front.lg])
		eng.SetTransform(n, f32.Affine{
			{lgSizeW, 0, a.bot.x + botSize/2 - lgSizeW/2},
			{0, lgSizeH, a.bot.y - 3.2*lgSizeH},
		})
	})
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		eng.SetSubTex(n, texs[texProxLgGrey+a.bot.rear.lg])
		eng.SetTransform(n, f32.Affine{
			{lgSizeW, 0, a.bot.x + botSize/2 - lgSizeW/2},
			{0, -lgSizeH, a.bot.y + botSize + 3.2*lgSizeH},
		})
	})

	return scene
}
예제 #9
0
파일: game.go 프로젝트: tayamahotate/game
func (g *Game) Scene(eng sprite.Engine) *sprite.Node {
	texs := loadTextures(eng)

	scene := &sprite.Node{}
	eng.Register(scene)
	eng.SetTransform(scene, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})

	newNode := func(fn arrangerFunc) {
		n := &sprite.Node{Arranger: arrangerFunc(fn)}
		eng.Register(n)
		scene.AppendChild(n)
	}

	// The ground.
	for i := range g.groundY {
		i := i
		// The top of the ground.
		newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
			eng.SetSubTex(n, texs[g.groundTex[i]])
			eng.SetTransform(n, f32.Affine{
				{tileWidth, 0, float32(i)*tileWidth - g.scroll.x},
				{0, tileHeight, g.groundY[i]},
			})
		})
		// The earth beneath.
		newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
			eng.SetSubTex(n, texs[texEarth])
			eng.SetTransform(n, f32.Affine{
				{tileWidth, 0, float32(i)*tileWidth - g.scroll.x},
				{0, tileHeight * tilesY, g.groundY[i] + tileHeight},
			})
		})
	}

	// The gopher.
	newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		a := f32.Affine{
			{tileWidth * 2, 0, tileWidth*(gopherTile-1) + tileWidth/8},
			{0, tileHeight * 2, g.gopher.y - tileHeight + tileHeight/4},
		}
		var x int
		switch {
		case g.gopher.dead:
			x = frame(t, 16, texGopherDead1, texGopherDead2)
			animateDeadGopher(&a, t-g.gopher.deadTime)
		case g.gopher.v < 0:
			x = frame(t, 4, texGopherFlap1, texGopherFlap2)
		case g.gopher.atRest:
			x = frame(t, 4, texGopherRun1, texGopherRun2)
		default:
			x = frame(t, 8, texGopherRun1, texGopherRun2)
		}
		eng.SetSubTex(n, texs[x])
		eng.SetTransform(n, a)
	})

	return scene
}