public void CollisionComparison() { CollisionDictionary d = new CollisionDictionary(); List<PhysicalObject2D> allSprites = new List<PhysicalObject2D>(); for (int i=0; i<1000000; i++) { Sprite s = new Sprite(this, "blocky"); s.Size = new Vector2(10); s.Position = i * s.Size; d.Add(s.Bounds); allSprites.Add(s); } Sprite firstSprite = new Sprite(this, "blocky"); firstSprite.Size = new Vector2(50); firstSprite.Position = new Vector2(300); allSprites.Add(firstSprite); Stopwatch sw = Stopwatch.StartNew(); DoConventionalCollisionCheck(firstSprite, allSprites); Console.WriteLine(sw.ElapsedMilliseconds); sw = Stopwatch.StartNew(); d.CalculateCollisions(firstSprite.Bounds); Console.WriteLine(sw.ElapsedMilliseconds); }
//List<Sprite> _menuElements; public PauseMenu(TheGame game) { _background = new Sprite(this, "pause", new Vector2(0, 0), new Vector2(300, 400)); _resume = new Button("button", "Resume", Color.Cyan, new Vector2(0, 0), new Vector2(150, 40), this); _controls = new Button("button", "Controls", Color.Orange, new Vector2(0, 0), new Vector2(150, 40), this); _restart = new Button("button", "Restart", Color.Lime, new Vector2(0, 0), new Vector2(150, 40), this); _mainMenu = new Button("button", "Main Menu", Color.Yellow, new Vector2(0, 0), new Vector2(150, 40), this); _quit = new Button("button","Quit",Color.Red, new Vector2(0, 0), new Vector2(150, 40), this); MenuElements = new List<Sprite>(); MenuElements.Add(_background); MenuElements.Add(_resume); MenuElements.Add(_restart); MenuElements.Add(_mainMenu); MenuElements.Add(_controls); MenuElements.Add(_quit); _background.Color = Color.White; _resume.AddOnClickListener(Resume); _controls.AddOnClickListener(Menu.MainMenu.goToChildMenu, "mainControls"); _quit.AddOnClickListener(game.Exit); _restart.AddOnClickListener(game.LoadLevel); _mainMenu.AddOnClickListener(OpenMainMenu); Id = "pause"; InputManager.AddKeyboardCallback(Keys.Escape, Pause, InputManager.InputState.OnInputDown, null, true); InputManager.AddKeyboardCallback(Keys.Escape, Resume, InputManager.InputState.OnInputDown, this, true); Active = true; for (int i = 0; i < MenuElements.Count; i++) MenuElements[i].LayerDepth = 0.29f - i / 100; }
public Sprite CreateLimp(Limb limb, Character character) { Sprite result = new Sprite( parent: character, textureId: limb.TextureId, size: limb.Size, collidable: false, elasticity: 0); result.RotationAngle = limb.RotationAngle; result.RotationOrigin = limb.RotationOrigin; result.LayerDepth = limb.LayerDepth; character.Add(result, limb.Position); return result; }
private void makeBody() { Body = new Sprite(this, "ebody", new Vector2(0, 13), new Vector2(15, 21), false, 0); Add(Body, new Vector2(0, 13)); Head = new Sprite(this, "ehead", new Vector2(0, 0), new Vector2(17, 18), false, 0); Head.RotationAngle = 0f; Head.RotationOrigin = new Vector2(8, 16); Add(Head, new Vector2(0, 0)); LeftLeg = new Sprite(this, "eleftleg", new Vector2(1, 31), new Vector2(9, 15), false, 0); LeftLeg.RotationAngle = 0f; LeftLeg.RotationOrigin = new Vector2(5, 0); Add(LeftLeg, new Vector2(1, 31)); RightLeg = new Sprite(this, "erightleg", new Vector2(5, 31), new Vector2(9, 15), false, 0); RightLeg.RotationAngle = 0f; RightLeg.RotationOrigin = new Vector2(5, 0); Add(RightLeg, new Vector2(5, 31)); LeftArm = new Sprite(this, "eleftarm", new Vector2(0, 16), new Vector2(3, 18), false, 0); LeftArm.RotationAngle = 0f; LeftArm.RotationOrigin = new Vector2(1.5f, 1); Add(LeftArm, new Vector2(0, 18)); if (Difficulty != -1) { Weapon = new Weapons.Knife(this, (World)Parent, Color.Red); } }
public void MovableBehaviourTest() { Sprite c = new Sprite(this, "test"); c.Size = new Vector2(10); c.Position = new Vector2(2); c.Velocity = new Vector2(2); c.Acceleration = new Vector2(0); c.MovableBehaviour = new MovableBehaviour(); GameTime g = new GameTime(); g.ElapsedGameTime = TimeSpan.FromMilliseconds(100); c.Update(g); float newPosition = 2 + 0.2f * World.PixelsPerMeter; Assert.AreEqual(new Vector2(newPosition), c.Position); c.Acceleration = new Vector2(1); c.Update(g); float newSpeed = 2 + 0.1f * World.PixelsPerMeter; Assert.AreEqual(new Vector2(newSpeed), c.Velocity); Assert.AreEqual(new Vector2(newPosition + newSpeed), c.Position); }
public void WeldTest() { Sprite sa = new Sprite(this, "test"); sa.Position = new Vector2(0); sa.Velocity = new Vector2(2); sa.Acceleration = new Vector2(2); sa.MovableBehaviour = new MovableBehaviour(); Sprite sw = new Sprite(this, "test"); WeldBehaviour wb = new WeldBehaviour(); wb.AnchorObject = sa; wb.WeldOrigin = new Vector2(0); sw.MovableBehaviour = wb; GameTime g = new GameTime(); g.ElapsedGameTime = TimeSpan.FromMilliseconds(100); sa.Update(g); sa.Update(g); sa.Update(g); sw.Update(g); sw.Update(g); sw.Update(g); Assert.AreEqual(sa.Position, sw.Position); }