Example #1
0
        public Bullet(World world, Car _car, Texture2D _dummyTexture)
        {
            car = _car;
            dummyTexture = _dummyTexture;

            bulletPhysicsObject=  BodyFactory.CreateRectangle(world, 0.1f, 0.1f, 1f, Vector2.Zero);
            bulletPhysicsObject.BodyType = BodyType.Dynamic;

            bulletPhysicsObject.IsSensor = true;
            bulletPhysicsObject.IsBullet = true;

            isGoing = false;

            bulletPhysicsObject.IgnoreCollisionWith(car._compound);

            bulletPhysicsObject.CollisionCategories = Category.Cat20;

            bulletPhysicsObject.OnCollision += bullet_OnCollision;
            graphics = GameServices.GetService<GraphicsDeviceManager>();

            pencilTexture = GameServices.GetService<ContentManager>().Load<Texture2D>("Images/pencilTextire");

            laserVertices = new VertexPositionColorTexture[6];

            laserVertices[0].Color = car.mColor;
            laserVertices[1].Color = car.mColor;
            laserVertices[2].Color = car.mColor;
            laserVertices[3].Color = car.mColor;
            laserVertices[4].Color = car.mColor;
            laserVertices[5].Color = car.mColor;

            laserSound = GameServices.GetService<ContentManager>().Load<SoundEffect>("Sounds/laserorribiledimmerda");

            laserSoundInstance=laserSound.CreateInstance();
        }
Example #2
0
        public PopupMessage(Car _car)
        {
            car = _car;
            textureScale = 0.5f;
            textureBg = GameServices.GetService<ContentManager>().Load<Texture2D>("Images/white_postit");
            thumbsDown= GameServices.GetService<ContentManager>().Load<Texture2D>("Images/awaken");
            thumbsUp = GameServices.GetService<ContentManager>().Load<Texture2D>("Images/dream_message");
            rainbowTex = GameServices.GetService<ContentManager>().Load<Texture2D>("Images/rainbow_texture");

            origin = new Vector2(textureBg.Width, textureBg.Height) * textureScale / 2f;

            stringWriter.nCharacters = 7;
            bgTextureVertices = new VertexPositionColorTexture[6];

            timer = 0.0f;
            popupTimeNormal = 1000f;
            popupTimeDead = 4000;
            popupTime = popupTimeNormal;

            currentTexture = thumbsUp;

            firstTime = true;
        }
