コード例 #1
0
        public void AddRoomAfter(BaseSprite sprite, Queue <int> index, Vector2 midpoint, TimeSpan untilWalk)
        {
            RoomNode tempNode = head;

            while (index.Count > 1)
            {
                tempNode = tempNode.adjRooms[index.Peek()];
                index.Dequeue();
            }

            int indexSuppliment = index.Peek() > 5 ? index.Peek() - 6 : index.Peek() + 6;

            RoomNode[] tempRoomArray = new RoomNode[12];
            tempRoomArray[indexSuppliment] = tempNode;
            Vector2[] tempRoomMidpointArray = new Vector2[12];
            tempRoomMidpointArray[indexSuppliment] = midpoint == Vector2.Zero ? (sprite.position + tempNode.sprite.position) / 2f : midpoint;

            RoomNode newNode = new RoomNode(sprite, untilWalk, tempRoomArray, tempRoomMidpointArray);

            newNode.howManyAdj++;
            tempNode.adjRooms[index.Peek()]          = newNode;
            tempNode.adjRoomsMidpoints[index.Peek()] = midpoint == Vector2.Zero ? (sprite.position + tempNode.sprite.position) / 2f : midpoint;
            tempNode.howManyAdj++;

            count++;
        }
コード例 #2
0
 public Base(BaseSprite sprite, TimeSpan untilWalk)
 {
     RoomNode[] tempRoomArray         = new RoomNode[12];
     Vector2[]  tempRoomMidpointArray = new Vector2[12];
     head  = new RoomNode(sprite, untilWalk, tempRoomArray, tempRoomMidpointArray);
     count = 1;
 }
