コード例 #1
0
        public Car(Vector2 position, GameContent gameContent, World world)
        {
            this.world = world;
            this.gameContent = gameContent;

            BodyDef bd = new BodyDef();
            bd.position = position / gameContent.Scale;
            bd.type = BodyType.Dynamic;
            bd.bullet = true;

            body = world.CreateBody(bd);
            body.SetLinearDamping(1f); body.SetAngularDamping(0.1f);

            float width = gameContent.playerCar.Width, height = gameContent.playerCar.Height;

            FixtureDef fd = new FixtureDef();
            fd.density = 0.1f;
            //fd.restitution = .1f;

            CircleShape cs = new CircleShape();
            cs._p = new Vector2(0, -(height - width / 2)) / gameContent.Scale;
            cs._radius = width / 2 / gameContent.Scale;
            fd.shape = cs; body.CreateFixture(fd);

            PolygonShape ps = new PolygonShape();
            ps.SetAsBox(width / 2 / gameContent.Scale, (height - width / 2) / 2 / gameContent.Scale,
                new Vector2(0, -(height - width / 2) / 2) / gameContent.Scale, 0);
            fd.shape = ps; body.CreateFixture(fd);

            CreateWheels();
        }
コード例 #2
0
        public Tutorial(GameContent gameContent, World world)
            : base(gameContent, world)
        {
            instructions = gameContent.content.Load<List<string>>("Levels/tutorial");

            NextMsg();
        }
コード例 #3
0
        public Player(GameContent gameContent, World world, Vector2 position)
        {
            this.gameContent = gameContent;
            this.world = world;

            idle = new Animation(gameContent.playerIdle, 2, 2f, true, new Vector2(0.5f));
            walk = new Animation(gameContent.playerWalk, 2, 0.2f, true, new Vector2(0.5f));
            die = new Animation(gameContent.playerDie, 2, 0.2f, false, new Vector2(0.5f));

            animationPlayer.PlayAnimation(idle);

            BodyDef bd = new BodyDef();
            bd.position = position / gameContent.b2Scale;
            bd.type = BodyType.Dynamic;
            bd.linearDamping = 10;
            body = world.CreateBody(bd);

            CircleShape cs = new CircleShape();
            cs._radius = (float)(idle.FrameWidth - 1) / gameContent.b2Scale / 2;
            FixtureDef fd = new FixtureDef();
            fd.shape = cs;
            fd.filter.groupIndex = -1;

            body.CreateFixture(fd);
        }
コード例 #4
0
        public Apple(Fixture connectedFixture, GameContent gameContent, World world)
        {
            this.world = world;
            this.gameContent = gameContent;
            texture = gameContent.apple;

            fallenFromAir = false;

            CreatBody();

            State = LeafState.Grow;

            if (connectedFixture != null)
            {
                this.connectedFixture = connectedFixture;
                AABB aabb; connectedFixture.GetAABB(out aabb);
                body.Position = aabb.GetCenter();

                RevoluteJointDef rjd = new RevoluteJointDef();
                rjd.bodyA = body;
                rjd.bodyB = connectedFixture.GetBody();

                rjd.localAnchorA = Vector2.Zero;
                rjd.localAnchorB = connectedFixture.GetBody().GetLocalPoint(body.Position);

                revoJoint = (RevoluteJoint)world.CreateJoint(rjd);
            }
        }
コード例 #5
0
        public Level(GameContent gameContent)
        {
            world = new World(atomGravity, false);
            this.gameContent = gameContent;

            if (gameContent.levelIndex == -1) this.isLAB = true;

            camera = new Camera2D(gameContent.viewportSize, false);

            if (!isLAB) LoadLevelComponent();
            else
            {
                labComponent = new LabComponent(gameContent, world);
                editMode = true;
                world.Gravity = equipGravity;
                camera.Scale = targetScale = scale = labComponent.EqScale;
                camera.Position = new Vector2(labComponent.Width, labComponent.Height) / 2;
                camera.Speed = 15;
                camera.ScrollBar = new Vector2(100, 50);
                camera.ScrollWidth = labComponent.Width;
                camera.ScrollHeight = labComponent.Height;
            }

            mouseGroundBody = world.CreateBody(new BodyDef());
        }