Example #3
0
        public void KillOrthogonalVelocity(Car car, float drift)
        {
            updateOrthogonalVelocityCounter++;

            Vector2 forwardVelocity = mDirection * Vector2.Dot(car._compound.LinearVelocity, mDirection);
            Vector2 rightVector = new Vector2(-mDirection.Y, mDirection.X);
            Vector2 rightVelocity = rightVector * Vector2.Dot(car._compound.LinearVelocity,rightVector);
            car._compound.LinearVelocity = forwardVelocity + rightVelocity * drift;

            if (burnoutCounter > burnoutCounterMaxValue - 4) {
                loopBurnout = true;
                burnoutCounter = 0;
            }

            if (drift != 0 && rightVelocity.Length() > 5f)
            {
                if (updateOrthogonalVelocityCounter % 2 == 0)
                {
                    newWVertBurnoutRight.X = tdPos.X - mDirection.Y * burnoutOffset - mDirection.X * tailOffset + (float)seed.NextDouble() * 0.05f + rightVector.X * wheelsDistance;
                    newWVertBurnoutRight.Y = tdPos.Y + mDirection.X * burnoutOffset - mDirection.Y * tailOffset + (float)seed.NextDouble() * 0.05f + rightVector.Y * wheelsDistance;

                    newEVertBurnoutRight.X = tdPos.X + mDirection.Y * burnoutOffset - mDirection.X * tailOffset + (float)seed.NextDouble() * 0.05f + rightVector.X * wheelsDistance;
                    newEVertBurnoutRight.Y = tdPos.Y - mDirection.X * burnoutOffset - mDirection.Y * tailOffset + (float)seed.NextDouble() * 0.05f + rightVector.Y * wheelsDistance;

                    burnoutsVertices[burnoutCounter * 6 + 0].Position = newWVertBurnoutRight;
                    burnoutsVertices[burnoutCounter * 6 + 1].Position = newEVertBurnoutRight;
                    burnoutsVertices[burnoutCounter * 6 + 2].Position = oldWVertBurnoutRight;
                    burnoutsVertices[burnoutCounter * 6 + 3].Position = oldWVertBurnoutRight;
                    burnoutsVertices[burnoutCounter * 6 + 4].Position = oldEVertBurnoutRight;
                    burnoutsVertices[burnoutCounter * 6 + 5].Position = newEVertBurnoutRight;

                    burnoutsVertices[burnoutCounter * 6 + 0].TextureCoordinate = texNW;
                    burnoutsVertices[burnoutCounter * 6 + 1].TextureCoordinate = texNE;
                    burnoutsVertices[burnoutCounter * 6 + 2].TextureCoordinate = texOW;
                    burnoutsVertices[burnoutCounter * 6 + 3].TextureCoordinate = texOW;
                    burnoutsVertices[burnoutCounter * 6 + 4].TextureCoordinate = texOE;
                    burnoutsVertices[burnoutCounter * 6 + 5].TextureCoordinate = texNE;

                    oldWVertBurnoutRight = newWVertBurnoutRight;
                    oldEVertBurnoutRight = newEVertBurnoutRight;

                    burnoutCounter++;

                    newWVertBurnoutLeft.X = tdPos.X - mDirection.Y * burnoutOffset - mDirection.X * tailOffset + (float)seed.NextDouble() * 0.05f - rightVector.X * wheelsDistance;
                    newWVertBurnoutLeft.Y = tdPos.Y + mDirection.X * burnoutOffset - mDirection.Y * tailOffset + (float)seed.NextDouble() * 0.05f - rightVector.Y * wheelsDistance;

                    newEVertBurnoutLeft.X = tdPos.X + mDirection.Y * burnoutOffset - mDirection.X * tailOffset + (float)seed.NextDouble() * 0.05f - rightVector.X * wheelsDistance;
                    newEVertBurnoutLeft.Y = tdPos.Y - mDirection.X * burnoutOffset - mDirection.Y * tailOffset + (float)seed.NextDouble() * 0.05f - rightVector.Y * wheelsDistance;

                    burnoutsVertices[burnoutCounter * 6 + 0].Position = newWVertBurnoutLeft;
                    burnoutsVertices[burnoutCounter * 6 + 1].Position = newEVertBurnoutLeft;
                    burnoutsVertices[burnoutCounter * 6 + 2].Position = oldWVertBurnoutLeft;
                    burnoutsVertices[burnoutCounter * 6 + 3].Position = oldWVertBurnoutLeft;
                    burnoutsVertices[burnoutCounter * 6 + 4].Position = oldEVertBurnoutLeft;
                    burnoutsVertices[burnoutCounter * 6 + 5].Position = newEVertBurnoutLeft;

                    burnoutsVertices[burnoutCounter * 6 + 0].TextureCoordinate = texNW;
                    burnoutsVertices[burnoutCounter * 6 + 1].TextureCoordinate = texNE;
                    burnoutsVertices[burnoutCounter * 6 + 2].TextureCoordinate = texOW;
                    burnoutsVertices[burnoutCounter * 6 + 3].TextureCoordinate = texOW;
                    burnoutsVertices[burnoutCounter * 6 + 4].TextureCoordinate = texOE;
                    burnoutsVertices[burnoutCounter * 6 + 5].TextureCoordinate = texNE;

                    oldWVertBurnoutLeft = newWVertBurnoutLeft;
                    oldEVertBurnoutLeft = newEVertBurnoutLeft;

                    burnoutCounter++;
                }

                /*
                newWVertBurnoutRightFront.X = tdPos.X - mDirection.Y * burnoutOffset + mDirection.X * tailOffset + (float)seed.NextDouble() * 0.05f + rightVector.X * wheelsDistance;
                newWVertBurnoutRightFront.Y = tdPos.Y + mDirection.X * burnoutOffset + mDirection.Y * tailOffset + (float)seed.NextDouble() * 0.05f + rightVector.Y * wheelsDistance;

                newEVertBurnoutRightFront.X = tdPos.X + mDirection.Y * burnoutOffset + mDirection.X * tailOffset + (float)seed.NextDouble() * 0.05f + rightVector.X * wheelsDistance;
                newEVertBurnoutRightFront.Y = tdPos.Y - mDirection.X * burnoutOffset + mDirection.Y * tailOffset + (float)seed.NextDouble() * 0.05f + rightVector.Y * wheelsDistance;

                burnoutsVertices[burnoutCounter * 6 + 0].Position = newWVertBurnoutRightFront;
                burnoutsVertices[burnoutCounter * 6 + 1].Position = newEVertBurnoutRightFront;
                burnoutsVertices[burnoutCounter * 6 + 2].Position = oldWVertBurnoutRightFront;
                burnoutsVertices[burnoutCounter * 6 + 3].Position = oldWVertBurnoutRightFront;
                burnoutsVertices[burnoutCounter * 6 + 4].Position = oldEVertBurnoutRightFront;
                burnoutsVertices[burnoutCounter * 6 + 5].Position = newEVertBurnoutRightFront;

                burnoutsVertices[burnoutCounter * 6 + 0].TextureCoordinate = texNW;
                burnoutsVertices[burnoutCounter * 6 + 1].TextureCoordinate = texNE;
                burnoutsVertices[burnoutCounter * 6 + 2].TextureCoordinate = texOW;
                burnoutsVertices[burnoutCounter * 6 + 3].TextureCoordinate = texOW;
                burnoutsVertices[burnoutCounter * 6 + 4].TextureCoordinate = texOE;
                burnoutsVertices[burnoutCounter * 6 + 5].TextureCoordinate = texNE;

                oldWVertBurnoutRightFront = newWVertBurnoutRightFront;
                oldEVertBurnoutRightFront = newEVertBurnoutRightFront;

                burnoutCounter++;

                newWVertBurnoutLeftFront.X = tdPos.X - mDirection.Y * burnoutOffset + mDirection.X * tailOffset + (float)seed.NextDouble() * 0.05f - rightVector.X * wheelsDistance;
                newWVertBurnoutLeftFront.Y = tdPos.Y + mDirection.X * burnoutOffset + mDirection.Y * tailOffset + (float)seed.NextDouble() * 0.05f - rightVector.Y * wheelsDistance;

                newEVertBurnoutLeftFront.X = tdPos.X + mDirection.Y * burnoutOffset + mDirection.X * tailOffset + (float)seed.NextDouble() * 0.05f - rightVector.X * wheelsDistance;
                newEVertBurnoutLeftFront.Y = tdPos.Y - mDirection.X * burnoutOffset + mDirection.Y * tailOffset + (float)seed.NextDouble() * 0.05f - rightVector.Y * wheelsDistance;

                burnoutsVertices[burnoutCounter * 6 + 0].Position = newWVertBurnoutLeftFront;
                burnoutsVertices[burnoutCounter * 6 + 1].Position = newEVertBurnoutLeftFront;
                burnoutsVertices[burnoutCounter * 6 + 2].Position = oldWVertBurnoutLeftFront;
                burnoutsVertices[burnoutCounter * 6 + 3].Position = oldWVertBurnoutLeftFront;
                burnoutsVertices[burnoutCounter * 6 + 4].Position = oldEVertBurnoutLeftFront;
                burnoutsVertices[burnoutCounter * 6 + 5].Position = newEVertBurnoutLeftFront;

                burnoutsVertices[burnoutCounter * 6 + 0].TextureCoordinate = texNW;
                burnoutsVertices[burnoutCounter * 6 + 1].TextureCoordinate = texNE;
                burnoutsVertices[burnoutCounter * 6 + 2].TextureCoordinate = texOW;
                burnoutsVertices[burnoutCounter * 6 + 3].TextureCoordinate = texOW;
                burnoutsVertices[burnoutCounter * 6 + 4].TextureCoordinate = texOE;
                burnoutsVertices[burnoutCounter * 6 + 5].TextureCoordinate = texNE;

                oldWVertBurnoutLeftFront = newWVertBurnoutLeftFront;
                oldEVertBurnoutLeftFront = newEVertBurnoutLeftFront;

                burnoutCounter++;

                 */

            }
            else
            {
                oldWVertBurnoutRight.X = tdPos.X - mDirection.Y * burnoutOffset + rightVector.X * wheelsDistance;
                oldWVertBurnoutRight.Y = tdPos.Y + mDirection.X * burnoutOffset + rightVector.Y * wheelsDistance;

                oldEVertBurnoutRight.X = tdPos.X + mDirection.Y * burnoutOffset + rightVector.X * wheelsDistance;
                oldEVertBurnoutRight.Y = tdPos.Y - mDirection.X * burnoutOffset + rightVector.Y * wheelsDistance;

                oldWVertBurnoutLeft.X = tdPos.X - mDirection.Y * burnoutOffset - rightVector.X * wheelsDistance;
                oldWVertBurnoutLeft.Y = tdPos.Y + mDirection.X * burnoutOffset - rightVector.Y * wheelsDistance;

                oldEVertBurnoutLeft.X = tdPos.X + mDirection.Y * burnoutOffset - rightVector.X * wheelsDistance;
                oldEVertBurnoutLeft.Y = tdPos.Y - mDirection.X * burnoutOffset - rightVector.Y * wheelsDistance;

                oldWVertBurnoutRightFront.X = tdPos.X - mDirection.Y * burnoutOffset + rightVector.X * wheelsDistance;
                oldWVertBurnoutRightFront.Y = tdPos.Y + mDirection.X * burnoutOffset + rightVector.Y * wheelsDistance;

                oldEVertBurnoutRightFront.X = tdPos.X + mDirection.Y * burnoutOffset + rightVector.X * wheelsDistance;
                oldEVertBurnoutRightFront.Y = tdPos.Y - mDirection.X * burnoutOffset + rightVector.Y * wheelsDistance;

                oldWVertBurnoutLeftFront.X = tdPos.X - mDirection.Y * burnoutOffset - rightVector.X * wheelsDistance;
                oldWVertBurnoutLeftFront.Y = tdPos.Y + mDirection.X * burnoutOffset - rightVector.Y * wheelsDistance;

                oldEVertBurnoutLeftFront.X = tdPos.X + mDirection.Y * burnoutOffset - rightVector.X * wheelsDistance;
                oldEVertBurnoutLeftFront.Y = tdPos.Y - mDirection.X * burnoutOffset - rightVector.Y * wheelsDistance;
            }
        }
