public Spider(World world, PhysicsGameScreen screen, Vector2 position) { //Load bodies _circle = BodyFactory.CreateCircle(world, SpiderBodyRadius, 0.1f, position); _circle.BodyType = BodyType.Dynamic; //Left upper leg _leftUpper = BodyFactory.CreateRectangle(world, _upperLegSize.X, _upperLegSize.Y, 0.1f, _circle.Position - new Vector2(SpiderBodyRadius, 0f) - new Vector2(_upperLegSize.X / 2f, 0f)); _leftUpper.BodyType = BodyType.Dynamic; //Left lower leg _leftLower = BodyFactory.CreateRectangle(world, _lowerLegSize.X, _lowerLegSize.Y, 0.1f, _circle.Position - new Vector2(SpiderBodyRadius, 0f) - new Vector2(_upperLegSize.X, 0f) - new Vector2(_lowerLegSize.X / 2f, 0f)); _leftLower.BodyType = BodyType.Dynamic; //Right upper leg _rightUpper = BodyFactory.CreateRectangle(world, _upperLegSize.X, _upperLegSize.Y, 0.1f, _circle.Position + new Vector2(SpiderBodyRadius, 0f) + new Vector2(_upperLegSize.X / 2f, 0f)); _rightUpper.BodyType = BodyType.Dynamic; //Right lower leg _rightLower = BodyFactory.CreateRectangle(world, _lowerLegSize.X, _lowerLegSize.Y, 0.1f, _circle.Position + new Vector2(SpiderBodyRadius, 0f) + new Vector2(_upperLegSize.X, 0f) + new Vector2(_lowerLegSize.X / 2f, 0f)); _rightLower.BodyType = BodyType.Dynamic; //Create joints JointFactory.CreateRevoluteJoint(world, _circle, _leftUpper, new Vector2(_upperLegSize.X / 2f, 0f)); _leftShoulderAngleJoint = JointFactory.CreateAngleJoint(world, _circle, _leftUpper); _leftShoulderAngleJoint.MaxImpulse = 3f; JointFactory.CreateRevoluteJoint(world, _circle, _rightUpper, new Vector2(-_upperLegSize.X / 2f, 0f)); _rightShoulderAngleJoint = JointFactory.CreateAngleJoint(world, _circle, _rightUpper); _rightShoulderAngleJoint.MaxImpulse = 3f; JointFactory.CreateRevoluteJoint(world, _leftUpper, _leftLower, new Vector2(_lowerLegSize.X / 2f, 0f)); _leftKneeAngleJoint = JointFactory.CreateAngleJoint(world, _leftUpper, _leftLower); _leftKneeAngleJoint.MaxImpulse = 3f; JointFactory.CreateRevoluteJoint(world, _rightUpper, _rightLower, new Vector2(-_lowerLegSize.X / 2f, 0f)); _rightKneeAngleJoint = JointFactory.CreateAngleJoint(world, _rightUpper, _rightLower); _rightKneeAngleJoint.MaxImpulse = 3; _screen = screen; //GFX AssetCreator creator = _screen.ScreenManager.Assets; _torso = new Sprite(creator.CircleTexture(SpiderBodyRadius, MaterialType.Waves, Color.Gray, 1f)); _upperLeg = new Sprite(creator.TextureFromShape(_leftUpper.FixtureList[0].Shape, MaterialType.Blank, Color.DimGray, 1f)); _lowerLeg = new Sprite(creator.TextureFromShape(_leftLower.FixtureList[0].Shape, MaterialType.Blank, Color.DarkSlateGray, 1f)); }
public Ragdoll(World world, PhysicsGameScreen screen, Vector2 position) { CreateBody(world, position); CreateJoints(world); _screen = screen; CreateGFX(); }
public MusicSelectScreen(PhysicsGameScreen physicsgamescreen) : base("Music", MenuType.Music) { PhysicsGameScreen = physicsgamescreen; AddMenuItem("Default Music", EntryType.DefaultMusic, physicsgamescreen); /////////////////////////////// //Check if the device has music /////////////////////////////// // if (MusicHelper.LibraryHasSongs()) // { // AddMenuItem("Random From My Music", EntryType.CustomMusic, physicsgamescreen); // } AddMenuItem("Let Mine Play", EntryType.BackgroundMuisc, physicsgamescreen); }
public BollHav(World world, PhysicsGameScreen screen, Vector2 position, int count, float density) { Vertices rect = PolygonTools.CreateCircle(0.5f, 10); CircleShape shape = new CircleShape(0.5f, density); Vector2 rowStart = position; rowStart.Y -= 0.5f + 24 * 1.1f; Vector2 deltaRow = new Vector2(0, 1.1f); const float spacing = 1.25f; _spheres = new List<Body>(); int y = (int)5; int x = (int)count / 5; rowStart.X -= (((float)x) * 0.5f); Random rand = new Random(); for (int i = 0; i < y; ++i) { Vector2 pos = rowStart; for (int j = 0; j < x; ++j) { Body body = BodyFactory.CreateBody(world); body.BodyType = BodyType.Dynamic; body.Position = pos; body.CreateFixture(shape); body.Restitution = (float)(rand.NextDouble()); _spheres.Add(body); pos.X += spacing; } rowStart += deltaRow; } _screen = screen; //GFX AssetCreator creator = _screen.ScreenManager.Assets; _sphere = new Sprite(creator.TextureFromVertices(rect, MaterialType.Dots, Color.SaddleBrown, 2f)); }
public Pyramid(World world, PhysicsGameScreen screen, Vector2 position, int count, float density) { Vertices rect = PolygonTools.CreateRectangle(0.5f, 0.5f); PolygonShape shape = new PolygonShape(rect, density); Vector2 rowStart = position; rowStart.Y -= 0.5f + count * 1.1f; Vector2 deltaRow = new Vector2(-0.625f, 1.1f); const float spacing = 1.25f; _boxes = new List <Body>(); for (int i = 0; i < count; ++i) { Vector2 pos = rowStart; for (int j = 0; j < i + 1; ++j) { Body body = BodyFactory.CreateBody(world); body.BodyType = BodyType.Dynamic; body.Position = pos; body.CreateFixture(shape); _boxes.Add(body); pos.X += spacing; } rowStart += deltaRow; } _screen = screen; //GFX AssetCreator creator = _screen.ScreenManager.Assets; _box = new Sprite(creator.TextureFromVertices(rect, MaterialType.Dots, Color.SaddleBrown, 2f)); }
public Agent(World world, PhysicsGameScreen screen, Vector2 position) { _collidesWith = Category.All; _collisionCategories = Category.All; _agentBody = BodyFactory.CreateBody(world, position); _agentBody.BodyType = BodyType.Dynamic; //Center FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody); //Left arm FixtureFactory.AttachRectangle(1.5f, 0.4f, 1f, new Vector2(-1f, 0f), _agentBody); FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(-2f, 0f)); //Right arm FixtureFactory.AttachRectangle(1.5f, 0.4f, 1f, new Vector2(1f, 0f), _agentBody); FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(2f, 0f)); //Top arm FixtureFactory.AttachRectangle(0.4f, 1.5f, 1f, new Vector2(0f, 1f), _agentBody); FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(0f, 2f)); //Bottom arm FixtureFactory.AttachRectangle(0.4f, 1.5f, 1f, new Vector2(0f, -1f), _agentBody); FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(0f, -2f)); _screen = screen; //GFX AssetCreator creator = _screen.ScreenManager.Assets; _box = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(1.75f, 0.2f), MaterialType.Blank, Color.White, 1f)); _knob = new Sprite(creator.CircleTexture(0.5f, MaterialType.Blank, Color.Orange, 1f)); _offset = ConvertUnits.ToDisplayUnits(2f); }
public Pyramid(World world, PhysicsGameScreen screen, Vector2 position, int count, float density) { Vertices rect = PolygonTools.CreateRectangle(0.5f, 0.5f); PolygonShape shape = new PolygonShape(rect, density); Vector2 rowStart = position; rowStart.Y -= 0.5f + count * 1.1f; Vector2 deltaRow = new Vector2(-0.625f, 1.1f); const float spacing = 1.25f; _boxes = new List<Body>(); for (int i = 0; i < count; ++i) { Vector2 pos = rowStart; for (int j = 0; j < i + 1; ++j) { Body body = BodyFactory.CreateBody(world); body.BodyType = BodyType.Dynamic; body.Position = pos; body.CreateFixture(shape); _boxes.Add(body); pos.X += spacing; } rowStart += deltaRow; } _screen = screen; //GFX AssetCreator creator = _screen.ScreenManager.Assets; _box = new Sprite(creator.TextureFromVertices(rect, MaterialType.Dots, Color.SaddleBrown, 2f)); }
public TheoJansenWalker(World world, PhysicsGameScreen screen, Vector2 position) { _position = position; _motorSpeed = 2.0f; _motorOn = true; _screen = screen; _walkerJoints = new List<DistanceJoint>(); _leftShoulders = new Body[3]; _rightShoulders = new Body[3]; _leftLegs = new Body[3]; _rightLegs = new Body[3]; Vector2 pivot = new Vector2(0f, -0.8f); // Chassis { PolygonShape shape = new PolygonShape(1f); shape.SetAsBox(2.5f, 1.0f); _body = new Sprite(_screen.ScreenManager.Assets.TextureFromShape(shape, MaterialType.Blank, Color.Beige, 1f)); _chassis = BodyFactory.CreateBody(world); _chassis.BodyType = BodyType.Dynamic; _chassis.Position = pivot + _position; Fixture fixture = _chassis.CreateFixture(shape); fixture.CollisionGroup = -1; } { CircleShape shape = new CircleShape(1.6f, 1f); _engine = new Sprite(_screen.ScreenManager.Assets.TextureFromShape(shape, MaterialType.Waves, Color.Beige * 0.8f, 1f)); _wheel = BodyFactory.CreateBody(world); _wheel.BodyType = BodyType.Dynamic; _wheel.Position = pivot + _position; Fixture fixture = _wheel.CreateFixture(shape); fixture.CollisionGroup = -1; } { _motorJoint = new RevoluteJoint(_wheel, _chassis, _wheel.GetLocalPoint(_chassis.Position), Vector2.Zero); _motorJoint.CollideConnected = false; _motorJoint.MotorSpeed = _motorSpeed; _motorJoint.MaxMotorTorque = 400f; _motorJoint.MotorEnabled = _motorOn; world.AddJoint(_motorJoint); } Vector2 wheelAnchor = pivot + new Vector2(0f, 0.8f); CreateLegTextures(); CreateLeg(world, -1f, wheelAnchor, 0); CreateLeg(world, 1f, wheelAnchor, 0); _leftLeg.Origin = AssetCreator.CalculateOrigin(_leftLegs[0]); _leftShoulder.Origin = AssetCreator.CalculateOrigin(_leftShoulders[0]); _rightLeg.Origin = AssetCreator.CalculateOrigin(_rightLegs[0]); _rightShoulder.Origin = AssetCreator.CalculateOrigin(_rightShoulders[0]); _wheel.SetTransform(_wheel.Position, 120f * Settings.Pi / 180f); CreateLeg(world, -1f, wheelAnchor, 1); CreateLeg(world, 1f, wheelAnchor, 1); _wheel.SetTransform(_wheel.Position, -120f * Settings.Pi / 180f); CreateLeg(world, -1f, wheelAnchor, 2); CreateLeg(world, 1f, wheelAnchor, 2); }
public Border(World world, PhysicsGameScreen screen, Viewport viewport) { _world = world; _screen = screen; float halfWidth = ConvertUnits.ToSimUnits(viewport.Width) / 2f - 0.75f; float halfHeight = ConvertUnits.ToSimUnits(viewport.Height) / 2f - 0.75f; Vertices borders = new Vertices(4); borders.Add(new Vector2(-halfWidth, halfHeight)); borders.Add(new Vector2(halfWidth, halfHeight)); borders.Add(new Vector2(halfWidth, -halfHeight)); borders.Add(new Vector2(-halfWidth, -halfHeight)); _anchor = BodyFactory.CreateLoopShape(_world, borders); _anchor.CollisionCategories = Category.All; _anchor.CollidesWith = Category.All; _basicEffect = new BasicEffect(_screen.ScreenManager.GraphicsDevice); _basicEffect.VertexColorEnabled = true; _basicEffect.TextureEnabled = true; _basicEffect.Texture = _screen.ScreenManager.Content.Load <Texture2D>("Materials/pavement"); VertexPositionColorTexture[] vertice = new VertexPositionColorTexture[8]; vertice[0] = new VertexPositionColorTexture(new Vector3(-halfWidth, -halfHeight, 0f), Color.LightGray, new Vector2(-halfWidth, -halfHeight) / 5.25f); vertice[1] = new VertexPositionColorTexture(new Vector3(halfWidth, -halfHeight, 0f), Color.LightGray, new Vector2(halfWidth, -halfHeight) / 5.25f); vertice[2] = new VertexPositionColorTexture(new Vector3(halfWidth, halfHeight, 0f), Color.LightGray, new Vector2(halfWidth, halfHeight) / 5.25f); vertice[3] = new VertexPositionColorTexture(new Vector3(-halfWidth, halfHeight, 0f), Color.LightGray, new Vector2(-halfWidth, halfHeight) / 5.25f); vertice[4] = new VertexPositionColorTexture(new Vector3(-halfWidth - 2f, -halfHeight - 2f, 0f), Color.LightGray, new Vector2(-halfWidth - 2f, -halfHeight - 2f) / 5.25f); vertice[5] = new VertexPositionColorTexture(new Vector3(halfWidth + 2f, -halfHeight - 2f, 0f), Color.LightGray, new Vector2(halfWidth + 2f, -halfHeight - 2f) / 5.25f); vertice[6] = new VertexPositionColorTexture(new Vector3(halfWidth + 2f, halfHeight + 2f, 0f), Color.LightGray, new Vector2(halfWidth + 2f, halfHeight + 2f) / 5.25f); vertice[7] = new VertexPositionColorTexture(new Vector3(-halfWidth - 2f, halfHeight + 2f, 0f), Color.LightGray, new Vector2(-halfWidth - 2f, halfHeight + 2f) / 5.25f); _borderVerts = new VertexPositionColorTexture[24]; _borderVerts[0] = vertice[0]; _borderVerts[1] = vertice[5]; _borderVerts[2] = vertice[4]; _borderVerts[3] = vertice[0]; _borderVerts[4] = vertice[1]; _borderVerts[5] = vertice[5]; _borderVerts[6] = vertice[1]; _borderVerts[7] = vertice[6]; _borderVerts[8] = vertice[5]; _borderVerts[9] = vertice[1]; _borderVerts[10] = vertice[2]; _borderVerts[11] = vertice[6]; _borderVerts[12] = vertice[2]; _borderVerts[13] = vertice[7]; _borderVerts[14] = vertice[6]; _borderVerts[15] = vertice[2]; _borderVerts[16] = vertice[3]; _borderVerts[17] = vertice[7]; _borderVerts[18] = vertice[3]; _borderVerts[19] = vertice[4]; _borderVerts[20] = vertice[7]; _borderVerts[21] = vertice[3]; _borderVerts[22] = vertice[0]; _borderVerts[23] = vertice[4]; }
public Border(World world, PhysicsGameScreen screen, Viewport viewport) { _world = world; _screen = screen; float halfWidth = ConvertUnits.ToSimUnits(viewport.Width) / 2f - 0.75f; float halfHeight = ConvertUnits.ToSimUnits(viewport.Height) / 2f - 0.75f; Vertices borders = new Vertices(4); borders.Add(new Vector2(-halfWidth, halfHeight)); borders.Add(new Vector2(halfWidth, halfHeight)); borders.Add(new Vector2(halfWidth, -halfHeight)); borders.Add(new Vector2(-halfWidth, -halfHeight)); _anchor = BodyFactory.CreateLoopShape(_world, borders); _anchor.CollisionCategories = Category.All; _anchor.CollidesWith = Category.All; _basicEffect = new BasicEffect(_screen.ScreenManager.GraphicsDevice); _basicEffect.VertexColorEnabled = true; _basicEffect.TextureEnabled = true; _basicEffect.Texture = _screen.ScreenManager.Content.Load<Texture2D>("Materials/pavement"); VertexPositionColorTexture[] vertice = new VertexPositionColorTexture[8]; vertice[0] = new VertexPositionColorTexture(new Vector3(-halfWidth, -halfHeight, 0f), Color.LightGray, new Vector2(-halfWidth, -halfHeight) / 5.25f); vertice[1] = new VertexPositionColorTexture(new Vector3(halfWidth, -halfHeight, 0f), Color.LightGray, new Vector2(halfWidth, -halfHeight) / 5.25f); vertice[2] = new VertexPositionColorTexture(new Vector3(halfWidth, halfHeight, 0f), Color.LightGray, new Vector2(halfWidth, halfHeight) / 5.25f); vertice[3] = new VertexPositionColorTexture(new Vector3(-halfWidth, halfHeight, 0f), Color.LightGray, new Vector2(-halfWidth, halfHeight) / 5.25f); vertice[4] = new VertexPositionColorTexture(new Vector3(-halfWidth - 2f, -halfHeight - 2f, 0f), Color.LightGray, new Vector2(-halfWidth - 2f, -halfHeight - 2f) / 5.25f); vertice[5] = new VertexPositionColorTexture(new Vector3(halfWidth + 2f, -halfHeight - 2f, 0f), Color.LightGray, new Vector2(halfWidth + 2f, -halfHeight - 2f) / 5.25f); vertice[6] = new VertexPositionColorTexture(new Vector3(halfWidth + 2f, halfHeight + 2f, 0f), Color.LightGray, new Vector2(halfWidth + 2f, halfHeight + 2f) / 5.25f); vertice[7] = new VertexPositionColorTexture(new Vector3(-halfWidth - 2f, halfHeight + 2f, 0f), Color.LightGray, new Vector2(-halfWidth - 2f, halfHeight + 2f) / 5.25f); _borderVerts = new VertexPositionColorTexture[24]; _borderVerts[0] = vertice[0]; _borderVerts[1] = vertice[5]; _borderVerts[2] = vertice[4]; _borderVerts[3] = vertice[0]; _borderVerts[4] = vertice[1]; _borderVerts[5] = vertice[5]; _borderVerts[6] = vertice[1]; _borderVerts[7] = vertice[6]; _borderVerts[8] = vertice[5]; _borderVerts[9] = vertice[1]; _borderVerts[10] = vertice[2]; _borderVerts[11] = vertice[6]; _borderVerts[12] = vertice[2]; _borderVerts[13] = vertice[7]; _borderVerts[14] = vertice[6]; _borderVerts[15] = vertice[2]; _borderVerts[16] = vertice[3]; _borderVerts[17] = vertice[7]; _borderVerts[18] = vertice[3]; _borderVerts[19] = vertice[4]; _borderVerts[20] = vertice[7]; _borderVerts[21] = vertice[3]; _borderVerts[22] = vertice[0]; _borderVerts[23] = vertice[4]; }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputHelper input, GameTime gameTime) { // Mouse or touch on a menu item int hoverIndex = GetMenuEntryAt(input.Cursor); if (hoverIndex > -1 && _menuEntries[hoverIndex].IsSelectable() && !_scrollLock) { _selectedEntry = hoverIndex; } else { _selectedEntry = -1; } _scrollSlider.Hover = false; if (input.IsCursorValid) { _scrollUp.Collide(input.Cursor); _scrollDown.Collide(input.Cursor); _scrollSlider.Collide(input.Cursor); } else { _scrollUp.Hover = false; _scrollDown.Hover = false; _scrollLock = false; } // Accept or cancel the menu? if (input.IsMenuSelect() && _selectedEntry != -1) { if (_menuEntries[_selectedEntry].IsExitItem()) { ScreenManager.Game.Exit(); } else if (_menuEntries[_selectedEntry].Screen == null) { ////////////////////////////////// //Navigate back to our old screen ////////////////////////////////// if (_menuEntries[_selectedEntry].IsNoAction()) { this.ExitScreen(); } ////////////////////////////////// //Resume the game ie Pause Menu ////////////////////////////////// if (_menuEntries[_selectedEntry].IsResumeGame()) { ////////////////// //Resume the music ////////////////// MusicHelper.ResumeSong(); this.ExitScreen(); } ////////////////////////////////// //Restart Game ////////////////////////////////// if (_menuEntries[_selectedEntry].IsRestart()) { GameScreen[] scrs = ScreenManager.GetScreens(); PhysicsGameScreen game = scrs[scrs.Length - 2] as PhysicsGameScreen; game.Reset(); this.ExitScreen(); } ////////////////////////////////// //Go to Next Level ////////////////////////////////// if (_menuEntries[_selectedEntry].IsNextLevel()) { GameScreen[] scrs = ScreenManager.GetScreens(); PhysicsGameScreen game = scrs[scrs.Length - 2] as PhysicsGameScreen; game.NextLevel(); this.ExitScreen(); } ////////////////////////////////// //Navigate back to Main Menu ////////////////////////////////// else if (_menuEntries[_selectedEntry].IsMainMenu()) { GameScreen[] scrs = ScreenManager.GetScreens(); for (int i = scrs.Length - 1; i > 4; i--) { scrs[i].ExitScreen(); } } } ////////////////////////////// //Play Default Music and game ////////////////////////////// else if (_menuEntries[_selectedEntry].Screen != null && _menuEntries[_selectedEntry].IsDefaultMusic()) { PhysicsGameScreen screen = _menuEntries[_selectedEntry].Screen as PhysicsGameScreen; ////////////////////////////////////// //Check whether it is game or Freeplay ////////////////////////////////////// if (_menuType == MenuType.FreePlayLevel) { ////////////////////////// //Force the FreePLay Level //Index plus on becuase //there is no option for //tutorial ////////////////////////// screen.GoToLevel(_selectedEntry + 1, 0); } else { screen.GoToLevel(_selectedEntry, 1); } MusicHelper.SetMusicType(MusicType.Default); ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen); } ////////////////////////////// //Play Custom Music and game ////////////////////////////// else if (_menuEntries[_selectedEntry].Screen != null && _menuEntries[_selectedEntry].IsCustomMusic()) { //MusicHelper.LoadSongFromLibrary(); ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen); } /////////////////////////////////////// //Leave the playing Music and play game /////////////////////////////////////// else if (_menuEntries[_selectedEntry].Screen != null && _menuEntries[_selectedEntry].IsBackgroundMuiscMuisc()) { PhysicsGameScreen mscreen = _menuEntries[_selectedEntry].Screen as PhysicsGameScreen; mscreen.GoToLevel(_selectedEntry, 1); MusicHelper.SetMusicType(MusicType.Background); ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen); } //////////////////////// //MainMenu GameMode Game //////////////////////// else if (_menuEntries[_selectedEntry].Screen != null && _menuEntries[_selectedEntry].IsGameModeGame()) { ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen); } //////////////////////////// //MainMenu GameMode FreePlay //////////////////////////// else if (_menuEntries[_selectedEntry].Screen != null && _menuEntries[_selectedEntry].IsGameModeFreePlay()) { ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen); } ////////////////////////////// //Normal Add Screen ////////////////////////////// else if (_menuEntries[_selectedEntry].Screen != null) { ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen); } /////////////////////// //Use for tutorial /////////////////////// if (_menuEntries[_selectedEntry].Screen is IDemoScreen) { ScreenManager.AddScreen( new MessageBoxScreen((_menuEntries[_selectedEntry].Screen as IDemoScreen).GetDetails())); } } else if (input.IsMenuCancel()) { ////////////////////////// //Main Menu ////////////////////////// if (_menuType == MenuType.MainMenu) { ScreenManager.Game.Exit(); } else if (_menuType != MenuType.MainMenu) { if (_menuType == MenuType.Pause) { MusicHelper.ResumeSong(); } this.ExitScreen(); } } if (input.IsMenuPressed()) { if (_scrollUp.Hover) { _menuOffset = Math.Max(_menuOffset - 200f * (float)gameTime.ElapsedGameTime.TotalSeconds, 0f); _scrollLock = false; } if (_scrollDown.Hover) { _menuOffset = Math.Min((_menuOffset + 200f * (float)gameTime.ElapsedGameTime.TotalSeconds), _maxOffset); _scrollLock = false; } if (_scrollSlider.Hover) { _scrollLock = true; } } if (input.IsMenuReleased()) { _scrollLock = false; } if (_scrollLock) { _scrollSlider.Hover = true; _menuOffset = Math.Max(Math.Min(((input.Cursor.Y - _menuBorderTop) / (_menuBorderBottom - _menuBorderTop)) * _maxOffset, _maxOffset), 0f); } }
public void AddLevelMenuItem(string name, EntryType type, GameScreen screen, PhysicsGameScreen physicsscreen) { MenuEntry entry = new MenuEntry(this, name, type, screen,_menuItemBackground, physicsscreen); _menuEntries.Add(entry); }
public Objects(World world, PhysicsGameScreen screen, Vector2 startPosition, Vector2 endPosition, int count, float radius, ObjectType type) { _bodies = new List <Body>(count); CollidesWith = Category.All; CollisionCategories = Category.All; for (int i = 0; i < count; ++i) { switch (type) { case ObjectType.Circle: _bodies.Add(BodyFactory.CreateCircle(world, radius, 1f)); break; case ObjectType.Rectangle: _bodies.Add(BodyFactory.CreateRectangle(world, radius, radius, 1f)); break; case ObjectType.Star: _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 0f, 1f, 1f)); break; case ObjectType.Gear: _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 100f, 1f, 1f)); break; } } for (int i = 0; i < _bodies.Count; ++i) { Body body = _bodies[i]; body.BodyType = BodyType.Dynamic; body.Position = Vector2.Lerp(startPosition, endPosition, i / (float)(count - 1)); body.Restitution = .7f; body.Friction = .2f; body.CollisionCategories = CollisionCategories; body.CollidesWith = CollidesWith; } _screen = screen; //GFX AssetCreator creator = _screen.ScreenManager.Assets; switch (type) { case ObjectType.Circle: _object = new Sprite(creator.CircleTexture(radius, MaterialType.Dots, Color.DarkRed, 0.8f)); break; case ObjectType.Rectangle: _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(radius / 2f, radius / 2f), MaterialType.Dots, Color.Blue, 0.8f)); break; case ObjectType.Star: _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 0f, 1f), MaterialType.Dots, Color.Yellow, 0.8f)); break; case ObjectType.Gear: _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 100f, 1f), MaterialType.Dots, Color.DarkGreen, 0.8f)); break; } }
public MenuEntry(MenuScreen menu, string text, EntryType type, GameScreen screen, Texture2D texture, PhysicsGameScreen phyisicsscreen) : this(menu, text, type, screen, texture) { _phyisicsGameScreen = phyisicsscreen; }
public PauseMenuScreen(PhysicsGameScreen gameScreen) { this.gameScreen = gameScreen; }
public Objects(World world, PhysicsGameScreen screen, Vector2 startPosition, Vector2 endPosition, int count, float radius, ObjectType type) { _bodies = new List<Body>(count); CollidesWith = Category.All; CollisionCategories = Category.All; for (int i = 0; i < count; ++i) { switch (type) { case ObjectType.Circle: _bodies.Add(BodyFactory.CreateCircle(world, radius, 1f)); break; case ObjectType.Rectangle: _bodies.Add(BodyFactory.CreateRectangle(world, radius, radius, 1f)); break; case ObjectType.Star: _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 0f, 1f, 1f)); break; case ObjectType.Gear: _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 100f, 1f, 1f)); break; } } for (int i = 0; i < _bodies.Count; ++i) { Body body = _bodies[i]; body.BodyType = BodyType.Dynamic; body.Position = Vector2.Lerp(startPosition, endPosition, i / (float)(count - 1)); body.Restitution = .7f; body.Friction = .2f; body.CollisionCategories = CollisionCategories; body.CollidesWith = CollidesWith; } _screen = screen; //GFX AssetCreator creator = _screen.ScreenManager.Assets; switch (type) { case ObjectType.Circle: _object = new Sprite(creator.CircleTexture(radius, MaterialType.Dots, Color.DarkRed, 0.8f)); break; case ObjectType.Rectangle: _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(radius / 2f, radius / 2f), MaterialType.Dots, Color.Blue, 0.8f)); break; case ObjectType.Star: _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 0f, 1f), MaterialType.Dots, Color.Yellow, 0.8f)); break; case ObjectType.Gear: _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 100f, 1f), MaterialType.Dots, Color.DarkGreen, 0.8f)); break; } }
public void AddLevelMenuItem(string name, EntryType type, GameScreen screen, PhysicsGameScreen physicsscreen) { MenuEntry entry = new MenuEntry(this, name, type, screen, _menuItemBackground, physicsscreen); _menuEntries.Add(entry); }
public TheoJansenWalker(World world, PhysicsGameScreen screen, Vector2 position) { _position = position; _motorSpeed = 2.0f; _motorOn = true; _screen = screen; _walkerJoints = new List <DistanceJoint>(); _leftShoulders = new Body[3]; _rightShoulders = new Body[3]; _leftLegs = new Body[3]; _rightLegs = new Body[3]; Vector2 pivot = new Vector2(0f, -0.8f); // Chassis { PolygonShape shape = new PolygonShape(1f); shape.SetAsBox(2.5f, 1.0f); _body = new Sprite(_screen.ScreenManager.Assets.TextureFromShape(shape, MaterialType.Blank, Color.Beige, 1f)); _chassis = BodyFactory.CreateBody(world); _chassis.BodyType = BodyType.Dynamic; _chassis.Position = pivot + _position; Fixture fixture = _chassis.CreateFixture(shape); fixture.CollisionGroup = -1; } { CircleShape shape = new CircleShape(1.6f, 1f); _engine = new Sprite(_screen.ScreenManager.Assets.TextureFromShape(shape, MaterialType.Waves, Color.Beige * 0.8f, 1f)); _wheel = BodyFactory.CreateBody(world); _wheel.BodyType = BodyType.Dynamic; _wheel.Position = pivot + _position; Fixture fixture = _wheel.CreateFixture(shape); fixture.CollisionGroup = -1; } { _motorJoint = new RevoluteJoint(_wheel, _chassis, _wheel.GetLocalPoint(_chassis.Position), Vector2.Zero); _motorJoint.CollideConnected = false; _motorJoint.MotorSpeed = _motorSpeed; _motorJoint.MaxMotorTorque = 400f; _motorJoint.MotorEnabled = _motorOn; world.AddJoint(_motorJoint); } Vector2 wheelAnchor = pivot + new Vector2(0f, 0.8f); CreateLegTextures(); CreateLeg(world, -1f, wheelAnchor, 0); CreateLeg(world, 1f, wheelAnchor, 0); _leftLeg.Origin = AssetCreator.CalculateOrigin(_leftLegs[0]); _leftShoulder.Origin = AssetCreator.CalculateOrigin(_leftShoulders[0]); _rightLeg.Origin = AssetCreator.CalculateOrigin(_rightLegs[0]); _rightShoulder.Origin = AssetCreator.CalculateOrigin(_rightShoulders[0]); _wheel.SetTransform(_wheel.Position, 120f * Settings.Pi / 180f); CreateLeg(world, -1f, wheelAnchor, 1); CreateLeg(world, 1f, wheelAnchor, 1); _wheel.SetTransform(_wheel.Position, -120f * Settings.Pi / 180f); CreateLeg(world, -1f, wheelAnchor, 2); CreateLeg(world, 1f, wheelAnchor, 2); }