コード例 #6
0
        public Soldier(Shape shape, Vector2 position, GameContent gameContent, World world)
        {
            this.gameContent = gameContent;
            this.world = world;

            idle = new Animation(gameContent.idle[(int)shape], 20f, false);
            walk = new Animation(gameContent.walk[(int)shape], 0.15f, true);
            animationPlayer.PlayAnimation(idle);

            MaxHealth = 10; health = gameContent.random.Next(2, 10);
            MaxReloadTime = gameContent.random.Next(50); reloadTime = 0;

            CircleShape cShape = new CircleShape();
            cShape._radius = (Size + 2) / 2 / gameContent.b2Scale;

            BodyDef bd = new BodyDef();
            bd.fixedRotation = true;
            bd.type = BodyType.Dynamic;
            bd.position = position / gameContent.b2Scale;
            body = world.CreateBody(bd);
            //body.SetLinearDamping(10);

            FixtureDef fd = new FixtureDef();
            fd.shape = cShape;
            fd.restitution = 0.5f;
            fd.friction = .1f;
            fd.density = .1f;

            body.CreateFixture(fd);
            body.SetUserData(this);
        }
コード例 #7
0
        public Enemy(World world, GameContent gameContent, int index, Vector2 position)
        {
            this.gameContent = gameContent;

            walk = new Animation(gameContent.enemy[index], 2, 0.15f, true, new Vector2(0.5f));
            animationPlayer.PlayAnimation(walk);

            if (index == 0) linearImpulse = 1f / 2;
            else linearImpulse = 0.75f / 2;

            BodyDef bd = new BodyDef();
            bd.position = position / gameContent.b2Scale;
            bd.type = BodyType.Dynamic;
            bd.linearDamping = 10;
            body = world.CreateBody(bd);

            CircleShape cs = new CircleShape();
            cs._radius = (float)(walk.FrameWidth - 1) / gameContent.b2Scale / 2;
            FixtureDef fd = new FixtureDef();
            fd.shape = cs;
            fd.filter.groupIndex = -1;

            body.CreateFixture(fd);
            body.SetUserData(this);
        }
コード例 #8
0
        public Level(ScreenManager screenManager, int levelIndex)
        {
            this.gameContent = screenManager.GameContent;
            this.levelIndex = levelIndex;

            Load();
        }
        public RadiationSmoke(GameContent gameContent, Atom atom)
        {
            this.gameContent = gameContent;
            this.atom = atom;

            for (int i = 0; i < MaxParticle; i++)
                particlePos[i] = MaxParticlePos / (MaxParticle - 1) * i;
        }
コード例 #10
0
 public Block(GameContent gameContent, MDGoal goal, int number, Vector2 position)
 {
     this.gameContent = gameContent;
     this.Goal = goal;
     this.position = position;
     this.number = number;
     Bounds = new Rectangle((int)position.X, (int)position.Y, Tile.Width, Tile.Width);
 }
コード例 #11
0
        public Block(GameContent gameContent, Vector2 position, char number)
        {
            this.position = oriPosition = position;
            BlockNumber = number >= 'a' ? number - 'a' + 10 : number - '0';
            State = BlockState.Ground;
            IsActive = false;

            this.gameContent = gameContent;
        }
コード例 #12
0
        public static void DrawBond(SpriteBatch spriteBatch, GameContent gameContent,
            Vector2 a, Vector2 b, int numberOfBonds)
        {
            float scale = Vector2.Distance(a, b) / (gameContent.bondOrigin[numberOfBonds].X * 2);
            float rotation = (float)Math.Atan((b.Y - a.Y) / (b.X - a.X));

            spriteBatch.Draw(gameContent.bond[numberOfBonds], (a + b) / 2, null, Color.White, rotation,
                gameContent.bondOrigin[numberOfBonds], new Vector2(scale, 1), SpriteEffects.None, 1);
        }
コード例 #13
0
        public Apple(Vector2 position, Body ground, GameContent gameContent, World world)
            : this(null, gameContent, world)
        {
            this.ground = ground;
            body.Position = position;
            originalPostion = position;
            State = LeafState.Drop;

            fallenFromAir = true;
        }
コード例 #14
0
        public Level(GameContent gameContent, int levelIndex, int previousScore)
        {
            GameContent = gameContent;

            LevelIndex = levelIndex;
            PreviousScore = previousScore;
            Score = 0;

            LoadTiles(levelIndex);
        }
