Example #1
0
        internal CCWindow(CCApplication application, CCSize screenSizeInPixels, GameWindow xnaWindow, GraphicsDeviceManager deviceManager)
        {
            sceneDirectors = new List <CCDirector>();

            AddSceneDirector(new CCDirector());

            EventDispatcher = new CCEventDispatcher(this);
            Stats           = new CCStats();

            #if !NETFX_CORE
            Accelerometer = new CCAccelerometer(this);
            #endif

            eventAfterDraw            = new CCEventCustom(EVENT_AFTER_DRAW);
            eventAfterDraw.UserData   = this;
            eventAfterVisit           = new CCEventCustom(EVENT_AFTER_VISIT);
            eventAfterVisit.UserData  = this;
            eventAfterUpdate          = new CCEventCustom(EVENT_AFTER_UPDATE);
            eventAfterUpdate.UserData = this;


            IsUseAlphaBlending = true;
            IsUseDepthTesting  = false;

            this.XnaWindow = xnaWindow;
            xnaWindow.OrientationChanged += OnOrientationChanged;
            xnaWindow.ClientSizeChanged  += OnWindowSizeChanged;
            xnaWindow.AllowUserResizing   = true;

            Application = application;

            designResolutionSize   = WindowSizeInPixels;
            DesignResolutionPolicy = CCSceneResolutionPolicy.ExactFit;
            Stats.Initialize();
        }
Example #2
0
        internal CCWindow(CCApplication application, CCSize screenSizeInPixels, GameWindow xnaWindow, GraphicsDeviceManager deviceManager)
        {
            sceneDirectors = new List <CCDirector>();

            AddSceneDirector(new CCDirector());

            EventDispatcher = new CCEventDispatcher(this);
            Stats           = new CCStats();

            #if !NETFX_CORE
            Accelerometer = new CCAccelerometer(this);
            #endif

            eventAfterDraw            = new CCEventCustom(EVENT_AFTER_DRAW);
            eventAfterDraw.UserData   = this;
            eventAfterVisit           = new CCEventCustom(EVENT_AFTER_VISIT);
            eventAfterVisit.UserData  = this;
            eventAfterUpdate          = new CCEventCustom(EVENT_AFTER_UPDATE);
            eventAfterUpdate.UserData = this;


            IsUseAlphaBlending = true;
            IsUseDepthTesting  = false;

            this.XnaWindow = xnaWindow;
            xnaWindow.OrientationChanged += OnOrientationChanged;
            xnaWindow.ClientSizeChanged  += OnWindowSizeChanged;

            DeviceManager = deviceManager;
            // Trying to set user resize when game is full-screen will cause app to crash
            if (!deviceManager.IsFullScreen)
            {
                xnaWindow.AllowUserResizing = true;
            }

            Application = application;

            if (CCScene.DefaultDesignResolutionSize == CCSize.Zero)
            {
                CCScene.DefaultDesignResolutionSize   = screenSizeInPixels;
                CCScene.DefaultDesignResolutionPolicy = CCSceneResolutionPolicy.ExactFit;
            }

            // Make sure we initialize the Cache's so that the correct Scheduler is used.
            // This needs to be looked at further for multiple windows.
            new CCTextureCache(application);
            new CCParticleSystemCache(application);

            Stats.Initialize();

            CCPoint center = screenSizeInPixels.Center;
            defaultViewMatrix = Matrix.CreateLookAt(new CCPoint3(center, 300.0f).XnaVector, new CCPoint3(center, 0.0f).XnaVector, Vector3.Up);
            defaultProjMatrix = Matrix.CreateOrthographic(screenSizeInPixels.Width, screenSizeInPixels.Height, 1024f, -1024);
            defaultViewport   = new Viewport(0, 0, (int)screenSizeInPixels.Width, (int)screenSizeInPixels.Height);
        }
        public void UpdateShipIA(CCEnemyBase enemy, CCPlayerBase player, CCSize wSize, int PLAYER_SPEED)
        {
            if (enemy.IsIA)
            {

                enemy.PositionX -= (PLAYER_SPEED + enemy.VELOCITY + enemy.VELOCITY + CCRandom.Next(1, 3));

                //Esta dentro de su rango;
                if (enemy.IADesiredActionState == EnemyDesiredActionState.Firing)
                {
                    if (ACTUAL_DELAY <= DELAY_SHOOT)
                        ACTUAL_DELAY++;
                    else
                    {
                        enemy.IADesiredActionState = EnemyDesiredActionState.SearchingTarget;
                        ACTUAL_DELAY = 0;
                    }
                }

                if (enemy.IAPersonalityState == EnemyPersonalityState.Suicide)
                {
                    if (enemy.PositionY > player.PositionY)
                        enemy.PositionY -= CCRandom.Next(1, 3);
                    else if (enemy.PositionY < player.PositionY)
                        enemy.PositionY += CCRandom.Next(1, 3);
                }
                else if (enemy.IAPersonalityState == EnemyPersonalityState.Attacking)
                {

                    //Si la posicion
                    if (enemy.IATarget.Y == enemy.Position.Y)
                        enemy.IATarget.Y = (int)CCRandom.GetRandomFloat(player.PositionY - 50f, player.PositionY + 50f);

                    if (enemy.PositionY > enemy.IATarget.Y)
                        enemy.PositionY -= CCRandom.Next(1, 3);
                    else if (enemy.PositionY < enemy.IATarget.Y)
                        enemy.PositionY += CCRandom.Next(1, 3);

                }

                if (enemy.PositionY > player.PositionY - 30 && enemy.PositionY < player.PositionY + 30 && enemy.PositionX < wSize.Width - 15)
                {

                    CCEventCustom eventC = new CCEventCustom(CCBeatEmUpGameLayer.EVENT_ENEMY_ID);
                    eventC.UserData = enemy;

                }

                if (player.PositionX > enemy.PositionX - 100)
                {
                    if (enemy.IADesiredActionState != EnemyDesiredActionState.OutOfRange)
                        enemy.IADesiredActionState = EnemyDesiredActionState.OutOfRange;
                }
            }
        }
