MessageClass.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 » MessageClass.cs
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Drawing;
using Global;
using Global.GlobalClass;

namespace KillerInstinct{
  public class MessageClass
  {
    private enum MessageStates
    {
      NotDisplaying,
      PoppingUp,
      Displaying,
      PoppingDown
    }
    // current state of pop-up box
    private MessageStates      m_messageState  = MessageStates.NotDisplaying;
    private MapClass.MissionTypes  m_mission;
    private StringCollection    m_messageText  = new StringCollection();
    private int            m_width      = 150;
    private int            m_height    = 50;
    private int            m_posX;
    private int            m_posY;
    //
    public MessageClass()
    {
      m_posX = global.options.SCR_WIDTH - m_width;
      m_posY = global.options.SCR_HEIGHT;
    }
    // pop's new message onto screen (add)
    public void Popup(MapClass.MissionTypes mission)
    {
      m_mission = mission;
      // if a message is already popped-up, pop-down
      if (m_messageState == MessageStates.Displaying)
        m_messageState = MessageStates.PoppingDown;
      else
        m_messageState = MessageStates.PoppingUp;
    }
    private void FillMessageText()
    {
      // clear any old messages
      m_messageText.Clear();
      if (m_mission == MapClass.MissionTypes.KillAll)
      {
        m_messageText.Add("Kill All Enemies!");
      }
      // show mission counter (energy, score limit, time limit)
      else if (m_mission == MapClass.MissionTypes.TimeLimit)
      {
        m_messageText.Add("Countdown: " + (global.options.TimeLimit-(System.Environment.TickCount-global.options.GameStartTime)/1000));
      }
      // display how many things left to destroy
      else if (m_mission == MapClass.MissionTypes.Destroy)
      {
        m_messageText.Add("Countdown: " + (global.Map.DestroyTimeLimit-(System.Environment.TickCount-global.options.GameStartTime)/1000));
        m_messageText.Add("Mines to Destroy: " + global.Map.ObjectsLeftToDestroy);
      }
      // display which exits are available
      else if (m_mission == MapClass.MissionTypes.UseExit)
      {
        m_messageText.Add("Go" + global.Map.GetCurrentExits());
      }
    }
    public void Draw()
    {
      if (m_messageState != MessageStates.NotDisplaying)
      {
        switch (m_messageState)
        {
          case MessageStates.PoppingUp:
            m_posY--;
            if (m_posY < global.options.SCR_HEIGHT-m_height)
              m_messageState = MessageStates.Displaying;
            break;
          case MessageStates.Displaying:
            // update message text to be displayed
            FillMessageText();
            break;
          case MessageStates.PoppingDown:
            m_posY++;
            if (m_posY > global.options.SCR_HEIGHT)
            {
              m_messageState = MessageStates.PoppingUp;
              // update message text to be displayed
              FillMessageText();
            }
            break;
        }
        // only draw what can be drawn
        int newHeight = global.options.SCR_HEIGHT - m_posY;
        if (newHeight > 0)
        {
          // draw black box where information is written
          global.DC.DrawBox(m_posX, m_posY, m_width, newHeight, Color.Black, Color.Transparent);
          for (int i=0; i<m_messageText.Count; ++i)
          {
            global.DC.DrawText(m_posX+10, m_posY+(12*(i+1)), m_messageText[i], Color.Firebrick);
          }
        }
      }
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.