void AddSegment() { FlxSprite segment = new FlxSprite(-20, -20); segment.MakeGraphic(BLOCK_SIZE - 2, BLOCK_SIZE - 2, Color.Green); segment.DebugColor = Color.Yellow; _snakeBody.Add(segment, true); }
protected override void Create() { BackgroundColor = Color.Gray; VisibleBoundingbox = true; spriteA = new FlxSprite(10, 10); spriteA.MakeGraphic(128, 128, Color.White); spriteA.ScrollFactor = Vector2.Zero; spriteB = new FlxSprite(200, 400); spriteB.MakeGraphic(160, 16, Color.Yellow); spriteB.Immovable = true; spriteB.ScrollFactor = new Vector2(0.5f, 0.5f); text1 = new FlxText("Font"); text2 = new FlxText("Font", 0, 0, FlxG.Width); text2.Alignment = FlxTextAlign.LEFT; text3 = new FlxText("Font", 0, 0, FlxG.Width); text3.Alignment = FlxTextAlign.CENTER; text4 = new FlxText("Font", 0, 0, FlxG.Width); text4.Alignment = FlxTextAlign.RIGHT; text5 = new FlxText("BigFont", 0, 0, FlxG.Width, "Hello World"); text5.BorderStyle = FlxTextBorderStyle.SHADOW; text5.BorderColor = Color.Black; text5.BorderSize = 4; text5.ScreenCenter(); text1.X = 10; text1.Y = FlxG.Height - 40; text2.X = 10; text2.Y = FlxG.Height - 20; text3.X = 10; text3.Y = FlxG.Height - 60; text4.X = 10; text4.Y = FlxG.Height - 80; flxBar = new FlxBar(50, 50); flxBar.CreateFilledBar(Color.DarkBlue, Color.Cyan, true, Color.Black); flxBar.Value = 40; flxBar.SetParent(spriteA, null, true, (int)(spriteA.FrameWidth - flxBar.Width) / 2, -20); Add(spriteA); Add(spriteB); Add(text1); Add(text2); Add(text3); Add(text4); Add(text5); Add(flxBar); }
protected override void Create() { //VisibleHitbox = true; int screenMiddleX = (int)Math.Floor(FlxG.Width / 2f); int screenMiddleY = (int)Math.Floor(FlxG.Height / 2f); _snakeHead = new FlxSprite(screenMiddleX - BLOCK_SIZE * 2, screenMiddleY); _snakeHead.MakeGraphic(BLOCK_SIZE - 2, BLOCK_SIZE - 2, Color.Lime); _snakeHead.DebugColor = Color.Yellow; OffsetSprite(_snakeHead); _headPositions = new List <Vector2> { new Vector2(_snakeHead.X, _snakeHead.Y) }; _snakeBody = new FlxSpriteGroup(); Add(_snakeBody); for (int i = 0; i < 3; i++) { AddSegment(); MoveSnake(); } Add(_snakeHead); _fruit = new FlxSprite(); _fruit.MakeGraphic(BLOCK_SIZE - 2, BLOCK_SIZE - 2, Color.Red); RandomizeFruitPosition(); OffsetSprite(_fruit); Add(_fruit); _scoreText = new FlxText(0, 0, 200, "Score: " + _score); Add(_scoreText); ResetTimer(); _gameOverSound = Game.Content.Load <SoundEffect>(FlxAssets.SOUND_FLIXEL); _beepSound = Game.Content.Load <SoundEffect>(FlxAssets.SOUND_BEEP); }
protected override void Create() { FlxG.Mouse.Visible = true; _bat = new FlxSprite(180, 220); _bat.MakeGraphic(40, 6, Color.Magenta); _bat.Immovable = true; _ball = new FlxSprite(180, 160); _ball.MakeGraphic(6, 6, Color.Magenta); _ball.Elasticity = 1; _ball.MaxVelocity = new Vector2(200, 200); _ball.Velocity.Y = 200; _walls = new FlxGroup(); _leftWall = new FlxSprite(0, 0); _leftWall.MakeGraphic(10, 240, Color.Gray); _leftWall.Immovable = true; _walls.Add(_leftWall); _rightWall = new FlxSprite(310, 0); _rightWall.MakeGraphic(10, 240, Color.Gray); _rightWall.Immovable = true; _walls.Add(_rightWall); _topWall = new FlxSprite(0, 0); _topWall.MakeGraphic(320, 10, Color.Gray); _topWall.Immovable = true; _walls.Add(_topWall); _bottomWall = new FlxSprite(0, 239); _bottomWall.MakeGraphic(320, 10, Color.Transparent); _bottomWall.Immovable = true; _walls.Add(_bottomWall); _bricks = new FlxGroup(); int bx = 10; int by = 30; Color[] brickColors = { new Color(208, 58, 209), new Color(247, 83, 82), new Color(253, 128, 20), new Color(255, 144, 36), new Color(5, 179, 32), new Color(109, 101, 246) }; for (int y = 0; y < 6; y++) { for (int x = 0; x < 20; x++) { FlxSprite tempBrick = new FlxSprite(bx, by); tempBrick.MakeGraphic(15, 15, brickColors[y]); tempBrick.Immovable = true; _bricks.Add(tempBrick); bx += 15; } bx = 10; by += 15; } Add(_walls); Add(_bat); Add(_ball); Add(_bricks); }