Example #4
0
        public override void LoadContent()
        {
            // We add to the GameServices objects that we want to be able to use accross different classes
            // without having to pass them explicitly every time.
            GraphicsDevice = GameServices.GetService<GraphicsDevice>();
            Content = GameServices.GetService<ContentManager>();
            graphics = GameServices.GetService<GraphicsDeviceManager>();
            soundManager = GameServices.GetService<SoundManager>();

            ScreenManager.AddScreen(RankScreen, null, false);
            ScreenManager.AddScreen(PauseScreen, null, false);

            world = new World(new Vector2(0, 0));
            GameServices.AddService<World>(world);

            this.world.ContactManager.PostSolve += new PostSolveDelegate(PostSolve);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Create a new track
            randomRaceTrack = RandomTrack.createTrack();

            randomRaceTrack.polygonList = polygonsList;

            int[] crucialPoints = { 300, 600, 1000 };
            Logic = new GameLogic(crucialPoints, randomRaceTrack.curvePointsMiddle.Count);

            randomRaceTrack.gameLogic = Logic;
            Logic.DidFinishLap += randomRaceTrack.ResetStickyNotes;

            mySneezesManager.randomTrack = randomRaceTrack;

            LoadPaperEffect();

            screenRenderer = new ScreenRenderer();
            GameServices.AddService<ScreenRenderer>(screenRenderer);
            Logic.DidEliminateCar += screenRenderer.setSadToPlayer;
            Logic.DidFinishLap += screenRenderer.setLap;

            for (int i = 0; i < 4; i++)
            {
                Car aCar = new Car(world, Content.Load<Texture2D>("Images/small_car"), Color.White, randomRaceTrack, i, playerIndexes[i]);
                Cars.Add(aCar);
            }

            assetCreator = new AssetCreator(graphics.GraphicsDevice);
            assetCreator.LoadContent(this.Content);

            defaultViewport = GraphicsDevice.Viewport;

            isFullHd=(ScreenManager.preferredHeight!=720);

            // Single screen mode only
            cameraFollowing = new Camera(defaultViewport, Vector2.Zero, new Vector2(defaultViewport.Width / 2, defaultViewport.Height / 2), 0.0f, Cars.Count, isFullHd);
            //ZOOM:

            //low res:
            //0.95 for 2 players
            //0.93 for 3 players
            //0.91 for 4 players

            //high res:
            //0.95 for 4 players

            GameServices.AddService<Camera>(cameraFollowing);

            mySneezesManager.camera = cameraFollowing;

            //generate starting positions and angles
            int startingPoint = 0;
               // positionCars(startingPoint);

            _debugView = new DebugViewXNA(world);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.Shape);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.DebugPanel);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.PerformanceGraph);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.Joint);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.ContactPoints);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.ContactNormals);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.Controllers);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.CenterOfMass);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.AABB);
            _debugView.DefaultShapeColor = Color.White;
            _debugView.SleepingShapeColor = Color.LightGray;
            _debugView.LoadContent(GraphicsDevice, Content);

            basicVert = new VertexPositionColorTexture[maxNumberOfTriangles];
            for (int i = 0; i < maxNumberOfTriangles; i++) basicVert[i].TextureCoordinate = new Vector2(-1);

            verticesBorders = new VertexPositionColorTexture[randomRaceTrack.curvePointsInternal.Count];

            fluid = new Fluid();
            fluid.Init();

            currentPoses = new Vector2[4];
            prevPoses = new Vector2[4];

            currentMousePos = new Vector2(100);
            prevMousePos = new Vector2(0);

            quad = new QuadRenderComponent(ScreenManager.Game, cameraFollowing, ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height);
            ScreenManager.Game.Components.Add(quad);

            fluidUpdateThread = new Thread(this.UpdateFluid);
            fluidUpdateThread.Start();

            mySneezesManager.fluid = fluid;

            fluidEffect = Content.Load<Effect>("Shaders/FluidEffect");
            fluidEffect.Parameters["random"].SetValue(randomTex);

            texInk = new Texture2D(graphics.GraphicsDevice,
                fluid.m_w, fluid.m_h, true,
                SurfaceFormat.Color);
            buffer = new RenderTarget2D(GraphicsDevice, ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height, true,
                SurfaceFormat.Color, GraphicsDevice.PresentationParameters.DepthStencilFormat);

            //gaussian = new GaussianBlur(ScreenManager.Game);
        }
