예제 #1
0
        void BuildEngine()
        {
            var world = new Engine.World(Arena.FromFile("Res/arena1.txt"));

            engine = new Engine.Engine(world);
            engine.PlayerHitEvent += Engine_PlayerHitEvent;
        }
예제 #2
0
 public override void Update(World world, GameTime gameTime)
 {
     KeyboardState keyboard = Keyboard.GetState ();
     MouseState mouse = Mouse.GetState ();
     foreach (Entity entity in world.Entities.WithComponent<InputBehaviorComponent>())
     {
         IInputBehavior inputBehavior = entity.GetComponent<InputBehaviorComponent> ().Behavior;
         inputBehavior.HandleInput (entity, keyboard, mouse);
     }
 }
예제 #3
0
        public void ClearWorld()
        {
            if (assetManager != null)
                assetManager = null;

            if (currentWorld != null)
                currentWorld = null;

            assetManager = new AssetManager(content);
            currentWorld = new World(assetManager);
            LoadEffects();
        }
예제 #4
0
파일: GameLoader.cs 프로젝트: 47th/Monogame
 public World LoadLevel()
 {
     _world = new World();
     _world.Physics.Gravity = new Vector2 (0, 500);
     CreateCage ();
     CreateWall (new Vector2 (_viewPort.Width / 2, 430));
     CreateBall (new Vector2 (_viewPort.Width / 2, 330), Vector2.Zero);
     // w = 64, h = 32
     //for (int i = 0; i < 12; ++i)
         //for (int j = 0; j < 10; ++j)
             //CreateWall (new Vector2 (32 + 64 * i, 16 + 32 * j));
     //CreateRacket (new Vector2 (_viewPort.Width / 2, 450));
     return _world;
 }
예제 #5
0
        public Entity GetEntityAtPosition(World world, int x, int y)
        {
            //Vector2 viewportTrans = new Vector2(graphicsDevice.Viewport.Width / 2, graphicsDevice.Viewport.Height / 2);
            //Vector2 clickPos = new Vector2(x - m_posCamera.X - viewportTrans.X, y - m_posCamera.Y - viewportTrans.Y);
            //Console.WriteLine(clickPos);
            foreach (Entity ent in world.GetEntities())
            {
                Vector2 pos = ent.Position;
                Vector2 pos2D = Project(new Vector3(pos.X, pos.Y, ent.Type==EntityType.Sprite?ent.Z:0));

                Rectangle rect = new Rectangle((int)pos2D.X, (int)pos2D.Y, 10, 10);;
                if(ent.Type==EntityType.Sprite)
                {
                    Texture2D tex = assetManager.GetTexture(ent.Sprite+"/dif");

                    rect = new Rectangle((int)pos2D.X, (int)pos2D.Y, (int)(tex.Width), (int)(tex.Height));
                }

                if (rect.Contains((int)x, (int)y))
                    return ent;
            }

            return null;
        }
