Esempio n. 1
0
        private void UpdateTexture(TojamGame game)
        {
            Debug.WriteLine("updating saved texture");

            // set the rendertarget as background
            game.GraphicsDevice.SetRenderTarget(this.renderTarget);
            game.GraphicsDevice.Clear(style.backgroundColor);
            game.spriteBatch.Begin(SpriteSortMode.Immediate);

            // draw messages from the bottom to the top
            Point origin = new Point(style.externalPadding, style.internalBounds.Height - style.externalPadding);
            int   i      = 0;

            for (; i < messages.Count; i++)
            {
                origin.Y -= messages[i].getHeight(style);
                messages[i].Draw(style, origin, game);

                origin.Y -= style.messagePadding;
                if (origin.Y < style.internalBounds.Y)
                {
                    break;
                }
            }

            // end batch and clear the rendertarget
            game.spriteBatch.End();
            game.GraphicsDevice.SetRenderTarget(null);

            // delete old messages that were not traversed
            while (i < messages.Count)
            {
                messages.RemoveAt(i);
            }
        }
Esempio n. 2
0
        public void UpdateRenderTarget(TojamGame game, GameTime gameTime)
        {
            game.graphics.GraphicsDevice.SetRenderTarget(renderTarget);
            game.graphics.GraphicsDevice.Clear(Color.White);
            game.spriteBatch.Begin(SpriteSortMode.BackToFront, null, SamplerState.PointClamp);

            if (sky != null)
            {
                sky.Draw(this.bounds, game, gameTime);
            }

            if (background != null)
            {
                background.Draw(this.bounds, game, gameTime);
            }

            if (midground != null)
            {
                midground.Draw(this.bounds, game, gameTime);
            }

            if (foreground != null)
            {
                foreground.Draw(this.bounds, game, gameTime);
            }


            game.spriteBatch.End();

            game.graphics.GraphicsDevice.SetRenderTarget(null);
        }
Esempio n. 3
0
        public static void LoadContent(TojamGame game)
        {
            Texture2D     alex        = game.Content.Load <Texture2D>("misc/alex");
            PlayerCostume alexCostume = new PlayerCostume(
                alex,
                "alexander biggs"
                );

            playerCostumes.Add(alexCostume);

            Texture2D     baby        = game.Content.Load <Texture2D>("misc/baby");
            PlayerCostume babyCostume = new PlayerCostume(
                baby,
                "a dumb baby"
                );

            playerCostumes.Add(babyCostume);

            Texture2D     cheetoes        = game.Content.Load <Texture2D>("misc/cheeotes");
            PlayerCostume cheetoesCostume = new PlayerCostume(
                cheetoes,
                "Flamin' Hot Cheetoes (tm)"
                );

            playerCostumes.Add(cheetoesCostume);
        }
Esempio n. 4
0
 public void Update(TojamGame game, GameTime gameTime)
 {
     foreach (Entity e in entities)
     {
         e.Update(game, gameTime);
     }
 }
Esempio n. 5
0
 public void Draw(Rectangle bounds, TojamGame game, GameTime gameTime)
 {
     foreach (PicturePart part in parts)
     {
         part.Draw(bounds, game, gameTime);
     }
 }
Esempio n. 6
0
        public void Update(TojamGame game, GameTime gameTime)
        {
            chatLog.Update(game, gameTime);
            textBox.Update(game, gameTime);

            if (game.gameInstance.GameStarted())
            {
                if (game.gameInstance.GetMyPlayer().carLocation != Player.CarLocation.NotInCar)
                {
                    carPicture.SetMidground(CarPicture.Midground.Car);
                }
                else
                {
                    carPicture.SetMidground(CarPicture.Midground.None);
                }

                Location currentLocation = game.gameInstance.world.GetLocation(game.gameInstance.GetMyPlayer().worldLocation);
                carPicture.SetBackground(currentLocation.Background);
            }

            // TODO process messages from the server

            // broadcast ready messages to the server
            if (Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                String textString = textBox.GetAndClear();
                if (textString != "")
                {
                    game.gameInstance.SendPlayerCommand(textString);
                }
            }

            carPicture.Update(game, gameTime);
            playerStatusIndicator.UpdateToPlayer(game, game.gameInstance.GetMyPlayer());
        }
