コード例 #1
0
ファイル: main.go プロジェクト: runningwild/arkanoid
func main() {
	runtime.GOMAXPROCS(2)
	sys := system.Make(gos.GetSystemInterface())
	sys.Startup()

	game := Game{}
	var lb LevelBlueprint
	loadJson(filepath.Join(base.DataDir(), "1p_basic_level.json"), &lb)
	if len(lb.Players) == 0 || len(lb.Walls) == 0 {
		panic(fmt.Sprintf("Invalid level config: %d players and %d walls.",
			len(lb.Players), len(lb.Walls)))
	}
	engine, _ := cgf.NewLocalEngine(&game, int(Config.FrameTime*1000), nil)
	engine.ApplyEvent(&NewLevelEvent{&lb})

	render.Init()
	render.Queue(func() {
		initWindow(sys, Config.WindowWidth, Config.WindowHeight)
	})
	render.Purge()

	ticker := time.Tick(time.Millisecond * time.Duration(Config.FrameTime*1000))
	for true {
		<-ticker
		LocalThink(sys, engine, &game)
		if gin.In().GetKey(gin.AnyEscape).FramePressCount() > 0 {
			break
		}
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: runningwild/jota
func debugHookup(version string) *cgf.Engine {
	var err error
	for false && len(sys.GetActiveDevices()[gin.DeviceTypeController]) < 2 {
		time.Sleep(time.Millisecond * 100)
		sys.Think()
	}

	var engine *cgf.Engine
	if version != "host" {
		engine, err = cgf.NewClientEngine(17, "thunderingvictory.dyndns.org", 20007, base.EmailCrashReport, base.Log())
		if err != nil {
			base.Log().Printf("Unable to connect: %v", err)
			base.Error().Fatalf("%v", err.Error())
		}
	} else {
		sys.Think()
		g := game.MakeGame()
		if version == "host" {
			engine, err = cgf.NewHostEngine(g, 17, "", 20007, base.EmailCrashReport, base.Log())
			if err != nil {
				panic(err)
			}
			err = cgf.Host(20007, "thunderball")
			if err != nil {
				panic(err)
			}
		} else {
			engine, err = cgf.NewLocalEngine(g, 17, base.EmailCrashReport, base.Log())
		}
		if err != nil {
			base.Error().Fatalf("%v", err.Error())
		}
	}
	engine.Pause()
	engine.GetState().(*game.Game).SetSystem(sys)
	engine.Unpause()

	base.Log().Printf("Engine Id: %v", engine.Id())
	base.Log().Printf("All Ids: %v", engine.Ids())
	return engine
}
コード例 #3
0
ファイル: main.go プロジェクト: runningwild/magnus
func debugHookup(version string) (*cgf.Engine, *game.LocalData) {
	// if version != "standard" && version != "moba" && version != "host" && version != "client" {
	// 	base.Log().Fatalf("Unable to handle Version() == '%s'", Version())
	// }

	for false && len(sys.GetActiveDevices()[gin.DeviceTypeController]) < 2 {
		time.Sleep(time.Millisecond * 100)
		sys.Think()
	}

	var engine *cgf.Engine
	var room game.Room
	generated := generator.GenerateRoom(1024, 1024, 100, 64, 64522029961391019)
	data, err := json.Marshal(generated)
	if err != nil {
		base.Error().Fatalf("%v", err)
	}
	err = json.Unmarshal(data, &room)
	// err = base.LoadJson(filepath.Join(base.GetDataDir(), "rooms/basic.json"), &room)
	if err != nil {
		base.Error().Fatalf("%v", err)
	}
	var players []game.Gid
	var localData *game.LocalData
	var g *game.Game
	if version != "host" {
		res, err := cgf.SearchLANForHosts(20007, 20002, 500)
		if err != nil || len(res) == 0 {
			base.Log().Printf("Unable to connect: %v", err)
			base.Error().Fatalf("%v", err.Error())
		}
		engine, err = cgf.NewClientEngine(17, res[0].Ip, 20007, base.EmailCrashReport, base.Log())
		if err != nil {
			base.Log().Printf("Unable to connect: %v", err)
			base.Error().Fatalf("%v", err.Error())
		}
		localData = game.NewLocalDataArchitect(engine, sys)
		g = engine.GetState().(*game.Game)
		for _, ent := range g.Ents {
			if _, ok := ent.(*game.PlayerEnt); ok {
				players = append(players, ent.Id())
			}
		}
	} else {
		sys.Think()
		g = game.MakeGame()
		if version == "host" {
			engine, err = cgf.NewHostEngine(g, 17, "", 20007, base.EmailCrashReport, base.Log())
			if err != nil {
				panic(err)
			}
			err = cgf.Host(20007, "thunderball")
			if err != nil {
				panic(err)
			}
		} else {
			engine, err = cgf.NewLocalEngine(g, 17, base.EmailCrashReport, base.Log())
		}
		if err != nil {
			base.Error().Fatalf("%v", err.Error())
		}
	}
	localData = game.NewLocalDataMoba(engine, gin.DeviceIndexAny, sys)
	// localData = game.NewLocalDataInvaders(engine, sys)

	// Hook the players up regardless of in we're architect or not, since we can
	// switch between the two in debug mode.
	// d := sys.GetActiveDevices()
	// n := 0
	// for _, index := range d[gin.DeviceTypeController] {
	// 	localData.SetLocalPlayer(g.Ents[players[n]], index)
	// 	n++
	// 	if n > len(players) {
	// 		break
	// 	}
	// }
	// if len(d[gin.DeviceTypeController]) == 0 {
	// 	localData.SetLocalPlayer(g.Ents[players[0]], 0)
	// }

	base.Log().Printf("Engine Id: %v", engine.Id())
	base.Log().Printf("All Ids: %v", engine.Ids())
	return engine, localData
}