protected State(ContentManager content, GraphicsDevice graphicsDevice, PlatformerGame game, SpriteBatch spriteBatch) { _content = content; _graphicsDevice = graphicsDevice; _game = game; _spriteBatch = spriteBatch; }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main(string[] args) { using (PlatformerGame game = new PlatformerGame()) { game.Run(); } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (PlatformerGame game = new PlatformerGame()) { game.Run(); } }
/// <summary> /// InitializeParticle is overridden to add the appearance of wind. /// </summary> /// <param name="p">the particle to set up</param> /// <param name="where">where the particle should be placed</param> protected override void InitializeParticle(Particle p, Vector2 where) { base.InitializeParticle(p, where); // the base is mostly good, but we want to simulate a little bit of wind // heading to the right. p.Acceleration.X += PlatformerGame.RandomBetween(10, 50); }
internal static void RunGame() { game = new PlatformerGame(); game.Run(); #if !__IOS__ && !__TVOS__ game.Dispose(); #endif }
public GamePage() { this.InitializeComponent(); // Create the game. var launchArguments = string.Empty; _game = MonoGame.Framework.XamlGame <PlatformerGame> .Create(launchArguments, Window.Current.CoreWindow, swapChainPanel); }
public LevelManager(List <Level> levels, int difficulty, ContentManager content, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, PlatformerGame game) : base(content, graphicsDevice, game, spriteBatch) { LevelCount = 0; Levels = levels; CurrentLevel = Levels[LevelCount]; SpriteBatch = spriteBatch; _game = game; _difficulty = difficulty; }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { NSApplication.Init(); //using (var game = new Game1()) using (PlatformerGame game = new PlatformerGame()) { game.Run(); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); _game = new PlatformerGame(); _view = _game.Services.GetService(typeof(View)) as View; SetContentView(_view); _game.Run(); }
// Use this for initialization void Start() { Application.targetFrameRate = 60; // Add an audio source and tell the media player to use it for playing sounds Microsoft.Xna.Framework.Media.MediaPlayer.AudioSource = gameObject.AddComponent <AudioSource>(); drawQueue = new DrawQueue(); game = new PlatformerGame(); game.DrawQueue = drawQueue; game.Begin(); timeleft = updateInterval; //Application.targetFrameRate = 30; }
// Use this for initialization void Start () { Application.targetFrameRate = 60; // Add an audio source and tell the media player to use it for playing sounds Microsoft.Xna.Framework.Media.MediaPlayer.AudioSource = gameObject.AddComponent<AudioSource>(); drawQueue = new DrawQueue(); game = new PlatformerGame(); game.DrawQueue = drawQueue; game.Begin(); timeleft = updateInterval; //Application.targetFrameRate = 30; }
/// <summary> /// PickRandomDirection is overriden so that we can make the particles always /// move have an initial velocity pointing up. /// </summary> /// <returns>a random direction which points basically up.</returns> protected override Vector2 PickRandomDirection() { // Point the particles somewhere between 80 and 100 degrees. // tweak this to make the smoke have more or less spread. float radians = PlatformerGame.RandomBetween( MathHelper.ToRadians(80), MathHelper.ToRadians(100)); Vector2 direction = Vector2.Zero; // from the unit circle, cosine is the x coordinate and sine is the // y coordinate. We're negating y because on the screen increasing y moves // down the monitor. direction.X = dir * (float)Math.Sin(radians); direction.Y = (float)Math.Cos(radians) * 2; return(direction); }
// initialize is called by ParticleSystem to set up the particle, and prepares // the particle for use. public void Initialize(Vector2 position, Vector2 velocity, Vector2 acceleration, float lifetime, float scale, float rotationSpeed) { // set the values to the requested values this.Position = position; this.Velocity = velocity; this.Acceleration = acceleration; this.Lifetime = lifetime; this.Scale = scale; this.RotationSpeed = rotationSpeed; // reset TimeSinceStart - we have to do this because particles will be // reused. this.TimeSinceStart = 0.0f; // set rotation to some random value between 0 and 360 degrees. this.Rotation = PlatformerGame.RandomBetween(0, MathHelper.TwoPi); }
public MenuState(ContentManager content, GraphicsDevice graphicsDevice, PlatformerGame game, SpriteBatch spriteBatch) : base(content, graphicsDevice, game, spriteBatch) { var buttonTexture = _content.Load <Texture2D>("Controls/Button"); var buttonFont = _content.Load <SpriteFont>("Fonts/Font"); var newGameButton = new Button(buttonTexture, buttonFont, spriteBatch) { Position = new Vector2(Constants.ScreenWidth / 2 - buttonTexture.Width / 2, Constants.ScreenHeight / 2 - 100), Text = "New Game" }; newGameButton.Click += NewGameButton_Click; var creditsButton = new Button(buttonTexture, buttonFont, spriteBatch) { Position = new Vector2(Constants.ScreenWidth / 2 - buttonTexture.Width / 2, Constants.ScreenHeight / 2), Text = "Credits" }; creditsButton.Click += CreditsButton_Click; var quitButton = new Button(buttonTexture, buttonFont, spriteBatch) { Position = new Vector2(Constants.ScreenWidth / 2 - buttonTexture.Width / 2, Constants.ScreenHeight / 2 + 100), Text = "Quit" }; quitButton.Click += QuitButton_Click; _components = new List <Component>() { quitButton, newGameButton, creditsButton }; }
/// <summary> /// InitializeParticle randomizes some properties for a particle, then /// calls initialize on it. It can be overriden by subclasses if they /// want to modify the way particles are created. For example, /// SmokePlumeParticleSystem overrides this function make all particles /// accelerate to the right, simulating wind. /// </summary> /// <param name="p">the particle to initialize</param> /// <param name="where">the position on the screen that the particle should be /// </param> protected virtual void InitializeParticle(Particle p, Vector2 where) { // first, call PickRandomDirection to figure out which way the particle // will be moving. velocity and acceleration's values will come from this. Vector2 direction = PickRandomDirection(); // pick some random values for our particle float velocity = PlatformerGame.RandomBetween(minInitialSpeed, maxInitialSpeed); float acceleration = PlatformerGame.RandomBetween(minAcceleration, maxAcceleration); float lifetime = PlatformerGame.RandomBetween(minLifetime, maxLifetime); float scale = PlatformerGame.RandomBetween(minScale, maxScale); float rotationSpeed = PlatformerGame.RandomBetween(minRotationSpeed, maxRotationSpeed); // then initialize it with those random values. initialize will save those, // and make sure it is marked as active. p.Initialize( where, velocity * direction, acceleration * direction, lifetime, scale, rotationSpeed); }
static void Main() { using (var game = new PlatformerGame()) game.Run(); }
public ExplosionSmokeParticleSystem(PlatformerGame game, int howManyEffects) : base(game, howManyEffects) { }
/// <summary> /// PickRandomDirection is used by InitializeParticles to decide which direction /// particles will move. The default implementation is a random vector in a /// circular pattern. /// </summary> protected virtual Vector2 PickRandomDirection() { float angle = PlatformerGame.RandomBetween(0, MathHelper.TwoPi); return(new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))); }
public SmokePlumeParticleSystem(PlatformerGame game, int howManyEffects) : base(game, howManyEffects) { }
internal static void RunGame() { game = new PlatformerGame(); game.Run(); }
/// <summary> /// Constructs a new ParticleSystem. /// </summary> /// <param name="game">The host for this particle system. The game keeps the /// content manager and sprite batch for us.</param> /// <param name="howManyEffects">the maximum number of particle effects that /// are expected on screen at once.</param> /// <remarks>it is tempting to set the value of howManyEffects very high. /// However, this value should be set to the minimum possible, because /// it has a large impact on the amount of memory required, and slows down the /// Update and Draw functions.</remarks> protected ParticleSystem(PlatformerGame game, int howManyEffects) : base(game.ScreenManager.Game) { this.game = game; this.howManyEffects = howManyEffects; }
public GameState2(ContentManager content, GraphicsDevice graphicsDevice, PlatformerGame game, SpriteBatch spriteBatch, int difficulty) : base(content, graphicsDevice, game, spriteBatch) { _content = content; _graphicsDevice = graphicsDevice; _game = game; _spriteBatch = spriteBatch; _content.RootDirectory = "Content"; List <Level> levels = new List <Level>(); #region Sprites List <Sprite> _sprites = new List <Sprite>(); Fly _fly = new Fly(_content.Load <Texture2D>("Enemies/enemies_spritesheet"), new Vector2(1150, 564), _spriteBatch, new Dictionary <string, Animation> { { "Right", new Animation(_content.Load <Texture2D>("Enemies/enemies_spritesheet"), 2, new List <Rectangle> { new Rectangle(0, 32, 72, 36), new Rectangle(0, 0, 75, 31) } ) }, { "Left", new Animation(_content.Load <Texture2D>("Enemies/enemies_spritesheet_mirrored"), 2, new List <Rectangle> { new Rectangle(281, 32, 72, 36), new Rectangle(276, 0, 75, 31) } ) }, }); Player _player = new Player(_content.Load <Texture2D>("Player/p3_spritesheet"), new Vector2(100, 600), _spriteBatch, new Dictionary <string, Animation> { { "WalkRight", new Animation(_content.Load <Texture2D>("Player/p3_spritesheet"), 11, new List <Rectangle> { new Rectangle(0, 0, 72, 97), new Rectangle(73, 0, 72, 97), new Rectangle(146, 0, 72, 97), new Rectangle(0, 98, 72, 97), new Rectangle(73, 98, 72, 97), new Rectangle(146, 98, 72, 97), new Rectangle(219, 0, 72, 97), new Rectangle(292, 0, 72, 97), new Rectangle(219, 98, 72, 97), new Rectangle(365, 0, 72, 97), new Rectangle(292, 98, 72, 97), }) }, { "WalkLeft", new Animation(_content.Load <Texture2D>("Player/p3_spritesheet_mirrored"), 11, new List <Rectangle> { new Rectangle(508 - 72, 0, 72, 97), new Rectangle(508 - 73 - 72, 0, 72, 97), new Rectangle(508 - 146 - 72, 0, 72, 97), new Rectangle(508 - 0 - 72, 98, 72, 97), new Rectangle(508 - 73 - 72, 98, 72, 97), new Rectangle(508 - 146 - 72, 98, 72, 97), new Rectangle(508 - 219 - 72, 0, 72, 97), new Rectangle(508 - 292 - 72, 0, 72, 97), new Rectangle(508 - 219 - 72, 98, 72, 97), new Rectangle(508 - 365 - 72, 0, 72, 97), new Rectangle(508 - 292 - 72, 98, 72, 97), } ) }, { "StandRight", new Animation(_content.Load <Texture2D>("Player/p3_spritesheet"), 1, new List <Rectangle> { new Rectangle(67, 196, 72, 97) }) }, { "StandLeft", new Animation(_content.Load <Texture2D>("Player/p3_spritesheet_mirrored"), 1, new List <Rectangle> { new Rectangle(508 - 67 - 72, 196, 72, 97) } ) }, { "JumpRight", new Animation(_content.Load <Texture2D>("Player/p3_spritesheet"), 1, new List <Rectangle> { new Rectangle(438, 93, 72, 97) } ) }, { "JumpLeft", new Animation(_content.Load <Texture2D>("Player/p3_spritesheet_mirrored"), 1, new List <Rectangle> { new Rectangle(508 - 438 - 72, 93, 72, 97) } ) }, { "HurtRight", new Animation(_content.Load <Texture2D>("Player/p3_spritesheet"), 1, new List <Rectangle> { new Rectangle(438, 0, 69, 92) } ) }, { "HurtLeft", new Animation(_content.Load <Texture2D>("Player/p3_spritesheet_mirrored"), 1, new List <Rectangle> { new Rectangle(508 - 438 - 69, 0, 69, 92) } ) }, }); _sprites.Add(_player); _sprites.Add(_fly); #endregion #region LoadMap XmlDocument _tileSet = new XmlDocument(); XmlDocument _mapFile = new XmlDocument(); _mapFile.Load("../../../../Content/Maps/Level2.tmx"); _tileSet.Load("../../../../Content/Maps/TileSetLevel2.tsx"); string[] _tileTextureSources = XmlParser.ToTextureArray(_tileSet); Texture2D[] _tileTextures = new Texture2D[_tileTextureSources.Length]; //Source dictionary omzetten naar een texture array : (int,string) --> (int,Texture2d) for (int i = 0; i < _tileTextureSources.Length; i++) { _tileTextures[i] = _content.Load <Texture2D>("Tiles/" + _tileTextureSources[i]); } int[] nonCollideTiles = { 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 16, 17, 18, 19, 30, 31, 32, 33, 34, 42, 43, 44 }; int _coinTile = 7; int[] _bridgeTiles = { }; int[] _killTiles = { 40, 41, 29 }; UserMadeBoard _userMadeBoard = new UserMadeBoard(_mapFile, _tileTextures, _spriteBatch, _sprites, nonCollideTiles, _coinTile, _bridgeTiles, _killTiles); #endregion #region Camera&Hud Camera _camera = new Camera(_player); HUD _HUD = new HUD( new Dictionary <string, Texture2D> { { "FullHeart", _content.Load <Texture2D>("HUD/hud_heartFull") }, { "HalfHeart", _content.Load <Texture2D>("HUD/hud_heartHalf") }, { "Coin", _content.Load <Texture2D>("HUD/hud_coins") }, { "Cross", _content.Load <Texture2D>("HUD/hud_x") }, { "1", _content.Load <Texture2D>("HUD/hud_1") }, { "2", _content.Load <Texture2D>("HUD/hud_2") }, { "3", _content.Load <Texture2D>("HUD/hud_3") }, { "4", _content.Load <Texture2D>("HUD/hud_4") }, { "5", _content.Load <Texture2D>("HUD/hud_5") }, { "6", _content.Load <Texture2D>("HUD/hud_6") }, { "7", _content.Load <Texture2D>("HUD/hud_7") }, { "8", _content.Load <Texture2D>("HUD/hud_8") }, { "9", _content.Load <Texture2D>("HUD/hud_9") }, { "0", _content.Load <Texture2D>("HUD/hud_0") }, }, _spriteBatch, _player, _camera); #endregion levels.Add(new Level(_spriteBatch, _game, _userMadeBoard, _sprites, _HUD)); levelManager = new LevelManager(levels, difficulty, _content, _graphicsDevice, _spriteBatch, _game); }
public RetroBloodSprayParticleSystem(PlatformerGame game, int howManyEffects) : base(game, howManyEffects) { }
/// <summary> /// Constructs a new level. /// </summary> /// <param name="serviceProvider"> /// The service provider that will be used to construct a ContentManager. /// </param> /// <param name="fileStream"> /// A stream containing the tile data. /// </param> public Level(IServiceProvider serviceProvider, Stream fileStream, int levelIndex, PlatformerGame game) { Game = game; Game.Penumbra.Lights.Clear(); Game.Penumbra.Hulls.Clear(); // Create a new content manager to load content used just by this level. // Disabled due to an occasional crash in XAudio2_7.dll //Content = new ContentManager(serviceProvider, "Content"); Content = game.Content; TimeRemaining = TimeSpan.FromMinutes(2.0); LoadTiles(fileStream); // Load background layer textures. For now, all levels must // use the same backgrounds and only use the left-most part of them. layers = new Texture2D[3]; for (var i = 0; i < layers.Length; ++i) { // Choose a random segment if each background layer for level variety. int segmentIndex = levelIndex; layers[i] = Content.Load<Texture2D>("Backgrounds/Layer" + i + "_" + segmentIndex); } // Load sounds. exitReachedSound = Content.Load<SoundEffect>("Sounds/ExitReached"); Game.Interpreter.RemoveVariable("level"); Game.Interpreter.AddVariable("level", this); }
public ChooseLevelState(ContentManager content, GraphicsDevice graphicsDevice, PlatformerGame game, SpriteBatch spriteBatch) : base(content, graphicsDevice, game, spriteBatch) { var buttonTexture = _content.Load <Texture2D>("Controls/Button"); var buttonFont = _content.Load <SpriteFont>("Fonts/Font"); _difficulty = 3; var easyButton = new Button(buttonTexture, buttonFont, spriteBatch) { Position = new Vector2(80, 100), Text = "Easy" }; easyButton.Click += EasyButton_Click; var mediumButton = new Button(buttonTexture, buttonFont, spriteBatch) { Position = new Vector2(80 + buttonTexture.Width, 100), Text = "Medium" }; mediumButton.Click += MediumButton_Click; var hardButton = new Button(buttonTexture, buttonFont, spriteBatch) { Position = new Vector2(80 + 2 * buttonTexture.Width, 100), Text = "Hard" }; hardButton.Click += HardButton_Click; var level1Button = new Button(buttonTexture, buttonFont, spriteBatch) { Position = new Vector2(Constants.ScreenWidth / 2 - buttonTexture.Width / 2, Constants.ScreenHeight / 2 - 100), Text = "Level 1" }; level1Button.Click += level1Button_Click; var level2Button = new Button(buttonTexture, buttonFont, spriteBatch) { Position = new Vector2(Constants.ScreenWidth / 2 - buttonTexture.Width / 2, Constants.ScreenHeight / 2), Text = "Level 2" }; level2Button.Click += level2Button_Click; var quitButton = new Button(buttonTexture, buttonFont, spriteBatch) { Position = new Vector2(Constants.ScreenWidth / 2 - buttonTexture.Width / 2, Constants.ScreenHeight / 2 + 100), Text = "Quit" }; quitButton.Click += QuitButton_Click; _components = new List <Component>() { easyButton, mediumButton, hardButton, level1Button, level2Button, quitButton, }; }
public override void Update() { MouseState = Mouse.GetState(); float moveSpeed = AirSpeed; if (Room.FindCollision(new Rectangle((Position + Sprite.Offset + new Vector2(0, 1)).ToPoint(), Sprite.Size.ToPoint()), "obj_block") != null) { Grounded = true; moveSpeed = GroundSpeed; if (Math.Abs(Velocity.X) > GroundFriction) { Velocity.X -= Math.Sign(Velocity.X) * GroundFriction; } else { Velocity.X = 0; } JumpsLeft = MaxJumpsLeft; } else { Grounded = false; } Input.Update(); if (Light != null) { Light.Position = Position; } if (Jump.Pressed && JumpsLeft > 0 && JumpCooldown == 0) { if (Grounded) { Room.Sounds.PlaySound(JumpSound); } else { Room.Sounds.PlaySound(AirJumpSound); } Velocity.Y = JumpSpeed; JumpsLeft--; JumpCooldown = MaxJumpCooldown; if (JumpsLeft == 0) { if (Left.Pressed && Velocity.X > -2) { Velocity.X = -2; } if (Right.Pressed && Velocity.X < 2) { Velocity.X = 2; } } Grounded = false; } if (Left.Pressed && Velocity.X > -MaxVelocity.X) { Velocity.X -= moveSpeed; } if (Right.Pressed && Velocity.X < MaxVelocity.X) { Velocity.X += moveSpeed; } if (Velocity.X > MinDirectionChangeSpeed) { Sprite.SpriteEffect = SpriteEffects.None; } else if (Velocity.X < -MinDirectionChangeSpeed) { Sprite.SpriteEffect = SpriteEffects.FlipHorizontally; } if (Math.Abs(Velocity.X) >= MinRunAnimationSpeed) { Sprite.Change(RunImage); } else { Sprite.Change(IdleImage); } Item?.Update(); if (MouseState.LeftPressed()) { Item?.DoUse(this); } PlatformerGame game = (PlatformerGame)Room.Engine.Game; if (Position.X > Room.Width && Velocity.X > 0) { Position.X -= Room.Width; game.GoToRoom(game.CurrentRoomX + 1, game.CurrentRoomY); JumpsLeft = MaxJumpsLeft; } else if (Position.X < 0 && Velocity.X < 0) { Position.X += Room.Width; game.GoToRoom(game.CurrentRoomX - 1, game.CurrentRoomY); JumpsLeft = MaxJumpsLeft; } else if (Position.Y > Room.Height && Velocity.Y > 0) { Position.Y -= Room.Height; game.GoToRoom(game.CurrentRoomX, game.CurrentRoomY + 1); JumpsLeft = MaxJumpsLeft; } else if (Position.Y < 0 && Velocity.Y < 0) { Position.Y += Room.Height; game.GoToRoom(game.CurrentRoomX, game.CurrentRoomY - 1); JumpsLeft = MaxJumpsLeft; } Rectangle hitbox = GetHitbox(); hitbox.Location += Position.ToPoint(); GameObject itemObject = Room.FindCollision(hitbox, "obj_item"); if (itemObject != null) { ItemObject itemContainer = (ItemObject)itemObject; Item = itemContainer.Item; UpgradeObject.Item = Item; Room.GameObjectList.Remove(itemObject); } else { itemObject = Room.FindCollision(hitbox, "obj_upgrade"); if (itemObject != null) { UpgradeObject upgradeObject = (UpgradeObject)itemObject; upgradeObject.Upgrade(); } } if (JumpCooldown > 0) { JumpCooldown--; } Velocity.Y += Gravity; base.Update(); PrevMouseState = MouseState; }
public RetroBloodSprayWide(PlatformerGame game, int howManyEffects) : base(game, howManyEffects) { }