Example #4
0
        internal CCWindow(CCApplication application, CCSize screenSizeInPixels, GameWindow xnaWindow, GraphicsDeviceManager deviceManager)
        {
            sceneDirectors = new List <CCDirector>();

            AddSceneDirector(new CCDirector());

            EventDispatcher = new CCEventDispatcher(this);
            Stats           = new CCStats();

            #if !NETFX_CORE
            Accelerometer = new CCAccelerometer(this);
            #endif

            eventAfterDraw            = new CCEventCustom(EVENT_AFTER_DRAW);
            eventAfterDraw.UserData   = this;
            eventAfterVisit           = new CCEventCustom(EVENT_AFTER_VISIT);
            eventAfterVisit.UserData  = this;
            eventAfterUpdate          = new CCEventCustom(EVENT_AFTER_UPDATE);
            eventAfterUpdate.UserData = this;


            IsUseAlphaBlending = true;
            IsUseDepthTesting  = false;

            this.XnaWindow = xnaWindow;
            xnaWindow.OrientationChanged += OnOrientationChanged;
            xnaWindow.ClientSizeChanged  += OnWindowSizeChanged;

            DeviceManager = deviceManager;
            // Trying to set user resize when game is full-screen will cause app to crash
            if (!deviceManager.IsFullScreen)
            {
                xnaWindow.AllowUserResizing = true;
            }

            Application = application;

            if (CCScene.DefaultDesignResolutionSize == CCSize.Zero)
            {
                CCScene.DefaultDesignResolutionSize   = screenSizeInPixels;
                CCScene.DefaultDesignResolutionPolicy = CCSceneResolutionPolicy.ExactFit;
            }

            Stats.Initialize();
        }
		void OnEvent2(CCEventCustom customEvent)
		{
			label2.Text = string.Format("Visit: {0}", count2++);
		}
		void OnEvent1(CCEventCustom customEvent)
		{
			label1.Text = string.Format("Update: {0}", count1++);
		}
		public override void OnEnter ()
		{
			base.OnEnter ();

			var origin = Layer.VisibleBoundsWorldspace.Origin;
			var size = Layer.VisibleBoundsWorldspace.Size;

			//MenuItemFont::setFontSize(20);

			var statusLabel = new CCLabelTtf("No custom event 1 received!", "", 20);
			statusLabel.Position = origin + new CCPoint(size.Width/2, size.Height-90);
			AddChild(statusLabel);

			listener = new CCEventListenerCustom("game_custom_event1", (customEvent) =>
				{
					var str = "Custom event 1 received, ";
					var buf = customEvent.UserData;
					str += buf;
					str += " times";
					statusLabel.Text = str;
			});

            AddEventListener(listener, 1);
			var count = 0;
			var sendItem = new CCMenuItemFont("Send Custom Event 1", (sender) =>
				{
					++count;
					var userData = string.Format("{0}", count);
					DispatchEvent("game_custom_event1",userData);
			});

			sendItem.Position = origin + size.Center;

			var statusLabel2 = new CCLabelTtf("No custom event 2 received!", "", 20);
			statusLabel2.Position = origin + new CCPoint(size.Width/2, size.Height-120);
			AddChild(statusLabel2);

			listener2 = new CCEventListenerCustom("game_custom_event2", (customEvent) =>
				{
					statusLabel2.Text = string.Format("Custom event 2 received, {0} times", customEvent.UserData);
				});

            AddEventListener(listener2, 1);

			var count2 = 0;
			var sendItem2 = new CCMenuItemFont("Send Custom Event 2", (sender) =>
				{
					var customEvent = new CCEventCustom("game_custom_event2");
					customEvent.UserData = ++count2;
                    DispatchEvent(customEvent);
				});

			sendItem2.Position = origin + new CCPoint(size.Width / 2, size.Height / 2 - 40);

			var menu = new CCMenu(sendItem, sendItem2);
			menu.Position = CCPoint.Zero;
			menu.AnchorPoint = CCPoint.AnchorUpperLeft;
			AddChild(menu, -1);
		}
