示例#1
0
        public Bullet(ContentManager content, SPoint position, SpaceInvaders gameRoot, SVector2D velocity, Color color) :
            base(content, position, "Bullet", BULLET_WIDTH, gameRoot)
        {
            m_gameObjectType       = GameObjectType.Bullet;
            m_velocity             = velocity;
            m_accumulatedFlickTime = 0.0;
            m_visibleState         = false;

            m_color = color;
        }
示例#2
0
        private bool PointInsideRect(SPoint point, SPoint center, double width, double height)
        {
            if (point.x >= center.x - (width / 2.0) && point.x <= center.x + (width / 2.0) &&
                point.y >= center.y - (height / 2.0) && point.y <= center.y + (height / 2.0))
            {
                return(true);
            }

            return(false);
        }
示例#3
0
        public void            TransformPoint(ref SPoint point)
        {
            double[] otherMatrix = { point.x, point.y, 1.0 };
            double[] result      = { 0.0, 0.0, 0.0 };

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    result[i] += otherMatrix[j] * m_matrix[j, i];
                }
            }

            point.x = result[0];
            point.y = result[1];
        }
示例#4
0
        public Alien(ContentManager content, SPoint position, SpaceInvaders gameRoot, bool virt, int layer, AlienBehaviour behaviour) :
            base(content, position, "Alien1", ALIEN_WIDTH, gameRoot)
        {
            m_gameObjectType = GameObjectType.Alien;
            m_isVirtualAlien = virt;
            m_goingRight     = true;

            m_hiddenPosition     = m_position;
            m_accumulatedTimePos = 0.0;
            m_layer = layer;

            m_gameRoot.GetAliensCountPerRow()[layer]++;

            m_behaviour                = behaviour;
            m_behaviourIndex           = 0;
            m_accumulatedBehaviourTime = 0.0;
        }
        public GameObject(ContentManager content,
                          SPoint position,
                          string texutreFilename,
                          double width,
                          SpaceInvaders gameRoot)
        {
            m_content         = content;
            m_position        = position;
            m_textureFileName = texutreFilename;
            m_width           = width;

            m_texture = m_content.Load <Texture2D>(m_textureFileName);

            m_gameRoot       = gameRoot;
            m_gameObjectType = GameObjectType.Default;

            m_dead = false;
        }
示例#6
0
 private void CreateCastle(SPoint origin)
 {
     Color[] rawData = new Color[m_castleTexture.Width * m_castleTexture.Height];
     m_castleTexture.GetData(rawData);
     for (int i = 0; i < m_castleTexture.Height; i++)
     {
         for (int j = 0; j < m_castleTexture.Width; j++)
         {
             Color pixel = rawData[i * m_castleTexture.Width + j];
             if (pixel.A >= 0.5)
             {
                 Instantiate(new Block(m_content,
                                       new SPoint(origin.x + (j - m_castleTexture.Width / 2.0) * Block.BLOCK_WIDTH,
                                                  origin.y + ((m_castleTexture.Height - i) - (m_castleTexture.Height / 2.0)) * Block.BLOCK_WIDTH),
                                       this));
             }
         }
     }
 }
        public void RenderSprite(SpriteBatch spriteBatch, Texture2D texture, SPoint position, double width, Color color)
        {
            double height = (width / texture.Height) * texture.Width;

            // center the sprite
            position.x -= width / 2.0;
            position.y += height / 2.0;

            // flip the sprite
            position.y = m_baseHeight - position.y;

            SVector2D rectangleOrigin = new SVector2D(0, 0);
            double    graphicsScale   = 1.0;
            double    modifiedWidth   = m_screenWidth;

            if (m_screenWidth / m_screenHeight > m_baseWidth / m_baseHeight)
            {
                double center = m_screenWidth / 2.0;
                graphicsScale = (m_screenHeight / m_baseHeight);
                double actualWidthSide = graphicsScale * m_baseWidth;
                modifiedWidth     = actualWidthSide;
                rectangleOrigin.x = center - (actualWidthSide / 2.0);
            }
            else
            {
                double center = m_screenHeight / 2.0;
                graphicsScale = (m_screenWidth / m_baseWidth);
                double actualHeightSide = graphicsScale * m_baseHeight;
                rectangleOrigin.y = center - (actualHeightSide / 2.0);
            }

            double textureWidthPercentage = texture.Width / modifiedWidth;
            double targetWidthPercentage  = width / m_baseWidth;
            double scale = targetWidthPercentage / textureWidthPercentage;

            SPoint drawPosition = new SPoint(position.x * graphicsScale, position.y * graphicsScale);

            drawPosition += rectangleOrigin;

            spriteBatch.Draw(texture, new Vector2((float)drawPosition.x, (float)drawPosition.y), null, color, 0.0f, Vector2.Zero, (float)scale, SpriteEffects.None, 1.0f);
        }
示例#8
0
        private void CreateAlienRow(double startHeight, int layer)
        {
            SPoint startingPos = new SPoint(Alien.ALIEN_WIDTH / 2.0,
                                            startHeight - (Alien.ALIEN_WIDTH / 2.0)); // it should be height, but it work because it's a square

            for (int i = 0; i < ALIENS_PER_ROW; i++)
            {
                Instantiate(new Alien(m_content, startingPos, this, false, layer, m_rowsBehaviours[layer].alienBehaviours[i]));

                if (i == 0 || i == ALIENS_PER_ROW - 1)
                {
                    Alien alien = new Alien(m_content, startingPos, this, true, layer, m_rowsBehaviours[layer].alienBehaviours[i]);
                    if (i == 0)
                    {
                        m_leftVirtualAlien = alien;
                    }
                    Instantiate(alien);
                }

                startingPos += new SVector2D(DISTANCE_BETWEEN_ALIENS, 0.0);
            }
        }
示例#9
0
 public Player(ContentManager content, SPoint position, SpaceInvaders gameRoot) :
     base(content, position, "Player", PLAYER_WIDTH, gameRoot)
 {
     m_gameObjectType = GameObjectType.Player;
     m_reloadingTime  = PLAYER_TIME_TO_RELOAD;
 }
示例#10
0
        public static SPoint operator -(SPoint point, double val)
        {
            SPoint result = new SPoint(point.x - val, point.y - val);

            return(result);
        }
示例#11
0
        public static SPoint operator -(SPoint point, SVector2D vec)
        {
            SPoint result = new SPoint(point.x - vec.x, point.y - vec.y);

            return(result);
        }