KillerInstinct.cs :  » Game » Killer-Instinct » KillerInstinct » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » Killer Instinct 
Killer Instinct » KillerInstinct » KillerInstinct.cs
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectDraw;
using Microsoft.DirectX.DirectInput;
using Global;
using Global.GlobalClass;
using KillerInstinct.Sprites;
using KillerInstinct.DirectX;

namespace KillerInstinct{
  public class GameClass : Form
  {
    // ATTRIBUTES   ////////////////////////////////////////////////////////
    static GameClass  Game;
    int            m_time        = 0;
    OptionsForm      m_optionForm    = null;
    // Sprites
    Sprites.MenuClass    MainMenu    = null;
    Sprites.TextClass    TextBmp         = null;
    // Methods ////////////////////////////////////////////////////////////
    //TODO: [STAThread], [MTAThread], or NOTHING ????????
    static void Main(string[] args) 
    {
      bool bFound = false;

      try
      {
        global.dbg.Out(Debug.INFO, "Parameters found: " + args.Length);
        if (args.Length > 0)
        {
          string strParams = "";
          for (uint i=0; i < args.Length; ++i)
          {
            bFound = false;
            strParams += args[i] + " ";  
            switch (args[i])
            {
              case "-log":
              {
                int logLevel = System.Convert.ToInt16(args[++i], 10);
                global.dbg.Level = logLevel;
                bFound = true;
                break;
              }
              case "-noGui":
              {
                global.options.noGui = true;
                bFound = true;
                break;
              }
              case "-noSound":
              {
                global.options.noSound = true;
                bFound = true;
                break;
              }
              case "-noAIShoot":
              {
                global.options.noAIShoot = true;
                bFound = true;
                break;
              }
              case "-quickStart":
              {
                global.options.quickStart = true;
                bFound = true;
                break;
              }
              case "-server":
              {
                global.options.isServer = true;
                bFound = true;
                break;
              }
              case "-defaultMap":
              {
                global.options.defaultMap = true;
                bFound = true;
                break;
              }
            }
            // only log the parameter if it was found
            if (bFound == true)
              global.dbg.Out(Debug.INFO, "Setting parameter: " + args[i]);
            else
              global.dbg.Out(Debug.INFO, "Ignoring invalid parameter: " + args[i]);
          }
        }
        // initialize DirectX components, start the main game "engine" running
        Game = new GameClass();
      }
      catch (DirectXException e)
      {
        MessageBox.Show("Unexpected DirectX exception: " + e.ToString(), "Killer Instinct");
        global.dbg.Out(Debug.ERR, "Unexpected DirectX exception: [" + e.ToString() + "]");
        Application.Exit();
        Application.ExitThread();
      }
      catch (Exception e)
      {
        MessageBox.Show("Unexpected exception: " + e.ToString(), "Killer Instinct");
        global.dbg.Out(Debug.ERR, "Unexpected exception: [" + e.ToString() + "]");
        Application.Exit();
        Application.ExitThread();
      }
    }
    // INITIALIZATION /////////////////////////////////////////////////////////////////////////////////
    GameClass()
    {
      global.dbg.Out(Debug.DBG1, "INITIALIZATION******************************************************");
      // Window properties
      AutoScaleBaseSize  = new System.Drawing.Size(5, 13);
      ClientSize      = new System.Drawing.Size(292, 273);
      Cursor        = System.Windows.Forms.Cursors.Cross;
      Icon        = new Icon(CONST.ICO_KILLERINSTINCT);
      FormBorderStyle    = System.Windows.Forms.FormBorderStyle.None;
      Name        = "Killer Instinct";
      Text        = "Killer Instinct";
      KeyUp        += new System.Windows.Forms.KeyEventHandler(KeyUpEvent);
      MouseMove      += new System.Windows.Forms.MouseEventHandler(MouseMoveEvent);
      if (InitDirectDraw())
      {
        if (InitDirectInput())
        {
          if (InitDirectSound())
          {
            if (InitLists())
            {
              if (InitDirectPlay())
              {
                // read game settings stored in registry to 'global.options'
                global.DC.DrawInfoTextBox("Reading registry...", Color.White);
                global.GameRegistry = new GameRegistry();
                // signal that everything has been initialized
                global.options.initialized = true;
                // global.Background picture
                global.DC.DrawInfoTextBox("Initializing Background...", Color.White);
                global.Background = new Sprites.BackgroundClass(CONST.BMP_BG_TITEL, 0, 0);
                // global map
                global.DC.DrawInfoTextBox("Initializing Maps...", Color.White);
                global.Map = new MapClass();
                // show titel
                global.options.GameState = GAMEVAR.GAMESTATE.TITEL_STARTING;
                // quick-start mode, just start a single player game
                if (global.options.quickStart) 
                {
                  global.options.GameState = GAMEVAR.GAMESTATE.GAME_STARTING;
                  global.options.multiplayer = false;
                }
                // if not in GUI mode, display main menu as window
                if (global.options.noGui)
                {
                  // open menu dialog
                  global.options.GameState = GAMEVAR.GAMESTATE.MPMENU_RUNNING;
                }
                global.DC.DrawInfoTextBox("Starting Game...", Color.White);
                // game looooop
                MainGameLoop();
              }
            }
          }
        }
      }
    }
    public bool InitDirectDraw()
    {
      global.dbg.Out(Debug.DBG1, "InitDirectDraw called.");
      if( !global.options.noGui )
      {
        // Create a new DrawDevice, using the default device.
        global.DC = new DrawClass(this);
      }
      return true;
    }
    public bool InitDirectInput()
    {
      global.dbg.Out(Debug.DBG1, "InitDirectInput called.");
      global.DC.DrawInfoTextBox("Initializing DirectInput...", Color.White);
      global.IC = new InputClass(this);
      return true;
    }
    public bool InitDirectSound()
    {
      global.dbg.Out(Debug.DBG1, "InitDirectSound called.");
      global.DC.DrawInfoTextBox("Initializing DirectSound...", Color.White);
      global.SC = new SoundClass(this, global.options.noSound, -10);
      //global.SC = new SoundClass(this, global.options.noSound, -10);
      return true;
    }
    public bool InitLists()
    {
      if (!global.options.noGui)
      {
        global.DC.DrawInfoTextBox("Initializing SpriteList...", Color.White);
        global.spriteList = new SpriteListClass();
      }
      return true;
    }
    public bool InitDirectPlay()
    {
      global.dbg.Out(Debug.DBG1, "InitDirectPlay called.");
      global.DC.DrawInfoTextBox("Initializing DirectPlay...", Color.White);
      global.PC = new PlayClass();
      return true;
    }
    // GAME LOOP ///////////////////////////////////////////////////////////////////////////////////////
    public void MainGameLoop()
    {
      global.dbg.Out(Debug.DBG1, "GAME LOOP***********************************************************");
      //get the current ticks
      int lastTickCount = System.Environment.TickCount;
      global.dbg.Out(Debug.DBG2, "   lastTickCount    = " + lastTickCount);
      //global.dbg.Out(Debug.DBG2, "   SurfacesInitialized = " + SurfacesInitialized);
      while (global.options.initialized == true)
      {
        //if the designated number of milliseconds have passed
        if (System.Environment.TickCount - lastTickCount  >= (1000/CONST.FRAMES_PER_SECOND))
        {
          // if too long since our last update, give a little warning
          if (System.Environment.TickCount - lastTickCount - 1000/CONST.FRAMES_PER_SECOND > 500)
            global.dbg.Out(Debug.TRACE, "TOO MUCH TIME USED SOMEWHERE??");
          /*global.dbg.Out(Debug.DBG2,
            "GetTickCount: [" + Global.Global.GetTickCount() + "] - " +
            "lastTickCount: [" + lastTickCount + "] --> [" +
            (Global.Global.GetTickCount() - lastTickCount) + "] " + 
            "   1000/FPS [" + ((1000/CONST.FRAMES_PER_SECOND)) + "] --> [" +
            (Global.Global.GetTickCount() - (1000/CONST.FRAMES_PER_SECOND)) + "]");*/

          // get current tick count
          lastTickCount = System.Environment.TickCount;
          // This will keep us from trying to blt in case we lose the surfaces (another fullscreen app takes over)
          bool restoreSurfaces = false;
          // this is a special debug mode to test non-gui related things
          if( !global.options.noGui )
          {
            // if there is a direct draw error (ie the surface has been lost)
            if (global.DC.Draw.TestCooperativeLevel() == false)
            {
              //do window events for application
              Application.DoEvents();
              //set boolean to indicate we need to restore the surfaces
              restoreSurfaces = true;
            }
            // If we lost and got back the surfaces, then restore them
            Application.DoEvents();
            if (restoreSurfaces == true)
            {
              restoreSurfaces = false;
              RestoreSurfaces();    
            }
          }
          global.dbg.Out(Debug.DBG3, "---GAMESTATE--- " + global.options.GameState);
          switch (global.options.GameState)
          {
              // titel init
            case GAMEVAR.GAMESTATE.TITEL_STARTING:
              InitTitel();
              break;    
              // titel is being displayed
            case GAMEVAR.GAMESTATE.TITEL_RUNNING:
              RunTitel();
              break;    
              // main menu is being started
            case GAMEVAR.GAMESTATE.MAINMENU_STARTING:
              InitMainMenu();
              break;            
              // main menu is now running
            case GAMEVAR.GAMESTATE.MAINMENU_RUNNING:
              RunMainMenu();
              break;
              // single player menu is running
            case GAMEVAR.GAMESTATE.SPMENU_RUNNING:
              RunSinglePlayerMenu();
              break;
              // multiplayer menu is running
            case GAMEVAR.GAMESTATE.MPMENU_RUNNING:
              RunMultiplayerMenu();
              break;
              // showing options form for single player and multiplayer
            case GAMEVAR.GAMESTATE.OPTIONS_RUNNING:
              RunOptions();
              break;
              // game is starting
            case GAMEVAR.GAMESTATE.GAME_STARTING:
              InitGame();
              break;
              // game is running
            case GAMEVAR.GAMESTATE.GAME_RUNNING:
              RunGame();
              break;
              // winnerscreen is starting
            case GAMEVAR.GAMESTATE.GAMEWINNING_STARTING:
              InitWinner();
              break;
              // party!!!
            case GAMEVAR.GAMESTATE.GAMEWINNING_RUNNING:
              RunGameWin();
              break;
              // game over sequence is starting
            case GAMEVAR.GAMESTATE.GAMEOVER_STARTING:
              InitGameOver();
              break;
              // game over sequence is now running
            case GAMEVAR.GAMESTATE.GAMEOVER_RUNNING:
              RunGameOver();
              break;
              // view statistic
            case GAMEVAR.GAMESTATE.STATS_DISPLAYING:
              RunStatistic();
              break;
              // exit the game
            case GAMEVAR.GAMESTATE.GAMEEXIT:
              Exit();
              return;
          }
        }
        // do windows events
        Application.DoEvents();
      }
    }
    // TITEL ////////////////////////////////////////////////////////////////////////////////////////////
    private void InitTitel()
    {
      global.dbg.Out(Debug.INFO, "InitTitel called");
      global.Background.ChangeBitmap(CONST.BMP_BG_TITEL);
      global.options.GameState = GAMEVAR.GAMESTATE.TITEL_RUNNING;
      global.dbg.Out(Debug.INFO, "RunTitel called");
    }
    private void RunTitel()
    {
      global.Background.Draw();
      global.DC.Front.Draw(global.DC.Back, DrawFlags.DoNotWait);
      global.IC.GetKeyboardInput();
      global.IC.GetMouseInput();
      if (global.IC.PressedKey(Key.Return) || global.IC.PressedMButton(global.IC.MButtonLeft))
      {
        global.dbg.Out(Debug.DBG3, "RunTitel:   Return");
        global.options.GameState = GAMEVAR.GAMESTATE.MAINMENU_STARTING;
      }
      global.IC.ReInit();
    }
    // MENU ////////////////////////////////////////////////////////////////////////////////////////////
    private void InitMainMenu()
    {
      global.dbg.Out(Debug.DBG1, "InitMainMenu called");
      if (!global.options.noGui)
      {
        global.SC.Stop();
        // play random intro sound
        global.SC.PlayRandomIntro();
        // global.Background image
        global.Background.ChangeBitmap(CONST.BMP_BG_MENU);
        // create menu
        MainMenu = new Sprites.MenuClass(CONST.BMP_MENU1, CONST.SCR_WIDTH/2-130, CONST.SCR_HEIGHT/2-170, 8, 80);
        // display main menu
        global.options.GameState = GAMEVAR.GAMESTATE.MAINMENU_RUNNING;
        // save game settings stored in 'global.options' to registry
        global.GameRegistry.SaveSettings();
        // set mouse cursor positon
        Cursor.Position = new Point(global.options.SCR_WIDTH/4, global.options.SCR_HEIGHT/4);
        global.dbg.Out(Debug.INFO, "RunMainMenu called");
      }
    }
    private void RunMainMenu()
    {
      global.Background.Draw();
      MainMenu.Draw();
      global.DC.Front.Draw(global.DC.Back, DrawFlags.DoNotWait);
      global.IC.GetKeyboardInput();
      global.IC.GetMouseInput();
      // keyboard
      if (global.IC.PressedKey(Key.UpArrow))
      {
        global.dbg.Out(Debug.DBG3, "RunMenu:   UpArrow");
        MainMenu.Previous(4);
      }
      if (global.IC.PressedKey(Key.DownArrow))
      {
        global.dbg.Out(Debug.DBG3, "RunMenu:   DownArrow");
        MainMenu.Next(4);
      }
      if (global.IC.PressedKey(Key.F1))
      {
        global.dbg.Out(Debug.DBG3, "RunMenu:   F1");
        global.SC.Stop();
        // play random intro sound
        global.SC.PlayRandomIntro();
      }
      if (global.IC.PressedKey(Key.Return))
      {
        global.dbg.Out(Debug.DBG3, "RunMenu:   Return");
        if (MainMenu.activeMenuPoint==1)
        {
          global.options.GameState = GAMEVAR.GAMESTATE.SPMENU_RUNNING;
          global.options.multiplayer = false;
        }
        else if (MainMenu.activeMenuPoint==2)
        {
          global.options.GameState = GAMEVAR.GAMESTATE.MPMENU_RUNNING;
          global.options.multiplayer = true;
        }
        else if (MainMenu.activeMenuPoint==3)
        {
          global.options.GameState = GAMEVAR.GAMESTATE.OPTIONS_RUNNING;
        }
        else if (MainMenu.activeMenuPoint==4)
        {
          global.options.GameState = GAMEVAR.GAMESTATE.GAMEEXIT;
        }
        global.SC.Play(SoundClass.SOUND_MENUSELECT, false);
      }
      // mouse
      // mouse over any menu item
      if (MainMenu.MouseOver())
      {
        // if menu selected (left mouse button)
        if (global.IC.PressedMButton(global.IC.MButtonLeft))
        {
          global.dbg.Out(Debug.DBG3, "RunMenu:   Mouse Pressed");
          if (MainMenu.activeMenuPoint==1)
          {
            global.options.GameState = GAMEVAR.GAMESTATE.SPMENU_RUNNING;
            global.options.multiplayer = false;
          }
          else if (MainMenu.activeMenuPoint==2)
          {
            global.options.GameState = GAMEVAR.GAMESTATE.MPMENU_RUNNING;
            global.options.multiplayer = true;
          }
          else if (MainMenu.activeMenuPoint==3)
          {
            global.options.GameState = GAMEVAR.GAMESTATE.OPTIONS_RUNNING;
          }
          else if (MainMenu.activeMenuPoint==4)
          {
            global.options.GameState = GAMEVAR.GAMESTATE.GAMEEXIT;
          }
          global.SC.Play(SoundClass.SOUND_MENUSELECT, false);
        }
      }
      global.IC.ReInit();
    }
    private void RunSinglePlayerMenu()
    {
      if (!global.options.noGui)
        global.DC.Front.Draw(global.DC.Back, DrawFlags.DoNotWait);
      // all we already waiting for the user to select a server?
      if( m_optionForm == null )
      {
        // let user select which server to join
        m_optionForm = new OptionsForm();
        m_optionForm.Disposed += new System.EventHandler(this.FormDisposed);
        // open form to SINGLE PLAYER menu
        m_optionForm.SetTab(1);
        //NOTE: with or without the line works, what exactly does this do?                
        this.AddOwnedForm(m_optionForm);
        m_optionForm.Show();
      }
    }
    private void RunMultiplayerMenu()
    {
      if (!global.options.noGui)
        global.DC.Front.Draw(global.DC.Back, DrawFlags.DoNotWait);
      // all we already waiting for the user to select a server?
      if( m_optionForm == null )
      {
        // let user select which server to join
        m_optionForm = new OptionsForm();
        m_optionForm.Disposed += new System.EventHandler(this.FormDisposed);
        // open form to MULTIPLAYER menu
        m_optionForm.SetTab(2);
        //NOTE: with or without the line works, what exactly does this do?                
        this.AddOwnedForm(m_optionForm);
        m_optionForm.Show();
      }
    }
    // OPTION MENU ////////////////////////////////////////////////////////////////////////////////////////////
    private void RunOptions()
    {
      if (!global.options.noGui)
        global.DC.Front.Draw(global.DC.Back, DrawFlags.DoNotWait);
      // all we already waiting for the user to select a server?
      if( m_optionForm == null )
      {
        // let user select which server to join
        m_optionForm = new OptionsForm();
        m_optionForm.Disposed += new System.EventHandler(this.FormDisposed);
        // open form to OPTIONS menu
        m_optionForm.SetTab(3);
        //NOTE: with or without the line works, what exactly does this do?                
        this.AddOwnedForm(m_optionForm);
        m_optionForm.Show();
      }
    }
    // NEW GAME ////////////////////////////////////////////////////////////////////////////////////////
    private void InitGame()
    {
      global.dbg.Out(Debug.INFO, "InitGame called");
      if (m_optionForm != null)
        m_optionForm.Dispose();

      global.SC.Stop();
      global.SC.Play(SoundClass.SOUND_GAMESTART, false);

      // this is a special debug mode to test non-gui related things
      if( !global.options.noGui )
      {
        // create pop-up message box
        global.Message = new MessageClass();
        // create text display
        TextBmp  = new Sprites.TextClass("GetReady", CONST.SCR_WIDTH/2-375/2, CONST.SCR_HEIGHT/2-70/2);
        bool overlapping = true;
        int x, y;
        while (overlapping)
        {
          global.spriteList.Clear();
          // set player tank to any position
          x = global.random(100, global.options.SCR_WIDTH-100);
          y = global.random(100, global.options.SCR_HEIGHT-100);
          global.Tank = new Sprites.TankClass(global.GetTeamResource(global.PC.MyPlayerTeam), x, y, global.PC.MyPlayerId, global.PC.MyPlayerName, false, 1, 0);
          global.spriteList.Add(global.Tank);
          if (global.options.multiplayer)
          {
            global.dbg.Out(Debug.DBG2, "InitGame: Multiplayer game");
            global.PC.MoveTank(global.Tank);
          }
          else
          {
            global.dbg.Out(Debug.DBG2, "InitGame: Singleplayer game");
          }
          // anything overlapping, when true new tank and level creation again
          if (overlapping = global.spriteList.Collision())
            global.dbg.Out(Debug.DBG2, "InitGame: Overlapping!");
        }
        // start countdown for gamestart
        global.options.GameStartTime = System.Environment.TickCount;
        // create map
        global.Map.Load();
        // set all sprites to 'in-active'
        global.spriteList.SetInactive();
        // if single play
        if (!global.options.quickStart && !global.options.multiplayer)
        {
          int countdown = 10;
          TextBmp.ChangeText("GetReady");
          while (countdown>0)
          {
            // paint objects
            global.Background.Draw();
            // draw only our own tank to see where we are before starting game
            global.Tank.Draw();
            TextBmp.Draw();
            if (System.Environment.TickCount - global.options.GameStartTime > 200)
            {
              global.options.GameStartTime = System.Environment.TickCount;
              if (countdown == 4)
              {
                TextBmp.ChangeText("Go");
              }
              countdown--;
            }
            // draw to screen
            global.DC.Front.Draw(global.DC.Back, DrawFlags.DoNotWait);
          }
        }
      }
      // create info bar on top 
      global.InfoBar = new InfoBarClass(global.Tank);
      // set mouse cursor near tank
      Cursor.Position = new Point((int)global.Tank.posX + 50, (int)global.Tank.posY + 50);
      // start game
      global.options.GameStartTime = System.Environment.TickCount;
      if (global.options.multiplayer)
      {
        global.options.GameState = GAMEVAR.GAMESTATE.MP_INIT;
      }
      else
      {
        global.dbg.Out(Debug.INFO, "RunGame called");
        global.options.GameState = GAMEVAR.GAMESTATE.GAME_RUNNING;
      }
      // set all sprites to 'active'
      global.spriteList.SetActive();
    }
    private void InitMultiplayerGame()
    {
      global.dbg.Out(Debug.DBG3, "InitMultiplayerGame called");
      if (global.PC.IsServer())
      {

      }
      else
      {
        TextBmp.ChangeText("Waiting");
      }
    }
    private void RunGame()
    {
      try
      {
        // this is a special debug mode to test non-gui related things
        if( !global.options.noGui )
        {
          // sometimes there's wind
          if (global.random(0, CONST.FRAMES_PER_SECOND*10) == 0) global.SC.Play(SoundClass.SOUND_WIND, false);
          // input handling
          ProcessGameInput();
          // update all sprites
          global.spriteList.Collision();
          // paint objects
          global.Background.Draw();
          // display all sprites
          global.spriteList.Draw();
          // display info bar if enabled
          if (global.options.showInfoBar)
          {
            // show info bar
            global.InfoBar.Draw();
          }
          // display pop-up messages for mission information
          global.Message.Draw();
          // draw to screen
          global.DC.Front.Draw(global.DC.Back, DrawFlags.DoNotWait);
          // play sound when player tank energy is low, when not played shortly
          global.Tank.IsEnergyLow();
          // when multiplayer then update all player tanks every second/30
          if (global.options.multiplayer && (m_time == CONST.FRAMES_PER_SECOND/30))
          {
            global.PC.MoveTank(global.Tank);
            m_time=0;
          }
          else
          {
            m_time++;
          }
          // control mission goals
          switch (global.Map.MissionComplete())
          {
            // if section completed, load next section
            case MapClass.MissionStates.SectionWinning:
              global.options.GameState = GAMEVAR.GAMESTATE.GAME_STARTING;
              break;
            // if all sections in the map completed, show "YOU WIN" screen
            case MapClass.MissionStates.Winning:
              global.options.GameState = GAMEVAR.GAMESTATE.GAMEWINNING_STARTING;
              break;
            // if losing, show "YOU LOSE" screen
            case MapClass.MissionStates.Losing:
              global.options.GameState = GAMEVAR.GAMESTATE.GAMEOVER_STARTING;
              break;
            // otherwise keep running
            case MapClass.MissionStates.Running:
            default:
              break;
          }
        }
      }
      catch (Exception e)
      {
        throw new Exception("RunGame Exception: " + e);
      }
    }
    private void ProcessGameInput()
    {
      global.IC.GetKeyboardInput();
      global.IC.GetMouseInput();
      // if chat/typing mode, all inputs are pushed into a buffer until ENTER is pressed
      if (global.options.chatMode)
      {
        global.IC.GetString(ref global.options.chatBuffer);
        if (global.IC.PressedKey(Key.Return))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   Return (type mode)");
          // disable chat/typing mode
          global.options.chatMode = false;
          // if something is in the chat buffer...
          if (global.options.chatBuffer.Length > 0)
          {
            // if we're in multiplayer mode, send the message
            if (global.options.multiplayer)
              //TODO: send (only) to FRIENDS, ENEMIES, ALL
              global.PC.Say(global.options.chatBuffer);
            global.spriteList.AddText(new SpriteListClass.TextObject(global.PC.MyPlayerName + ": " + global.options.chatBuffer, 0));
          }
        }
      }
      else
      {
        if (global.IC.PressedKey(Key.D))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   Right");
          global.Tank.TurnRight();
        }
        if (global.IC.PressedKey(Key.A))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   Left");
          global.Tank.TurnLeft();
        }
        if (global.IC.PressedKey(Key.W))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   Up");
          global.Tank.SpeedUp();
        }
        if (global.IC.PressedKey(Key.S))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   Down");
          global.Tank.SpeedDown();
        }
        if (global.IC.PressedKey(Key.T))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   T");
          // enable "chat" mode, i.e. normal typing
          global.options.chatMode = true;
          // if old buffer exists, erase
          if (global.options.chatBuffer != null)
            global.options.chatBuffer = null;
          // create new chat buffer
          global.options.chatBuffer = "";
        }
        if (global.IC.PressedKey(Key.Up))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   Louder");
          global.SC.ChangeVolume(1);
        }
        if (global.IC.PressedKey(Key.Down))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   Quieter");
          global.SC.ChangeVolume(-1);
        }
        if (global.IC.PressedKey(Key.D1))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   1");
          global.Tank.ShotType    = ShotClass.ShotTypes.Basic;
          global.Tank.AltShotType = ShotClass.ShotTypes.AltBasic;
        }
        if (global.IC.PressedKey(Key.D2))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   2");
          global.Tank.ShotType    = ShotClass.ShotTypes.L2;
          global.Tank.AltShotType = ShotClass.ShotTypes.AltL2;
      }
        if (global.IC.PressedKey(Key.D3))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   3");
          global.Tank.ShotType    = ShotClass.ShotTypes.L3;
          global.Tank.AltShotType = ShotClass.ShotTypes.AltL3;
        }
        if (global.IC.PressedKey(Key.D4))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   4");
          global.Tank.ShotType    = ShotClass.ShotTypes.L4;
          global.Tank.AltShotType = ShotClass.ShotTypes.AltL4;
        }
        if (global.IC.PressedKey(Key.F1))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F1");
          global.SC.Play(SoundClass.VOICE_AWCRAP, false);
          if (global.options.multiplayer)
            global.PC.PlaySound(SoundClass.VOICE_AWCRAP, false);
        }
        if (global.IC.PressedKey(Key.F2))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F2");
          global.SC.Play(SoundClass.VOICE_BREATHIN, false);
          if (global.options.multiplayer)
            global.PC.PlaySound(SoundClass.VOICE_BREATHIN, false);
        }
        if (global.IC.PressedKey(Key.F3))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F3");
          global.SC.Play(SoundClass.VOICE_BREATHOUT, false);
          if (global.options.multiplayer)
            global.PC.PlaySound(SoundClass.VOICE_BREATHOUT, false);
        }
        if (global.IC.PressedKey(Key.F4))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F4");
          global.SC.Play(SoundClass.VOICE_COMEONYO, false);
          if (global.options.multiplayer)
            global.PC.PlaySound(SoundClass.VOICE_COMEONYO, false);
        }
        if (global.IC.PressedKey(Key.F5))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F5");
          global.SC.Play(SoundClass.VOICE_FEELSGOOD, false);
          if (global.options.multiplayer)
            global.PC.PlaySound(SoundClass.VOICE_FEELSGOOD, false);
        }
        if (global.IC.PressedKey(Key.F6))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F6");
          global.SC.Play(SoundClass.VOICE_NOWORD, false);
          if (global.options.multiplayer)
            global.PC.PlaySound(SoundClass.VOICE_NOWORD, false);
        }
        if (global.IC.PressedKey(Key.F7))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F7");
          global.SC.Play(SoundClass.VOICE_STEREOBENEFITS, false);
          if (global.options.multiplayer)
            global.PC.PlaySound(SoundClass.VOICE_STEREOBENEFITS, false);
        }
        if (global.IC.PressedKey(Key.F8))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F8");
          global.SC.Play(SoundClass.VOICE_STOPPED, false);
          if (global.options.multiplayer)
            global.PC.PlaySound(SoundClass.VOICE_STOPPED, false);
        }
        if (global.IC.PressedKey(Key.F9))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F9");
          global.SC.Play(SoundClass.VOICE_STUPID, false);
          if (global.options.multiplayer)
            global.PC.PlaySound(SoundClass.VOICE_STUPID, false);
        }
        if (global.IC.PressedKey(Key.F10))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F10");
          global.SC.Play(SoundClass.VOICE_SUCK, false);
          if (global.options.multiplayer)
            global.PC.PlaySound(SoundClass.VOICE_SUCK, false);
        }
        if (global.IC.PressedKey(Key.F11))
        {
          global.dbg.Out(Debug.DBG3, "ProcessGameInput:   F11");
          //        global.SC.Play(SoundClass.SOUND_WISP, false);
          string msg = "Piss off!";
          if (global.options.multiplayer)
            global.PC.Say(msg);
          global.spriteList.AddText(new SpriteListClass.TextObject(global.PC.MyPlayerName + ": " + msg, 0));
        }
      }
      if (global.IC.PressedMButton(global.IC.MButtonLeft))
      {
        global.dbg.Out(Debug.DBG3, "ProcessGameInput:   Shoot");
        global.Tank.Shoot();
      }
      if (global.IC.PressedMButton(global.IC.MButtonRight))
      {
        global.dbg.Out(Debug.DBG3, "ProcessGameInput:   ShootAlternativ");
        global.Tank.ShootAlternativ(global.IC.GetMouseXY());
      }
      global.IC.ReInit();
    }
    // WINNER /////////////////////////////////////////////////////////////////////////////////////////
    public void InitWinner()
    {
      global.dbg.Out(Debug.INFO, "InitWinner called");
      TextBmp.ChangeText("Win");
      // play win sound
      //global.SC.Play();
      // tel other players
      if (global.options.multiplayer)
      {
        // global.PC.SetWinner(global.PC.MyPlayerId, global.PC.MyPlayerName);
      }
      global.options.GameState = GAMEVAR.GAMESTATE.GAMEWINNING_RUNNING;
      global.dbg.Out(Debug.INFO, "RunWinner called");
    }
    public void RunGameWin()
    {
      // paint objects
      global.Background.Draw();
      global.spriteList.Draw();
      TextBmp.Draw();
      global.DC.Front.Draw(global.DC.Back, DrawFlags.DoNotWait);
      global.IC.GetKeyboardInput();
      global.IC.GetMouseInput();
      if (global.IC.PressedKey(Key.Return) || global.IC.PressedKey(Key.Escape))
      {
        global.dbg.Out(Debug.DBG3, "RunWinner:   Return");
        if (global.options.showStats)
          global.options.GameState = GAMEVAR.GAMESTATE.STATS_DISPLAYING;
        else
          global.options.GameState = GAMEVAR.GAMESTATE.GAME_STARTING;
        global.spriteList.Clear();
      }
      global.IC.ReInit();      
    }
    // GAMEOVER /////////////////////////////////////////////////////////////////////////////////////////
    public void InitGameOver()
    {
      global.dbg.Out(Debug.INFO, "InitGameOver called");
      TextBmp.ChangeText("Lose");
      // play lose sound
      //TODO: global.SC.Play(SoundClass.SOUND_LOSER1, true);
      global.SC.Play(SoundClass.SOUND_LOSER1, true);
      // tel other players
      if (global.options.multiplayer)
      {
        // global.PC.SetLoser(global.PC.MyPlayerId, global.PC.MyPlayerName);
      }
      global.options.GameState = GAMEVAR.GAMESTATE.GAMEOVER_RUNNING;
      global.dbg.Out(Debug.INFO, "RunGameOver called");
      global.SC.Stop();
    }
    public void RunGameOver()
    {
      global.dbg.Out(Debug.INFO, "RunGameOver called");
      // paint objects
      global.Background.Draw();
      global.spriteList.Draw();
      TextBmp.Draw();
      global.DC.Front.Draw(global.DC.Back, DrawFlags.DoNotWait);
      global.IC.GetKeyboardInput();
      global.IC.GetMouseInput();
      if (global.IC.PressedKey(Key.Return) || global.IC.PressedKey(Key.Escape))
      {
        global.dbg.Out(Debug.DBG3, "RunWinner:   Return");
        if (global.options.showStats)
          global.options.GameState = GAMEVAR.GAMESTATE.STATS_DISPLAYING;
        else
          global.options.GameState = GAMEVAR.GAMESTATE.MAINMENU_STARTING;
        global.spriteList.Clear();
      }
      global.IC.ReInit();  
    }
    // GAMESTATS /////////////////////////////////////////////////////////////////////////////////////////
    public void RunStatistic()
    {
      // black global.Background
      global.DC.Back.ColorFill(new Rectangle(0, 0, CONST.SCR_WIDTH, CONST.SCR_HEIGHT), Color.Black);
      // display statistics
      global.DC.DrawText(CONST.SCR_WIDTH/2-70, CONST.SCR_HEIGHT/2-50, "No statistic available!", Color.CadetBlue);
      // display on screen
      global.DC.Front.Draw(global.DC.Back, DrawFlags.DoNotWait);
      // get input
      global.IC.GetKeyboardInput();
      global.IC.GetMouseInput();
      if (global.IC.PressedKey(Key.Return) || global.IC.PressedKey(Key.Escape))
      {
        global.dbg.Out(Debug.DBG3, "RunStatistic:   Return");
        global.options.GameState = GAMEVAR.GAMESTATE.GAME_STARTING;
        global.spriteList.Clear();
      }
      global.IC.ReInit();  
    }
    // EXIT /////////////////////////////////////////////////////////////////////////////////////////////
    public void Exit()
    {
      // save game settings stored in 'global.options' to registry
      global.GameRegistry.SaveSettings();
      if (m_optionForm != null)
        m_optionForm.Dispose();
      // stop sorting thread
      global.spriteList = null;
      // stop main game loop
      global.options.initialized = false;
      // play final exiting sound
      global.SC.Play(SoundClass.SOUND_GAMEEXIT, false);
      global.SC.Stop();
      global.SC = null;
            // this is a special debug mode to test non-gui related things
            if( !global.options.noGui )
            {
                // close down DirectDraw
                global.DC.FreeDirectDraw();
          global.DC = null;
          }
            // close down DirectInput
      global.IC.FreeDirectInput();
      global.IC = null;
            // close down DirectPlay
            global.PC.Shutdown();
      global.PC = null;
      Application.Exit();
      Application.ExitThread();
    }  
        // simple handler for when a form is disposed of
        public void FormDisposed(object sender, EventArgs e)
        {
      if (sender == m_optionForm)
        m_optionForm = null;
    }
        protected override void Dispose(bool disposing)
    {
            base.Dispose(disposing);
            // close down logger AFTER disposing all other resources since things like
            // forms will might still be using logging in the form cleanup/destructur!!
            global.dbg.Close();
        }
    // OTHER /////////////////////////////////////////////////////////////////////////////////////////////
    private void RestoreSurfaces()
    {
      // this is a special debug mode to test non-gui related things
      if (!global.options.noGui)
      {
        //global.DC.Draw.RestoreAllSurfaces();
        global.Background.Restore();
        global.spriteList.Restore();
      }
    }
    private void Game_Load(object sender, System.EventArgs e)
    {
      Cursor.Dispose();
    }
    private void KeyUpEvent(object sender, System.Windows.Forms.KeyEventArgs e)
    {
      if (e.KeyCode == Keys.Escape)
      {
        if (global.options.GameState == GAMEVAR.GAMESTATE.MAINMENU_RUNNING)
          global.options.GameState = GAMEVAR.GAMESTATE.GAMEEXIT;
        else
          global.options.GameState = GAMEVAR.GAMESTATE.MAINMENU_STARTING;
      }
    }
    private void MouseMoveEvent(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      if (global.options.initialized)
      {
        global.IC.MouseX = e.X;
        global.IC.MouseY = e.Y;
      }
    }

    private void InitializeComponent()
    {
      // 
      // GameClass
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.BackColor = System.Drawing.Color.Black;
      this.ClientSize = new System.Drawing.Size(280, 280);
      this.ControlBox = false;
      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
      this.MaximizeBox = false;
      this.MinimizeBox = false;
      this.Name = "GameClass";
      this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

    }
  
    private void OnExit_Click(object sender, System.EventArgs e)
    {
      global.options.GameState = GAMEVAR.GAMESTATE.GAMEEXIT;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.