예제 #1
0
        public static void UpdateSensors()
        {
            // Agents pairwise check
            for (int i = 0; i < AgentManager.GetCount(); ++i)
            {
                Agent a1 = AgentManager.GetAgent(i);
                for (int j = 0; j < AgentManager.GetCount(); ++j)
                {
                    if (i != j)
                    {
                        Agent a2 = AgentManager.GetAgent(j);

                        // If close enough
                        if (Vector2.Distance(a1.CurrentPosition, a2.CurrentPosition) < SENSE_RANGE)
                        {
                            // Propogate the sense
                            if (propogator.PropogateSense(a1.CurrentPosition, a2.CurrentPosition))
                            {
                                // Sense the agent
                                Sense sense = new Sense(a2.Id, a1.Id, SenseType.Sight);
                                a1.HandleSenseEvent(sense);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
파일: TileMap.cs 프로젝트: anokta/CS7056
        public void Draw(SpriteBatch spriteBatch, int screenOffsetX, int screenOffsetY)
        {
            spriteBatch.Begin();

            // tiles
            for (int i = 0; i < mapRows; ++i)
            {
                int y = screenOffsetY + (i - (mapRows - 1) / 2) * tileSize - tileSize / 2;
                for (int j = 0; j < mapCols; ++j)
                {
                    int x = screenOffsetX + (j - (mapCols - 1) / 2) * tileSize - tileSize / 2;

                    // terrain
                    spriteBatch.Draw(terrainSet, new Rectangle(x, y, tileSize, tileSize), GetSourceRectangle(tiles[i][j].TileID, terrainSet.Height), Color.White);

                    // location
                    if (tiles[i][j].LocationID >= 0)
                    {
                        spriteBatch.Draw(locationSet, new Rectangle(x, y, tileSize, tileSize), GetSourceRectangle(tiles[i][j].LocationID, locationSet.Height), Color.White);
                    }

                    // overlay
                    spriteBatch.Draw(overlay, new Rectangle(x, y, tileSize, tileSize), tiles[i][j].TintColor * tiles[i][j].TintAlpha);
                }
            }

            // characters
            for (int i = 0; i < AgentManager.GetCount(); ++i)
            {
                Vector2 position = AgentManager.GetAgent(i).CurrentPosition;
                int     x        = screenOffsetX + ((int)position.X - (mapCols - 1) / 2) * tileSize - tileSize / 2;
                int     y        = screenOffsetY + ((int)position.Y - (mapRows - 1) / 2) * tileSize - tileSize / 2;

                spriteBatch.Draw(characterSet, new Rectangle(x, y, tileSize, tileSize), GetSourceRectangle(i, characterSet.Height), Color.White);
            }

            spriteBatch.End();
        }