func (p *Player) Draw(game *Game) { if p.Exiled() { return } var t *texture.Data 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.X-float64(t.Dx())/2, p.Y-float64(t.Dy())/2, float64(t.Dx()), float64(t.Dy()), p.Angle, false) for _, proc := range p.Processes { proc.Draw(p.Id(), game) } }
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("") }
func setupSound() { soundInit.Do(func() { var err error // fmodSys, err = fmod.CreateSystem() if err != nil { // base.Error().Fatalf("Unable to initialize fmod: %v", err) } // err = fmodSys.Init(2, 0, nil) if err != nil { // base.Error().Fatalf("Unable to initialize fmod: %v", err) } target := filepath.Join(base.GetDataDir(), "sound/ping.wav") base.Log().Printf("Trying to load ", target) // sound, err = fmodSys.CreateSound_FromFilename(target, fmod.MODE_DEFAULT) if err != nil { base.Error().Fatalf("Unable to load sound: %v", err) } }) }
func MakeGame() *Game { var g Game g.Setup = &Setup{} g.Setup.Mode = "moba" g.Setup.Sides = make(map[int64]*SetupSideData) // NOTE: Obviously this isn't threadsafe, but I don't intend to be Init()ing // multiple game objects at the same time. base.RemoveRegistry("champs") base.RegisterRegistry("champs", make(map[string]*champ.ChampionDef)) base.RegisterAllObjectsInDir("champs", filepath.Join(base.GetDataDir(), "champs"), ".json", "json") names := base.GetAllNamesInRegistry("champs") g.Champs = make([]champ.Champion, len(names)) for i, name := range names { g.Champs[i].Defname = name base.GetObject("champs", &g.Champs[i]) } return &g }
func main() { fmt.Printf("%v\n", key_map) sys.Startup() err := gl.Init() if err != nil { panic(err) } render.Init() render.Queue(func() { sys.CreateWindow(10, 10, wdx, wdy) sys.EnableVSync(true) err := gl.Init() if err != nil { panic(err) } }) base.InitShaders() runtime.GOMAXPROCS(2) ui, err = gui.Make(gin.In(), gui.Dims{wdx, wdy}, filepath.Join(datadir, "fonts", "skia.ttf")) if err != nil { panic(err) } sys.Think() for false && len(sys.GetActiveDevices()[gin.DeviceTypeController]) < 2 { time.Sleep(time.Millisecond * 100) sys.Think() } var ids []int var engine *cgf.Engine var room game.Room err = base.LoadJson(filepath.Join(base.GetDataDir(), "rooms/basic.json"), &room) if err != nil { panic(err) } if IsHost() { sys.Think() var g game.Game g.Rng = cmwc.MakeGoodCmwc() g.Rng.SeedWithDevRand() g.Dx = 900 g.Dy = 600 g.Friction = 0.97 g.Friction_lava = 0.85 g.Room = room var p game.Player p.Color.R = 255 err := json.NewDecoder(bytes.NewBuffer([]byte(` { "Base": { "Max_turn": 0.07, "Max_acc": 0.2, "Mass": 750, "Max_rate": 10, "Influence": 75, "Health": 1000 }, "Dynamic": { "Health": 1000 } } `))).Decode(&p.Stats) if err != nil { panic(err) } Nx := 2 Ny := 1 p.X = float64(g.Dx-Nx)/2 - 200 p.Y = float64(g.Dy-Ny)/2 - 200 for x := 0; x < Nx; x++ { for y := 0; y < Ny; y++ { p.X += float64(x * 25) p.Y += float64(y * 25) p.Gid++ // p.Mass += float64(x+y) * 150 p.Processes = make(map[int]game.Process) temp := p ids = append(ids, g.AddEnt(&temp)) // p.Mass -= float64(x+y) * 150 p.X -= float64(x * 25) p.Y -= float64(y * 25) } } g.Ents[0].(*game.Player).X = 500 g.Ents[0].(*game.Player).Y = 300 g.Ents[1].(*game.Player).X = 550 g.Ents[1].(*game.Player).Y = 300 g.SetLocalData() d := sys.GetActiveDevices() base.Log().Printf("%v\n", d) n := 0 base.Log().Printf("%v\n", d[gin.DeviceTypeController]) for _, index := range d[gin.DeviceTypeController] { // panic("ASD") g.SetLocalPlayer(g.Ents[n].(*game.Player), index) n++ if n > 2 { break } } if len(d[gin.DeviceTypeController]) == 0 { g.SetLocalPlayer(g.Ents[0].(*game.Player), 0) } // g.Ents[0], g.Ents[(N*N)/2+(1-N%2)*N/2] = g.Ents[(N*N)/2+(1-N%2)*N/2], g.Ents[0] g.Init() // engine, err = cgf.NewLocalEngine(&g, 17, base.Log()) engine, err = cgf.NewHostEngine(&g, 17, "", 1231, base.Log()) if err != nil { panic(err.Error()) } g.SetEngine(engine) } else { engine, err = cgf.NewClientEngine(17, "", 1231, base.Log()) if err != nil { panic(err.Error()) } engine.CopyState().(*game.Game).SetEngine(engine) } anchor := gui.MakeAnchorBox(gui.Dims{wdx, wdy}) ui.AddChild(anchor) anchor.AddChild(&game.GameWindow{Engine: engine}, gui.Anchor{0.5, 0.5, 0.5, 0.5}) var v float64 var profile_output *os.File var num_mem_profiles int // ui.AddChild(base.MakeConsole()) base.LoadAllDictionaries() for gin.In().GetKey(gin.AnyEscape).FramePressCount() == 0 { sys.Think() render.Queue(func() { ui.Draw() }) render.Queue(func() { sys.SwapBuffers() }) render.Purge() game.LocalThink() if IsHost() { for i := 0; i <= 0; i++ { // down_axis := gin.In().GetKeyFlat(gin.ControllerAxis0Positive+1, gin.DeviceTypeController, gin.DeviceIndexAny) // up_axis := gin.In().GetKeyFlat(gin.ControllerAxis0Negative+1, gin.DeviceTypeController, gin.DeviceIndexAny) // right_axis := gin.In().GetKeyFlat(gin.ControllerAxis0Positive, gin.DeviceTypeController, gin.DeviceIndexAny) // left_axis := gin.In().GetKeyFlat(gin.ControllerAxis0Negative, gin.DeviceTypeController, gin.DeviceIndexAny) // up := key_map[fmt.Sprintf("%dup", i)].FramePressAvg() // down := key_map[fmt.Sprintf("%ddown", i)].FramePressAvg() // left := key_map[fmt.Sprintf("%dleft", i)].FramePressAvg() // right := key_map[fmt.Sprintf("%dright", i)].FramePressAvg() // up = axisControl(up_axis.FramePressAmt()) // down = axisControl(down_axis.FramePressAmt()) // left = axisControl(left_axis.FramePressAmt()) // right = axisControl(right_axis.FramePressAmt()) // if up-down != 0 { // engine.ApplyEvent(game.Accelerate{ids[i], 2 * (up - down)}) // } // if left-right != 0 { // engine.ApplyEvent(game.Turn{ids[i], (left - right)}) // } // if key_map[fmt.Sprintf("%d-1", i)].FramePressCount() > 0 { // engine.ApplyEvent(game.Pull{ids[i], 0, 20000}) // } // if key_map[fmt.Sprintf("%d-2", i)].FramePressCount() > 0 { // engine.ApplyEvent(game.MoonFire{ids[i], 1, 50, 50}) // } // if gin.In().GetKeyFlat(gin.ControllerButton0, gin.DeviceTypeController, gin.DeviceTypeAny).FramePressCount() > 0 { // if key_map[fmt.Sprintf("%d-3", i)].FramePressCount() > 0 { // engine.ApplyEvent(game.Burst{ids[i], 2, 3, 100000}) // } } } // TODO: Replace the 'P' key with an appropriate keybind if gin.In().GetKey(gin.AnyKeyP).FramePressCount() > 0 { if profile_output == nil { profile_output, err = os.Create(filepath.Join(datadir, "cpu.prof")) if err == nil { err = pprof.StartCPUProfile(profile_output) if err != nil { fmt.Printf("Unable to start CPU profile: %v\n", err) profile_output.Close() profile_output = nil } fmt.Printf("profout: %v\n", profile_output) } else { fmt.Printf("Unable to start CPU profile: %v\n", err) } } else { pprof.StopCPUProfile() profile_output.Close() profile_output = nil } } // TODO: Replace the 'M' key with an appropriate keybind if gin.In().GetKey(gin.AnyKeyM).FramePressCount() > 0 { f, err := os.Create(filepath.Join(datadir, fmt.Sprintf("mem.%d.prof", num_mem_profiles))) if err != nil { base.Error().Printf("Unable to write mem profile: %v", err) } pprof.WriteHeapProfile(f) f.Close() num_mem_profiles++ } v += 0.01 } }
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 }