Esempio n. 7
0
        internal static void RunGame()
        {
            game = new TojamGame();
            game.Run();
#if !__IOS__ && !__TVOS__
            game.Dispose();
#endif
        }
Esempio n. 8
0
        public override void Draw(Rectangle bounds, TojamGame game, GameTime gameTime)
        {
            if (animating)
            {
                this.texture = textures[((int)gameTime.TotalGameTime.TotalMilliseconds / frameRate) % this.textures.Length];
            }

            base.Draw(bounds, game, gameTime);
        }
Esempio n. 9
0
        public SignAnimation(SpriteFont font, Texture2D sign, TojamGame game)
        {
            this.sign = sign;
            this.game = game;
            this.font = font;

            target     = new RenderTarget2D(game.GraphicsDevice, (int)(sign.Width * signScale), (int)(sign.Height * signScale));
            textCenter = new Vector2(target.Width / 2, 25);
        }
Esempio n. 10
0
 public void Update(TojamGame game, GameTime gameTime)
 {
     // update animation positions
     animationTime += gameTime.ElapsedGameTime.Milliseconds / 1000f;
     if (animationTime > animationDuration)
     {
         animationTime = animationDuration;
     }
 }
Esempio n. 11
0
 public void Update(TojamGame game, GameTime gameTime)
 {
     // re-render to the rendertarget if needed
     if (dirty)
     {
         this.UpdateTexture(game);
         this.dirty = false;
     }
 }
Esempio n. 12
0
 public GameInstance(TojamGame game)
 {
     this.game    = game;
     myPlayerId   = 0;
     carIsDriving = false;
     carLocation  = 0;
     world        = new World();
     rand         = new Random();
 }
Esempio n. 13
0
        public void Update(TojamGame game, GameTime gameTime)
        {
            // check for a player that has pressed start or something that hasn't
            for (int i = selectedPlayers.Count - 1; i >= 0; i--)
            {
                if (selectedPlayers[i].input.KeyPressed(Key.CANCEL))
                {
                    selectedPlayers.RemoveAt(i);
                }

                else if (selectedPlayers[i].input.KeyPressed(Key.START) || selectedPlayers[i].input.KeyPressed(Key.CANCEL))
                {
                    // transition into the actual game if 2+ players have joined
                    if (selectedPlayers.Count >= 2)
                    {
                        StartGame(game);
                    }
                }
            }


            // check for a player pressing start and put them in the boundInputs page
            for (int i = 0; i < inputs.Count; i++)
            {
                Input input = inputs[i];
                if (input.KeyPressed(Key.START) && selectedPlayers.TrueForAll(p => p.input != input))
                {
                    PlayerSelection selection = new PlayerSelection(input, 0);
                    selectedPlayers.Add(selection);
                    selectors[selectedPlayers.Count - 1].SetSelection(selection, 1);
                }
            }

            // check for a player pressing start and put them in the boundInputs page
            for (int i = 0; i < selectedPlayers.Count; i++)
            {
                PlayerSelection selection = selectedPlayers[i];
                if (selection.input.KeyPressed(Key.DOWN) || selection.input.KeyPressed(Key.RIGHT))
                {
                    selection.playerSpriteId = (selection.playerSpriteId + 1) % PlayerCostume.playerCostumes.Count;
                    selectors[i].SetSelection(selection, 1);
                }

                if (selection.input.KeyPressed(Key.UP) || selection.input.KeyPressed(Key.LEFT))
                {
                    selection.playerSpriteId = (selection.playerSpriteId - 1 + PlayerCostume.playerCostumes.Count) % PlayerCostume.playerCostumes.Count;
                    selectors[i].SetSelection(selection, -1);
                }
            }

            foreach (PlayerSelector selector in selectors)
            {
                selector.Update(game, gameTime);
            }
        }