Example #8
0
        internal CCWindow(CCApplication application, CCSize screenSizeInPixels, GameWindow xnaWindow, GraphicsDeviceManager deviceManager)
        {
            sceneDirectors = new List<CCDirector>();

            AddSceneDirector(new CCDirector());

            EventDispatcher = new CCEventDispatcher(this);
            //Stats = new CCStats();

            #if !NETFX_CORE
            Accelerometer = new CCAccelerometer(this);
            #endif

            eventAfterDraw = new CCEventCustom(EVENT_AFTER_DRAW);
            eventAfterDraw.UserData = this;
            eventAfterVisit = new CCEventCustom(EVENT_AFTER_VISIT);
            eventAfterVisit.UserData = this;
            eventAfterUpdate = new CCEventCustom(EVENT_AFTER_UPDATE);
            eventAfterUpdate.UserData = this;


            IsUseAlphaBlending = true;
            IsUseDepthTesting = false;

            this.XnaWindow = xnaWindow;
            xnaWindow.OrientationChanged += OnOrientationChanged;
            xnaWindow.ClientSizeChanged += OnWindowSizeChanged;
            xnaWindow.AllowUserResizing = true;

            Application = application;

            designResolutionSize = WindowSizeInPixels;
            DesignResolutionPolicy = CCSceneResolutionPolicy.ExactFit;
            //Stats.Initialize();
        }
Example #9
0
		/// <summary>
		/// Convenience method to dispatch a custom event
		/// </summary>
		/// <param name="eventToDispatch"></param>
		public void DispatchEvent(string customEvent, object userData = null)
		{
			var custom = new CCEventCustom(customEvent, userData);
			DispatchEvent(custom);

		}
Example #10
0
		protected void OnEvent(CCEventCustom eventC)
		{

			CCPhysicsContact contact = (CCPhysicsContact)eventC.UserData;
			// PhysicsContact) contact = dynamic_cast<PhysicsContact*>(event);


			if (contact == null)
			{
				return;
			}

			switch (contact.GetEventCode())
			{
				case EventCode.BEGIN:
					{
						bool ret = true;

						if (onContactBegin != null
							&& HitTest(contact.GetShapeA(), contact.GetShapeB()))
						{
							contact.GenerateContactData();
							ret = onContactBegin(contact);
						}

						contact.SetResult(ret);
						break;
					}
				case EventCode.PRESOLVE:
					{
						bool ret = true;

						if (onContactPreSolve != null
							&& HitTest(contact.GetShapeA(), contact.GetShapeB()))
						{
							CCPhysicsContactPreSolve solve = new CCPhysicsContactPreSolve(contact._contactInfo);
							contact.GenerateContactData();

							ret = onContactPreSolve(contact, solve);
						}

						contact.SetResult(ret);
						break;
					}
				case EventCode.POSTSOLVE:
					{
						if (onContactPostSolve != null
							&& HitTest(contact.GetShapeA(), contact.GetShapeB()))
						{
							CCPhysicsContactPostSolve solve = new CCPhysicsContactPostSolve(contact._contactInfo);
							onContactPostSolve(contact, solve);
						}
						break;
					}
				case EventCode.SEPERATE:
					{
						if (onContactSeperate != null
							&& HitTest(contact.GetShapeA(), contact.GetShapeB()))
						{
							onContactSeperate(contact);
						}
						break;
					}
				default:
					break;
			}

		}
Example #11
0
 public override void OnEnemyShoot(CCEventCustom obj)
 {
     //LOGIC ON ENEMY SHOOT -> Obj.UserData sends the enemy who fired
 }
