Beispiel #1
0
        public void doCollision()
        {
            if (!_noCollide)
            {
                foreach (Type actor in _collidables)
                {
                    //fetch all actors of this type and check them for collisions
                    CActor[] collideCheck = Map.CMapManager.queryActorRegistry(actor, layer);
                    if (collideCheck == null)
                    {
                        continue;
                    }

                    foreach (CActor x in collideCheck)
                    {
                        if (_hitBox != null && x._hitBox != null && x != this && !x._noCollide && _hitBox.checkCollision(x))
                        {
                            //trigger collision event
                            _collideFlag = true;
                            _hitBox.getCollisionDirection(x);
                            onCollide(this, x);
                        }
                        else
                        {
                            _collideFlag = false;
                        }

                        if (_previousCollideFlag && !_collideFlag)
                        {
                            onCollideExit(this, x);
                        }


                        _previousCollideFlag = _collideFlag;
                    }
                }
            }
        }
Beispiel #2
0
        public virtual void update(GameTime gameTime)
        {
            //onFrame(this);

            //check collisions
            foreach (Type actor in _collidables)
            {
                //fetch all actors of this type and check them for collisions
                CActor[] collideCheck = Map.CMapManager.queryActorRegistry(actor, layer);
                if (collideCheck == null)
                {
                    continue;
                }

                foreach (CActor x in collideCheck)
                {
                    if (_hitBox.checkCollision(x._hitBox))
                    {
                        //trigger collision event
                        onCollide(this, x);
                    }
                }
            }

            if (_animationHasEnded)
            {
                try
                {
                    onAnimationEnd(this);
                }
                catch (NotImplementedException) {; }
            }


            _oldPosition = _position;

            if (image != null)
            {
                image.X = (int)_position.X;
                image.Y = (int)_position.Y;
            }

            if ((Master.GetInputManager().GetCurrentInputHandler() as CInput).areKeysPressed)
            {
                onKeyDown(this);
            }

            if ((Master.GetInputManager().GetCurrentInputHandler() as CInput).areKeysReleased)
            {
                onKeyRelease(this);
            }

            if ((Master.GetInputManager().GetCurrentInputHandler() as CInput).mouseLeftClick)
            {
                onMouseClick(this);


                if (_hitBox != null && _hitBox.checkCollision(new Vector2((Master.GetInputManager().GetCurrentInputHandler() as CInput).mouseX,
                                                                          (Master.GetInputManager().GetCurrentInputHandler() as CInput).mouseY)))
                {
                    click(this);
                }
            }

            //do timer events


            foreach (uint ID in _userEventsToFire)
            {
                _userEvents[ID](this);
            }

            _userEventsToFire.Clear();

            _animationHasEnded = false;
            userParams.Clear();
        }