Esempio n. 14
0
        private void StartGame(TojamGame game)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            for (int i = 0; i < 4; i++)
            {
                parameters["player" + (i + 1)] = selectedPlayers.Count > i ? selectedPlayers[i] : null;
            }

            game.SwitchScene(TojamGame.GameScenes.Game, parameters);
        }
 public void UpdateToPlayer(TojamGame game, Player p)
 {
     if (p == null)
     {
         this.text = "";
         return;
     }
     this.text = String.Format("HAPPINESS = {0}     HUNGER = {1}     THIRST = {2}     TIRED = {3}    MONEY = {4}",
                               p.happyness, p.hunger, p.thirst, p.tired, p.money
                               );
 }
Esempio n. 16
0
        public void Initialize(TojamGame game)
        {
            Debug.WriteLine("ChatLog : making rendertarget");
            Rectangle externalBounds = style.GetExternalBounds();

            renderTarget = new RenderTarget2D(
                game.GraphicsDevice,
                externalBounds.Width,
                externalBounds.Height
                );
        }
Esempio n. 17
0
        public void Draw(TojamGame game, GameTime gameTime)
        {
            game.graphics.GraphicsDevice.Clear(Color.Gainsboro);
            game.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            foreach (Entity e in entities)
            {
                e.Draw(game, gameTime);
            }

            game.spriteBatch.End();
        }
Esempio n. 18
0
 public void Draw(ChatLogStyle style, Point origin, TojamGame game)
 {
     for (int i = 0; i < lines.Count; i++)
     {
         Point drawOrigin = origin + new Point(0, (style.linePadding + style.font.LineSpacing) * i);
         game.spriteBatch.DrawString(
             style.font,
             lines[i],
             new Vector2(drawOrigin.X, drawOrigin.Y),
             lineColor
             );
     }
 }
Esempio n. 19
0
        public void Draw(TojamGame game, GameTime gameTime)
        {
            game.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            game.graphics.GraphicsDevice.Clear(Color.Salmon);

            foreach (PlayerSelector selector in selectors)
            {
                selector.Draw(game, gameTime);
            }


            game.spriteBatch.End();
        }
Esempio n. 20
0
        public void Initialize(TojamGame game)
        {
            // get dimensions to size thingsa round
            renderTarget = new RenderTarget2D(game.GraphicsDevice, chatSceneDimensions.Width, chatSceneDimensions.Height);
            Rectangle screenBounds       = chatSceneDimensions;
            int       messageBufferWidth = 200;

            // build chatlog
            ChatLogStyle style = new ChatLogStyle();

            style.font            = game.GameFont;
            style.linePadding     = 1;
            style.messagePadding  = 5;
            style.externalPadding = 10;
            style.internalBounds  = new Rectangle(
                screenBounds.Width - messageBufferWidth + style.externalPadding,
                style.externalPadding,
                messageBufferWidth - style.externalPadding * 2,
                screenBounds.Height - style.externalPadding
                );
            style.backgroundColor = Color.Black;

            chatLog = new ChatLog(style);
            chatLog.Initialize(game);
            chatLog.AppendMessage("Welcome to Algonquin Park Roadtrip Simulator 2018!", Color.White);
            chatLog.AppendMessage("Your goal is to reach Algonquin Park and have happy camping trip", Color.Gray);
            chatLog.AppendMessage("Type `help` to see commands", Color.Gray);
//			chatLog.AppendMessage("Type 'join <ip>' to join a game, or 'host' to start a new one", Color.Gray);
            chatLog.AppendMessage("Type 'setname <name>' set your name before starting a game", Color.Gray);

            // build textbox
            textBox = new TextBox(
                game.GameFont,
                new Rectangle(
                    0,
                    screenBounds.Height - game.GameFont.LineSpacing,
                    screenBounds.Width - messageBufferWidth,
                    game.GameFont.LineSpacing
                    ));

            // initialize displayable scene
            carPicture = new CarPicture(new Rectangle(0, 0, screenBounds.Width - messageBufferWidth, screenBounds.Height - game.GameFont.LineSpacing * 2 - 5));
            carPicture.Initialize(game);
            carPicture.SetSky(CarPicture.Sky.Day);
            carPicture.SetBackground(CarPicture.Background.Title);
            //carPicture.TriggerEvent("town", new Dictionary<String, Object> { { "townName", "Algonquin" } });

            playerStatusIndicator = new PlayerStatusIndicator(game.GameFont, new Vector2(0, screenBounds.Height - game.GameFont.LineSpacing * 2));
        }