Example #12
0
        /// <summary>
        /// Dispatchs a custom event.
        /// </summary>
        /// <param name="customEvent">Custom event.</param>
        /// <param name="userData">User data.</param>
        public void DispatchEvent(string customEvent, object userData = null)
        {
            var custom = new CCEventCustom(customEvent, userData);

            DispatchEvent(custom);
        }
Example #13
0
        internal CCWindow(CCApplication application, CCSize screenSizeInPixels, GameWindow xnaWindow, GraphicsDeviceManager deviceManager)
        {
            sceneDirectors = new List<CCDirector>();

            AddSceneDirector(new CCDirector());

            EventDispatcher = new CCEventDispatcher(this);
            Stats = new CCStats();

            #if !NETFX_CORE
            Accelerometer = new CCAccelerometer(this);
            #endif

            eventAfterDraw = new CCEventCustom(EVENT_AFTER_DRAW);
            eventAfterDraw.UserData = this;
            eventAfterVisit = new CCEventCustom(EVENT_AFTER_VISIT);
            eventAfterVisit.UserData = this;
            eventAfterUpdate = new CCEventCustom(EVENT_AFTER_UPDATE);
            eventAfterUpdate.UserData = this;


            IsUseAlphaBlending = true;
            IsUseDepthTesting = false;

            this.XnaWindow = xnaWindow;
            xnaWindow.OrientationChanged += OnOrientationChanged;
            xnaWindow.ClientSizeChanged += OnWindowSizeChanged;
            
            DeviceManager = deviceManager;
            // Trying to set user resize when game is full-screen will cause app to crash 
            if(!deviceManager.IsFullScreen)
                xnaWindow.AllowUserResizing = true;

            Application = application;

            if (CCScene.DefaultDesignResolutionSize == CCSize.Zero)
            {
                CCScene.DefaultDesignResolutionSize = screenSizeInPixels;
                CCScene.DefaultDesignResolutionPolicy = CCSceneResolutionPolicy.ExactFit;
            }

            // Make sure we initialize the Cache's so that the correct Scheduler is used.
            // This needs to be looked at further for multiple windows.
            new CCTextureCache(application);
            new CCParticleSystemCache(application);

            Stats.Initialize();

            CCPoint center = screenSizeInPixels.Center;
            defaultViewMatrix = Matrix.CreateLookAt(new CCPoint3(center, 300.0f).XnaVector, new CCPoint3(center, 0.0f).XnaVector, Vector3.Up);
            defaultProjMatrix = Matrix.CreateOrthographic(screenSizeInPixels.Width, screenSizeInPixels.Height, 1024f, -1024);
            defaultViewport = new Viewport(0, 0, (int)screenSizeInPixels.Width, (int)screenSizeInPixels.Height);
        }
Example #14
0
        internal CCWindow(CCApplication application, CCSize screenSizeInPixels, GameWindow xnaWindow, GraphicsDeviceManager deviceManager)
        {
            sceneDirectors = new List<CCDirector>();

            AddSceneDirector(new CCDirector());

            EventDispatcher = new CCEventDispatcher(this);
            Stats = new CCStats();

            #if !NETFX_CORE
            Accelerometer = new CCAccelerometer(this);
            #endif

            eventAfterDraw = new CCEventCustom(EVENT_AFTER_DRAW);
            eventAfterDraw.UserData = this;
            eventAfterVisit = new CCEventCustom(EVENT_AFTER_VISIT);
            eventAfterVisit.UserData = this;
            eventAfterUpdate = new CCEventCustom(EVENT_AFTER_UPDATE);
            eventAfterUpdate.UserData = this;


            IsUseAlphaBlending = true;
            IsUseDepthTesting = false;

            this.XnaWindow = xnaWindow;
            xnaWindow.OrientationChanged += OnOrientationChanged;
            xnaWindow.ClientSizeChanged += OnWindowSizeChanged;
            
            DeviceManager = deviceManager;
            // Trying to set user resize when game is full-screen will cause app to crash 
            if(!deviceManager.IsFullScreen)
                xnaWindow.AllowUserResizing = true;

            Application = application;

            if (CCScene.DefaultDesignResolutionSize == CCSize.Zero)
            {
                CCScene.DefaultDesignResolutionSize = screenSizeInPixels;
                CCScene.DefaultDesignResolutionPolicy = CCSceneResolutionPolicy.ExactFit;
            }

            Stats.Initialize();
        }
Example #15
0
 public override void OnPlayerShoot(CCEventCustom obj)
 {
 }
Example #16
0
 public override void OnEnemyShoot(CCEventCustom obj)
 {
 }