コード例 #15
0
        public Level(ScreenManager screenManager, int levelIndex)
        {
            this.gameContent = screenManager.GameContent;
            this.levelIndex = levelIndex;

            for (int i = 0; i < GameContent.MaxGoals; i++)
                blockNumber[i] = gameContent.random.Next(gameContent.blockCount[i]);

            LoadBlocks(levelIndex);
        }
コード例 #16
0
        public Level(ScreenManager screenManager, int levelIndex)
        {
            this.gameContent = screenManager.GameContent;
            this.levelIndex = levelIndex;

            LoadTiles(levelIndex);

            if (blocks.Count == 4) timeBonus = 10;
            if (blocks.Count == 9) timeBonus = 20;
            if (blocks.Count == 16) timeBonus = 30;
        }
コード例 #17
0
        public Tutorial(GameContent gameContent, World world)
            : base(gameContent, world)
        {
            #if WINDOWS
            instructions = gameContent.content.Load<List<string>>("Levels/tutorial");
            #endif
            #if WINDOWS_PHONE
            instructions = gameContent.content.Load<List<string>>("Levels/tutorialPhone");
            #endif

            NextMsg();
        }
コード例 #18
0
ファイル: Level.cs プロジェクト: BitSits/BitSits-Framework-10
        public Level(ScreenManager screenManager, int levelIndex)
        {
            this.gameContent = screenManager.GameContent;
            this.levelIndex = levelIndex;

            basicEffect = new BasicEffect(screenManager.GraphicsDevice);
            basicEffect.VertexColorEnabled = true;

            //Render._device = screenManager.GraphicsDevice;
            //Render._batch = screenManager.SpriteBatch;
            //Render._font = debugFont;
        }
コード例 #19
0
        public leaf(Fixture fixture, float rotation, int index, GameContent gameContent)
        {
            this.gameContent = gameContent;
            this.connectedFixture = fixture;
            this.rotation = rotation / 180 * (float)Math.PI;
            oriRotation = this.rotation;

            AABB aabb; fixture.GetAABB(out aabb);
            position = aabb.GetCenter();

            texture = gameContent.leaves[index];
        }
コード例 #20
0
        // For Tutorial Level
        public Formula(string strFormula, Vector2 position, GameContent gameContent)
        {
            this.position = position;
            this.gameContent = gameContent;

            this.strFormula = strFormula;

            time = float.NegativeInfinity;

            charSize = 20;
            SetPos();
        }
コード例 #21
0
        public Castle(GameContent gameContent, Shape shape, Vector2 tileCenter)
        {
            this.Shape = shape;
            this.gameContent = gameContent;

            this.position = tileCenter;

            int halfSize = Tile.Width / 2;
            BoundingRectangle = new Rectangle((int)position.X - halfSize, (int)position.Y - halfSize,
                2 * halfSize, 2 * halfSize);

            AttackRectangle = BoundingRectangle; AttackRectangle.Inflate(200, 600);
        }
コード例 #22
0
        public Asteroid(GameContent gameContent, int index, Body body)
        {
            this.gameContent = gameContent;
            tex = gameContent.asteroid[index];
            this.body = body;
            body.SetUserData(this);
            originalPosition = body.Position;

            for (int i = 0; i < 5; i++)
                blastTex[i] = gameContent.asteroid[(index + i) % 16];

            blastSound = gameContent.boom[index % 3];
            blastSoundInstance = blastSound.CreateInstance();
            blastSoundInstance.Volume = 0.8f;
        }
コード例 #23
0
        public Level(GameContent gameContent, int levelIndex)
        {
            this.gameContent = gameContent;
            this.levelIndex = levelIndex;

            LoadTiles(levelIndex);
            //LoadGround();

            car = new Car(new Vector2(-200), gameContent, world);

            camera = new Camera2D(gameContent.viewportSize, false);
            camera.Position = gameContent.viewportSize / 2;
            camera.Origin = new Vector2(400, 550);
            camera.Scale = .6f;
        }
