public virtual void Draw(Main main) { foreach (Component child in children) { child.Draw(main); } }
public override void Initialize(Main main) { base.Initialize(main); Panel panel = new TextPanel("Tutorial", Color.Black); panel.alignment = new Vector2(0.5f, 0.5f); panel.position = new Vector2(0f, -70f); panel.size = new Vector2(300f, 50f); panel.OnClick += (m => m.changeScreen = new Tutorial()); AddComponent(panel); panel = new TextPanel("Earth", Color.Black); panel.alignment = new Vector2(0.5f, 0.5f); panel.size = new Vector2(300f, 50f); panel.OnClick += (m => m.changeScreen = new EarthDungeon()); AddComponent(panel); panel = new TextPanel("Fire", Color.Black); panel.alignment = new Vector2(0.5f, 0.5f); panel.position = new Vector2(0f, 70f); panel.size = new Vector2(300f, 50f); panel.OnClick += (m => m.changeScreen = new FireDungeon()); AddComponent(panel); panel = new TextPanel("Demo", Color.Black); panel.alignment = new Vector2(0.5f, 0.5f); panel.position = new Vector2(0f, 140f); panel.size = new Vector2(300f, 50f); panel.OnClick += (m => m.changeScreen = new DemoScreen()); AddComponent(panel); }
public override void Initialize(Main main) { base.Initialize(main); player = new Player(); player.position = new Vector2(tileSize * 1.5f, tileSize * 1.5f); currentRoom = SetupLevel(player); camera = player.position; }
public Main() { instance = this; graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 1000; graphics.PreferredBackBufferHeight = 600; this.IsMouseVisible = true; Content.RootDirectory = "Content"; SetupDefaultControls(); }
public virtual void Update(Main main) { if (Main.leftMouseClick && ContainsPoint(Main.mousePos) && OnClick != null) { OnClick(main); } foreach (Component child in children) { child.Update(main); } }
public override void Draw(GameScreen screen, Main main) { if (!collision) { main.spriteBatch.Draw(before, screen.DrawPos(main, position), null, color, before.Center()); } else { main.spriteBatch.Draw(after, screen.DrawPos(main, position), null, color, after.Center()); } }
public override void Draw(Main main) { Vector2 canvasSize = CanvasSize; Vector2 pos = Position; int spaceWidth = Textures.Panel.Width - 2 * panelBorder; int spaceHeight = Textures.Panel.Height - 2 * panelBorder; Rectangle dest = new Rectangle((int)pos.X, (int)pos.Y, panelBorder, panelBorder); Rectangle source = new Rectangle(0, 0, panelBorder, panelBorder); main.spriteBatch.Draw(Textures.Panel, dest, source, Color.White); dest.Y += panelBorder; dest.Height = (int)canvasSize.Y; source.Y += panelBorder; source.Height = spaceHeight; main.spriteBatch.Draw(Textures.Panel, dest, source, Color.White); dest.Y += (int)canvasSize.Y; dest.Height = panelBorder; source.Y += spaceHeight; source.Height = panelBorder; main.spriteBatch.Draw(Textures.Panel, dest, source, Color.White); dest.X += panelBorder; dest.Width = (int)canvasSize.X; source.X += panelBorder; source.Width = spaceWidth; main.spriteBatch.Draw(Textures.Panel, dest, source, Color.White); dest.Y -= (int)canvasSize.Y; dest.Height = (int)canvasSize.Y; source.Y -= spaceHeight; source.Height = spaceHeight; main.spriteBatch.Draw(Textures.Panel, dest, source, Color.White); dest.Y -= panelBorder; dest.Height = 2; source.Y -= panelBorder; source.Height = panelBorder; main.spriteBatch.Draw(Textures.Panel, dest, source, Color.White); dest.X += (int)canvasSize.X; dest.Width = 2; source.X += spaceWidth; source.Width = panelBorder; main.spriteBatch.Draw(Textures.Panel, dest, source, Color.White); dest.Y += panelBorder; dest.Height = (int)canvasSize.Y; source.Y += panelBorder; source.Height = spaceHeight; main.spriteBatch.Draw(Textures.Panel, dest, source, Color.White); dest.Y += (int)canvasSize.Y; dest.Height = 2; source.Y += spaceHeight; source.Height = panelBorder; main.spriteBatch.Draw(Textures.Panel, dest, source, Color.White); base.Draw(main); }
public override void DrawScreen(Main main) { Lava.IncrementTimer(); int startTileX, endTileX, startTileY, endTileY; ScreenBoundTiles(out startTileX, out endTileX, out startTileY, out endTileY); for (int x = startTileX; x <= endTileX; x++) { for (int y = startTileY; y <= endTileY; y++) { Texture2D texture = floorTexture[currentRoom.tiles[x, y].Floor]; if (texture != null) { Vector2 worldPos = tileSize * new Vector2(x, y); main.spriteBatch.Draw(texture, DrawPos(main, worldPos), null, Color.White, Vector2.Zero); } } } for (int x = startTileX; x <= endTileX; x++) { for (int y = startTileY; y <= endTileY; y++) { Texture2D texture = wallTexture[currentRoom.tiles[x, y].Wall]; if (texture != null) { Vector2 worldPos = tileSize * new Vector2(x, y); main.spriteBatch.Draw(texture, DrawPos(main, worldPos), null, Color.White, Vector2.Zero); } } } foreach (Point pos in currentRoom.puzzleCache) { currentRoom.tiles[pos.X, pos.Y].puzzle.Draw(this, pos.X, pos.Y, main); } foreach (Enemy enemy in currentRoom.enemies) { enemy.Draw(this, main); } player.Draw(this, main); currentRoom.bullets.Draw(this, main); currentRoom.particles.Draw(this, main); if (player.life <= 0) { float alpha = 0.1f + 0.4f * ((float)reviveTimer / (float)maxReviveTimer); main.spriteBatch.Draw(Textures.Pixel, Vector2.Zero, null, Color.Black * alpha, 0f, Vector2.Zero, size, SpriteEffects.None, 0f); } DrawHUD(main); }
public override void Initialize(Main main) { base.Initialize(main); Text text = new Text("Congratulations!", Color.White, Color.Black); text.alignment = new Vector2(0.5f, 0.25f); AddComponent(text); text = new Text("You have completed", Color.White, Color.Black); text.alignment = new Vector2(0.5f, 0.5f); text.position = new Vector2(0f, -20f); AddComponent(text); text = new Text(levelName, Color.White, Color.Black); text.alignment = new Vector2(0.5f, 0.5f); text.position = new Vector2(0f, 20f); AddComponent(text); Panel panel = new TextPanel("Continue", Color.Black); panel.alignment = new Vector2(0.5f, 0.75f); panel.size = new Vector2(300f, 50f); panel.OnClick += (m => m.changeScreen = new MainMenu()); AddComponent(panel); }
public override void UpdateScreen(Main main) { if (player.life <= 0) { reviveTimer++; if (reviveTimer >= maxReviveTimer) { player.Revive(this); reviveTimer = 0; } return; } if (currentRoom.cameraEvent != null) { if (currentRoom.cameraEvent.Update(currentRoom, player, ref camera)) { currentRoom.cameraEvent = null; } return; } player.Update(currentRoom); foreach (Enemy enemy in currentRoom.enemies) { enemy.UpdateEnemy(currentRoom, player); if (!enemy.IsHurt && enemy.Collides(player)) { player.TakeDamage(1); } } currentRoom.bullets.Update(currentRoom, player); foreach (Point pos in currentRoom.puzzleCache) { currentRoom.tiles[pos.X, pos.Y].puzzle.Update(currentRoom, pos.X, pos.Y, player); } currentRoom.particles.Update(currentRoom, player); if (currentRoom.usePortal != null) { ChangeRoom(currentRoom.usePortal.targetRoom, currentRoom.usePortal.targetPos); } camera = player.position; }
public abstract void Draw(GameScreen screen, Main main);
public virtual void Draw(GameScreen screen, int x, int y, Main main) { }
public override void Draw(Main main) { main.spriteBatch.DrawBorderString(Textures.Font, text, Position, color, borderColor, textBorder); }
public override void Initialize(Main main) { border = new Vector2(textBorder, textBorder); size = Textures.Font.MeasureString(text) + 2f * border; }
public override void DrawScreen(Main main) { main.spriteBatch.Draw(playerTexture, main.Center(), null, Color.White, playerTexture.Center()); foreach (Vector2 pos in turretPos) { main.spriteBatch.Draw(turretTexture, DrawPos(main, pos), null, Color.White, turretTexture.Center()); } foreach (Vector2 pos in bulletPos) { main.spriteBatch.Draw(bulletTexture, DrawPos(main, pos), null, Color.White, bulletTexture.Center()); } for (int k = 0; k < switchPressed.Length; k++) { Texture2D texture = switchPressed[k] ? switchPressedTexture : switchTexture; main.spriteBatch.Draw(texture, DrawPos(main, switchPos[k]), null, Color.White, texture.Center()); } if (level > 1 && !win) { for (int k = 0; k < numCircles; k++) { float angle = circleAngle + k * 2f * (float)Math.PI / numCircles; Vector2 pos = circleCenter + circleRadius * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); main.spriteBatch.Draw(bulletTexture, DrawPos(main, pos), null, Color.White, bulletTexture.Center()); } } }
public virtual void DrawScreen(Main main) { }
public virtual void Initialize(Main main) { }
public virtual void UpdateScreen(Main main) { }
public Vector2 DrawPos(Main main, Vector2 pos) { return size / 2f + pos - playerPos; }
public override void Initialize(Main main) { base.Initialize(main); Reset(); }
public override void UpdateScreen(Main main) { if (dead) { Reset(); } Vector2 velocity = Vector2.Zero; if (Main.IsControlHeld(KeyControl.Up)) { velocity.Y -= 1f; } if (Main.IsControlHeld(KeyControl.Down)) { velocity.Y += 1f; } if (Main.IsControlHeld(KeyControl.Left)) { velocity.X -= 1f; } if (Main.IsControlHeld(KeyControl.Right)) { velocity.X += 1f; } if (velocity != Vector2.Zero) { velocity.Normalize(); velocity *= 4f; playerPos += velocity; } foreach (Vector2 pos in turretPos) { if (Vector2.Distance(playerPos, pos) <= 20f) { dead = true; } if (!win && time > 0 && (time % (level > 2 ? 40 : 60) == 0)) { bulletPos.Add(pos); Vector2 speed = playerPos - pos; if (speed == Vector2.Zero) { speed = new Vector2(0f, 1f); } else { speed.Normalize(); } speed *= 4f; bulletSpeed.Add(speed); if (bulletPos.Count > 60) { bulletPos.RemoveAt(0); bulletSpeed.RemoveAt(0); } } } for (int k = 0; k < bulletPos.Count; k++) { bulletPos[k] += bulletSpeed[k]; if (Vector2.Distance(playerPos, bulletPos[k]) <= 15f) { dead = true; } } for (int k = 0; k < switchPos.Length; k++) { if (Vector2.Distance(playerPos, switchPos[k]) <= 20f) { switchPressed[k] = true; win = true; foreach (bool pressed in switchPressed) { if (!pressed) { win = false; break; } } if (win) { bulletPos.Clear(); bulletSpeed.Clear(); } } } if (level > 1 && !win) { circleRadius -= 1f; if (circleRadius < 0f) { circleAngle = 0f; circleRadius = 150f; circleCenter = playerPos; } circleAngle += 0.03f; for (int k = 0; k < numCircles; k++) { float angle = circleAngle + k * 2f * (float)Math.PI / numCircles; Vector2 pos = circleCenter + circleRadius * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); if (Vector2.Distance(playerPos, pos) <= 15f) { dead = true; } } } rainbow += 0.001f; rainbow %= 1f; time++; }
public override void Draw(GameScreen screen, Main main) { main.spriteBatch.Draw(texture, screen.DrawPos(main, position), null, color, texture.Center()); }
public override void Initialize(Main main) { border = new Vector2(panelBorder, panelBorder); }
public void Draw(GameScreen screen, Main main) { Color color = Color.White; if (invincible > 0) { color *= 0.75f; } Texture2D texture = textures[(int)direction]; main.spriteBatch.Draw(texture, screen.DrawPos(main, position), null, color, texture.Center()); if (Attacking) { color = Color.White; if (!AttackCanDamage) { color *= 0.5f; } float rotation = Helper.DirectionToRotation(direction); main.spriteBatch.Draw(slashTexture, screen.DrawPos(main, position), null, color, rotation, slashTexture.Center(), 1f, SpriteEffects.None, 1f); } }
public override sealed void Update(Main main) { size = main.Size(); UpdateScreen(main); base.Update(main); }
private void DrawHUD(Main main) { string text = "LVL1 HP:" + player.life + "/" + player.maxLife + " EXP:" + player.exp + "/9999"; Vector2 offset = new Vector2(10f, 10f); Vector2 textSize = Textures.Font.MeasureString(text); main.spriteBatch.DrawBorderString(Textures.Font, text, offset, Color.White, Color.Black, 2); offset.X += textSize.X + 40f; main.spriteBatch.Draw(SilverKey.texture, offset - new Vector2(0f, 5f), null, Color.White, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); offset.X += 30f; text = "X" + player.silverKeys; main.spriteBatch.DrawBorderString(Textures.Font, text, offset, Color.White, Color.Black, 2); if (player.life <= 0) { text = "YOU HAVE DIED!"; main.spriteBatch.DrawCenteredBorderString(Textures.Font, text, size / 2f + new Vector2(0f, 50f), Color.White, Color.Black, 2); } }
public override sealed void Draw(Main main) { size = main.Size(); DrawScreen(main); base.Draw(main); }
public Vector2 DrawPos(Main main, Vector2 pos) { return size / 2f + pos - camera; }
public override void Initialize(Main main) { size = main.Size(); }
public override void Draw(Main main) { base.Draw(main); main.spriteBatch.DrawCenteredString(Textures.Font, Text, Position + Size / 2f, TextColor); }