Example #17
0
        public override void Step(CSKPlayer player, CSKEnemy enemy, CCSize wSize, float dt)
        {
            if (!enemy.klass.IsIA)
                return;

            //int alive = 0;
            float distanceSQ;
            int randomChoice = 0;
            enemy.Update(dt);

            if (enemy.actionState != ActionState.KnockedOut)
            {
                if (enemy.HasPassedDecisionTime())
                {
                    CCPoint pos = player.Position;
                    //distanceSQ = enemy.Position.DistanceSQ(ref pos);
                    distanceSQ = enemy.DistanceSQ(player);

                    //3
                    if (enemy.DistanceSQ(player, 50 * 50))
                    {
                        enemy.SetNextDecisionTime(1, 5);

                        RandomChoice(rnd =>
                        {
                            if (rnd)
                                enemy.idle();
                            else
                            {
                                if (player.IsOnRight(enemy))
                                    enemy.SetFlip(true);
                                else
                                    enemy.SetFlip(false);

                                //4
                                enemy.attack();
                                if (enemy.actionState == ActionState.Attack)
                                {
                                    if (Math.Abs(player.PositionY - enemy.PositionY) < 10)
                                    {
                                        if (player.AbsoluteHitBoxRect.IntersectsRect(enemy.AbsoluteAttackBoxRect))
                                        {
                                            CCEventCustom eventHurts = new CCEventCustom(EVENT_IA_PLAYER_HURTS, enemy);
                                            if (layer != null)
                                                layer.DispatchEvent(eventHurts);
                                        }
                                    }
                                }
                            }
                        });

                        randomChoice = CCRandom.GetRandomInt(0, 1);
                    }
                    else if (distanceSQ <= wSize.Width * wSize.Width)
                    {
                        //5
                        enemy.SetNextDecisionTime(1, 5);
                        randomChoice = CCRandom.GetRandomInt(0, 2);
                        if (randomChoice == 0)
                        {
                            CCPoint moveDirection = CCPoint.Normalize(player.Position - enemy.Position);
                            enemy.moveWithDirection(moveDirection);
                        }
                        else
                        {
                            enemy.idle();
                        }
                    }
                }
            }
        }
 /// <summary>
 /// This is fired by the IA System
 /// </summary>
 /// <param name="obj"></param>
 public virtual void OnEnemyShoot(CCEventCustom obj)
 {
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="obj"></param>
 public virtual void OnPlayerShoot(CCEventCustom obj)
 {
 }
Example #20
0
 public override void OnEnemyShoot(CCEventCustom obj)
 {
     //Se debería pasar el ataque del monstruo más el CCEnemy
     //LOGIC ON ENEMY SHOOT -> Obj.UserData sends the enemy who fired
 }
Example #21
0
 public override void OnPlayerShoot(CCEventCustom obj)
 {
     //LOGIC ON PLAYER SHOOT -> Obj.UserData sends the player who fired
 }
Example #22
0
        protected void OnEvent(CCEventCustom eventC)
        {
            CCPhysicsContact contact = (CCPhysicsContact)eventC.UserData;

            // PhysicsContact) contact = dynamic_cast<PhysicsContact*>(event);


            if (contact == null)
            {
                return;
            }

            switch (contact.GetEventCode())
            {
            case EventCode.BEGIN:
            {
                bool ret = true;

                if (onContactBegin != null &&
                    HitTest(contact.GetShapeA(), contact.GetShapeB()))
                {
                    contact.GenerateContactData();
                    ret = onContactBegin(contact);
                }

                contact.SetResult(ret);
                break;
            }

            case EventCode.PRESOLVE:
            {
                bool ret = true;

                if (onContactPreSolve != null &&
                    HitTest(contact.GetShapeA(), contact.GetShapeB()))
                {
                    CCPhysicsContactPreSolve solve = new CCPhysicsContactPreSolve(contact._contactInfo);
                    contact.GenerateContactData();

                    ret = onContactPreSolve(contact, solve);
                }

                contact.SetResult(ret);
                break;
            }

            case EventCode.POSTSOLVE:
            {
                if (onContactPostSolve != null &&
                    HitTest(contact.GetShapeA(), contact.GetShapeB()))
                {
                    CCPhysicsContactPostSolve solve = new CCPhysicsContactPostSolve(contact._contactInfo);
                    onContactPostSolve(contact, solve);
                }
                break;
            }

            case EventCode.SEPERATE:
            {
                if (onContactSeperate != null &&
                    HitTest(contact.GetShapeA(), contact.GetShapeB()))
                {
                    onContactSeperate(contact);
                }
                break;
            }

            default:
                break;
            }
        }