Example #1
0
        public void Update()
        {
            if (isAlive)
            {
                float deltaX = speed * GfxTools.Win.deltaTime;
                position.X += deltaX;
                float maxX = position.X + width / 2;
                float minX = position.X - width / 2;

                if (maxX > GfxTools.Win.width - distToSide)
                {
                    float overflowX = maxX - (GfxTools.Win.width - distToSide);
                    position.X -= overflowX;
                    deltaX     -= overflowX;
                }
                else if (minX < distToSide)
                {
                    float overflowX = minX - distToSide;
                    position.X -= overflowX;
                    deltaX     -= overflowX;
                }

                sprite.Translate(deltaX, 0);

                //Translate heart sprite energy under player
                for (int i = 0; i < heartsEnergy.Length; i++)
                {
                    if (heartsEnergy[i] != null)
                    {
                        heartsEnergy[i].Translate(deltaX, 0);
                    }
                }

                for (int i = 0; i < bullets.Length; i++)
                {
                    if (bullets[i].IsAlive)
                    {
                        bullets[i].Update();
                        // Console.WriteLine("X: " + bullets[i].Position.X + " Y: " + bullets[i].Position.Y);

                        if (BarrierManager.Collides(bullets[i].Position, bullets[i].GetWidth() / 2)) //perchè non /2
                        {
                            // Game.Stop();
                            bullets[i].IsAlive = false;
                        }

                        else if (EnemyMng.CollideWithBullet(bullets[i]))
                        {
                            bullets[i].IsAlive = false;
                            Game.AddScore(5);
                        }
                    }
                }
            }
        }
Example #2
0
        public Player(Vector2 pos, /*ColorRGB colorBackground, ColorRGB colorBorder*/ int energy = 3)
        {
            position   = pos;
            distToSide = 20;
            shootDelay = 1f;
            counter    = shootDelay;
            isAlive    = true;

            isFirePressed = false;
            isVisible     = true;
            this.energy   = energy;

            //timeDeadAnim = 0.05f;
            //currentTimeDead = timeDeadAnim;
            //this.colorBackground = colorBackground;
            //this.colorBorder = colorBorder;

            //baseRect = new Rectangle(position.X - width / 2, position.Y - height / 2, height / 2, width);
            //baseRect.SetColor(colorBackground, colorBorder);
            //int cannWidth = width / 3;
            //cannonRect = new Rectangle(position.X - cannWidth / 2, position.Y - height, height / 2, cannWidth);
            //cannonRect.SetColor(colorBackground, colorBorder);

            sprite = new SpriteObj("Assets/player.png", position);
            sprite.Translate(-sprite.Width / 2, -sprite.Height); //la sposttiamo sopra, il pivot no però
            width   = sprite.Width;
            height  = sprite.Height;
            ray     = width / 2;
            bullets = new Bullet[30];

            //bullet
            ColorRGB bulletCol = new ColorRGB(255, 255, 255);
            Vector2  velocity  = new Vector2(0, -200f);

            for (int i = 0; i < bullets.Length; i++)
            {
                bullets[i] = new Bullet(2, 11, 1, bulletCol, velocity);
            }

            //hearts energy
            heartsEnergy = new SpriteObj[energy];
            Vector2 heartPos = new Vector2(position.X - width / 2 - 6, position.Y);

            for (int i = 0; i < energy; i++)
            {
                heartsEnergy[i] = new SpriteObj(HEART_SPRITE_NAME, heartPos);
                heartPos.X     += heartsEnergy[i].Width - 5;
            }
        }
Example #3
0
        public void Update()
        {
            animation.Update();

            float deltaY = velocity.Y * GfxTools.Win.deltaTime;

            Position.X += velocity.X * GfxTools.Win.deltaTime;
            Position.Y += deltaY;

            if (sprite != null)
            {
                sprite.Translate(0, deltaY);
            }

            if (Position.Y + Height / 2 < 0 || Position.Y - Height / 2 >= GfxTools.Win.height)
            {
                IsAlive = false;
            }
        }
Example #4
0
 public Barrier(int x, int y)
 {
     sprite   = new SpriteObj(BARRIER_FILE, x, y);
     position = new Vector2(x, y);
     sprite.Translate(-Width / 2, -Height / 2);
 }