public GameControlObjects(GameControl_Score score, GameControl_Points points, GameControl_Lives lives, GameControl_FPS fps, GameControl_Debug debug, GameControl_Sound sound) { this.score = score; this.points = points; this.lives = lives; this.fps = fps; this.debug = debug; this.sound = sound; }
private void StartGame(string filename, PlayMode playMode) { // check if file exists if (!File.Exists(filename)) { MessageBox.Show("Can't load " + filename + "!", "Error - File not found", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } this.BackColor = Color.DarkSeaGreen; LoadingForm f = new LoadingForm(); f.Show(); if (!(Location.X == 0 && Location.Y == 0)) f.Location = new System.Drawing.Point(Location.X + (Width - f.Width) / 2, Location.Y + (Height - f.Height) / 2); f.Message("Set title"); // set form title string title = ""; if (filename.StartsWith(Path.GetTempPath())) { Text = "littleRunner"; } else { int lastBackslash = filename.LastIndexOf("/"); if (lastBackslash == -1) title = filename.Substring(0); else title = filename.Substring(lastBackslash + 1); int lastDot = title.LastIndexOf("."); if (lastDot != -1) { title = title.Substring(0, lastDot); } Text = "littleRunner - " + title; } // main game AI - world neets AiEventHandler f.Message("Creating Game AI"); ai = new GameAI(GameAIInteract); if (session == null) // first run or complete new run (after game over) { session = new GameSession(); } // The world f.Message("Creating World"); world = new World(filename, drawHandler, ai.getEvent, session, playMode); // Main game object f.Message("Creating MGO"); Tux tux = new Tux( mgoChangeTop == 0 ? Globals.Scroll.Top : Globals.Scroll.Top + mgoChangeTop, mgoChangeLeft == 0 ? Globals.Scroll.X : Globals.Scroll.X + mgoChangeLeft ); tux.Init(world, ai.getEvent); // can init // set viewport if need if (mgoChangeTop != 0 || mgoChangeLeft != 0) { world.Viewport.Y -= mgoChangeTop; world.Viewport.X -= mgoChangeLeft; } // got MGO! f.Message("Initializing World"); world.Init(tux); // change window size ignoreSizeChange = true; Width = world.Settings.GameWindowWidth + 5; Height = world.Settings.GameWindowHeight + 29; ignoreSizeChange = false; // GameControls f.Message("Creating GameControlObjects"); if (gameControlObjs == null) // first run or complete new run (after game over) { GameControl_Score gameControlObjScore = new GameControl_Score(15, 20, "Verdana", 12); GameControl_Points gameControlObjPoints = new GameControl_Points(15, Width / 2 - 120 / 2, "Verdana", 12); GameControl_Lives gameControlObjLives = new GameControl_Lives(15, Width - 140, 4, "Verdana", 12); GameControl_FPS gameControlObjFPS = new GameControl_FPS(40, Width - 140, "Verdana", 12); GameControl_Debug gameControlObjDebug = new GameControl_Debug(65, Width - 25, "Verdana", 12); GameControl_Sound gameControlObjSound = new GameControl_Sound(); gameControlObjs = new GameControlObjects(gameControlObjScore, gameControlObjPoints, gameControlObjLives, gameControlObjFPS, gameControlObjDebug, gameControlObjSound); } // init AI with the world - now we have the GameControlObjects f.Message("Initializing Game AI"); ai.Init(world, gameControlObjs); // init Script Engine f.Message("Initializing ScriptEngine"); ai.InitScript(); if (!lastModeIsNull) ai.World.MGO.Mode = lastMode; f.Message("Initializing Sound"); gameControlObjs.Sound.Start(); Cursor.Hide(); f.Close(); this.BackColor = Color.White; ai.Pause(true); }