Example #5
0
        public void changePostItColor(int index, Car car)
        {
            //color the post it and update car score
            postItDreamsList[index].color = car.mColor;
            if (postItDreamsList[index].isNightmare!=1)
            {
              //   gameLogic.UpdateScore(car, 0);
                car.message.activate("!",0);
                car.message.currentTexture = car.message.thumbsUp;

                Vector2 postitCenter = ConvertUnits.ToDisplayUnits(postItDreamsList[index].contourPhysicsObject._compound.Position);

                _particleComponent.particleEmitterList[car.index + carsCount*2].Position = postitCenter;
                _particleComponent.particleEmitterList[car.index + carsCount * 2].Active = true;

                wishSound.Play(0.5f,0,0);
            }
            else
            {
              //  gameLogic.UpdateScore(car,-1);
                car.message.activate("?",0);
                car.message.currentTexture = car.message.thumbsUp;

                Vector2 postitCenter = ConvertUnits.ToDisplayUnits(postItDreamsList[index].contourPhysicsObject._compound.Position);
                _particleComponent.particleEmitterList[car.index + carsCount].Position = postitCenter;
                _particleComponent.particleEmitterList[car.index + carsCount].Active = true;

                nightmareSound.Play(0.5f, 0, 0);
            }
        }
Example #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="car"></param>
        /// <param name="position">Must be between [0, kMaximumPlayers-1]</param>
        public void UpdateScore(Car car, int position)
        {
            if (car.hasNeverStarted)
            {
                return;
            }

            // -1: last position
            if (position == -1)
            {
                position = PlayersCount - 1;
            }
            int scoreMultiplier = 3;
            int newScore = (position == 0) ? scoreMultiplier * (PlayersCount - 1) : -scoreMultiplier * position;

            newScore += car.score;
            car.score = Math.Min(Math.Max(1, newScore), 54); // Score must be between [1,54]
        }