예제 #6
0
        /// <summary>
        /// Given a world object, the renderer draws it using the
        /// XNA frameworks
        /// </summary>
        /// <param name="world">The world object to render</param>
        /// <returns></returns>
        public bool RenderWorld(World world)
        {
            world.SortEntities();
            ClearScreen();

            Effect shader = assetManager.GetEffect("shaders/sprite/SimpleSprite");
            Effect channel = assetManager.GetEffect("shaders/ChannelRender");

            Vector2 viewportTrans = new Vector2(graphicsDevice.Viewport.Width / 2, graphicsDevice.Viewport.Height / 2);

            SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice);

            // Step 1: Generate a stencil of which pixels to render

            // Draw the actual sprites
            Color[] t = { Color.White, Color.Yellow, Color.Purple, Color.Blue };
            int i = 0;

            ClearRenderTargets();

            List<Entity> lstEntities = world.GetEntities();

            // First pass: Draw the entities
            // This pass generates the dif, nrm and hgt textures
            // Objects intersect as if in 3D
            RenderEntities(lstEntities, spriteBatch, m_rtDif, m_rtDepthStencil, m_rtNormal, temp);

            // Render the lights!
            RenderLights(lstEntities, spriteBatch, m_rtDif, m_rtDepthStencil, m_rtNormal, m_rtLights, m_rtSpc, temp);

            // Render the overlays!
            Texture2D lightPos = assetManager.GetTexture("sprites/test/lightpos");
            Texture2D lightBulb = assetManager.GetTexture("sprites/test/lightbulb");
            graphicsDevice.SetRenderTarget(m_rtOverlay);
            if (m_bDrawLights)
            {
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
                foreach (Entity ent in lstEntities)
                {
                    if (ent.Type != EntityType.Light)
                        continue;

                    Entities.Lights.Light light = (Entities.Lights.Light)ent;
                    Vector2 posBase = Project(new Vector3(light.Position.X, light.Position.Y, 0));
                    Vector2 posBulb = Project(new Vector3(light.Position.X, light.Position.Y, light.Z));

                    spriteBatch.Draw(lightPos, posBase, light.Color);
                    spriteBatch.Draw(lightBulb, posBulb, light.Color);
                }
                spriteBatch.End();
            }

            // Render out 'selection rectangles'
            Texture2D selectionRect = new Texture2D(graphicsDevice, 1, 1);
            selectionRect.SetData<Color>(new[] { Color.Red });

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            foreach (Entity ent in lstEntities)
            {
                if (!ent.Selected)
                    continue;

                Vector2 upperLeft = Project(new Vector3(ent.Position.X, ent.Position.Y, ent.Type==EntityType.Sprite?ent.Z:0));
                upperLeft.X -= 2;
                upperLeft.Y -= 2;

                Vector2 size = new Vector2(14, 14);

                if (ent.Type == EntityType.Sprite)
                {
                    Texture2D sprite = assetManager.GetTexture(ent.Sprite + "/dif");
                    size = new Vector2(sprite.Width+4, sprite.Height+4);
                }

                spriteBatch.Draw(selectionRect, new Rectangle((int)upperLeft.X, (int)upperLeft.Y, 1, (int)size.Y), Color.White);
                spriteBatch.Draw(selectionRect, new Rectangle((int)upperLeft.X, (int)upperLeft.Y, (int)size.X, 1), Color.White);
                spriteBatch.Draw(selectionRect, new Rectangle((int)(upperLeft.X+size.X), (int)upperLeft.Y, 1, (int)size.Y), Color.White);
                spriteBatch.Draw(selectionRect, new Rectangle((int)(upperLeft.X), (int)(upperLeft.Y+size.Y), (int)size.X, 1), Color.White);
            }
            spriteBatch.End();

            ////////////////////////////////////////////////////////////////////
            // finalResult stores the final beauty pass
            // That is, a combination of the dif and the lighting outputs
            graphicsDevice.SetRenderTarget(finalResult);
            graphicsDevice.Textures[1] = m_rtLights;
            graphicsDevice.Textures[2] = m_rtSpc;

            Effect combine = assetManager.GetEffect("shaders/Combine");

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            combine.Parameters["scalarAdd"].SetValue(m_colAmbient.ToVector4() * m_fAmbientIntensity);
            combine.Techniques[0].Passes[0].Apply();
            spriteBatch.Draw(m_rtDif, Vector2.Zero, Color.White);
            spriteBatch.End();

            //////////////////////////////////////////////////////////////////
            graphicsDevice.SetRenderTarget(null);
            graphicsDevice.Clear(Color.Transparent);
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            switch(m_rstType)
            {
                case RenderSceneType.Diffuse:
                    spriteBatch.Draw(m_rtDif, Vector2.Zero, Color.White);
                    break;

                case RenderSceneType.Height:
                    spriteBatch.Draw(m_rtDepthStencil, Vector2.Zero, Color.White);
                    break;

                case RenderSceneType.Normal:
                    spriteBatch.Draw(m_rtNormal, Vector2.Zero, Color.White);
                    break;

                case RenderSceneType.Lights:
                    spriteBatch.Draw(m_rtLights, Vector2.Zero, Color.White);
                    break;

                case RenderSceneType.Beauty:
                    spriteBatch.Draw(finalResult, Vector2.Zero, Color.White);
                    break;
            }
            spriteBatch.Draw(m_rtOverlay, Vector2.Zero, Color.White);
            spriteBatch.End();

            return true;
        }