コード例 #24
0
        public Atom(Symbol symbol, Vector2 position, GameContent gameContent, World world)
        {
            this.gameContent = gameContent;
            this.world = world;

            if (symbol == Symbol.Ra) eye = EyeState.Angry;

            this.symbol = symbol;
            this.symbolStr = symbol.ToString();
            symbolCenter = gameContent.symbolFont.MeasureString(this.symbolStr);
            symbolCenter.X *= 0.5f;
            symbolCenter.Y *= 0.92f;

            bondsLeft = (int)symbol;

            BodyDef bd = new BodyDef();
            bd.type = BodyType.Dynamic;
            bd.position = this.position = position / gameContent.b2Scale;
            bd.bullet = true;
            body = world.CreateBody(bd);
            body.SetUserData(this);

            CircleShape cs = new CircleShape();
            cs._radius = gameContent.atomRadius / gameContent.b2Scale;

            FixtureDef fd = new FixtureDef();
            fd.shape = cs;
            fd.restitution = 0.2f;
            fd.friction = 0.5f;

            fixture = body.CreateFixture(fd);

            electroShockAnimation = new Animation(gameContent.electroShock, 3, 0.1f, true, new Vector2(0.5f, 0.5f));

            radiationSmoke = new RadiationSmoke(gameContent, this);

            // Collide only with Ground but not with itself and bonded Filter
            mouseFilter = new Filter();
            mouseFilter.categoryBits = 0x0002; mouseFilter.maskBits = 0x0001; mouseFilter.groupIndex = -2;

            // Collide with every thing
            atomFilter = new Filter();
            atomFilter.categoryBits = 0x0001; atomFilter.maskBits = 0x0001; atomFilter.groupIndex = 1;

            fixture.SetFilterData(ref atomFilter);

            SetMode(false, false);
        }
コード例 #25
0
        public Level(GameContent gameContent, int levelIndex, int score)
        {
            GameContent = gameContent;

            LevelIndex = levelIndex;
            Score = score;

            LoadGround();

            LoadShip();

            LoadAsteroidField((int)asteroidsCount);

            engineInstance = gameContent.engine.CreateInstance();
            engineInstance.IsLooped = true;
            engineInstance.Volume = 0.65f;
        }
コード例 #26
0
ファイル: Asteroid.cs プロジェクト: hixio-mh/Speedy-Crash
        public Asteroid(GameContent gameContent, int index, Body body)
        {
            this.gameContent = gameContent;
            tex       = gameContent.asteroid[index];
            this.body = body;
            body.SetUserData(this);
            originalPosition = body.Position;

            for (int i = 0; i < 5; i++)
            {
                blastTex[i] = gameContent.asteroid[(index + i) % 16];
            }

            blastSound                = gameContent.boom[index % 3];
            blastSoundInstance        = blastSound.CreateInstance();
            blastSoundInstance.Volume = 0.8f;
        }
コード例 #27
0
        public Level(GameContent gameContent, int levelIndex, int score)
        {
            GameContent = gameContent;

            LevelIndex = levelIndex;
            Score      = score;

            LoadGround();

            LoadShip();

            LoadAsteroidField((int)asteroidsCount);

            engineInstance          = gameContent.engine.CreateInstance();
            engineInstance.IsLooped = true;
            engineInstance.Volume   = 0.65f;
        }
コード例 #28
0
        public override void LoadContent()
        {
            gameContent = ScreenManager.GameContent;

            //titleString = "High\nScores";
            titleTexture = gameContent.highScores;
            //titlePosition = new Vector2(20, 20);

            highScores = BitSitsGames.ScoreData.HighScores;
            spriteBatch = ScreenManager.SpriteBatch;

            MenuEntry exitMenuEntry = new MenuEntry(this, "Back", new Vector2(60, 360));

            exitMenuEntry.Selected += OnCancel;

            MenuEntries.Add(exitMenuEntry);
        }
        public LevelComponent(GameContent gameContent, World world)
        {
            this.gameContent = gameContent;
            this.world = world;

            levelData = gameContent.content.Load<LevelData>("Levels/level" + gameContent.levelIndex);

            MaxAtoms = levelData.MaxAtoms;

            int totalProbability = 0;
            for (int i = 0; i < levelData.AtomProbability.Length; i++) totalProbability += levelData.AtomProbability[i];

            if (totalProbability != 100) throw new Exception("must be 100");

            entryPoint = levelData.Entry;

            bonusType = levelData.BonusType;

            BodyDef bd = new BodyDef();
            Body ground = world.CreateBody(bd);

            PolygonShape ps = new PolygonShape();

            List<Vector2> v = levelData.ContinuousBoundry;
            for (int i = 0; i < v.Count - 1; i++)
            {
                if (v[i + 1].X == -1 && v[i + 1].Y == -1) { i++; continue; }

                ps.SetAsEdge(v[i] / gameContent.scale, v[i + 1] / gameContent.scale);
                ground.CreateFixture(ps, 0);
            }

            for (int i = 0; i < levelData.EquipmentDetails.Count; i++)
            {
                Equipment eq = new Equipment(levelData.EquipmentDetails[i].EquipmentName, gameContent, world);
                eq.body.Position = levelData.EquipmentDetails[i].Position / gameContent.scale;
                eq.body.Rotation = levelData.EquipmentDetails[i].RotationInDeg / 180 * (float)MathHelper.Pi;
                eq.isClamped = levelData.EquipmentDetails[i].IsClamped;
                eq.body.SetType(BodyType.Static);
                equipments.Add(eq);

                if (eq.equipName == EquipmentName.thermometer) thermometer = eq;

                if (eq.equipName == EquipmentName.pHscale) pHscale = eq;
            }
        }
