public void draw(Main main, Texture2D smokeImage, int offsetX, int offsetY) { for (int i = 0; i < smoke.Length; i++) { main.spriteBatch.Draw(smokeImage, new Rectangle((int)(smoke[i].x * main.scale) - (int)(offsetX * main.scale), (int)(smoke[i].y * main.scale) - (int)(offsetY * main.scale), (int)(smoke[i].currentSize * main.scale), (int)(smoke[i].currentSize * main.scale)), new Rectangle(0, 0, smokeImage.Width, smokeImage.Height), new Color(Color.White.R, Color.White.G, Color.White.B, smoke[i].currentAlpha), smoke[i].angle, new Vector2(smokeImage.Width * main.scale / 2, smokeImage.Height * main.scale / 2), SpriteEffects.None, 0.3f); } }
public static void drawStuff(Main main) { main.spriteBatch.Draw(main.background, new Rectangle(-main.offsetX / 2, -main.offsetY / 2, main.background.Width * 2, main.background.Height * 2), new Rectangle(0, 0, main.background.Width, main.background.Height), Color.White, 0, new Vector2(0, 0), SpriteEffects.None, 1); foreach (Planet planet in main.planets) { main.spriteBatch.Draw(planet.circle, new Rectangle((int)(planet.x * main.scale) - (int)(main.offsetX * main.scale), (int)(planet.y * main.scale) - (int)(main.offsetY * main.scale), (int)(planet.width * main.scale), (int)(planet.height * main.scale)), new Rectangle(0, 0, planet.width, planet.height), Color.White, 0, new Vector2(0, 0), SpriteEffects.None, 0.4f); } foreach (Ship ship in main.ships) { if (ship != null) { if (ship.moving) { ship.smoke.draw(main, main.smokeImage, main.offsetX, main.offsetY); } main.spriteBatch.Draw(main.shipImage, new Rectangle((int)(ship.x * main.scale) - (int)(main.offsetX * main.scale), (int)(ship.y * main.scale) - (int)(main.offsetY * main.scale), (int)(20 * main.scale), (int)(20 * main.scale)), new Rectangle(0, 0, main.shipImage.Width, main.shipImage.Height), Color.White, ship.angle, new Vector2(10, 10), SpriteEffects.None, 0.2f); } } if (main.infoOnPlanet > -1 && main.leftMouseDown) { main.spriteBatch.Draw(main.popup1, new Rectangle(Mouse.GetState().X + 15, Mouse.GetState().Y + 30, main.popup1.Width, main.popup1.Height), new Rectangle(0, 0, main.popup1.Width, main.popup1.Height), Color.White, 0, new Vector2(0, 0), SpriteEffects.None, 0.1f); } main.spriteBatch.Draw(main.currentCursor, new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, main.cursor1.Width, main.cursor1.Height), new Rectangle(0, 0, main.cursor1.Width, main.cursor1.Height), Color.White, 0, new Vector2(0, 0), SpriteEffects.None, 0); }
public static void updateStuff(Main main) { foreach (Ship ship in main.ships) { if (ship != null && rectanglesCollide(ship.x, ship.y, 20, 20, ship.targetX, ship.targetY, ship.targetWidth, ship.targetHeight)) { int planet = main.noise.random.Next(0, main.totalPlanets); ship.targetX = main.planets[planet].x; ship.targetY = main.planets[planet].y; ship.targetWidth = main.planets[planet].width; ship.targetHeight = main.planets[planet].height; ship.currentSpeed = 0; } else if(ship != null) { ship.angle = turnTo(ship.x + 10, ship.y + 10, ship.targetX + ship.targetWidth / 2, ship.targetY + ship.targetHeight / 2, ship.angle, 0.1f); ship.moveInCurrentDirection(); ship.currentSpeed += ship.currentSpeed <= ship.maxSpeed ? 0.1f : 0; } ship.smoke.updateSmokeParticles(main.noise, ship.x - 3, ship.y); } // while (true) // { // for (int i = 0; i < totalShips; i++) // { // if (ships[i] != null) // { // Ship ship = ships[i]; // for (int j = 0; j < totalShips; j++) // { // if (i != j && ships[j] != null) // { // Ship ship2 = ships[j]; // if (rectanglesCollide(ship.x, ship.y, 20, 20, ship2.x, ship2.y, 20, 20)) // { // ships[i] = null; // ships[j] = null; // } // } // } // } // } // } main.infoOnPlanet = -1; for (int i = 0; i < main.totalPlanets; i++) { if (PhysicsProcessor.rectanglesCollide(Mouse.GetState().X + main.offsetX, Mouse.GetState().Y + main.offsetY, 10, 10, main.planets[i].x, main.planets[i].y, main.planets[i].width, main.planets[i].height)) { main.infoOnPlanet = i; break; } } }
public static void updateMusic(Main main) { if (MediaPlayer.State == MediaState.Stopped) { if (main.music1 != null) { MediaPlayer.Play(main.music1); } } }
public static void centerOnTarget(Main main, int x, int y, bool imediatly) { main.targetOffsetX = x - (int)((main.screenWidth / 2)/main.scale); main.targetOffsetY = y - (int)((main.screenHeight / 2)/main.scale); if (imediatly) { main.offsetX = main.targetOffsetX; main.offsetY = main.targetOffsetY; } }
public static void generateBackground(Main main) { main.background = new Texture2D(main.device, main.quadrantWidth * 2, main.quadrantHeight * 2); Color[] noisyColors = new Color[main.background.Width * main.background.Height]; int stars = main.noise.random.Next(100, 201); for (int i = 0; i < stars; i++) { float rgb = (float)(main.noise.random.NextDouble()); //int size = noise.random.Next(3, 7); noisyColors[main.noise.random.Next(0, main.background.Width) + main.noise.random.Next(0, main.background.Height) * main.background.Width] = new Color(new Vector3(rgb, rgb, rgb)); } main.background.SetData(noisyColors); }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new StartupForm()); if (start) { using (Main game = new Main(resX, resY, planets, ships, fullScreen)) { game.Run(); } } }
public static void processAutoScroll(Main main) { if (main.targetOffsetX > main.offsetX + main.scrollSpeed) main.offsetX += main.scrollSpeed; else if (main.targetOffsetX < main.offsetX - main.scrollSpeed) main.offsetX -= main.scrollSpeed; if (main.targetOffsetY > main.offsetY + main.scrollSpeed) main.offsetY += main.scrollSpeed; else if (main.targetOffsetY < main.offsetY - main.scrollSpeed) main.offsetY -= main.scrollSpeed; if (main.targetScale > main.scale + 0.01f) { main.scale += 0.01f; //centerOnTarget(main, main.offsetX + main.offsetX / 2, main.offsetY + main.offsetY / 2, true); } else if (main.targetScale < main.scale - 0.01f) { main.scale -= 0.01f; //centerOnTarget(main, main.offsetX + main.offsetX / 2, main.offsetY + main.offsetY / 2, true); } }
public Loader(Main main) { this.main = main; loadingThread = new Thread(loadInBackground); }
public static void processInput(Main main) { if (Keyboard.GetState().IsKeyDown(Keys.Left)) { main.offsetX -= main.offsetX > 10 ? 10 : 0; main.targetOffsetX = main.offsetX; } if (Keyboard.GetState().IsKeyDown(Keys.Up)) { main.offsetY -= main.offsetY > 10 ? 10 : 0; main.targetOffsetY = main.offsetY; } if (Keyboard.GetState().IsKeyDown(Keys.Right)) { main.offsetX += main.offsetX + main.screenWidth < main.quadrantWidth - 10 ? 10 : 0; main.targetOffsetX = main.offsetX; } if (Keyboard.GetState().IsKeyDown(Keys.Down)) { main.offsetY += main.offsetY + main.screenHeight < main.quadrantHeight - 10 ? 10 : 0; main.targetOffsetY = main.offsetY; } main.currentCursor = main.cursor1; if (Mouse.GetState().X < 30 && main.offsetX > 0) { main.currentCursor = main.cursorL; main.targetOffsetX = main.offsetX -= main.scrollSpeed; } if (Mouse.GetState().X + main.cursor1.Width > main.screenWidth - 30 && main.offsetX < main.quadrantWidth - main.screenWidth) { main.currentCursor = main.cursorR; main.targetOffsetX = main.offsetX += main.scrollSpeed; } if (Mouse.GetState().Y < 30 && main.offsetY > 0) { main.currentCursor = main.cursorU; main.targetOffsetY = main.offsetY -= main.scrollSpeed; } if (Mouse.GetState().Y + main.cursor1.Height > main.screenHeight - 30 && main.offsetY < main.quadrantHeight - main.screenHeight) { main.currentCursor = main.cursorD; main.targetOffsetY = main.offsetY += main.scrollSpeed; } if (Mouse.GetState().LeftButton == ButtonState.Pressed) { main.leftMouseDown = true; } else if (Mouse.GetState().LeftButton == ButtonState.Released && main.leftMouseDown) { main.leftMouseDown = false; main.leftMouseClicked = true; } if (Mouse.GetState().RightButton == ButtonState.Pressed) { main.rightMouseDown = true; } else if (Mouse.GetState().RightButton == ButtonState.Released && main.rightMouseDown) { main.rightMouseDown = false; main.rightMouseClicked = true; } if (Mouse.GetState().ScrollWheelValue > main.lastMouseWheelScroll && main.targetScale < 2.3f) { main.lastMouseWheelScroll = Mouse.GetState().ScrollWheelValue; main.targetScale += 0.3f; ViewProcessor.centerOnTarget(main, Mouse.GetState().X + main.offsetX, Mouse.GetState().Y + main.offsetY, false); } else if (Mouse.GetState().ScrollWheelValue < main.lastMouseWheelScroll && main.targetScale > 0.6f) { main.lastMouseWheelScroll = Mouse.GetState().ScrollWheelValue; main.targetScale -= 0.3f; ViewProcessor.centerOnTarget(main, Mouse.GetState().X + main.offsetX, Mouse.GetState().Y + main.offsetY, false); } if (Keyboard.GetState().IsKeyDown(Keys.Escape)) main.Exit(); }
public static void drawLoadingStrings(Main main) { main.spriteBatch.DrawString(main.font1, main.loading1, new Vector2((main.screenWidth / 2) - 100, (main.screenHeight / 2) - 100), Color.Yellow); main.spriteBatch.DrawString(main.font1, main.loading2, new Vector2((main.screenWidth / 2) - 100, (main.screenHeight / 2) - 80), Color.Yellow); }