MenuClass.cs :  » Game » Killer-Instinct » KillerInstinct » Sprites » 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 » Sprites » MenuClass.cs
using System;
using Microsoft.DirectX.DirectDraw;
using Global;
using Global.GlobalClass;
using KillerInstinct.DirectX;

namespace KillerInstinct.Sprites{
  public class MenuClass : SpriteClass
  {
    public  int  activeMenuPoint = 1;
    public  int textDistance    = 0;
    public MenuClass(string file, float x, float y, int framesCount, int textdistance)
    {
      frame.Width  = 300;
      frame.Height = 50;
      this.framesCount = framesCount;
      framesPerRow = 2;
      whichFrame   = 0;
      layer        = LAYER_TOP;
      textDistance = textdistance;
      Init(file, CONST.COLORKEY_BLACK, x, y);
    }
    public new void Draw()
    {
      global.dbg.Out(Debug.DBG3, "MenuClass.Draw called");
      int i=0, j=0;
      try
      {
        global.dbg.Out(Debug.DBG3, "---------------------------------");
        global.dbg.Out(Debug.DBG3, "file         = " + file);
        global.dbg.Out(Debug.DBG3, "posX         = " + posX);
        global.dbg.Out(Debug.DBG3, "posY         = " + posY);
        global.dbg.Out(Debug.DBG3, "whichFrame   = " + whichFrame);
        global.dbg.Out(Debug.DBG3, "frame.X      = " + frame.X);
        global.dbg.Out(Debug.DBG3, "frame.Y      = " + frame.Y);
        global.dbg.Out(Debug.DBG3, "framesCount  = " + framesCount);
        global.dbg.Out(Debug.DBG3, "textDistance = " + textDistance);
        
        for (i=0; i<framesCount/2; ++i)
        {
          //global.dbg.Out(Debug.TRACE, "j = " + j);
          if (activeMenuPoint == (i+1))
          {
            global.DC.Back.DrawFast((int)posX, (int)(posY+textDistance*i), surface, GetBitmapFrameRect(j), DrawFastFlags.Wait | DrawFastFlags.SourceColorKey);
          }
          else
          {
            global.DC.Back.DrawFast((int)posX, (int)(posY+textDistance*i), surface, GetBitmapFrameRect(j+1), DrawFastFlags.Wait | DrawFastFlags.SourceColorKey);
          }
          j += 2;
        }
      }
      catch (Exception e)
      {
        //TODO: this exception occurs every once in a while ... ???
        global.dbg.Out(Debug.WARN, "MenuClass.Draw exception: x=[" + posX + "] y=[" + posY + "] whichFrame=[" + whichFrame + "] getFRect=[" + GetBitmapFrameRect(whichFrame) + "] file=[" + file + "]" + "] i=[" + i + "]" + "] j=[" + j + "]");
        global.dbg.Out(Debug.WARN, "MenuClass.Draw exception: " + e);
      }
    }
    public string GetSoundResource(int which)
    {
      return (CONST.DIR_SOUND + "Menu" + which + ".bmp");
    }
    public void Previous(int max)
    {
      if (activeMenuPoint > 1)
        activeMenuPoint--;
      else
        activeMenuPoint=max;
      global.SC.Play(SoundClass.SOUND_MENUNEXT, false);
    }
    public void Next(int max)
    {
      if (activeMenuPoint < max)
        activeMenuPoint++;
      else
        activeMenuPoint=1;
      global.SC.Play(SoundClass.SOUND_MENUNEXT, false);
    }
    public override void Update()
    {
    }
    public override void ReactToCollision(SpriteClass s)
    {
    }
    public bool MouseOver()
    {
      for (int i=0; i<framesCount/2; i++)
      {
        if (global.IC.GetMouseXY().X > posX                  && 
          global.IC.GetMouseXY().X < posX + frame.Width    &&
          global.IC.GetMouseXY().Y > posY + textDistance*i && 
          global.IC.GetMouseXY().Y < posY + textDistance*(i+1))
        {
          if (activeMenuPoint!=i+1)
            global.SC.Play(SoundClass.SOUND_MENUNEXT, false);
          activeMenuPoint = i+1;
          return true;
        }
      }
      return false;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.