コード例 #1
0
ファイル: game.go プロジェクト: runningwild/magnus
func (p *PlayerEnt) Draw(game *Game, side int) {
	var t *texture.Data
	var alpha gl.Ubyte
	if side == p.Side() {
		alpha = gl.Ubyte(255.0 * (1.0 - p.Stats().Cloaking()/2))
	} else {
		alpha = gl.Ubyte(255.0 * (1.0 - p.Stats().Cloaking()))
	}
	gl.Color4ub(255, 255, 255, alpha)
	// if p.Id() == 1 {
	t = texture.LoadFromPath(filepath.Join(base.GetDataDir(), "ships/ship.png"))
	// } else if p.Id() == 2 {
	// 	t = texture.LoadFromPath(filepath.Join(base.GetDataDir(), "ships/ship3.png"))
	// } else {
	// 	t = texture.LoadFromPath(filepath.Join(base.GetDataDir(), "ships/ship2.png"))
	// }
	t.RenderAdvanced(
		p.Position.X-float64(t.Dx())/2,
		p.Position.Y-float64(t.Dy())/2,
		float64(t.Dx()),
		float64(t.Dy()),
		p.Angle,
		false)

	for _, proc := range p.Processes {
		proc.Draw(p.Id(), game, side)
	}
	base.EnableShader("status_bar")
	base.SetUniformF("status_bar", "inner", 0.08)
	base.SetUniformF("status_bar", "outer", 0.09)
	base.SetUniformF("status_bar", "buffer", 0.01)

	base.SetUniformF("status_bar", "frac", 1.0)
	gl.Color4ub(125, 125, 125, alpha/2)
	texture.Render(p.Position.X-100, p.Position.Y-100, 200, 200)

	health_frac := float32(p.Stats().HealthCur() / p.Stats().HealthMax())
	if health_frac > 0.5 {
		color_frac := 1.0 - (health_frac-0.5)*2.0
		gl.Color4ub(gl.Ubyte(255.0*color_frac), 255, 0, alpha)
	} else {
		color_frac := health_frac * 2.0
		gl.Color4ub(255, gl.Ubyte(255.0*color_frac), 0, alpha)
	}
	base.SetUniformF("status_bar", "frac", health_frac)
	texture.Render(p.Position.X-100, p.Position.Y-100, 200, 200)
	base.EnableShader("")
}
コード例 #2
0
ファイル: mana_source.go プロジェクト: runningwild/magnus
func (ms *ManaSource) Draw(local *LocalData, zoom float64, dx float64, dy float64) {
	if local.nodeTextureData == nil {
		//		gl.Enable(gl.TEXTURE_2D)
		local.nodeTextureData = make([]byte, ms.options.NumNodeRows*ms.options.NumNodeCols*3)
		gl.GenTextures(1, &local.nodeTextureId)
		gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
		gl.TexImage2D(
			gl.TEXTURE_2D,
			0,
			gl.RGB,
			gl.Sizei(ms.options.NumNodeRows),
			gl.Sizei(ms.options.NumNodeCols),
			0,
			gl.RGB,
			gl.UNSIGNED_BYTE,
			gl.Pointer(&local.nodeTextureData[0]))
	}
	for i := range ms.rawNodes {
		for c := 0; c < 3; c++ {
			color_frac := ms.rawNodes[i].Mana[c] * 1.0 / ms.options.NodeMagnitude
			color_range := float64(ms.options.MaxNodeBrightness - ms.options.MinNodeBrightness)
			local.nodeTextureData[i*3+c] = byte(
				color_frac*color_range + float64(ms.options.MinNodeBrightness))
		}
	}
	gl.Enable(gl.TEXTURE_2D)
	//gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)
	gl.TexSubImage2D(
		gl.TEXTURE_2D,
		0,
		0,
		0,
		gl.Sizei(ms.options.NumNodeRows),
		gl.Sizei(ms.options.NumNodeCols),
		gl.RGB,
		gl.UNSIGNED_BYTE,
		gl.Pointer(&local.nodeTextureData[0]))

	base.EnableShader("nodes")
	base.SetUniformI("nodes", "width", ms.options.NumNodeRows*3)
	base.SetUniformI("nodes", "height", ms.options.NumNodeCols*3)
	base.SetUniformI("nodes", "drains", 1)
	base.SetUniformI("nodes", "tex0", 0)
	base.SetUniformI("nodes", "tex1", 1)
	base.SetUniformF("nodes", "zoom", float32(zoom))
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)

	// I have no idea why this value for move works, but it does.  So, hooray.
	move := (dx - dy) / 2
	texture.RenderAdvanced(move, -move, dy, dx, 3.1415926535/2, true)
	base.EnableShader("")
	gl.Disable(gl.TEXTURE_2D)
}
コード例 #3
0
ファイル: moba_tower.go プロジェクト: runningwild/magnus
func (cpap *controlPointAttackProcess) Draw(id Gid, g *Game, side int) {
	base.EnableShader("circle")
	base.SetUniformF("circle", "edge", 0.9)

	// For people on the controlling side this will draw a circle around the area
	// that is being targeted by the control point.
	if cpap.Side == side && cpap.Timer >= cpap.LockTime {
		gl.Color4ub(200, 200, 200, 80)
		texture.Render(
			cpap.LockPos.X-50,
			cpap.LockPos.Y-50,
			2*50,
			2*50)
	}

	// This draws the projectile itself.
	if cpap.Timer >= cpap.FireTime {
		gl.Color4ub(255, 50, 50, 240)
		texture.Render(
			cpap.ProjPos.X-5,
			cpap.ProjPos.Y-5,
			2*5,
			2*5)
	}
	base.EnableShader("")
}
コード例 #4
0
ファイル: fire.go プロジェクト: runningwild/magnus
func (f *fireProcessExplosion) Draw(gid game.Gid, g *game.Game, side int) {
	base.EnableShader("circle")
	base.SetUniformF("circle", "edge", 0.7)
	for _, expl := range f.Explosions {
		expl.Draw(false)
	}
	base.EnableShader("")
}
コード例 #5
0
ファイル: rift_walk.go プロジェクト: runningwild/magnus
func (p *riftWalkProcess) Draw(gid game.Gid, g *game.Game, side int) {
	player, ok := g.Ents[p.PlayerGid].(*game.PlayerEnt)
	if !ok {
		return
	}
	if side != player.Side() {
		return
	}
	frac := p.Stored.Magnitude() / p.Threshold
	if frac < 1 {
		gl.Color4ub(255, 0, 0, 255)
	} else {
		gl.Color4ub(0, 255, 0, 255)
	}
	base.EnableShader("status_bar")
	var outer float32 = 0.2
	var increase float32 = 0.01
	if frac > 1 {
		frac = 1
	}
	base.SetUniformF("status_bar", "frac", float32(frac))
	base.SetUniformF("status_bar", "inner", outer-increase)
	base.SetUniformF("status_bar", "outer", outer)
	base.SetUniformF("status_bar", "buffer", 0.01)
	texture.Render(player.Pos().X-100, player.Pos().Y-100, 200, 200)
	base.EnableShader("")

	dist, radius := p.GetVals()
	dest := player.Pos().Add((linear.Vec2{dist, 0}).Rotate(player.Angle))
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4d(1, 1, 1, 1)
	gl.Begin(gl.LINES)
	gl.Vertex2d(gl.Double(player.Pos().X), gl.Double(player.Pos().Y))
	gl.Vertex2d(gl.Double(dest.X), gl.Double(dest.Y))
	gl.End()
	n := 20
	gl.Begin(gl.LINES)
	for i := 0; i < n; i++ {
		v1 := dest.Add((linear.Vec2{radius, 0}).Rotate(float64(i) / float64(n) * 2 * math.Pi))
		v2 := dest.Add((linear.Vec2{radius, 0}).Rotate(float64(i+1) / float64(n) * 2 * math.Pi))
		gl.Vertex2d(gl.Double(v1.X), gl.Double(v1.Y))
		gl.Vertex2d(gl.Double(v2.X), gl.Double(v2.Y))
	}
	gl.End()
}
コード例 #6
0
ファイル: place_mine.go プロジェクト: runningwild/magnus
// TODO: This function really needs to take not just the side, but the player
// that this is being drawn for.
func (p *placeMineCastProcess) Draw(gid game.Gid, g *game.Game, side int) {
	player, _ := g.Ents[p.PlayerGid].(*game.PlayerEnt)
	if player == nil {
		return
	}
	if side != player.Side() {
		return
	}
	ready := int(p.Stored[game.ColorBlue] / p.Cost)
	base.EnableShader("status_bar")
	if ready == 0 {
		gl.Color4ub(255, 0, 0, 255)
	} else {
		gl.Color4ub(0, 255, 0, 255)
	}
	var outer float32 = 0.2
	var increase float32 = 0.01
	frac := p.Stored[game.ColorBlue] / p.Cost
	base.SetUniformF("status_bar", "frac", float32(frac-float64(ready)))
	base.SetUniformF("status_bar", "inner", outer-increase*float32(ready+1))
	base.SetUniformF("status_bar", "outer", outer)
	base.SetUniformF("status_bar", "buffer", 0.01)
	texture.Render(player.Pos().X-100, player.Pos().Y-100, 200, 200)
	if ready > 0 {
		base.SetUniformF("status_bar", "frac", 1.0)
		base.SetUniformF("status_bar", "inner", outer-float32(ready)*increase)
		base.SetUniformF("status_bar", "outer", outer)
		texture.Render(player.Pos().X-100, player.Pos().Y-100, 200, 200)
	}
	base.EnableShader("")
}
コード例 #7
0
ファイル: burst.go プロジェクト: dgthunder/magnus
func (p *burstProcess) Draw(player_id int, g *game.Game) {
	player := g.GetEnt(player_id).(*game.Player)
	base.EnableShader("circle")
	prog := p.Remaining_initial.Magnitude() / p.Initial.Magnitude()
	base.SetUniformF("circle", "progress", 1-float32(prog))
	gl.Color4ub(255, 255, 255, 255)
	radius := 40.0
	texture.Render(
		player.X-radius,
		player.Y-radius,
		2*radius,
		2*radius)
	base.EnableShader("")
}
コード例 #8
0
ファイル: fire.go プロジェクト: runningwild/magnus
func (fe fireExplosion) Draw(test bool) {
	base.EnableShader("circle")
	base.SetUniformF("circle", "edge", 0.7)
	if test {
		gl.Color4ub(200, 200, 200, gl.Ubyte(150*fe.Alpha()))
	} else {
		gl.Color4ub(255, 50, 10, gl.Ubyte(150*fe.Alpha()))
	}
	texture.Render(
		fe.Pos.X-fe.Size(),
		fe.Pos.Y-fe.Size(),
		2*fe.Size(),
		2*fe.Size())
	base.EnableShader("")
}
コード例 #9
0
ファイル: burst.go プロジェクト: runningwild/magnus
func (p *burstProcess) Draw(gid game.Gid, g *game.Game, side int) {
	player, ok := g.Ents[p.PlayerGid].(*game.PlayerEnt)
	if !ok {
		return
	}
	base.EnableShader("circle")
	prog := p.Remaining_initial.Magnitude() / p.Initial.Magnitude()
	base.SetUniformF("circle", "progress", 1-float32(prog))
	gl.Color4ub(255, 255, 255, 255)
	radius := 40.0
	texture.Render(
		player.Position.X-radius,
		player.Position.Y-radius,
		2*radius,
		2*radius)
	base.EnableShader("")
}
コード例 #10
0
ファイル: local.go プロジェクト: runningwild/magnus
func (g *Game) renderLosMask(local *LocalData) {
	ent := g.Ents[local.moba.currentPlayer.gid]
	if ent == nil {
		return
	}
	walls := g.temp.VisibleWallCache[GidInvadersStart].GetWalls(int(ent.Pos().X), int(ent.Pos().Y))
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4ub(0, 0, 0, 255)
	gl.Begin(gl.TRIANGLES)
	for _, wall := range walls {
		if wall.Right(ent.Pos()) {
			continue
		}
		a := wall.P
		b := ent.Pos().Sub(wall.P).Norm().Scale(-10000.0).Add(wall.P)
		mid := wall.P.Add(wall.Q).Scale(0.5)
		c := ent.Pos().Sub(mid).Norm().Scale(-10000.0).Add(mid)
		d := ent.Pos().Sub(wall.Q).Norm().Scale(-10000.0).Add(wall.Q)
		e := wall.Q
		gl.Vertex2d(gl.Double(a.X), gl.Double(a.Y))
		gl.Vertex2d(gl.Double(b.X), gl.Double(b.Y))
		gl.Vertex2d(gl.Double(c.X), gl.Double(c.Y))

		gl.Vertex2d(gl.Double(a.X), gl.Double(a.Y))
		gl.Vertex2d(gl.Double(c.X), gl.Double(c.Y))
		gl.Vertex2d(gl.Double(d.X), gl.Double(d.Y))

		gl.Vertex2d(gl.Double(a.X), gl.Double(a.Y))
		gl.Vertex2d(gl.Double(d.X), gl.Double(d.Y))
		gl.Vertex2d(gl.Double(e.X), gl.Double(e.Y))
	}
	gl.End()
	base.EnableShader("horizon")
	base.SetUniformV2("horizon", "center", ent.Pos())
	base.SetUniformF("horizon", "horizon", LosMaxDist)
	gl.Begin(gl.QUADS)
	dx := gl.Int(g.Levels[GidInvadersStart].Room.Dx)
	dy := gl.Int(g.Levels[GidInvadersStart].Room.Dy)
	gl.Vertex2i(0, 0)
	gl.Vertex2i(dx, 0)
	gl.Vertex2i(dx, dy)
	gl.Vertex2i(0, dy)
	gl.End()
	base.EnableShader("")
}
コード例 #11
0
ファイル: heat_seaker.go プロジェクト: runningwild/magnus
func (m *HeatSeeker) Draw(g *Game, side int) {
	base.EnableShader("status_bar")
	base.SetUniformF("status_bar", "inner", 0.01)
	base.SetUniformF("status_bar", "outer", 0.03)
	base.SetUniformF("status_bar", "buffer", 0.01)
	base.SetUniformF("status_bar", "frac", 1.0)
	gl.Color4ub(255, 255, 255, 255)
	texture.Render(m.Position.X-100, m.Position.Y-100, 200, 200)
	base.SetUniformF("status_bar", "inner", 0.04)
	base.SetUniformF("status_bar", "outer", 0.045)
	base.SetUniformF("status_bar", "buffer", 0.01)
	health_frac := float32(m.Stats().HealthCur() / m.Stats().HealthMax())
	if health_frac > 0.5 {
		color_frac := 1.0 - (health_frac-0.5)*2.0
		gl.Color4ub(gl.Ubyte(255.0*color_frac), 255, 0, 255)
	} else {
		color_frac := health_frac * 2.0
		gl.Color4ub(255, gl.Ubyte(255.0*color_frac), 0, 255)
	}
	base.SetUniformF("status_bar", "frac", health_frac)
	texture.Render(m.Position.X-100, m.Position.Y-100, 200, 200)
	base.EnableShader("")
}
コード例 #12
0
ファイル: moba_tower.go プロジェクト: runningwild/magnus
func (cp *ControlPoint) Draw(g *Game, side int) {
	base.EnableShader("circle")
	base.SetUniformF("circle", "edge", 0.95)
	gl.Color4ub(50, 50, 100, 150)
	texture.Render(
		cp.Position.X-cp.Stats().Size()*2,
		cp.Position.Y-cp.Stats().Size()*2,
		2*cp.Stats().Size()*2,
		2*cp.Stats().Size()*2)

	base.EnableShader("status_bar")
	base.SetUniformF("status_bar", "inner", 0.0)
	base.SetUniformF("status_bar", "outer", 0.5)
	base.SetUniformF("status_bar", "buffer", 0.01)
	base.SetUniformF("status_bar", "frac", 1.0)
	gl.Color4ub(50, 50, 50, 200)
	texture.Render(
		cp.Position.X-cp.Stats().Size(),
		cp.Position.Y-cp.Stats().Size(),
		2*cp.Stats().Size(),
		2*cp.Stats().Size())

	base.SetUniformF("status_bar", "frac", float32(cp.Control))
	if cp.Controlled {
		if side == cp.Controller {
			gl.Color4ub(0, 255, 0, 255)
		} else {
			gl.Color4ub(255, 0, 0, 255)
		}
	} else {
		gl.Color4ub(100, 100, 100, 255)
	}

	// The texture is flipped if this is being drawn for the controlling side.
	// This makes it look a little nicer when someone neutralizes a control point
	// because it makes the angle of the pie slice thingy continue going in the
	// same direction as it passes the neutralization point.
	texture.RenderAdvanced(
		cp.Position.X-cp.Stats().Size(),
		cp.Position.Y-cp.Stats().Size(),
		2*cp.Stats().Size(),
		2*cp.Stats().Size(),
		0,
		side == cp.Controller)
	base.EnableShader("")
}