コード例 #3
0
ファイル: Lunarian.cs プロジェクト: bfrederick18/LunarSim
        public Lunarian(Texture2D texture, Base aBase, RoomNode startingRoom, bool inInner)
            : base(texture, startingRoom.sprite.position, new Rectangle(0, 0, texture.Width, texture.Height), Color.White, 0.0f, new Vector2(texture.Width / 2, texture.Height / 2), new Vector2(0.5f, 0.5f), SpriteEffects.None, 0, 1.0f, Vector2.Zero)
        {
            rand = new Random();

            rotation    = (float)(rand.NextDouble() * 2 * Math.PI);
            state       = LunarianState.Idle;
            lastWalk    = DateTime.Now;
            lastWander  = DateTime.Now;
            untilWander = new TimeSpan(0, 0, 0, 1);
            this.aBase  = aBase;
            currRoom    = startingRoom;

            this.inInner   = inInner;
            velocityCount  = 0;
            VELOCITY_MULTI = 0.02f;
            p     = Vector2.Zero;
            oldP  = Vector2.Zero;
            covid = false;
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: bfrederick18/LunarSim
        protected override void LoadContent()
        {
            Random rand = new Random();

            spriteBatch  = new SpriteBatch(GraphicsDevice);
            pixel        = Content.Load <Texture2D>("Textures/white3By3");
            roundRoom    = Content.Load <Texture2D>("Textures/circularBase_v2_0");
            squareRoom   = Content.Load <Texture2D>("Textures/square_v2_0");
            blank        = Content.Load <Texture2D>("Textures/blank_v1_0");
            oblong       = Content.Load <Texture2D>("Textures/oblong_v2_0");
            centerScreen = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
            centerBase   = centerScreen + new Vector2(-70, -100);

            middlePx = new BaseSprite(pixel, centerScreen, Color.White, Vector2.One);

            Queue <int> q = new Queue <int>();

            //main circle: aBase
            aBase = new Base(new BaseSprite(roundRoom, centerBase, Color.White, new Vector2(1.0f, 1.0f)), new TimeSpan(0, 0, 3));

            //long rectangle: aBase-3
            q.Clear();
            q.Enqueue(3); //Med-Bay
            aBase.AddRoomAfter(new BaseSprite(squareRoom, centerBase + new Vector2(220, 45), Color.White, new Vector2(0.4f, 0.6f)), q, centerBase + new Vector2(180, 0), new TimeSpan(0, 0, 3));

            //small circle: aBase-3-9
            q.Clear();
            q.Enqueue(3);
            q.Enqueue(6);
            aBase.AddRoomAfter(new BaseSprite(roundRoom, centerBase + new Vector2(220, 135), Color.White, new Vector2(0.19f, 0.19f)), q, Vector2.Zero, new TimeSpan(0, 0, 2));

            int howFarFromMain = 225;

            for (int i = 0; i < 5; i++) //The 5 Living Quarters
            {
                q.Clear();
                q.Enqueue((i + 10) % 12);
                double tAngle       = i == 0 ? Math.PI / 5 : i == 1 ? Math.PI / 5 * 2 : i == 2 ? Math.PI / 5 * 3 : i == 3 ? Math.PI / 5 * 4 : Math.PI / 1;
                double tHowFarMulti = 0.685f;
                aBase.AddRoomAfter(new BaseSprite(roundRoom, centerBase + new Vector2((float)(Math.Cos(tAngle) * howFarFromMain * tHowFarMulti), (float)(-Math.Sin(tAngle) * howFarFromMain * tHowFarMulti)), Color.White, new Vector2(0.35f, 0.35f)), q, Vector2.Zero, new TimeSpan(0, 0, 3));
            }

            //small circle: aBase-4
            q.Clear();
            q.Enqueue(4); //Main WC
            aBase.AddRoomAfter(new BaseSprite(squareRoom, centerBase + new Vector2((float)(Math.Cos(-Math.PI / 6) * howFarFromMain * 0.71f) + -10, (float)(-Math.Sin(-Math.PI / 6) * howFarFromMain * 0.71f) + 80), Color.White, new Vector2(0.29f, 0.59f)), q, new Vector2(782, 440), new TimeSpan(0, 0, 3));

            //main corridor: aBase-6
            //q.Clear();
            //q.Enqueue(6);
            //aBase.AddRoomAfter(new BaseSprite(pixel, centerBase + new Vector2(0, 200), Color.White, new Vector2(1f, 1f)), q, Vector2.Zero, new TimeSpan(0, 0, 0));

            //biq square: aBase-6-9
            q.Clear();
            q.Enqueue(7);
            aBase.AddRoomAfter(new BaseSprite(squareRoom, centerBase + new Vector2(-100, 200), Color.White, new Vector2(0.55f, 0.55f)), q, centerBase + new Vector2(0, 200), new TimeSpan(0, 0, 4));

            //small square: aBase-6-3
            q.Clear();
            q.Enqueue(5);
            aBase.AddRoomAfter(new BaseSprite(squareRoom, centerBase + new Vector2(62, 200), Color.White, new Vector2(0.25f, 0.25f)), q, centerBase + new Vector2(0, 200), new TimeSpan(0, 0, 4));

            //long rectangle at bottom: aBase-6-6
            q.Clear();
            q.Enqueue(6);
            aBase.AddRoomAfter(new BaseSprite(squareRoom, centerBase + new Vector2(0, 330), Color.White, new Vector2(0.8f, 0.42f)), q, centerBase + new Vector2(0, 200), new TimeSpan(0, 0, 4));

            RoomNode temp = aBase.head.adjRooms[6];

            aBase.head.adjRooms[5].adjRooms[6]          = temp;
            aBase.head.adjRooms[6].adjRooms[5]          = aBase.head.adjRooms[5];
            aBase.head.adjRooms[5].adjRoomsMidpoints[6] = aBase.head.adjRoomsMidpoints[6];
            aBase.head.adjRooms[6].adjRoomsMidpoints[5] = aBase.head.adjRoomsMidpoints[5];
            aBase.head.adjRooms[5].howManyAdj++;
            aBase.head.adjRooms[6].howManyAdj++;

            temp = aBase.head.adjRooms[7];
            aBase.head.adjRooms[5].adjRooms[7]          = temp;
            aBase.head.adjRooms[7].adjRooms[5]          = aBase.head.adjRooms[5];
            aBase.head.adjRooms[5].adjRoomsMidpoints[7] = aBase.head.adjRoomsMidpoints[7];
            aBase.head.adjRooms[7].adjRoomsMidpoints[5] = aBase.head.adjRoomsMidpoints[5];
            aBase.head.adjRooms[5].howManyAdj++;
            aBase.head.adjRooms[7].howManyAdj++;

            temp = aBase.head.adjRooms[7];
            aBase.head.adjRooms[6].adjRooms[7]          = temp;
            aBase.head.adjRooms[7].adjRooms[6]          = aBase.head.adjRooms[6];
            aBase.head.adjRooms[6].adjRoomsMidpoints[7] = aBase.head.adjRoomsMidpoints[7];
            aBase.head.adjRooms[7].adjRoomsMidpoints[6] = aBase.head.adjRoomsMidpoints[6];
            aBase.head.adjRooms[6].howManyAdj++;
            aBase.head.adjRooms[7].howManyAdj++;

            temp = aBase.head.adjRooms[4];
            aBase.head.adjRooms[5].adjRooms[4]          = temp;
            aBase.head.adjRooms[4].adjRooms[5]          = aBase.head.adjRooms[5];
            aBase.head.adjRooms[5].adjRoomsMidpoints[4] = centerBase + new Vector2(92, 200);
            aBase.head.adjRooms[4].adjRoomsMidpoints[5] = centerBase + new Vector2(92, 200);
            aBase.head.adjRooms[5].howManyAdj++;
            aBase.head.adjRooms[4].howManyAdj++;

            //tiny circle: aBase-6-9-9
            //q.Clear();
            //q.Enqueue(7);
            //q.Enqueue(9);
            //aBase.AddRoomAfter(new BaseSprite(roundRoom, centerBase + new Vector2(-220, 200), Color.White, new Vector2(0.15f, 0.15f)), q, Vector2.Zero, new TimeSpan(0, 0, 3));

            //small square at bottom: aBase-6-6-9
            q.Clear();
            q.Enqueue(6);
            q.Enqueue(9);
            aBase.AddRoomAfter(new BaseSprite(squareRoom, centerBase + new Vector2(-123, 330), Color.White, new Vector2(0.25f, 0.25f)), q, Vector2.Zero, new TimeSpan(0, 0, 3));

            corridors = new BaseSprite[]
            {
                new BaseSprite(squareRoom, new Vector2(821, 345), (float)Math.PI / 2, new Vector2(0.191f, 0.5f)),
                new BaseSprite(squareRoom, centerBase + new Vector2(0, 200), 0f, new Vector2(0.191f, 0.9f)),
                new BaseSprite(squareRoom, centerBase + new Vector2(0, 200), 0f, new Vector2(0.5f, 0.191f)),
                new BaseSprite(squareRoom, centerBase + new Vector2(92, 200), 0f, new Vector2(0.2f, 0.191f)),
                new BaseSprite(roundRoom, new Vector2(777, 437), 0f, new Vector2(0.17f, 0.17f))
            };
            doors = new BaseSprite[]
            {
                new BaseSprite(blank, new Vector2(821, 345), (float)Math.PI / 2, new Vector2(0.17f, 0.5f)),
                new BaseSprite(blank, centerBase + new Vector2(0, 200), 0f, new Vector2(0.18f, 0.9f)),
                new BaseSprite(blank, centerBase + new Vector2(0, 200), 0f, new Vector2(0.5f, 0.18f)),
                new BaseSprite(blank, centerBase + new Vector2(92, 200), 0f, new Vector2(0.2f, 0.18f)),
                new BaseSprite(blank, new Vector2(777, 437), (float)Math.PI / 4, new Vector2(0.3f, 0.12f)),
                new BaseSprite(blank, new Vector2(600, 675), 0f, new Vector2(0.5f, 0.17f)),
                new BaseSprite(blank, centerBase + new Vector2(220, 90), 0f, new Vector2(0.09f, 0.5f)),

                new BaseSprite(blank, centerBase + new Vector2((float)(Math.Cos(Math.PI / 5) * howFarFromMain * 0.5f), (float)(-Math.Sin(Math.PI / 5) * howFarFromMain * 0.5f)), (float)Math.PI / 5, new Vector2(0.11f, 0.11f)),
                new BaseSprite(blank, centerBase + new Vector2((float)(Math.Cos(Math.PI / 5 * 2) * howFarFromMain * 0.5f), (float)(-Math.Sin(Math.PI / 5 * 2) * howFarFromMain * 0.5f)), (float)Math.PI / 5 * 2, new Vector2(0.11f, 0.11f)),
                new BaseSprite(blank, centerBase + new Vector2((float)(Math.Cos(Math.PI / 5 * 3) * howFarFromMain * 0.5f), (float)(-Math.Sin(Math.PI / 5 * 3) * howFarFromMain * 0.5f)), (float)Math.PI / 5 * 3, new Vector2(0.11f, 0.11f)),
                new BaseSprite(blank, centerBase + new Vector2((float)(Math.Cos(Math.PI / 5 * 4) * howFarFromMain * 0.5f), (float)(-Math.Sin(Math.PI / 5 * 4) * howFarFromMain * 0.5f)), (float)Math.PI / 5 * 4, new Vector2(0.11f, 0.11f)),
                new BaseSprite(blank, centerBase + new Vector2((float)(Math.Cos(Math.PI) * howFarFromMain * 0.5f), (float)(-Math.Sin(Math.PI) * howFarFromMain * 0.5f)), (float)Math.PI, new Vector2(0.11f, 0.11f))
            };

            lunarians = new Lunarian[10];
            bool tempInInner = false;

            RoomNode[] allRooms = new RoomNode[]
            {
                aBase.head,
                aBase.head.adjRooms[0],
                aBase.head.adjRooms[1],
                aBase.head.adjRooms[2],
                aBase.head.adjRooms[3],
                aBase.head.adjRooms[3].adjRooms[6],
                aBase.head.adjRooms[4],
                aBase.head.adjRooms[5],
                aBase.head.adjRooms[6],
                aBase.head.adjRooms[6].adjRooms[9],
                aBase.head.adjRooms[7],
                aBase.head.adjRooms[10],
                aBase.head.adjRooms[11],
            };
            for (int i = 0; i < lunarians.Length; i++)
            {
                lunarians[i] = new Lunarian(Content.Load <Texture2D>("Textures/topDownPerson_v2_0"), aBase, allRooms[(int)(rand.NextDouble() * allRooms.Length)], tempInInner);
                tempInInner  = !tempInInner;
                System.Threading.Thread.Sleep(100);
            }
        }
コード例 #5
0
ファイル: Lunarian.cs プロジェクト: bfrederick18/LunarSim
        public override void Update(GameTime gameTime, Viewport screen)
        {
            if (covid)
            {
                tint = Color.Yellow;
            }

            if (state == LunarianState.Idle)
            {
                if (DateTime.Now - lastWander >= untilWander)
                {
                    oldP = p;
                    double tRadian = (rand.NextDouble() * 2 * Math.PI);
                    //rotation = (float)(tRadian - (Math.PI / 2));

                    float pX = 0.0f, pY = 0.0f;
                    if (inInner)
                    {
                        pX = (float)(Math.Cos(tRadian) * (currRoom.innerRadius + (currRoom.outerRadius.X - currRoom.innerRadius) * rand.NextDouble())); //(rotRange.X + (rotRange.Y - rotRange.X)
                        pY = (float)(Math.Sin(tRadian) * (currRoom.innerRadius + (currRoom.outerRadius.Y - currRoom.innerRadius) * rand.NextDouble()));
                    }
                    else if (!inInner)
                    {
                        pX = (float)(Math.Cos(tRadian) * (currRoom.innerRadius) * rand.NextDouble()); //(rotRange.X + (rotRange.Y - rotRange.X)
                        pY = (float)(Math.Sin(tRadian) * (currRoom.innerRadius) * rand.NextDouble());
                    }

                    p = new Vector2(pX, pY);
                    Vector2 r = -oldP + p;

                    rotation = (float)(Math.Atan2(r.Y, r.X) - (Math.PI / 2));

                    destination = currRoom.sprite.position - p;

                    velocity  = new Vector2((position.X - destination.X), (position.Y - destination.Y));// rotation > Math.PI ? new Vector2(-(position.X - destination.Y), -(position.Y - destination.Y)) : new Vector2((position.X - destination.Y), -(position.Y - destination.Y));
                    velocity *= -VELOCITY_MULTI;

                    state = LunarianState.Wandering;
                }
                if (DateTime.Now - lastWalk >= currRoom.untilWalk)
                {
                    //state = LunarianState.Walking;
                }
            }
            if (state == LunarianState.Wandering)
            {
                velocityCount++;
                if (velocityCount > 1 / VELOCITY_MULTI)
                {
                    Vector2 debugVelocity = velocity;
                    velocity      = Vector2.Zero;
                    position      = destination;
                    lastWander    = DateTime.Now;
                    untilWander   = new TimeSpan(0, 0, 0, (int)(rand.NextDouble() * 2), (int)(rand.NextDouble() * 1000));
                    inInner       = !inInner;
                    state         = LunarianState.Idle;
                    velocityCount = 0;
                }
            }

            if (state == LunarianState.Idle && inInner)
            {
                if (DateTime.Now - lastWalk >= currRoom.untilWalk)
                {
                    int[] tempMidpoint = new int[currRoom.howManyAdj];
                    int   howManySoFar = 0;

                    for (int i = 0; i < currRoom.adjRoomsMidpoints.Length; i++)
                    {
                        if (currRoom.adjRoomsMidpoints[i] != Vector2.Zero)
                        {
                            tempMidpoint[howManySoFar] = i;
                            howManySoFar++;
                        }
                    }

                    int whichRoom = (int)(rand.NextDouble() * (tempMidpoint.Length));

                    destination = currRoom.adjRoomsMidpoints[tempMidpoint[whichRoom]];

                    Vector2 r = -destination + position;

                    rotation = (float)(Math.Atan2(r.Y, r.X) - (Math.PI / 2));

                    velocity  = new Vector2((position.X - destination.X), (position.Y - destination.Y));
                    velocity *= -VELOCITY_MULTI;

                    currRoom = currRoom.adjRooms[tempMidpoint[whichRoom]];
                    if (currRoom == null)
                    {
                        tint = Color.GreenYellow;
                    }
                    state = LunarianState.WalkingOne;
                }
            }
            if (state == LunarianState.WalkingOne)
            {
                velocityCount++;
                if (velocityCount > 1 / VELOCITY_MULTI)
                {
                    oldP = p;
                    double tRadian = (rand.NextDouble() * 2 * Math.PI);
                    //rotation = (float)(tRadian - (Math.PI / 2));

                    float pX = (float)(Math.Cos(tRadian) * (currRoom.innerRadius) * rand.NextDouble());
                    float pY = (float)(Math.Sin(tRadian) * (currRoom.innerRadius) * rand.NextDouble());

                    p           = new Vector2(pX, pY);
                    destination = currRoom.sprite.position - p;

                    Vector2 r = -destination + position;

                    rotation = (float)(Math.Atan2(r.Y, r.X) - (Math.PI / 2));

                    velocity  = new Vector2((position.X - destination.X), (position.Y - destination.Y));// rotation > Math.PI ? new Vector2(-(position.X - destination.Y), -(position.Y - destination.Y)) : new Vector2((position.X - destination.Y), -(position.Y - destination.Y));
                    velocity *= -VELOCITY_MULTI;

                    state         = LunarianState.WalkingTwo;
                    velocityCount = 0;
                }
            }
            if (state == LunarianState.WalkingTwo)
            {
                velocityCount++;
                if (velocityCount > 1 / VELOCITY_MULTI)
                {
                    Vector2 debugVelocity = velocity;
                    velocity      = Vector2.Zero;
                    position      = destination;
                    lastWalk      = DateTime.Now;
                    lastWander    = DateTime.Now;
                    state         = LunarianState.Idle;
                    velocityCount = 0;
                }
            }

            base.Update(gameTime, screen);
        }