コード例 #30
0
        public LabComponent(GameContent gameContent, World world)
        {
            this.gameContent = gameContent;

            EqScale = 0.4f; AtomScale = 0.7f;

            Width = (int)(gameContent.viewportSize.X * 2 / EqScale);
            Height = (int)(gameContent.viewportSize.Y * 1 / EqScale);

            gameContent.clampDistance = (int)(gameContent.viewportSize.X / 2 / EqScale);

            PolygonShape ps = new PolygonShape();
            Body ground = world.CreateBody(new BodyDef());

            Vector2 pos = new Vector2(Width / 2, Height) / gameContent.scale;
            ps.SetAsBox(Width / 2 / gameContent.scale, (float)gameContent.labTable.Height
                / gameContent.scale, pos, 0);
            ground.CreateFixture(ps, 0);
        }
コード例 #31
0
        public Army(GameContent gameContent, Shape shape, Rank rank, Vector2 position)
        {
            this.gameContent = gameContent;
            Shape = shape; Rank = rank;
            this.position = position;

            walkAnimation = new Animation(gameContent.walk[(int)shape], 2, 0.1f, true, new Vector2(0.5f));
            idleAnimation = new Animation(gameContent.idle[(int)shape], 1, 0.1f, true, new Vector2(0.5f));
            dieAnimation = new Animation(gameContent.die[(int)shape], 3, 0.1f, false, new Vector2(0.5f));
            animationPlayer.PlayAnimation(idleAnimation);

            ArmyDetails details = gameContent.content.Load<ArmyDetails>("Graphics/" + rank);
            Damage = details.Damage;
            health = MaxHealth = details.Health;
            MaxReloadTime = details.ReloadTime;
            Range = details.Range;
            MoveSpeed = details.MoveSpeed;

            rotation = defaultRotaion = (shape == Shape.square) ? 0 : (float)Math.PI;
        }
コード例 #32
0
        public Formula(int[] atomCount, int twiceNumberOfBonds, int numberOfRings, BonusType bonusType,
            Vector2 position, GameContent gameContent)
        {
            this.position = position;
            this.gameContent = gameContent;
            this.twiceNumberOfBonds = twiceNumberOfBonds;
            this.numberOfRings = numberOfRings;

            this.atomCount = new int[gameContent.symbolCount];
            atomCount.CopyTo(this.atomCount, 0);

            int bonus = 1;

            if (bonusType == BonusType.Ring)
                bonus = numberOfRings + 1;
            else if (bonusType == BonusType.Hydrogen)
                bonus = atomCount[(int)Symbol.H];

            score = twiceNumberOfBonds * bonus; strScore = "+" + twiceNumberOfBonds;
            if (bonus > 1) strScore += " x" + bonus;

            Symbol[] symbolPref = new Symbol[atomCount.Length]; // C_H_N_O_X_Ra
            symbolPref[0] = Symbol.C;
            symbolPref[1] = Symbol.H;
            symbolPref[2] = Symbol.N;
            symbolPref[3] = Symbol.O;
            symbolPref[4] = Symbol.X;
            symbolPref[5] = Symbol.Ra;

            for (int i = 0; i < symbolPref.Length; i++)
            {
                int count = atomCount[(int)symbolPref[i]];
                if (count > 0)
                {
                    strFormula += symbolPref[i];
                    if (count > 1) strFormula += count;
                }
            }

            SetPos();
        }