Example #1
0
         /// <summary>
        /// Leaf object constructor
        /// </summary>
        /// <param name="name"></param>
        public PrimitiveObject(string name, Locator locator, Engine engine) : base(name, locator, engine)
        {
            Size = new Vector(_initialObjSize, _initialObjSize);

            Viewer = null;

            CollisionShape = CollisionShape.None;
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        public void Fire()
        {
            if (ChargedTime < RechargeTime) return;

            int bulletVelocity = 50;

            SoundManager.PlayBoomSound();

            double angle_rad = Math.PI * AbsoluteAngle / 180.0;
      
            Vector tower_end = new Vector(Math.Cos(angle_rad), Math.Sin(angle_rad)) * Size.X + AbsoluteCenter;
   
            Locator loc = new Locator(tower_end, AbsoluteAngle + 45, 5);

            Engine engine = new Engine(new Vector(bulletVelocity * Math.Cos(angle_rad), bulletVelocity * Math.Sin(angle_rad)), new Vector(0, 0), 0, 0);

            GameProcess.Current_Game.Builder.BuildBullet("bullet", loc, engine);

            ChargedTime = 0;                   
        }   
Example #3
0
        /// <summary>
        /// Game process class constructor
        /// </summary>
        /// <param name="input_controller"></param>
        /// <param name="map"></param>
        /// <param name="obj"></param>
        public GameProcess(FrameworkElement gField, String mapName)
        {
            Current_Game = this;

            Camera = new Camera(new Vector(500, 500), new Vector(gField.ActualWidth, gField.ActualHeight), new Vector(200, 100));

            updateInterval = 1000 / FPS;

            Builder = new TanksMapBuilder();

            TmxBuildDirrector director = new TmxBuildDirrector(mapName, Builder);

            director.CreateMap();

            gameMap = Builder.GetMap();

            Manager = new CollisionManager(gameMap);

            director.CreateLandscape();

            director.CreateObjects();

            frameImages = TmxBuildDirrector.GetImagesFromCropedImage("Maps/Textures/explosion.png", 128, 128, 512, 512);

            Controllers = new List<Controller>();


         
            Locator loc = new Locator(new Vector(310, 310), 0, 2);       

            Engine  engine = new Engine(new Vector(0, 0), new Vector(0, 0), 0, 0);
                                                                              

            Player = Builder.BuildTank("Player", loc, engine);
            //Player.Body.Viewer = Boom;
     

            HITankController controller = new HITankController(gField, Player);

            Controllers.Add(controller);

            Enemies = new List<Tank>();

            List<GameObject> Objects = gameMap.GetObjects();

            for(int i = 0; i < Objects.Count; i++)
            {
                if(Objects[i].GetType().Name.ToLower() == "respaun")
                {
                    Engine eng = new Engine(new Vector(0, 0), new Vector(0, 0), 0, 0);

                    Tank enemy = Builder.BuildTank("Enemy_" + i.ToString(), new Locator(Objects[i].AbsoluteCenter, 0, 2), eng);

                    AITankController AIController = new AITankController(enemy);

                    Controllers.Add(AIController);
                }
            }

            Player.LocationChanged += GameProcess.Current_Game.Camera.UpdateFocus; 
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="locator"></param>
        public GameObject(string name, Locator locator, Engine engine)
        {
            this.Name = name;

            this.Parent = null;

            this.locator = locator;

            this.Engine = engine;

            this.life = 100;
        }
Example #5
0
        public Bullet BuildBullet(string name, Locator locator, Engine engine)
        {
            Func<Bullet> action = () =>
                {
                    Bullet bl = new Bullet(name);

                    bl.LocalCenter = locator.Center;
                    bl.LocalAngle = locator.Angle;
                    bl.LocalZIndex = locator.ZIndex;

                    bl.Engine = engine;

                    bl.Viewer = new Viewer(new Sprite("Maps/Textures/rocket.png", 30, 30));

                    bl.Size = new Vector(15, 15);

                    bl.CollisionShape = CollisionShape.Rectangle;

                    bl.LocationChanged += map.UpdateObject;
                    bl.LocationChanged += GameProcess.Current_Game.Manager.RegisterObject;
                  
                    bl.Crashed += map.RemoveObject;
                    bl.Crashed += GameProcess.Current_Game.Manager.UnRegisterObject;

                    map.AddObject(bl);

                    return bl;
                };


            if (!Application.Current.Dispatcher.CheckAccess())
            {
                return Application.Current.Dispatcher.Invoke(action);
            }
            else
            {
                return action();
            }        
        }
Example #6
0
        public Tank BuildTank(string name, Locator locator, Engine engine)
        {
            Tank tank = new Tank(name);

            tank.LocalCenter = locator.Center;
            tank.LocalAngle = locator.Angle;
            tank.LocalZIndex = locator.ZIndex;

            tank.Engine = engine;
            tank.Engine.Enabled = true;

            if(tank.Name.ToLower() =="player")
                tank.Body =  BuildMachineBody("Body", @"Maps/Textures/dbody128.png");
            else
                tank.Body = BuildMachineBody("Body", @"Maps/Textures/dbodyred128.png");

            tank.Gun = BuildMachineTower("Gun", @"Maps/Textures/dtower128.png");
         
            tank.LocationChanged += map.UpdateObject;
            tank.LocationChanged += GameProcess.Current_Game.Manager.RegisterObject;
 

            tank.Crashed += map.RemoveObject;
            tank.Crashed += GameProcess.Current_Game.Camera.TryRemoveIndicator;
            tank.Crashed += GameProcess.Current_Game.Manager.UnRegisterObject;

            tank.LifeChanged += GameProcess.Current_Game.Camera.IndicateLifeChange;

            map.AddObject(tank);

            return tank;
        }
Example #7
0
 /// <summary>
 /// Composite object constructor
 /// </summary>
 /// <param name="name"></param>
 public CompositeObject(string name, Locator locator, Engine engine) : base(name, locator, engine)
 {
     components = new List<GameObject>();
 }