예제 #7
0
        /// <summary>
        /// Kreira objekat World
        /// inicijalizuje game loop handler (TimerClock_Tick)
        /// inicijalizuje event handler za obradu ulaza sa tastature 
        /// </summary>
        private void StartGame()
        {
            SoundUtility.Play("Sounds/StingTheEndOfTheGame.mp3");

            world = new World(Settings.WorldColNum, Settings.WorldRowNum);
            //world.Level = 1;

            if (gameLoop == null)
            {
                btnPause.IsEnabled = true;
                btnStart.Content = "RESTART";

                //gravity loop initialization
                gravityLoop = new DispatcherTimerGameLoop(GetGameSpeed(world.Level));
                gravityLoop.Update += new GameLoop.UpdateHandler(gravityLoop_Update);

                //game loop initialization
                gameLoop = new DispatcherTimerGameLoop();
                gameLoop.Update += new GameLoop.UpdateHandler(gameLoop_Update);

                keyHandler = new KeyHandler(this);
            }

            gravityLoop.Start();
            gameLoop.Start();
        }
예제 #8
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            splitContainer.SplitterDistance = 100;
            splitContainer.Invalidate();
            ResizeViews();

            currentWorld = formRenderer.CurrentWorld;
            currentRenderer = formRenderer.CurrentRenderer;

            //currentWorld.AddEntity(new Engine.Entities.Test.Cuboid());
            //currentWorld.AddEntity(new Engine.Entities.Lights.PointLight());

            UpdateViews();
        }
예제 #9
0
파일: Player.cs 프로젝트: Nelson2306/RPG
 private void MoveHome()
 {
     MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
 }
예제 #10
0
        private void MoveTo(Location newLocation)
        {
            if (!HasRequiredItemToEnterThisLocation(newLocation))
            {
                RaiseMessage("You must have a " + newLocation.ItemRequiredToEnter.Name + " to enter this location.");
                return;
            }

            CurrentLocation = newLocation;

            CurrentHitPoints = MaximumHitPoints;

            if (newLocation.QuestAvailableHere != null)
            {
                bool playerAlreadyHasQuest       = HasThisQuest(newLocation.QuestAvailableHere);
                bool playerAlreadyCompletedQuest = CompletedThisQuest(newLocation.QuestAvailableHere);

                if (playerAlreadyHasQuest)
                {
                    if (!playerAlreadyCompletedQuest)
                    {
                        bool playerHasAllItemsToCompleteQuest = HasAllQuestCompletionItems(newLocation.QuestAvailableHere);

                        if (playerHasAllItemsToCompleteQuest)
                        {
                            RaiseMessage("");
                            RaiseMessage("You complete the '" + newLocation.QuestAvailableHere.Name + "' quest.");

                            RemoveQuestCompletionItems(newLocation.QuestAvailableHere);

                            RaiseMessage("You receive: ");
                            RaiseMessage(newLocation.QuestAvailableHere.RewardExperiencePoints + " experience points");
                            RaiseMessage(newLocation.QuestAvailableHere.RewardGold + " gold");
                            RaiseMessage(newLocation.QuestAvailableHere.RewardItem.Name, true);

                            AddExperiencePoints(newLocation.QuestAvailableHere.RewardExperiencePoints);
                            Gold += newLocation.QuestAvailableHere.RewardGold;

                            AddItemToInventory(newLocation.QuestAvailableHere.RewardItem);

                            MarkQuestCompleted(newLocation.QuestAvailableHere);
                        }
                    }
                }
                else
                {
                    RaiseMessage("You receive the " + newLocation.QuestAvailableHere.Name + " quest.");
                    RaiseMessage(newLocation.QuestAvailableHere.Description);
                    RaiseMessage("To complete it, return with:");
                    foreach (QuestCompletionItem qci in newLocation.QuestAvailableHere.QuestCompletionItems)
                    {
                        if (qci.Quantity == 1)
                        {
                            RaiseMessage(qci.Quantity + " " + qci.Details.Name);
                        }
                        else
                        {
                            RaiseMessage(qci.Quantity + " " + qci.Details.NamePlural);
                        }
                    }
                    RaiseMessage("");

                    Quests.Add(new PlayerQuest(newLocation.QuestAvailableHere));
                }
            }

            if (newLocation.MonsterLivingHere != null)
            {
                RaiseMessage("You see a " + newLocation.MonsterLivingHere.Name);

                Monster standardMonster = World.MonsterByID(newLocation.MonsterLivingHere.ID);

                _currentMonster = new Monster(standardMonster.ID, standardMonster.Name, standardMonster.MaximumDamage, standardMonster.RewardExperiencePoints, standardMonster.RewardGold, standardMonster.CurrentHitPoints, standardMonster.MaximumHitPoints);

                foreach (LootItem lootItem in standardMonster.LootTable)
                {
                    _currentMonster.LootTable.Add(lootItem);
                }
            }
            else
            {
                _currentMonster = null;
            }
        }
