Ejemplo n.º 1
0
        public StarlingGameSpriteWithTank()
        {
            var textures = new StarlingGameSpriteWithTankTextures(new_texsprite_crop);

            this.autorotate = true;

            this.onbeforefirstframe += delegate
            {
                // this will be called once.



                // 12 FPS
                //var c = 64;

                // 60 FPS
                // ios 17FPS ?
                //var c = 20;

                // ios8 60FPS!
                var c = 10;

                for (int i = 0; i < c; i++)
                {
                    for (int yi = 0; yi < c; yi++)
                    {
                        var rot = random.NextDouble() * Math.PI;

                        var tank1 = new VisualTank(textures, this);


                        // setting up some randomization
                        tank1.SetPositionAndAngle(i * 128, yi * 128, rot);

                        // this will be called a lot.
                        onframe += delegate
                        {
                            tank1.Animate(1);
                        };
                    }
                }
            };
        }
Ejemplo n.º 2
0
        public PhysicalTank(StarlingGameSpriteWithTankTextures textures, StarlingGameSpriteWithPhysics Context)
        {
            this.CurrentInput = new KeySample();

            this.textures = textures;
            this.Context = Context;
            this.driverseat = new DriverSeat();
            this.visual = new VisualTank(textures, Context);

            for (int i = 0; i < 7; i++)
            {
                this.KarmaInput0.Enqueue(
                    new KeySample()
                );
            }


            #region b2world



            {
                var bodyDef = new b2BodyDef();

                bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;

                // stop moving if legs stop walking!
                bodyDef.linearDamping = 1.0;
                bodyDef.angularDamping = 8;
                //bodyDef.angle = 1.57079633;
                //bodyDef.fixedRotation = true;

                body = Context.ground_b2world.CreateBody(bodyDef);
                //current = body;


                var fixDef = new Box2D.Dynamics.b2FixtureDef();
                fixDef.density = 0.1;
                fixDef.friction = 0.01;
                fixDef.restitution = 0;

                var fixdef_shape = new b2PolygonShape();

                fixDef.shape = fixdef_shape;

                // physics unit is looking to right
                fixdef_shape.SetAsBox(3, 2);



                var fix = body.CreateFixture(fixDef);

                var fix_data = new Action<double>(
                    jeep_forceA =>
                    {
                        if (jeep_forceA < 1)
                            return;

                        Context.oncollision(this, jeep_forceA);
                    }
                );
                fix.SetUserData(fix_data);
            }


            {
                var bodyDef = new b2BodyDef();

                bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;

                // stop moving if legs stop walking!
                bodyDef.linearDamping = 1.0;
                bodyDef.angularDamping = 8;
                //bodyDef.angle = 1.57079633;
                //bodyDef.fixedRotation = true;

                karmabody = Context.groundkarma_b2world.CreateBody(bodyDef);
                //current = body;


                var fixDef = new Box2D.Dynamics.b2FixtureDef();
                fixDef.density = 0.1;
                fixDef.friction = 0.01;
                fixDef.restitution = 0;

                var fixdef_shape = new b2PolygonShape();

                fixDef.shape = fixdef_shape;

                // physics unit is looking to right
                fixdef_shape.SetAsBox(3, 2);



                var fix = karmabody.CreateFixture(fixDef);
            }


            #endregion

            #region b2world



            {
                var bodyDef = new b2BodyDef();

                bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;

                // stop moving if legs stop walking!
                bodyDef.linearDamping = 1.0;
                bodyDef.angularDamping = 8;
                //bodyDef.angle = 1.57079633;
                //bodyDef.fixedRotation = true;

                damagebody = Context.damage_b2world.CreateBody(bodyDef);
                //current = body;


                var fixDef = new Box2D.Dynamics.b2FixtureDef();
                fixDef.density = 0.1;
                fixDef.friction = 0.01;
                fixDef.restitution = 0;

                var fixdef_shape = new b2PolygonShape();

                fixDef.shape = fixdef_shape;

                // physics unit is looking to right
                fixdef_shape.SetAsBox(3, 2);



                var fix = damagebody.CreateFixture(fixDef);

                var fix_data = new Action<double>(
                    jeep_forceA =>
                    {
                        if (jeep_forceA < 1)
                            return;

                        Context.oncollision(this, jeep_forceA);
                    }
                );
                fix.SetUserData(fix_data);
            }



            #endregion


            Context.internalunits.Add(this);


        }