public override void onDraw(SpriteBatch sprite_batch)
        {
            base.onDraw(sprite_batch);

            int?score_to_unlock_next_level = this.GetScoreToUnlockNextLevel();

            if (score_to_unlock_next_level != null)
            {
                var         texture = ContentHolder.Get(Settings.CurrentSnake);
                const float scale   = 0.3125f;

                for (int i = 0; i < LevelRequirementsLogo.BaseTextLocations.Length; i++)
                {
                    var pos = LevelRequirementsLogo.BaseTextLocations[i];
                    sprite_batch.Draw(texture, pos, null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }

                string    score_string = score_to_unlock_next_level.ToString();
                const int start_x      = 240 + 32 - 10 - 11 - 6;
                const int start_y      = 480 - 60 + 5;
                const int spread_x     = 23;
                for (int i = 0; i < score_string.Length; i++)
                {
                    int integer  = int.Parse(score_string[i].ToString());
                    var base_pos = new Vector2(start_x + spread_x * i, start_y);
                    foreach (var pos in LogoDrawData.ScoreNumberLocations[integer])
                    {
                        sprite_batch.Draw(texture, base_pos + pos, null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                    }
                }
            }
        }
Beispiel #2
0
        public override void onDraw(SpriteBatch sprite_batch)
        {
            base.onDraw(sprite_batch);

            var scale = new Vector2(2 / 3f);

            sprite_batch.Draw(ContentHolder.Get(AvailableTextures.splash), Vector2.Zero, null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
        }
Beispiel #3
0
        private FallingEntity spawnEntity(Vector2 position)
        {
            Array             values         = Enum.GetValues(typeof(AvailableTextures));
            AvailableTextures random_texture = (AvailableTextures)values.GetValue(Utilities.Random.Next(values.Length));
            var texture = ContentHolder.Get(random_texture);

            return(new FallingEntity(texture, new Vector2(position.X, position.Y)));
        }
Beispiel #4
0
            internal SnakeTail()
            {
                var texture = ContentHolder.Get(Settings.CurrentSnake);
                var region  = new Region(texture, 0, 0, Snake.Size, Snake.Size, Snake.Size / 2, Snake.Size / 2);
                var sprite  = new Sprite(region);

                this.AddSprite("main", sprite);
                this.AddColliderRectangle("main", -Snake.Size / 2, -Snake.Size / 2, Snake.Size, Snake.Size);
            }
Beispiel #5
0
        public Food(int x, int y)
        {
            this.Position = new Vector2(x, y);
            var texture = ContentHolder.Get(Settings.CurrentFood);
            var region  = new Region(texture, 0, 0, Food.Size, Food.Size, Food.Size / 2, Food.Size / 2);
            var sprite  = new Sprite(region);

            this.AddSprite("main", sprite);
            this.AddColliderRectangle("main", -Food.Size / 2, -Food.Size / 2, Food.Size, Food.Size);
        }
Beispiel #6
0
        public override void onDraw(SpriteBatch sprite_batch)
        {
            base.onDraw(sprite_batch);

            // Set up variables for drawing selector
            float x           = this.Position.X;
            float y           = this.Position.Y;
            float width       = this.Size.X;
            float height      = this.Size.Y;
            var   texture     = ContentHolder.Get(Settings.CurrentSnake);
            var   scale       = new Vector2(0.3125f);
            float draw_width  = texture.Width * scale.X;
            float draw_height = texture.Height * scale.Y;

            // Draw vertical selector parts
            float draw_start_y = y - draw_height;
            float draw_y       = draw_start_y;
            float total_height = draw_start_y + height + draw_height * 2;

            while (draw_y < total_height)
            {
                Rectangle?source_rectangle = null;
                if (draw_y + draw_height > total_height)
                {
                    float remaining_space = total_height - draw_y;
                    float draw_percent    = remaining_space / draw_height;
                    source_rectangle = new Rectangle(0, 0, texture.Width, (int)(texture.Height * draw_percent));
                }

                sprite_batch.Draw(texture, new Vector2(x - draw_width, draw_y), source_rectangle, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 1);
                sprite_batch.Draw(texture, new Vector2(x + width, draw_y), source_rectangle, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 1);
                draw_y += draw_height;
            }

            // Draw horizontal selector parts
            float draw_start_x = x - draw_width;
            float draw_x       = draw_start_x;
            float total_width  = draw_start_x + width + draw_width * 2;

            while (draw_x < total_width)
            {
                Rectangle?source_rectangle = null;
                if (draw_x + draw_width > total_width)
                {
                    float remaining_space = total_width - draw_x;
                    float draw_percent    = remaining_space / draw_width;
                    source_rectangle = new Rectangle(0, 0, (int)(texture.Width * draw_percent), texture.Height);
                }

                sprite_batch.Draw(texture, new Vector2(draw_x, y - draw_height), source_rectangle, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 1);
                sprite_batch.Draw(texture, new Vector2(draw_x, y + height), source_rectangle, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 1);
                draw_x += draw_width;
            }
        }
        public override void onDraw(SpriteBatch sprite_batch)
        {
            base.onDraw(sprite_batch);

            var texture = ContentHolder.Get(Settings.CurrentWall);

            foreach (var position in this.DrawPositions)
            {
                sprite_batch.Draw(texture, position, Color.White);
            }
        }
        public override void onDraw(SpriteBatch sprite_batch)
        {
            base.onDraw(sprite_batch);
            int spread = (int)(22 * this.Scale);

            for (int i = 0; i < this.ButtonText.Length; i++)
            {
                string text   = this.ButtonText[i];
                var    offset = new Vector2(0, spread * (i == 0 ? -1 : 1));
                sprite_batch.DrawString(ContentHolder.Get(AvailableFonts.blippo), text, this.Position + offset, Color.White, 0, DrawFrom.Center, this.Scale, SpriteEffects.None, 0);
            }
        }
Beispiel #9
0
        public override void onDraw(SpriteBatch sprite_batch)
        {
            base.onDraw(sprite_batch);

            var texture = ContentHolder.Get(Settings.CurrentSnake);

            for (int i = 0; i < TitleLogo.SnakeLogoLocations.Length; i++)
            {
                var pos = TitleLogo.SnakeLogoLocations[i];
                sprite_batch.Draw(texture, this.Position + pos, Color.White);
            }
        }
 public override void onKeyDown(KeyboardEventArgs e)
 {
     base.onKeyDown(e);
     if (e.Key == Keys.Back || e.Key == Keys.Escape)
     {
         if (this.ShouldPlaySoundOnClick)
         {
             ContentHolder.Get(AvailableSounds.click).TryPlay();
         }
         this.OnClick?.Invoke();
     }
 }
Beispiel #11
0
        public override void onDraw(SpriteBatch sprite_batch)
        {
            base.onDraw(sprite_batch);

            var texture = ContentHolder.Get(Settings.CurrentFood);
            var scale   = new Vector2(5 / (float)texture.Width);

            for (int i = 0; i < DeveloperLogo.DeveloperLogoLocations.Length; i++)
            {
                var pos = DeveloperLogo.DeveloperLogoLocations[i];
                sprite_batch.Draw(texture, this.Position + pos, null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
            }
        }
Beispiel #12
0
        public override void onDraw(SpriteBatch sprite_batch)
        {
            base.onDraw(sprite_batch);

            if (Engine.IsPaused())
            {
                var texture = ContentHolder.Get(Settings.CurrentFood);
                for (int i = 0; i < ControlPause.PausedLogoLocations.Length; i++)
                {
                    var pos = ControlPause.PausedLogoLocations[i];
                    sprite_batch.Draw(texture, pos, Color.White);
                }
            }
        }
Beispiel #13
0
        public Wall(int x, int y, float scale = 1)
        {
            this.Depth    = 1;
            this.Position = new Vector2(x, y);
            var texture = ContentHolder.Get(Settings.CurrentWall);
            var region  = new Region(texture, 0, 0, Wall.Size, Wall.Size, 0, 0);
            var sprite  = new Sprite(region)
            {
                Scale = new Vector2(scale)
            };

            this.AddSprite("main", sprite);
            this.AddColliderRectangle("main", 0, 0, (int)(Wall.Size * scale), (int)(Wall.Size * scale));
        }
Beispiel #14
0
        public Scoreboard()
        {
            this.Depth    = -100;
            this.Position = new Vector2(Engine.Game.CanvasWidth / 2 - Scoreboard.Width / 2, 30 + 30 + 20);

            this.BackgroundRegion = new Region(ContentHolder.Get(Settings.CurrentBackground), (int)this.Position.X, (int)this.Position.Y, Scoreboard.Width, Scoreboard.Height, 0, 0);
            this.SnakeRegion      = new Region(ContentHolder.Get(Settings.CurrentSnake));

            string data    = SaveDataHandler.LoadData(Settings.CurrentSaveFilePath);
            bool   success = (data != null && int.TryParse(data, out this.HighScore));

            if (!success)
            {
                this.SaveHighscore();
            }
        }
        public override void onDraw(SpriteBatch sprite_batch)
        {
            var font = ContentHolder.Get(AvailableFonts.blippo);

            base.onDraw(sprite_batch);
            int spread = (int)(22 * this.Scale);

            for (int i = 0; i < this.ButtonText.Length; i++)
            {
                string text       = this.ButtonText[i];
                float  line_scale = 1.0f;
                var    text_size  = font.MeasureString(text);
                if (text_size.X > ButtonRokuIP.MaxFontWidth)
                {
                    line_scale = ButtonRokuIP.MaxFontWidth / text_size.X;
                }
                var offset = new Vector2(0, spread * (i == 0 ? -1 : 1));
                sprite_batch.DrawString(font, text, this.Position + offset, Color.White, 0, DrawFrom.Center, this.Scale * line_scale, SpriteEffects.None, 0);
            }
        }
 public void onTouchPressed(TouchLocation touch)
 {
     if (this.IsClickOnSelf(touch.Position.ToPoint()))
     {
         if (this.ShouldVibrateOnClick)
         {
             VibrationHelper.Vibrate();
         }
         if (this.ShouldPlaySoundOnClick)
         {
             ContentHolder.Get(AvailableSounds.click).TryPlay();
         }
         this.OnClick?.Invoke();
         this.LastClickWasOnSelf = true;
         this.LastClickTouchID   = touch.Id;
     }
     else
     {
         this.LastClickWasOnSelf = false;
     }
 }
Beispiel #17
0
        public Portal(int x, int y, int id, int goto_up, int goto_down, int goto_left, int goto_right, ReadOnlyDictionary <Directions, bool> reverse_direction = null)
        {
            this.Depth          = 100;
            this.Position       = new Vector2(x, y);
            this.ID             = id;
            this.DestinationIDs = new ReadOnlyDictionary <Directions, int>(new Dictionary <Directions, int> {
                [Directions.Up]    = goto_up,
                [Directions.Down]  = goto_down,
                [Directions.Left]  = goto_left,
                [Directions.Right] = goto_right
            });
            this.ReverseDirection = reverse_direction;

            var regions = new Region[] {
                new Region(ContentHolder.Get(AvailableTextures.portal_0), 0, 0, Portal.Size, Portal.Size, 0, 0),
                new Region(ContentHolder.Get(AvailableTextures.portal_1), 0, 0, Portal.Size, Portal.Size, 0, 0),
            };

            this.MainSprite = new AnimatedSprite(regions);
            this.AddSprite("main", this.MainSprite);
            this.MainCollider = this.AddColliderRectangle("main", 0, 0, Portal.Size, Portal.Size);
        }
Beispiel #18
0
        public Snake(int start_delay, Point position)
        {
            this.InitialWaitDelay        = start_delay;
            this.CurrentLocation         = position;
            this.DirectionChangeLocation = this.CurrentLocation;
            this.InternalLocation        = position.ToVector2();
            this.Position  = this.InternalLocation;
            this.Direction = Directions.Right;
            this.State     = (this.InitialWaitDelay == 0) ? States.Alive : States.Waiting;

            var texture = ContentHolder.Get(Settings.CurrentSnake);
            var region  = new Region(texture, 0, 0, Snake.Size, Snake.Size, Snake.Size / 2, Snake.Size / 2);
            var sprite  = new Sprite(region);

            this.AddSprite("main", sprite);

            this.AddColliderRectangle(Directions.Up.ToString(), -Snake.Size / 2, -Snake.Size / 2, Snake.Size, 1, false);
            this.AddColliderRectangle(Directions.Down.ToString(), -Snake.Size / 2, Snake.Size / 2 - 1, Snake.Size, 1, false);
            this.AddColliderRectangle(Directions.Left.ToString(), -Snake.Size / 2, -Snake.Size / 2, 1, Snake.Size, false);
            this.AddColliderRectangle(Directions.Right.ToString(), Snake.Size / 2 - 1, -Snake.Size / 2, 1, Snake.Size, true);
            this.AddColliderRectangle(this.MouthColliderName, -Snake.Size / 2, -Snake.Size / 2, Snake.Size, Snake.Size, true);

            for (int i = 0; i < 2; i++)
            {
                var tail = new SnakeTail {
                    Position = new Vector2(this.Position.X - (i + 1) * Snake.Size, this.Position.Y),
                    Depth    = this.Depth + 1 + i
                };
                Engine.SpawnInstance(tail);
                this.Tail.Add(tail);
            }

            for (int i = 0; i < this.Tail.Count * Snake.Size; i++)
            {
                this.SnakeLocations["x"].Add(this.CurrentLocation.X - i);
                this.SnakeLocations["y"].Add(this.CurrentLocation.Y);
            }
        }
        public override void onDraw(SpriteBatch sprite_batch)
        {
            base.onDraw(sprite_batch);

            // This animation processing is locked to the on screen movement of the the snake position (updated through posting of game events).
            // So where tweening would normally be done with time and duration, here it is done with movement ticks related to the snake part size.
            var         texture = ContentHolder.Get(Settings.CurrentSnake);
            float       t       = this.AnimationTick;
            const float d       = Snake.Size - 1;

            float in_x         = Tweening.LinearTween(this.InSnakePos.X, this.InPortalPos.X, t, d);
            float in_y         = Tweening.LinearTween(this.InSnakePos.Y, this.InPortalPos.Y, t, d);
            float out_x        = Tweening.LinearTween(this.OutPortalPos.X, this.OutSnakePos.X, t, d);
            float out_y        = Tweening.LinearTween(this.OutPortalPos.Y, this.OutSnakePos.Y, t, d);
            float shrink_scale = Tweening.LinearTween(1, 0, t, d);
            float grow_scale   = Tweening.LinearTween(0, 1, t, d);

            sprite_batch.Draw(texture, new Vector2(in_x, in_y), null, Color.White, 0, new Vector2(Snake.Size / 2f), new Vector2(shrink_scale), SpriteEffects.None, 1);
            if (this.TailIndex < this.SnakeLength)
            {
                sprite_batch.Draw(texture, new Vector2(out_x, out_y), null, Color.White, 0, new Vector2(Snake.Size / 2f), new Vector2(grow_scale), SpriteEffects.None, 1);
            }
        }
 public override void onMouseDown(MouseEventArgs e)
 {
     base.onMouseDown(e);
     if (e.Button == MouseButtons.LeftButton)
     {
         if (this.IsClickOnSelf(e.Position))
         {
             if (this.ShouldVibrateOnClick)
             {
                 VibrationHelper.Vibrate();
             }
             if (this.ShouldPlaySoundOnClick)
             {
                 ContentHolder.Get(AvailableSounds.click).TryPlay();
             }
             this.OnClick?.Invoke();
             this.LastClickWasOnSelf = true;
         }
         else
         {
             this.LastClickWasOnSelf = false;
         }
     }
 }
Beispiel #21
0
        public override void onDraw(SpriteBatch sprite_batch)
        {
            base.onDraw(sprite_batch);

            var scaled_pos = new Vector2(
                this.Position.X - (this.BaseWidth / 2f) * this.Scale,
                this.Position.Y - (this.BaseHeight / 2f) * this.Scale);
            float scaled_width  = this.BaseWidth * this.Scale;
            float scaled_height = this.BaseHeight * this.Scale;
            var   vector_zero   = Vector2.Zero;
            var   textures      = new Dictionary <DrawDataTextures, Texture2D> {
                [DrawDataTextures.Snake]  = this.SnakeTexture,
                [DrawDataTextures.Food]   = this.FoodTexture,
                [DrawDataTextures.Wall]   = this.WallTexture,
                [DrawDataTextures.Portal] = ContentHolder.Get(AvailableTextures.portal_0)
            };

            // Cut out the base position from background and redraw (applicable for user imported themes)
            var background = new Region(this.BackgroundTexture, this.BaseX - this.BaseWidth / 2, this.BaseY - this.BaseHeight / 2, this.BaseWidth, this.BaseHeight, 0, 0);

            sprite_batch.Draw(background, scaled_pos, Color.White, 0, new Vector2(this.Scale));

            // Draw transparent overlay and borders
            float       edge  = 2 * this.Scale;
            const float alpha = (28 / 255f);

            RectangleDrawer.Draw(sprite_batch, scaled_pos.X, scaled_pos.Y, scaled_width, scaled_height, Color.Black * alpha);
            if (this.ShouldDrawBorder)
            {
                RectangleDrawer.Draw(sprite_batch, scaled_pos.X, scaled_pos.Y, scaled_width, edge, Color.Black * alpha);
                RectangleDrawer.Draw(sprite_batch, scaled_pos.X, scaled_pos.Y + scaled_height - edge, scaled_width, edge, Color.Black * alpha);
                RectangleDrawer.Draw(sprite_batch, scaled_pos.X, scaled_pos.Y + edge, edge, scaled_height - edge * 2, Color.Black * alpha);
                RectangleDrawer.Draw(sprite_batch, scaled_pos.X + scaled_width - edge, scaled_pos.Y + edge, edge, scaled_height - edge * 2, Color.Black * alpha);
            }

            this.ExtraDrawingBegin?.Invoke(sprite_batch);

            for (int i = 0; i < this.DrawData.Length; i++)
            {
                var data    = this.DrawData[i];
                var texture = textures[data.DrawDataTexture];
                for (int j = 0; j < data.Locations.Length; j++)
                {
                    var pos = data.Locations[j];
                    var source_rectangle = new Rectangle(0, 0, texture.Width, texture.Height);;

                    // Cut off left and top if necessary
                    if (pos.X < 0)
                    {
                        source_rectangle.X      = (int)(-pos.X / data.Scale);
                        source_rectangle.Width -= source_rectangle.X;
                        pos.X += source_rectangle.X * data.Scale;
                    }
                    if (pos.Y < 0)
                    {
                        source_rectangle.Y       = (int)(-pos.Y / data.Scale);
                        source_rectangle.Height -= source_rectangle.Y;
                        pos.Y += source_rectangle.Y * data.Scale;
                    }

                    // Cut off right and bottom if necessary
                    float right_x = pos.X + source_rectangle.Width * data.Scale;
                    if (right_x > this.BaseWidth)
                    {
                        source_rectangle.Width -= (int)((right_x - this.BaseWidth) / data.Scale);
                    }
                    float bottom_y = pos.Y + source_rectangle.Height * data.Scale;
                    if (bottom_y > this.BaseHeight)
                    {
                        source_rectangle.Height -= (int)((bottom_y - this.BaseHeight) / data.Scale);
                    }

                    sprite_batch.Draw(texture, scaled_pos + pos * this.Scale, source_rectangle, Color.White, 0, vector_zero, data.Scale * this.Scale, SpriteEffects.None, 0);
                }
            }

            this.ExtraDrawingEnd?.Invoke(sprite_batch);
        }
Beispiel #22
0
        public override void onSwitchTo(Room previous_room, Dictionary <string, object> args)
        {
            Engine.SpawnInstance <ControlPause>();
            Engine.SpawnInstance <ControlPortalAnimation>();

            // Set start delay if passed in through args
            int start_delay = 0;

            if (args != null && args.ContainsKey("start_delay"))
            {
                start_delay = (int)args["start_delay"];
            }

            // Load level data if called for by current game mode
            LevelData level_data = null;

            if (Settings.CurrentGameRoom == GameRooms.Classic)
            {
                level_data = new ClassicLevelData();
            }
            else if (Settings.CurrentGameRoom != GameRooms.Open)
            {
                level_data = Levels.Load((int)Settings.CurrentGameRoom);
            }

            // If level data exists either build level instantly if replaying room or spawn constructor if first entering room
            if (level_data != null)
            {
                if (previous_room is RoomPlay)
                {
                    if (level_data.WallSpawns != null)
                    {
                        foreach (var spawn in level_data.WallSpawns)
                        {
                            Engine.SpawnInstance(new Wall(spawn.X, spawn.Y, spawn.Scale));
                        }
                    }
                    if (level_data.PortalSpawns != null)
                    {
                        foreach (var spawn in level_data.PortalSpawns)
                        {
                            Engine.SpawnInstance(new Portal(spawn));
                        }
                    }
                }
                else
                {
                    start_delay += ControlLevelConstructor.TotalTimeToSpawnLevel(level_data);
                    Engine.SpawnInstance(new ControlLevelConstructor(level_data));
                }
            }

            // Spawn first food piece
            if (level_data?.FoodSpawn != null)
            {
                var spawn = level_data.FoodSpawn.Value;
                Engine.SpawnInstance(new ControlFoodSpawner(spawn.X, spawn.Y));
            }
            else
            {
                Engine.SpawnInstance <ControlFoodSpawner>();
            }

            // Spawn snake
            if (level_data?.SnakeSpawn != null)
            {
                var spawn = level_data.SnakeSpawn.Value;
                Engine.SpawnInstance(new Entities.Snake(start_delay, spawn));
            }
            else
            {
                Engine.SpawnInstance(new Entities.Snake(start_delay));
            }

            // Spawn timed execution to start music at snake movement start
            Engine.SpawnInstance(new TimedExecution(start_delay, () => {
                MediaPlayer.IsRepeating = true;
                MediaPlayer.Play(ContentHolder.Get(AvailableMusic.background_music));
            }));
        }
Beispiel #23
0
 public override void onDraw(SpriteBatch sprite_batch)
 {
     base.onDraw(sprite_batch);
     sprite_batch.Draw(ContentHolder.Get(Settings.CurrentBackground), this.Position, Color.White);
 }