/// <summary> /// Luodaan peliin taulukossa olevien koordinaattien kohdalle pienet pallot /// </summary> /// <param name="pisteet">piirrettävien pisteiden koordinaatit</param> /// <param name="r">säde kullekin pisteelle</param> /// <param name="game">peli, johon pisteet lisätään</param> public static void LuoPisteet(PhysicsGame game, Vector[] pisteet, double r) { // TODO: Tehtävä 1 // Ota taulukosta pisteet kukin piste ja luo sitä vastaavaan paikkaan // r-säteinen musta ympyrä. Kutsu alempana olevaa LuoPalloa sopivasti. // Älä luo pisteitä, sillä ne on luotu ArvoPisteet (Tehtävä 2) funktiossa. }
public SceneGameSelection(PhysicsGame physicsGame, Game xnaGame, Type[] sceneClassTypes) { this.physicsGame = physicsGame; this.xnaGame = xnaGame; camera = new CameraMoveable(new Vector3(0, 4, 3), new Vector3(0, 0, 0), Vector3.Up, 0.01f, 4000.0f, (float)xnaGame.Window.ClientBounds.Width / (float)xnaGame.Window.ClientBounds.Height); //Build the menu SpriteFont menuFont = xnaGame.Content.Load <SpriteFont>("Fonts\\info1"); SpriteFont titleFont = xnaGame.Content.Load <SpriteFont>("Fonts\\info2"); //Get from the types of the scene the description string[] sceneDescriptions = new string[sceneClassTypes.Length]; for (int i = 0; i < sceneClassTypes.Length; i++) { FieldInfo fieldInfo = sceneClassTypes[i].GetField("SceneDescription", BindingFlags.Public | BindingFlags.Static); sceneDescriptions[i] = (string)fieldInfo.GetValue(null); } this.Menu = new SimpleSelectMenu(physicsGame.RenderManager.SpriteBatch, menuFont, Color.Red, new Vector2(50, 100), sceneDescriptions); this.Menu.OnSelectedIndexChanged += new EventHandler(Menu_OnSelectedIndexChanged); //Add components cube = new Cube(xnaGame, new Vector3(1, 1, 1), cubeModel, null, false); cube.RigidBody.Position = new Vector3(1, 2, 0); cube.RigidBody.AddTorque(new Vector3(50, 50, 0)); cube2 = new Cube(xnaGame, new Vector3(1, 1, 1), cubeModel, null, false); cube2.RigidBody.Position = new Vector3(2, 0, 0); cube2.RigidBody.AddTorque(new Vector3(-30, 0, -30)); //Title titleText = new Text2d(physicsGame.RenderManager.SpriteBatch, titleFont, new Vector2(10, 10), Color.Red, Text2d.TextAlignment.Left, "wellcome! \nthis a test application\nthat use my simple Physics Engine\nplease select an example scene:"); }
/// <summary> /// Luodaan peliin taulukossa olevien koordinaattien kohdalle pienet pallot /// </summary> /// <param name="pisteet">piirrettävien pisteiden koordinaatit</param> /// <param name="r">säde kullekin pisteelle</param> /// <param name="game">peli, johon pisteet lisätään</param> public static void LuoPisteet(PhysicsGame game, IEnumerable <Vector> pisteet, double r) { foreach (Vector p in pisteet) { LuoPallo(game, p, r, Color.Black); } }
static void Main() { using (var game = new PhysicsGame()) { game.Run(); } }
/// <summary> /// Luodaan pelaaja eli prinsessa /// </summary> /// <param name="Karkkimaa">peli</param> /// <returns></returns> private PhysicsObject LuoPrinsessa(PhysicsGame Karkkimaa) { PhysicsObject prinsessa = Olio(this, PRINSESSANLEVEYS, PRINSESSANKORKEUS, PRINSESSAPAIKKA, PRINSESSAPAIKKA, "prinsessa", false, false, false, 0, "prinsessa", Color.Transparent, Shape.Rectangle, false); return(prinsessa); }
public void LuoNaytot(PhysicsGame peli) { Vector p1 = this.Naytot; //voi yksinkertaistaa this.elamaNaytto = new Label(); elamaNaytto.Font = Font.DefaultSmallBold; elamaNaytto.Position = p1; elamaNaytto.BindTo(this.alus.ElamaLaskuri); elamaNaytto.TextColor = Color.White; elamaNaytto.Title = "Aluksen kunto"; peli.Add(elamaNaytto); this.alusNaytto = new Label(); alusNaytto.Font = Font.DefaultSmallBold; alusNaytto.Position = new Vector(p1.X, p1.Y - 25); alusNaytto.BindTo(this.AlusLaskuri); alusNaytto.TextColor = Color.White; alusNaytto.Title = "Aluksia jäljellä"; peli.Add(alusNaytto); this.ammusNaytto = new Label(); ammusNaytto.Font = Font.DefaultSmallBold; ammusNaytto.Position = new Vector(p1.X, p1.Y - 50); ammusNaytto.BindTo(this.Alus.AmmusLaskuri); ammusNaytto.TextColor = Color.White; ammusNaytto.Title = "Ase1 ammuksia jäljellä"; peli.Add(ammusNaytto); }
public static void RunGame() { game = new PhysicsGame(); // iOS requires a user triggered action to play web audio if (CustomScripts.IsIOS()) { game.Content.OnAllResourceLoaded = () => { game.IsActive = false; Html5.Canvas.Remove(); HTMLButtonElement button = new HTMLButtonElement(); button.InnerHTML = "Activate web audio for iOS"; button.SetAttribute("style", CustomScripts.FullScreenButtonStyle); button.OnClick = (e) => { WebAudioHelper.Activate(); Document.Body.RemoveChild(button); game.IsActive = true; Document.Body.AppendChild(Html5.Canvas); }; Document.Body.AppendChild(button); }; } game.Run(); }
public Alus(PhysicsGame peli, Vector p, double r, Color vari, string tunniste, string pelaaja, int tarkistin) : base(r, r) { this.koko = r; this.Shape = Shape.Circle; this.Position = p; this.Color = vari; this.Mass = 5; this.Restitution = 0.1; this.CanRotate = false; this.Tag = tunniste; this.pelaaja = pelaaja; this.tarkistin = tarkistin; this.ase1.Power.Value = 100000; this.ase1.Power.DefaultValue = 100000; this.ase1.FireRate = 1; this.ase1.CanHitOwner = false; this.ase1.IsVisible = false; this.Add(ase1); this.ase2.Power.Value = 500; this.ase2.Power.DefaultValue = 500; this.ase2.FireRate = 10; this.ase2.CanHitOwner = false; this.ase2.IsVisible = false; this.ase2.Ammo.Value = 20; this.Add(ase2); peli.Add(this); }
public RRShip(PhysicsGame me, double width, double height, int startHP, double scoreValue, Vector spawnPosition, Action<RRShip, PhysicsObject> onCollision, Action<RRShip> updateHPMeter) : base(width, height) { this.Shape = Shape.Diamond; this.Tag = "P"; //It is a player.. this.Health = startHP; this.ScoreValue = scoreValue; this.Position = spawnPosition; this.CanRotate = false; this.Color = Color.Red; this.CollisionIgnoreGroup = 2; this.IgnoresGravity = true; this.IgnoresExplosions = true; // We know what to do this.Add(new GameObject(PhysicsGame.LoadImage("PlayerSprite"))); this.collisionFunc = onCollision; this.updateMeters = updateHPMeter; me.AddCollisionHandler<RRShip, PhysicsObject>(this, collisionHandler); // Call the meter handler just to reinit updateMeters(this); }
public static void Piirrapallo(PhysicsGame peli, double x, double y, double r) //Aliohjelma pallojen piirtämiseen. { PhysicsObject p = new PhysicsObject(2 * r, 2 * r, Shape.Circle); //PhysicsObject ottaa mitat ja muodon, r = säde joten 2*r on halkaisija p.Y = y; p.X = x; peli.Add(p); }
/// <summary> /// Lisätään peliin pallo /// </summary> /// <param name="game">peli johon pallo lisätään</param> /// <param name="p">pallon keskipiste</param> /// <param name="r">pallon säde</param> /// <param name="color">pallon väri</param> /// <returns>lisätyn pallon viite</returns> public static PhysicsObject LuoPallo(PhysicsGame game, Vector p, double r, Color color) { PhysicsObject pallo = new PhysicsObject(r * 2, r * 2, Shape.Circle); pallo.Position = p; pallo.Color = color; game.Add(pallo); return(pallo); }
public override void Init() { physicsExample = new HelloWorldBullet2(); physicsExample.Init(this); UserVars.addVar("MeshCount"); Camara = new TgcRotationalCamera(new TGCVector3(0, 20, 0), 100, Input); }
public static PhysicsObject PiirraNelio(PhysicsGame peli, double x, double y) { PhysicsObject PiirraNelio = new PhysicsObject(80, 80, Shape.Rectangle); PiirraNelio.X = x; PiirraNelio.Y = y; peli.Add(PiirraNelio); return(PiirraNelio); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { physicsGame = new PhysicsGame(this); //asse = new CartesianAxis(this, 1000, Color.Red, Color.Black, Color.Green, physicsGame.Camera); //this.Components.Add(asse); //Basic base.Initialize(); }
public static void PiirraNelio(PhysicsGame peli, double x, double y) { PhysicsObject p = new PhysicsObject(80, 80, Shape.Rectangle, 80); { p.X = x + 40; p.Y = y + 40; peli.Add(p); } }
/// <summary> /// Luo peliin juoman satunnaiseen sijaintiin maaratylla spawnAlueelle. /// </summary> /// <returns>juoma.</returns> /// <param name="peli">Peli johon juoma luodaan.</param> /// <param name="rect">Maaratty alue, johon juoma luodaan.</param> public void LuoJuoma(PhysicsGame peli, BoundingRectangle rect) { PhysicsObject juoma = PhysicsObject.CreateStaticObject(15.0, 30.0); juoma.Shape = Shape.Rectangle; juoma.Color = Color.Red; juoma.Position = RandomGen.NextVector(rect); juoma.Tag = "juoma"; juoma.Image = koff; peli.Add(juoma); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { physicsGame = new PhysicsGame(this); physicsGame.UpdateEnabled = true; boxRadius = 100f; //Basic base.Initialize(); }
/// <summary> /// Aliohjelma, jossa kuvataan pelaajan elämiä. Kun hedelmä menee ohi korista, elämiä vähenee. /// </summary> private PhysicsObject LuoElamat(PhysicsGame peli, double x, double y) { PhysicsObject sydan = new PhysicsObject(25.0, 25.0, Shape.Heart); sydan.Color = Color.Red; sydan.X = x; sydan.Y = y; sydan.CollisionIgnoreGroup = 1; Add(sydan); return(sydan); }
public SceneRigidBodyGravity(PhysicsGame physicsGame, Game xnaGame) : base(physicsGame, xnaGame) { cube = new Cube(xnaGame, new Vector3(1, 1, 1), cubeModel, Color.Red, true); cube.RigidBody.Position = new Vector3(0, 10, 0); //this.physicsGame.RigidBodyWorld.ForceRegistry.Add(cube.RigidBody, new GravityForce(GravityForce.gravityConstant)); //Cube cube2 = new Cube(xnaGame, new Vector3(1, 1, 1), "Models\\CuboTextures", null, false); //cube2.RigidBody.Position = new Vector3(0, 0, 0); //cube2.RigidBody.AddTorque(new Vector3(50, 50, 0)); //this.physicsGame.AddComponent("cube2", cube2); }
public void FireMachinegun(GameModel gameModel, PhysicsGame nivel) { if (timerMachineGun == 0) { var b = new MachinegunBullet(nivel.world, this); b.fire(neg, gameModel.DirectSound.DsDevice); nivel.bullets.Add(b); timerMachineGun += gameModel.ElapsedTime; neg *= -1; } }
/// <summary> /// Aliohjelma luo peliin tippuvan alasimen /// </summary> /// <param name="peli"></param> /// <param name="x">Alasimen sijainti x-akselilla.</param> /// <param name="y">Alasimen sijainti y-akselilla.</param> private void Alasimet(PhysicsGame peli, double x, double y) { PhysicsObject alasin = new PhysicsObject(100, 100, Shape.Rectangle); alasin.Position = new Vector(x, y); alasin.IgnoresCollisionResponse = true; peli.Add(alasin); alasin.LinearDamping = 1.0; alasin.Image = alasinKuva; alasin.Tag = "alasin"; }
public Asteroidi(PhysicsGame peli, Vector p, double r, Color vari, String tunniste) : base(r, r) { this.Shape = Shape.Circle; this.Position = p; this.Color = vari; this.Mass = 10 * r; this.Angle = Angle.FromDegrees(RandomGen.NextDouble(0, 360)); this.Tag = tunniste; this.Restitution = 0.1; this.CanRotate = false; peli.Add(this); }
/// <summary> /// Aliohjelma lisää peliin putoavan laatan. /// </summary> /// <param name="peli"></param> /// <param name="x">Laatan sijainti x-akselilla.</param> /// <param name="y">Laatan sijainti y-akselilla.</param> /// <param name="z">Laatan leveys.</param> private void PiirraSuorakulmio(PhysicsGame peli, double x, double y, double z) { suorakulmio = new PhysicsObject(z, 15, Shape.Rectangle); suorakulmio.Position = new Vector(x, y); int kuva = RandomGen.NextInt(laatat.Length); suorakulmio.Image = laatat[kuva]; suorakulmio.LinearDamping = 0.75; suorakulmio.Mass = 100000; peli.Add(suorakulmio); suorakulmio.Tag = "laatta"; suorakulmio.CanRotate = false; }
/// <summary> /// Aliohjelma palauttaa pelimerkin taulukosta. /// </summary> /// <param name="peli"></param> /// <param name="x">Pelimerkin sijainti x-akselilla.</param> /// <param name="y">Pelimerkin sijainti y-akselilla.</param> private void Pelimerkit(PhysicsGame peli, double x, double y) { PhysicsObject pelimerkki = new PhysicsObject(35, 25, Shape.Rectangle); pelimerkki.Position = new Vector(x, y); pelimerkki.IgnoresCollisionResponse = true; peli.Add(pelimerkki); pelimerkki.LinearDamping = 0.9; pelimerkki.Tag = "pelimerkki"; int kuva = RandomGen.NextInt(pelimerkit.Length); pelimerkki.Image = pelimerkit[kuva]; }
public static PhysicsObject Karkit(PhysicsGame peli) { PhysicsObject karkki = new PhysicsObject(35, 35); karkki.Color = Color.Blue; peli.Add(karkki); karkki.Y = 10; karkki.X = 10; Vector suunta = RandomGen.NextVector(400, 500); karkki.Hit(suunta); karkki.Image = LoadImage("karkkiHR"); return(karkki); }
public static PhysicsObject Kynat(PhysicsGame peli) { PhysicsObject kyna = new PhysicsObject(20, 40); kyna.Color = Color.Red; peli.Add(kyna); kyna.Y = 100; kyna.X = 100; Vector suunta = RandomGen.NextVector(100, 200); kyna.Hit(suunta); return(kyna); }
public void TakeAction(GameModel gameModel, PhysicsGame nivel) { // Chequea y actualiza el status del Salto CheckJumpStatus(gameModel); //reseteo todo ResetBrake(); ResetSteering(); ResetEngineForce(); TurboOff(); ia.ShootMachineGun = false; ia.ShootSpecialWeapon = false; ia.TakeAction(this, gameModel, nivel); }
public void FireWeapon(GameModel gameModel, PhysicsGame nivel, Weapon SelectedWeapon) { if (SelectedWeapon != null) { Bullet b = null; switch (SelectedWeapon.Name) { case "Power Missile": b = new PowerMissile(nivel.world, this); break; } b.fire(gameModel.DirectSound.DsDevice); SelectedWeapon.Ammo--; nivel.bullets.Add(b); this.ReassignWeapon(); } }
public BasicGameScene(PhysicsGame physicsGame, Game xnaGame) { this.physicsGame = physicsGame; this.xnaGame = xnaGame; Mouse.SetPosition(xnaGame.Window.ClientBounds.Width / 2, xnaGame.Window.ClientBounds.Height / 2); //Camera CameraMoveable camera = new CameraMoveable(new Vector3(0, 8, 12), new Vector3(0, 0, 0), Vector3.Up, 0.01f, 4000.0f, (float)xnaGame.Window.ClientBounds.Width / (float)xnaGame.Window.ClientBounds.Height); fpsCameraMover = new FPSCameraMover(xnaGame, camera); physicsGame.ActiveCamera = camera; //Cartesian Axis cartesianAxis = new CartesianAxis(xnaGame.GraphicsDevice, 1000, Color.Red, Color.Black, Color.Green, physicsGame.ActiveCamera); }
public static PhysicsObject LuoNelikulmio(PhysicsGame peli, string tunniste, double x, double y) { PhysicsObject ukko = new PhysicsObject(70, 100, Shape.Rectangle); ukko.Color = Color.Black; ukko.Tag = tunniste; // ukko.Mass = 1.0; peli.Add(ukko); ukko.LinearDamping = 0.93; ukko.Restitution = 0; ukko.AngularDamping = 0.9; ukko.MaxVelocity = 40000; ukko.X = x; ukko.Y = y; return(ukko); }
public static PhysicsObject LuoNelikulmio(PhysicsGame peli, string tunniste) { PhysicsObject ukko = new PhysicsObject(70, 100, Shape.Rectangle); ukko.Color = Color.Black; // Vector suunta = new Vector(vauhti, vauhti); // ukko.Hit(suunta); ukko.Tag = tunniste; // ukko.Mass = 1.0; peli.Add(ukko); ukko.LinearDamping = 0.93; ukko.Restitution = 0; ukko.AngularDamping = 0.9; ukko.MaxVelocity = 40000; return(ukko); }
/// <summary> /// Creates a new RREnemy /// </summary> /// <param name="x">XPosition</param> /// <param name="y">YPosition</param> /// <param name="gameObject">Game object</param> /// <param name="shootingInterval">How often this object shall shoot?</param> /// <param name="onColl">Collision handler</param> public RREnemy(double x, double y, PhysicsGame gameObject, double shootingInterval, Action<PhysicsObject, PhysicsObject> onColl) : this(x, y) { thisGame = gameObject; this.shootingInterval = shootingInterval; this.onCollision = onColl; weapon = new RRWeapon(20, 20, true, 50.0, 10.0); weapon.randomizedAngleSlate = 10; this.Add(weapon); createShooterDelegates(); RampageRebellion.getGame().AddCollisionHandler<RREnemy, PhysicsObject>(this, collisionOnBorders); SoundEffect EnemyShot = Jypeli.Game.LoadSoundEffect("BlankSound"); weapon.projectileGenerator.ignoresCollisionResponse = true; weapon.projectileGenerator.shotSound = EnemyShot; weapon.ProjectileCollision = projectileCollisionHandler; }