예제 #11
0
        public virtual void DrawTiles(World world)
        {
            RectangleF viewRect = camera.ViewRect;

            // Calculate the range of tiles to consider for drawing
            int tileLeft   = (int)viewRect.left / Tile.size;
            int tileTop    = (int)viewRect.top / Tile.size;
            int tileRight  = (int)viewRect.right / Tile.size;
            int tileBottom = (int)viewRect.bottom / Tile.size;

            // Make sure in tile bounds
            if (tileLeft < 0)
            {
                tileLeft = 0;
            }
            if (tileTop < 0)
            {
                tileTop = 0;
            }
            if (tileRight >= world.width)
            {
                tileRight = world.width - 1;
            }
            if (tileBottom >= world.height)
            {
                tileBottom = world.height - 1;
            }
            if (tileRight < 0 || tileBottom < 0)
            {
                return;
            }


            for (int x = tileLeft; x <= tileRight; x++)
            {
                for (int y = tileTop; y <= tileBottom; y++)
                {
                    Tile t = world.tileArray[x, y];
                    if (t.val < 0.0001f)
                    {
                        continue;                   // if not in player vision, don't draw
                    }
                    Color tint = t.glow;
                    //if (tint.R < 5 && tint.G < 5 && tint.B < 5) continue; // if near black, don't draw
                    if (t.opaque)
                    {
                        spriteBatch.Draw(world.tileTextureSet[t.imgIndex], new Vector2(t.x, t.y), (t.MAKERED) ? Color.Red : tint);
                    }
                    else
                    {
                        Color tint1 = Color.Lerp(t.left == null || t.left.opaque ? tint : t.left.glow, t.up == null ? tint : t.up.glow, 0.5f);
                        Color tint2 = Color.Lerp(t.right == null || t.right.opaque ? tint : t.right.glow, t.up == null ? tint : t.up.glow, 0.5f);
                        Color tint3 = Color.Lerp(t.left == null || t.left.opaque ? tint : t.left.glow, t.down == null ? tint : t.down.glow, 0.5f);
                        Color tint4 = Color.Lerp(t.right == null || t.right.opaque ? tint : t.right.glow, t.down == null ? tint : t.down.glow, 0.5f);

                        Texture2D tex = world.tileTextureSet[t.imgIndex];
                        int       w = Tile.size / 2, h = Tile.size / 2;
                        spriteBatch.Draw(tex, new Vector2(t.x + 0, t.y + 0), new Rectangle(0, 0, w, h),
                                         (t.MAKERED) ? Color.Red : Color.Lerp(tint, tint1, 0.5f));
                        spriteBatch.Draw(tex, new Vector2(t.x + w, t.y + 0), new Rectangle(w, 0, w, h),
                                         (t.MAKERED) ? Color.Red : Color.Lerp(tint, tint2, 0.5f));
                        spriteBatch.Draw(tex, new Vector2(t.x + 0, t.y + h), new Rectangle(0, h, w, h),
                                         (t.MAKERED) ? Color.Red : Color.Lerp(tint, tint3, 0.5f));
                        spriteBatch.Draw(tex, new Vector2(t.x + w, t.y + h), new Rectangle(w, h, w, h),
                                         (t.MAKERED) ? Color.Red : Color.Lerp(tint, tint4, 0.5f));
                    }

                    //t.MAKERED = false;
                }
            }
        }
예제 #12
0
파일: Game.cs 프로젝트: Basilid/Spheres
        private static void CreateTestWorld()
        {
            curw = new World();

        }