// Public // Constructor public WorldLoader(Size worldDimensions, Size realityBubbleSize) { // setup machinery to make it fast to run this.blockSize = new Size(realityBubbleSize.Width / 8, realityBubbleSize.Height / 4); Size characterActiveDimensions = new Size(realityBubbleSize.Width, realityBubbleSize.Height * 1.5); Size terrainActiveDimensions = new Size(characterActiveDimensions.Width + blockSize.Width * 2, characterActiveDimensions.Height + blockSize.Height * 2); this.worldDimensions = worldDimensions; // make the world this.world = new World(terrainActiveDimensions); // Inform the world who it needs to tell whenever something moves this.world.setLoader(this); // Setup to hold the unspawned objects this.terrainSearcher = new WorldSearcher(2, blockSize, worldDimensions); this.characterSearcher = new WorldSearcher(2, blockSize, worldDimensions); // calculate the initial reality bubbles WorldBox terrainRegion = new WorldBox(0, terrainActiveDimensions.Width, 0, terrainActiveDimensions.Height); WorldBox characterRegion = new WorldBox(0, characterActiveDimensions.Width, 0, characterActiveDimensions.Height); this.realityBubble = this.initialRealityBubble = new RealityBubble(characterRegion, terrainRegion); this.objectsToUnspawn = new System.Collections.Generic.HashSet <GameObject>(); this.objectsToDeactivate = new System.Collections.Generic.HashSet <GameObject>(); this.loadedObjects = new System.Collections.Generic.HashSet <GameObject>(); this.populate(); }
/*void moveItem(GameObject item, double[] move) * { * }*/ // Finds all objects in the rectangle public System.Collections.Generic.List <GameObject> getObjectsInWorldBox(WorldBox worldBox) { System.Collections.Generic.List <GameObject> resultantList = new System.Collections.Generic.List <GameObject>(); IndexBox indexBox = this.getIndexBoxFromWorldBox(worldBox); return(this.getObjectsInIndexBox(indexBox)); }
// newItem a hyper-box that bounds the item in all dimension private IndexBox getIndexRange(GameObject item) { WorldBox boundingBox = item.getBoundingBox(); IndexBox indexBox = this.getIndexBoxFromWorldBox(boundingBox); return(indexBox); }
public WorldBox(WorldBox original) { this.lowCoordinates = new double[original.lowCoordinates.Length]; this.highCoordinates = new double[original.highCoordinates.Length]; original.lowCoordinates.CopyTo(this.lowCoordinates, 0); original.highCoordinates.CopyTo(this.highCoordinates, 0); }
// newItem a hyper-box that bounds the item in all dimension at all points during the given move private IndexBox getIndexRange(GameObject item, double[] move) { WorldBox boundingBox = item.getBoundingBoxForMove(move); IndexBox indexBox = this.getIndexBoxFromWorldBox(boundingBox); return(indexBox); }
// get the bounding box of all the positions the box would public WorldBox getBoundingBoxForMove(double[] move) { double x1, x2, y1, y2; if (move[0] >= 0) { x1 = this.center[0] - this.getShape().getWidth() / 2; x2 = this.center[0] + this.getShape().getWidth() / 2 + move[0]; } else { x1 = this.center[0] - this.getShape().getWidth() / 2 + move[0]; x2 = this.center[0] + this.getShape().getWidth() / 2; } if (move[1] >= 0) { y1 = this.center[1] - this.getShape().getHeight() / 2; y2 = this.center[1] + this.getShape().getHeight() / 2 + move[1]; } else { y1 = this.center[1] - this.getShape().getHeight() / 2 + move[1]; y2 = this.center[1] + this.getShape().getHeight() / 2; } WorldBox box = new WorldBox(x1, x2, y1, y2); return(box); }
// get the bounding box for this object where it currently is public WorldBox getBoundingBox() { WorldBox box = new WorldBox(this.center[0] - this.getShape().getWidth() / 2, this.center[0] + this.getShape().getWidth() / 2, this.center[1] - this.getShape().getHeight() / 2, this.center[1] + this.getShape().getHeight() / 2); return(box); }
public bool Equals(AGSBoundingBoxes boxes) { if (this == boxes) { return(true); } if (boxes == null) { return(false); } if (TextureBox == null && boxes.TextureBox != null) { return(false); } if (TextureBox != null && boxes.TextureBox == null) { return(false); } if (TextureBox != null && !TextureBox.Equals(boxes.TextureBox)) { return(false); } return(ViewportBox.Equals(boxes.ViewportBox) && WorldBox.Equals(boxes.WorldBox) && PreCropViewportBox.Equals(boxes.PreCropViewportBox)); }
// get the bounding box for where this object would be if it were to make the given move public WorldBox getBoundingBoxShifted(double[] move) { WorldBox currentBox = this.getBoundingBox(); WorldBox shiftedBox = new WorldBox(currentBox.getLowCoordinate(0) + move[0], currentBox.getHighCoordinate(0) + move[0], currentBox.getLowCoordinate(1) + move[1], currentBox.getHighCoordinate(1) + move[1]); return(shiftedBox); }
void Start() { controls = GameObject.Find("TravelingBallSliders").GetComponent <TravelingBallControl>(); world = GameObject.Find("WorldBox").GetComponent <WorldBox>(); GetComponent <Renderer>().material = Resources.Load("Black") as Material; speed = controls.getSpeed(); aliveTime = controls.getAliveTime(); dir = world.aim; end = world.end.transform.localPosition; }
void setUpWorldBox() { WorldBox = new WorldBox(); WorldBox.Initialize(); VSplit.RightPanel.AddDrawBox(WorldBox); VSplit.UpdateSize(); WorldBox.Fill(); }
public Camera(WorldBox worldRect, WorldBox screenRect) { this.worldBox = worldRect; this.screenBox = screenRect; this.Transform = new MatrixTransform(); // The padding is a measure of the minimum amount of world we always show on each side of the user this.padding = new double[2]; padding[0] = worldRect.getSize(0) / 6; padding[1] = worldRect.getSize(1) / 12; }
public System.Collections.Generic.List <GameObject> getObjectsOnlyInA(WorldBox boxA, WorldBox boxB) { System.Collections.Generic.List <GameObject> results = new System.Collections.Generic.List <GameObject>(); System.Collections.Generic.HashSet <GameObject> localItems; IndexBox box1 = this.getIndexBoxFromWorldBox(boxA); IndexBox box2 = this.getIndexBoxFromWorldBox(boxB); int[] coordinates = new int[2]; int[] indices = new int[2]; //int i; IndexBox itemIndexBox; //GameObject currentItem; // Check each box inside the larger indexbox for (coordinates[0] = box1.getLowCoordinate(0); coordinates[0] <= box1.getHighCoordinate(0); coordinates[0]++) { // wraparound indices[0] = coordinates[0] % this.numBlocks[0]; if (indices[0] < 0) { indices[0] += this.numBlocks[0]; } for (coordinates[1] = box1.getLowCoordinate(1); coordinates[1] <= box1.getHighCoordinate(1); coordinates[1]++) { // wraparound indices[1] = coordinates[1] % this.numBlocks[1]; if (indices[1] < 0) { indices[1] += this.numBlocks[1]; } // Make sure that the current point isn't inside the smaller index box if (!(box2.contains(coordinates))) { // Iterate over each item inside the box localItems = this.worldBlocks[indices[0], indices[1]]; foreach (GameObject currentItem in localItems) { //currentItem = localItems[i]; itemIndexBox = this.getIndexBoxFromWorldBox(currentItem.getBoundingBox()); // Make sure that the item does intersect the larger box but not the smaller index box if (itemIndexBox.intersects(box1) && !(itemIndexBox.intersects(box2))) { // Now add it to the resultant list if needed if (!results.Contains(currentItem)) { results.Add(currentItem); } } } } } } return(results); }
// Snap the coordinates to multiples of the box size public IndexBox getIndexBoxFromWorldBox(WorldBox worldBox) { int x1 = (int)(worldBox.getLowCoordinate(0) / this.blockSize.Width); int x2 = (int)(worldBox.getHighCoordinate(0) / this.blockSize.Width); int y1 = (int)(worldBox.getLowCoordinate(1) / this.blockSize.Height); int y2 = (int)(worldBox.getHighCoordinate(1) / this.blockSize.Height); //Rectangle indexRect(x1, y1, x2 - x1, y2 - y1); IndexBox indexBox = new IndexBox(x1, x2, y1, y2); return(indexBox); }
public void centerOn(WorldBox other) { int i; double activeCenter, existenceCenter, desiredCenter; for (i = 0; i < 2; i++) { desiredCenter = (other.getHighCoordinate(i) + other.getLowCoordinate(i)) / 2; activeCenter = (activeRegion.getHighCoordinate(i) + activeRegion.getLowCoordinate(i)) / 2; activeRegion.shift(i, desiredCenter - activeCenter); existenceCenter = (existentRegion.getHighCoordinate(i) + existentRegion.getLowCoordinate(i)) / 2; existentRegion.shift(i, desiredCenter - existenceCenter); } }
// Moves the reality bubble to be centered on the given box public void RecenterRealityBubble(WorldBox boxToCenterOn) { // First remove anything from the previous tick that fell off the edge of the world foreach (GameObject o2 in this.objectsToUnspawn) { this.world.unloadItem(o2); } this.objectsToUnspawn.Clear(); // Determine the location of the new reality bubble RealityBubble newRealityBubble = new RealityBubble(this.initialRealityBubble); newRealityBubble.centerOn(boxToCenterOn); WorldBox newExistenceRegion = newRealityBubble.getExistentRegion(); WorldBox oldExistenceRegion = this.realityBubble.getExistentRegion(); WorldBox newActiveRegion = newRealityBubble.getActiveRegion(); WorldBox oldActiveRegion = this.realityBubble.getActiveRegion(); // Find everything that is no longer active System.Collections.Generic.List <GameObject> previouslyActive = this.characterSearcher.getObjectsOnlyInA(oldActiveRegion, newActiveRegion); foreach (GameObject o2 in previouslyActive) { this.world.removeItem(o2); } // Find everything that is no longer present System.Collections.Generic.List <GameObject> oldItems = this.terrainSearcher.getObjectsOnlyInA(oldExistenceRegion, newExistenceRegion); foreach (GameObject o2 in oldItems) { this.world.removeItem(o2); } // Find everything that just became present System.Collections.Generic.List <GameObject> newItems = this.terrainSearcher.getObjectsOnlyInA(newExistenceRegion, oldExistenceRegion); foreach (GameObject o2 in newItems) { this.world.addItem(o2); } // Find everything that just became active System.Collections.Generic.List <GameObject> newlyActive = this.characterSearcher.getObjectsOnlyInA(newActiveRegion, oldActiveRegion); foreach (GameObject o2 in newlyActive) { this.world.addItem(o2); } this.realityBubble = newRealityBubble; }
// get the current screenshot and save it in the world somewhere public void saveScreenshotInWorld() { // find everything that is slightly to the right of the screen RealityBubble newBubble = this.realityBubble; WorldBox realBox = new WorldBox(newBubble.getActiveRegion()); realBox.shift(0, 3000); GameObject collisionBox = new GameObject(); collisionBox.setShape(new GameRectangle(realBox.getSize(0), realBox.getSize(1))); collisionBox.setCenter(realBox.getCenter()); List <GameObject> collisions = this.terrainSearcher.getCollisions(collisionBox); // find a painting Painting bestPainting = null; foreach (GameObject collision in collisions) { if (collision.isAPainting()) { Painting tempPainting = (Painting)collision; if ((tempPainting.getShape().getWidth() <= 400) && (tempPainting.getShape().getWidth() > 200)) { bestPainting = tempPainting; break; } } } if (bestPainting != null) { // TODO fix this // get the current screenshot // ImageSource source = this.getScreenshot(); // put the screenshot in the painting // bestPainting.setBitmap(source); } }
/// <summary> /// Load all initial game logic. /// </summary> private void InitializeGame() { this.gameState = GameState.Start; player = TurretManager.spawnTurret(TurretType.Basic, Vector3.Empty, Vector3.Empty, new Vector3(1f, 1f, 1f), keyboard); this.camera = new ThirdPersonCamera(player, new Vector3(0f, 10f, -15f)); player.Head.addChild(camera); List<Wave> waves = new List<Wave>(); for (int i = 1; i <= 10; i++) { Wave wave = new Wave(); wave.waveNumber = i; wave.enemiesPerSpawn = i; wave.planeSpeed = 5f + i * 2; wave.planeTurnSpeed = (float)(Math.PI / 8); wave.tankSpeed = 5f + i; wave.tankTurnSpeed = (float)(Math.PI / 8); wave.planesToSpawn = (int)(i / 2); wave.tanksToSpawn = (int)(i / 2) + (i % 2); wave.spawnDelay = 1f + i; wave.minimumSpawnDistance = 150f; wave.maximumSpawnDistance = 200f; waves.Add(wave); } managers = new List<Manager>(); BulletManager bulletManager = new BulletManager(); managers.Add(bulletManager); TurretManager turretManager = new TurretManager(); managers.Add(turretManager); EnemyManager enemyManager = new EnemyManager(waves, 0); managers.Add(enemyManager); ParticleEmitterManager particleEmitterManager = new ParticleEmitterManager(camera); managers.Add(particleEmitterManager); world = new WorldBox( ContentLoader.WorldBoxTop, ContentLoader.WorldBoxBottom, ContentLoader.WorldBoxLeft, ContentLoader.WorldBoxRight, ContentLoader.WorldBoxFront, ContentLoader.WorldBoxBack); // TODO: make the gui redraw based on the window size gui = new GUI(player, new Rectangle(this.Width - (int)(this.Width * 0.0625), (int)(this.Height * 0.0052), (int)(this.Width * 0.0521), (int)(this.Height * 0.0104)), new Point(this.Width - (int)(this.Width * 0.183), 0), device, this.Width, this.Height); }
//public: // creates a reality bubble public RealityBubble(WorldBox activeRegion, WorldBox existentRegion) { this.activeRegion = activeRegion; this.existentRegion = existentRegion; }