Beispiel #1
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            DebugTextures.LoadTextures(GraphicsDevice);

            Text.defaultFont = Content.Load <SpriteFont>("fonts\\npc1");
            Text.guiFont     = Content.Load <SpriteFont>("fonts\\gui");

            Cell.CreateGrid(new Point(-3200, -3200), 500, 500);

            Dialogue.InitializeDialogueSystem(graphics.GraphicsDevice.Viewport);

            map = new Map();

            screenCenter = new Vector2(gameWidth / 2f, gameHeight / 2f);

            character = new Character();

            map.npcs.Add(new NPC(new Vector2(100, -100), DebugTextures.GenerateRectangle(16, 32, Color.Yellow), "Hello world!!", "Great to see you decided to play this game!!"));
            map.npcs.Add(new NPC(new Vector2(150, 10), DebugTextures.GenerateRectangle(16, 32, Color.Yellow), "Hello, my name is tommy! I used to live in peace", "watering me plants in me garden everyday, until the unpredictable struck"));
            map.enemies.Add(new PeasantSoldier(50f, 0.005f, 200f, 300f, 100, screenCenter, DebugTextures.GenerateRectangle(16, 16, Color.DarkGray), character));
            map.enemies.Add(new PeasantSoldier(86, 0.004f, 200f, 300f, 100, new Vector2(53, 3466), DebugTextures.GenerateRectangle(16, 16, Color.GreenYellow), character));
            map.enemies.Add(new PeasantSoldier(70f, 0.004f, 200f, 300f, 100, new Vector2(62, 23), DebugTextures.GenerateRectangle(16, 16, Color.DarkRed), character));
            map.enemies.Add(new PeasantSoldier(69f, 0.004f, 200f, 300f, 100, new Vector2(97, 2), DebugTextures.GenerateRectangle(16, 16, Color.Red), character));
            map.enemies.Add(new PeasantSoldier(82f, 0.004f, 200f, 300f, 100, new Vector2(64, 0), DebugTextures.GenerateRectangle(16, 16, Color.Yellow), character));
            map.enemies.Add(new PeasantSoldier(56f, 0.004f, 200f, 300f, 100, new Vector2(2, 49), DebugTextures.GenerateRectangle(16, 16, Color.Blue), character));

            Vector2 pos = Cell.SnapToGrid(Vector2.One * 40);

            map.objects.Add(new Wall(pos, 64, 64, true));

            Raycast.RayCastTest();
        }
Beispiel #2
0
        public bool Intersecting(Raycast ray, out Vector2 point)
        {
            Vector2 c = ray.a;
            Vector2 d = ray.b;
            Vector2 s = d - c;

            t = Cross(c - a, s) / Cross(r, s);
            u = Cross(c - a, r) / Cross(r, s);

            if (t >= 0f && t <= 1f && u >= 0f && u <= 1f)
            {
                point = a + r * t;
                return(true);
            }
            point = Vector2.Zero;
            return(false);
        }
Beispiel #3
0
        public virtual void Update(GameTime gameTime, Vector2 position, float rotation, Vector2 lookDirection)
        {
            this.position = position + lookDirection * positionOffset;
            this.rotation = rotation;

            /*if (timeToFire > 0)
             * {
             *  timeToFire -= (float)gameTime.ElapsedGameTime.TotalSeconds;
             * }*/

            #region bullet movement and collisions

            if (bullets.Count > 0)
            {
                for (int i = 0; i < bullets.Count; i++)
                {
                    bullets[i].Update(gameTime);

                    Vector2 start = bullets[i].previousPosition - bullets[i].forwardDirection * bullets[i].sprite.Height;
                    Vector2 end   = bullets[i].position + bullets[i].forwardDirection * bullets[i].sprite.Height;

                    if (bullets[i].destroyTime < 0)
                    {
                        bullets.RemoveAt(i);
                        return;
                    }
                    ray = new Raycast(start, end);
                    // this collision rectangle does not change according to its rotation - NEED RAYCASTS (I'M TAKING TIME TO DEVELOP RETARDED METHODS JUST TO THEN REMOVE THEM AND IMPLEMENT ANOTHER METHOD) pls help
                    if (ray.Intersecting(out Collider[] colInfo))
                    {
                        Hit(colInfo, i);
                        return;
                    }
                }
            }
            if (timeToFire > 0)
            {
                timeToFire -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            #endregion
        }