예제 #1
0
        public void render(SpriteBatch batch)
        {
            bombCounter = (bombCounter + 1) % bombCounterMax;

            foreach (Character c in enemies)
            {
                c.render(batch);
            }
            foreach (Character c in enemyBullets)
            {
                c.render(batch);
            }
            foreach (Character c in playerBullets)
            {
                c.render(batch);
            }
            foreach (Character c in eggs)
            {
                c.render(batch);
            }
            foreach (Character c in effects)
            {
                c.render(batch);
            }
            if (player.isAlive())
            {
                // draw egg vector
                if (eggs.Count > 0)
                {
                    Vector2 playerVec = (eggs[0].getPos() - player.getPos());
                    float   r         = (float)Math.Atan((double)(playerVec.Y / playerVec.X)) + (float)Math.PI / 2;
                    if (playerVec.X < -0.01f)
                    {
                        r = (float)Math.PI + r;
                    }
                    else
                    {
                        r = (2.0f * (float)Math.PI) + r;
                    }
                    batch.Draw(arrowSprite,
                               player.getPos(),
                               null,
                               Color.Red,
                               r,
                               new Vector2(arrowSprite.Width / 2, arrowSprite.Height / 2),
                               0.5f,
                               SpriteEffects.None,
                               0.0f);
                }
                player.render(batch);
            }
        }
예제 #2
0
파일: Enemy1.cs 프로젝트: Adhesion/ld22
        protected void facePlayer()
        {
            float   r;
            Player  player    = characterManager.getPlayer();
            Vector2 playerVec = (player.getPos() - pos) + (player.getVel() * 70.0f);

            r = (float)Math.Atan((double)(playerVec.Y / playerVec.X)) + (float)Math.PI / 2;
            if (playerVec.X < -0.01f)
            {
                r = (float)Math.PI + r;
            }
            else
            {
                r = (2.0f * (float)Math.PI) + r;
            }
            //rotate((rotation - r)/20.0f);
            //setRotation(r + (((float)Game1.random.NextDouble() * (float)Math.PI / 16) - (float)Math.PI / 8));
            setRotation(r);
            //rotation = r;
            //destRotation = r;

            if (chase)
            {
                float   dist      = Vector2.Distance(player.getPos(), pos);
                Vector2 followVel = playerVec / 40.0f * dist / 1000.0f;
                if (followVel.X > maxVel)
                {
                    followVel.X = maxVel;
                }
                if (followVel.Y > maxVel)
                {
                    followVel.Y = maxVel;
                }
                float   velX    = ((float)Game1.random.NextDouble() * 2 * maxVel) - maxVel;
                float   velY    = ((float)Game1.random.NextDouble() * 2 * maxVel) - maxVel;
                Vector2 randVel = new Vector2(velX, velY);
                addVel(followVel + randVel);
            }
        }
예제 #3
0
파일: Camera.cs 프로젝트: Adhesion/ld22
        public void update(GameTime gameTime)
        {
            move(player.getPos() - pos);

            camArea = levelManager.getCurrentLevelArea();
            camArea.Inflate(-200, -200);

            if (pos.X < camArea.Left)
            {
                pos.X = camArea.Left;
            }
            else if (pos.X > camArea.Right)
            {
                pos.X = camArea.Right;
            }
            if (pos.Y > camArea.Bottom)
            {
                pos.Y = camArea.Bottom;
            }
            else if (pos.Y < camArea.Top)
            {
                pos.Y = camArea.Top;
            }

            /*if (pos.X - screenPos.X < levelManager.getCurrentLevelArea().Left)
             *  pos.X = levelManager.getCurrentLevelArea().Left + screenPos.X;
             * else if (pos.X + screenPos.X > levelManager.getCurrentLevelArea().Right)
             *  pos.X = levelManager.getCurrentLevelArea().Right - screenPos.X;
             * if (pos.Y + screenPos.Y > levelManager.getCurrentLevelArea().Bottom)
             *  pos.Y = levelManager.getCurrentLevelArea().Bottom - screenPos.Y;
             * else if (pos.Y - screenPos.Y < levelManager.getCurrentLevelArea().Top)
             *  pos.Y = levelManager.getCurrentLevelArea().Top + screenPos.Y;*/

            updateTransform();
            //Console.WriteLine(transform);
        }