Esempio n. 21
0
        public void Draw(TojamGame game, GameTime gameTime)
        {
            // press Start to join
            if (currentName == null)
            {
                game.spriteBatch.DrawString(font, "Press Start to Join", this.position, Color.White);
            }
            else
            {
                // do some easing
                float effectiveTime = (float)Math.Sin(animationTime / animationDuration / (Math.PI / 4.0));
                if (animationDirection == -1)
                {
                    effectiveTime = 1 - effectiveTime;
                }
                Debug.WriteLine(effectiveTime);

                Vector2 introImageInterpolated = (introImagePosition * (1 - effectiveTime)) + restingImagePosition * effectiveTime;

                // draw the first text
                Vector2 introInterpolated = (introTextPosition * (1 - effectiveTime)) + restingTextPosition * effectiveTime;
                game.spriteBatch.DrawString(font, currentName, this.position + introInterpolated, Color.White * effectiveTime);
                game.spriteBatch.Draw(currentSprite,
                                      new Rectangle(
                                          (int)(position.X + introImageInterpolated.X),
                                          (int)(position.Y + introImageInterpolated.Y),
                                          64,
                                          64
                                          ),
                                      Color.White * effectiveTime);

                if (previousName != null)
                {
                    // draw the previous name easing out
                    Vector2 outroInterpolated      = (restingTextPosition * (1 - effectiveTime)) + exitingTextPosition * effectiveTime;
                    Vector2 outroImageInterpolated = (introImagePosition * effectiveTime) + restingImagePosition * (1 - effectiveTime);
                    game.spriteBatch.DrawString(font, previousName, this.position + outroInterpolated, Color.White * (1 - effectiveTime));
                    game.spriteBatch.Draw(
                        previousSprite,
                        new Rectangle(
                            (int)(position.X + outroImageInterpolated.X),
                            (int)(position.Y + outroImageInterpolated.Y),
                            64,
                            64
                            ),
                        Color.White * (1 - effectiveTime));
                }
            }
        }
Esempio n. 22
0
        public void Draw(Rectangle bounds, TojamGame game, GameTime gameTime)
        {
            if (animating)
            {
                time += (int)gameTime.ElapsedGameTime.Milliseconds;
            }

            int millis = time - animationStartTime;

            if (millis > animationLength)
            {
                animating = false;
                paused    = false;
                return;
            }

            if (!this.animating && !this.paused)
            {
                return;
            }

            float   frac = 1.0f * millis / animationLength;
            Vector2 interpolatedPosition = startPoint * (1 - frac) + endPoint * frac;

            interpolatedPosition -= new Vector2(target.Width, target.Height);
            float scale = startScale * (1 - frac) + endScale * frac;

            game.spriteBatch.Draw(
                target,
                new Rectangle(
                    (int)interpolatedPosition.X,
                    (int)interpolatedPosition.Y,
                    (int)(scale * target.Width),
                    (int)(scale * target.Height)
                    ),
                new Rectangle(
                    0,
                    0,
                    target.Width,
                    target.Height
                    ),
                Color.White
                );
        }
Esempio n. 23
0
        public void Initialize(TojamGame game)
        {
            // initialize bound controllers
            inputs.Add(new Input(Input.Type.Keyboard));
            inputs.Add(new Input(Input.Type.JoypadOne));
            inputs.Add(new Input(Input.Type.JoypadTwo));
            inputs.Add(new Input(Input.Type.JoypadThree));
            inputs.Add(new Input(Input.Type.JoypadFour));

            // do some selectors
            selectors.Add(new PlayerSelector(new Vector2(20, 200)));
            selectors.Add(new PlayerSelector(new Vector2(220, 200)));
            selectors.Add(new PlayerSelector(new Vector2(420, 200)));
            selectors.Add(new PlayerSelector(new Vector2(620, 200)));
            foreach (PlayerSelector selector in selectors)
            {
                selector.SetFont(renderFont);
            }
        }
