func (g *Game) RenderLocalSetup(region g2.Region, local *LocalData) { dict := base.GetDictionary("luxisr") size := 60.0 y := 100.0 dict.RenderString("Engines:", size, y, 0, size, gui.Left) for i, id := range g.Setup.EngineIds { y += size if id == local.engine.Id() { gui.SetFontColor(0.7, 0.7, 1, 1) } else { gui.SetFontColor(0.7, 0.7, 0.7, 1) } dataStr := fmt.Sprintf("Engine %d, Side %d, %s", id, g.Setup.Sides[id].Side, g.Champs[g.Setup.Sides[id].Champ].Name) dict.RenderString(dataStr, size, y, 0, size, gui.Left) if local.engine.Id() == 1 && i == local.setup.index { dict.RenderString(">", 50, y, 0, size, gui.Right) } } y += size gui.SetFontColor(0.7, 0.7, 0.7, 1) if local.engine.Id() == 1 { dict.RenderString("Start!", size, y, 0, size, gui.Left) if local.setup.index == len(g.Setup.EngineIds) { dict.RenderString(">", 50, y, 0, size, gui.Right) } } ids := local.engine.Ids() if len(ids) > 0 { // This is the host engine - so update the list of ids in case it's changed local.engine.ApplyEvent(SetupSetEngineIds{ids}) } }
func (b *Button) Draw(region Region, style StyleStack) { b.Last = region selected, ok := style.Get("selected").(bool) var xOffset float64 var renderName string if b.Hover || (ok && selected) { gui.SetFontColor(0, 0, 0, 1) renderName = ">" + b.Name xOffset = 0.0 } else { gui.SetFontColor(0, 0, 0, 0.7) renderName = b.Name xOffset = base.GetDictionary("luxisr").StringWidth(">", float64(b.Size)) } base.GetDictionary("luxisr").RenderString(renderName, xOffset+float64(region.X), float64(region.Y), 0, float64(b.Size), gui.Left) }
func (g *Game) renderLocalMoba(region g2.Region, local *LocalData) { g.renderLocalHelper(region, local, &local.moba.currentPlayer.camera, local.moba.currentPlayer.side) if g.Ents[local.moba.currentPlayer.gid] == nil { var id int64 fmt.Sscanf(string(local.moba.currentPlayer.gid), "Engine:%d", &id) seconds := float64(g.Engines[id].CountdownFrames) / 60.0 dict := base.GetDictionary("luxisr") gui.SetFontColor(0.7, 0.7, 1, 1) dict.RenderString(fmt.Sprintf("%2.3f", seconds), 300, 300, 0, 100, gui.Left) } }
func (p *pullProcess) Draw(player_id int, g *game.Game) { gl.Color4d(1, 1, 1, 1) gl.Disable(gl.TEXTURE_2D) player := g.GetEnt(player_id).(*game.Player) v1 := player.Pos() v2 := v1.Add(linear.Vec2{1000, 0}) v3 := v2.RotateAround(v1, player.Angle-p.Angle/2) v4 := v2.RotateAround(v1, player.Angle+p.Angle/2) gl.Begin(gl.LINES) vs := []linear.Vec2{v3, v4, linear.Vec2{player.X, player.Y}} for i := range vs { gl.Vertex2d(gl.Double(vs[i].X), gl.Double(vs[i].Y)) gl.Vertex2d(gl.Double(vs[(i+1)%len(vs)].X), gl.Double(vs[(i+1)%len(vs)].Y)) } gl.End() s := fmt.Sprintf("%.2f", p.supplied) base.Log().Printf("'%s'", s) if true { base.GetDictionary("luxisr").RenderString(s, 10, 10, 0, 50, gin.Left) } }
func (g *Game) renderLocalArchitect(region g2.Region, local *LocalData) { local.architect.camera.doArchitectFocusRegion(g, local.sys) gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() // Set the viewport so that we only render into the region that we're supposed // to render to. // TODO: Check if this works on all graphics cards - I've heard that the opengl // spec doesn't actually require that viewport does any clipping. gl.PushAttrib(gl.VIEWPORT_BIT) gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy)) defer gl.PopAttrib() current := local.architect.camera.current gl.Ortho( gl.Double(current.mid.X-current.dims.X/2), gl.Double(current.mid.X+current.dims.X/2), gl.Double(current.mid.Y+current.dims.Y/2), gl.Double(current.mid.Y-current.dims.Y/2), gl.Double(1000), gl.Double(-1000), ) defer func() { gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) }() gl.MatrixMode(gl.MODELVIEW) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) zoom := local.architect.camera.current.dims.X / float64(region.Dims.Dx) level := g.Levels[GidInvadersStart] level.ManaSource.Draw(local, zoom, float64(level.Room.Dx), float64(level.Room.Dy)) gl.Begin(gl.LINES) gl.Color4d(1, 1, 1, 1) for _, poly := range g.Levels[GidInvadersStart].Room.Walls { for i := range poly { seg := poly.Seg(i) gl.Vertex2d(gl.Double(seg.P.X), gl.Double(seg.P.Y)) gl.Vertex2d(gl.Double(seg.Q.X), gl.Double(seg.Q.Y)) } } gl.End() gl.Color4ub(0, 255, 0, 255) for side, pos := range g.Levels[GidInvadersStart].Room.Starts { base.GetDictionary("luxisr").RenderString(fmt.Sprintf("S%d", side), pos.X, pos.Y, 0, 100, gui.Center) } gl.Color4d(1, 1, 1, 1) for _, ent := range g.temp.AllEnts { ent.Draw(g, -1) // TODO: Side isn't defined for architect yet } gl.Disable(gl.TEXTURE_2D) g.renderLosMask(local) if local.architect.abs.activeAbility != nil { local.architect.abs.activeAbility.Draw("", g, -1) // TODO: side not defined for architect } }
// For invaders or moba, does a lot of basic stuff common to both func (g *Game) renderLocalHelper(region g2.Region, local *LocalData, camera *cameraInfo, side int) { camera.doInvadersFocusRegion(g, side) gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() // Set the viewport so that we only render into the region that we're supposed // to render to. // TODO: Check if this works on all graphics cards - I've heard that the opengl // spec doesn't actually require that viewport does any clipping. gl.PushAttrib(gl.VIEWPORT_BIT) gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy)) defer gl.PopAttrib() current := camera.current gl.Ortho( gl.Double(current.mid.X-current.dims.X/2), gl.Double(current.mid.X+current.dims.X/2), gl.Double(current.mid.Y+current.dims.Y/2), gl.Double(current.mid.Y-current.dims.Y/2), gl.Double(1000), gl.Double(-1000), ) defer func() { gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) }() gl.MatrixMode(gl.MODELVIEW) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) level := g.Levels[GidInvadersStart] zoom := camera.current.dims.X / float64(region.Dims.Dx) level.ManaSource.Draw(local, zoom, float64(level.Room.Dx), float64(level.Room.Dy)) gl.Color4d(1, 1, 1, 1) var expandedPoly linear.Poly for _, poly := range g.Levels[GidInvadersStart].Room.Walls { // Don't draw counter-clockwise polys, specifically this means don't draw // the boundary of the level. if poly.IsCounterClockwise() { continue } // KLUDGE: This will expand the polygon slightly so that it actually shows // up when the los shadows are drawn over it. Eventually there should be // separate los polys, colision polys, and draw polys so that this isn't // necessary. gl.Begin(gl.TRIANGLE_FAN) expandPoly(poly, &expandedPoly) for _, v := range expandedPoly { gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y)) } gl.End() } gui.SetFontColor(0, 255, 0, 255) for side, pos := range g.Levels[GidInvadersStart].Room.Starts { base.GetDictionary("luxisr").RenderString(fmt.Sprintf("S%d", side), pos.X, pos.Y, 0, 100, gui.Center) } gl.Color4d(1, 1, 1, 1) for _, ent := range g.temp.AllEnts { ent.Draw(g, side) } gl.Disable(gl.TEXTURE_2D) if local.mode != LocalModeMoba { panic("Need to implement drawing players from standard mode data") } for i := range local.moba.players { p := &local.moba.players[i] if p.abs.activeAbility != nil { p.abs.activeAbility.Draw(p.gid, g, side) } } for _, proc := range g.Processes { proc.Draw(Gid(""), g, side) } gl.Color4ub(0, 0, 255, 200) g.renderLosMask(local) }
func (b *Button) RequestedDims() Dims { mark := base.GetDictionary("luxisr").StringWidth(">", float64(b.Size)) name := base.GetDictionary("luxisr").StringWidth(b.Name, float64(b.Size)) return Dims{int(mark + name), b.Size} }
func standardHookup() { g := g2.Make(0, 0, wdx, wdy) var tm g2.ThunderMenu tm.Subs = make(map[string]*g2.ThunderSubMenu) triggers := map[gin.KeyId]struct{}{ gin.AnyReturn: struct{}{}, gin.In().GetKeyFlat(gin.ControllerButton0+2, gin.DeviceTypeController, gin.DeviceIndexAny).Id(): struct{}{}, } action := "" tm.Subs[""] = g2.MakeThunderSubMenu( []g2.Widget{ &g2.Button{Size: 50, Triggers: triggers, Name: "Debug", Callback: func() { tm.Push("debug") }}, &g2.Button{Size: 50, Triggers: triggers, Name: "Host LAN game", Callback: func() { base.Log().Printf("HOST"); print("HOST\n") }}, &g2.Button{Size: 50, Triggers: triggers, Name: "Join LAN game", Callback: func() { base.Log().Printf("JOIN"); print("JOIN\n") }}, &g2.Button{Size: 50, Triggers: triggers, Name: "Quit", Callback: func() { action = "Quit" }}, }) tm.Subs["debug"] = g2.MakeThunderSubMenu( []g2.Widget{ &g2.Button{Size: 50, Triggers: triggers, Name: "Standard", Callback: func() { action = "standard" }}, &g2.Button{Size: 50, Triggers: triggers, Name: "Moba", Callback: func() { action = "moba" }}, &g2.Button{Size: 50, Triggers: triggers, Name: "Back", Callback: func() { tm.Pop() }}, }) tm.Start(500) g.AddChild(&tm, g2.AnchorDeadCenter) g.AddChild(g2.MakeConsole(wdx, wdy), g2.AnchorDeadCenter) t := texture.LoadFromPath(filepath.Join(base.GetDataDir(), "background/buttons1.jpg")) for { sys.Think() if action == "Quit" { return } if action == "standard" || action == "moba" { g.StopEventListening() engine, local := debugHookup(action) mainLoop(engine, local, action) g.RestartEventListening() action = "" } render.Queue(func() { gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) if true { ratio := float64(wdx) / float64(wdy) t.RenderAdvanced(-1+(1-1/ratio), -1, 2/ratio, 2, 0, false) } gl.Disable(gl.TEXTURE_2D) base.GetDictionary("luxisr").RenderString("INvASioN!!!", 0, 0.5, 0, 0.03, gui.Center) }) render.Queue(func() { g.Draw() sys.SwapBuffers() }) render.Purge() } // 1 Start with a title screen // 2 Option to host or join // 3a If host then wait for a connection // 3b If join then ping and connect // 4 Once joined up the 'game' will handle choosing sides and whatnot }