예제 #1
0
        public Player(Vector2 pos, Color col)
        {
            position = pos;
            sprite   = new SpriteObj("Assets/player.png", position);
            width    = sprite.Width;
            height   = sprite.Height;
            sprite.Translate(-width / 2, -height);
            distToSide = 20;
            shootDelay = 0.5f;
            color      = col;
            ray        = width / 2;
            nrg        = 3;
            score      = 0;

            IsAlive = true;


            //baseRect = new Rect(position.X - width / 2, position.Y - height / 2, width, height / 2, color);
            //int cannWidth = width / 3;
            //cannonRect = new Rect(position.X - cannWidth / 2, position.Y - height, cannWidth, height / 2, color);

            bullets = new Bullet[30];

            Color bulletCol = new Color(200, 0, 0);

            for (int i = 0; i < bullets.Length; i++)
            {
                bullets[i] = new Bullet(10, 20, bulletCol);
            }
        }
예제 #2
0
 public Barrier(int x, int y)
 {
     position = new Vector2(x, y);
     sprite   = new SpriteObj("Assets/barrier.png", x, y);
     sprite.Translate(-Width / 2, -Height / 2);
     counter = 0;
 }
예제 #3
0
        public void Update()
        {
            animation.Update();

            float deltaX = velocity.X * GfxTools.Win.deltaTime;

            Position.X += deltaX;

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

            Position.Y += deltaY;

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

            if (Position.X - ray >= GfxTools.Win.width)
            {
                IsAlive = false;
            }
        }
예제 #4
0
        public void Update()
        {
            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;
            }

            //rectangles update
            //baseRect.Translate(deltaX, 0);
            //cannonRect.Translate(deltaX, 0);
            sprite.Translate(deltaX, 0);

            for (int i = 0; i < bullets.Length; i++)
            {
                if (bullets[i].IsAlive)
                {
                    bullets[i].Update();

                    if (Game.BarriersCollides(bullets[i].Position, bullets[i].GetWidth() / 2))
                    {
                        bullets[i].IsAlive = false;
                    }
                    else if (EnemyMgr.CollideWithBullet(bullets[i]))
                    {
                        bullets[i].IsAlive = false;
                    }
                }
            }
        }