Esempio n. 24
0
        public virtual void Draw(Rectangle bounds, TojamGame game, GameTime gameTime)
        {
            Rectangle src  = new Rectangle(0, 0, texture.Width, texture.Height);
            Rectangle dest = new Rectangle(0, 0, bounds.Width, bounds.Height);

            // fit dest ratio to a slice of src
            float     scalingFactor = Math.Min(1.0f * src.Width / bounds.Width, 1.0f * src.Height / bounds.Height);
            Rectangle scaledDest    = new Rectangle(0, 0, (int)(scalingFactor * dest.Width), (int)(scalingFactor * dest.Height));

            scaledDest.X = -(scaledDest.Width - src.Width) / 2;
            scaledDest.Y = -(scaledDest.Height - src.Height) / 2;

            game.spriteBatch.Draw(
                this.texture,
                new Rectangle(0, 0, bounds.Width, bounds.Height),
                scaledDest,
                Color.White
                );
        }
Esempio n. 25
0
        public void Draw(TojamGame game, GameTime gameTime)
        {
            game.graphics.GraphicsDevice.SetRenderTarget(this.renderTarget);
            game.graphics.GraphicsDevice.Clear(Color.Black);
            game.spriteBatch.Begin(SpriteSortMode.Immediate, null, SamplerState.PointClamp);

            carPicture.Draw(game, gameTime);
            chatLog.Draw(game, gameTime);
            textBox.Draw(game, gameTime);
            playerStatusIndicator.Draw(game, gameTime);

            game.spriteBatch.End();
            game.graphics.GraphicsDevice.SetRenderTarget(null);

            game.graphics.GraphicsDevice.Clear(Color.Black);
            game.spriteBatch.Begin(SpriteSortMode.Immediate, null, SamplerState.PointClamp);

            // deferred rendering

            Rectangle realScreenBounds   = game.GraphicsDevice.PresentationParameters.Bounds;
            Rectangle renderTargetBounds = this.renderTarget.Bounds;
            float     ratio = Math.Min((float)realScreenBounds.Width / renderTarget.Width,
                                       (float)realScreenBounds.Height / renderTarget.Height);
            //Debug.WriteLine(
            //	(float)realScreenBounds.Width / renderTarget.Width +
            //	", " +
            //	(float)realScreenBounds.Height / renderTarget.Height
            //);

            Rectangle scaledRenderTarget = new Rectangle(
                0,
                0,
                (int)(this.renderTarget.Width * ratio),
                (int)(this.renderTarget.Height * ratio)
                );

            scaledRenderTarget.X = (realScreenBounds.Width - scaledRenderTarget.Width) / 2;
            scaledRenderTarget.Y = (realScreenBounds.Height - scaledRenderTarget.Height) / 2;

            game.spriteBatch.Draw(renderTarget, scaledRenderTarget, renderTargetBounds, Color.White);
            game.spriteBatch.End();
        }
Esempio n. 26
0
 public void Draw(TojamGame game, GameTime gameTime)
 {
     // start a new batch to draw the buffer to the screen
     game.spriteBatch.Draw(renderTarget, style.GetExternalBounds(), Color.White);
 }
Esempio n. 27
0
 public void LoadContent(TojamGame game)
 {
 }
Esempio n. 28
0
 public void Initialize(TojamGame game)
 {
     // TODO Load spritesheets for each player character
 }
Esempio n. 29
0
 public void LoadContent(TojamGame game)
 {
     renderFont = game.Content.Load <SpriteFont>("fonts/Cutive_Mono");
 }
Esempio n. 30
0
 public void LoadContent(TojamGame game)
 {
     Debug.WriteLine("Chat : Load Content");
     CarPicture.LoadContent(game);
 }