private void Initialize(Event e) { RemoveEventListener(Event.ADDED_TO_STAGE, Initialize); var bg = new Bitmap(Assets.GetBitmapData("background")); AddChild(bg); bg.ScaleX = bg.ScaleY = stage.StageWidth; bgContainer = new Sprite(); bgLayers = new Sprite[3]; AddChild(bgContainer); for (int i = 0; i < 3; ++i) { bgLayers[i] = new Sprite(); var bmp1 = new Bitmap(Assets.GetBitmapData(String.Format("layer{0}", i + 1))); var bmp2 = new Bitmap(Assets.GetBitmapData(String.Format("layer{0}", i + 1))); bmp2.X = bmp1.Width; bgLayers[i].AddChild(bmp1); bgLayers[i].AddChild(bmp2); bgContainer.AddChild(bgLayers[i]); } bgLayers[0].Y -= bgLayers[0].Height * 0.2f; bgLayers[0].ScaleY *= 1.2f; }
private void Initialize(Event e) { RemoveEventListener(Event.ADDED_TO_STAGE, Initialize); bgContainer = new Sprite(); bgLayers = new Sprite[3]; AddChild(bgContainer); for (int i = 0; i < 3; ++i) { bgLayers[i] = new Sprite(); var bmp1 = new Bitmap(Assets.GetBitmapData(String.Format("layer{0}", i + 1))); var bmp2 = new Bitmap(Assets.GetBitmapData(String.Format("layer{0}", i + 1))); bmp2.X = bmp1.Width; bgLayers[i].AddChild(bmp1); bgLayers[i].AddChild(bmp2); bgContainer.AddChild(bgLayers[i]); } AddEventListener(Event.ENTER_FRAME, Update); }
public Bullet(bool flipped) { this.flipped = flipped; bmp = new Bitmap(Assets.GetBitmapData("simple", true)); bmp.X = -bmp.Width / 2; bmp.Y = -bmp.Height / 2; bmp.Rotation = 90; AddChild(bmp); }
public override void Load() { // Создаем фон bgContainer = new Sprite(); bgLayers = new Sprite[3]; AddChild(bgContainer); for (int i = 0; i < 3; ++i) { bgLayers[i] = new Sprite(); var bmp1 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true)); var bmp2 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true)); bmp2.X = bmp1.Width; bgLayers[i].AddChild(bmp1); bgLayers[i].AddChild(bmp2); bgContainer.AddChild(bgLayers[i]); } // Интерфейс Меню guiContainer = new Sprite(); AddChild(guiContainer); // Лого logo = new Bitmap(Assets.GetBitmapData("assets/logo", true)); // logo.font = Assets.GetFont("assets/MainFont"); // logo.text = "MULTIPLANES"; logo.X = GameMain.ScreenWidth / 2 - logo.Width / 2; logo.Y = 10 / GameMain.mainScale; time = 0; guiContainer.AddChild(logo); // Кнопка join joinButton = new TextField(); joinButton.font = Assets.GetFont("assets/MainFont"); joinButton.text = "Join game"; joinButton.ScaleX = joinButton.ScaleY = 0.5f; joinButton.X = GameMain.ScreenWidth / 2 - joinButton.Width / 2; joinButton.Y = GameMain.ScreenHeight / 2 + joinButton.Height; guiContainer.AddChild(joinButton); // Самолетик plane = new Bitmap(Assets.GetBitmapData("assets/plane_red")); plane.Y = (joinButton.Y + (logo.Y + logo.Height)) / 2 - plane.Height / 2; plane.X = GameMain.ScreenWidth / 2 - plane.Width / 2; guiContainer.AddChild(plane); // Кнопка host hostButton = new TextField(); hostButton.font = joinButton.font; hostButton.text = "Host game"; hostButton.ScaleX = hostButton.ScaleY = 0.5f; hostButton.X = GameMain.ScreenWidth / 2 - hostButton.Width / 2; hostButton.Y = joinButton.Y + joinButton.Height; guiContainer.AddChild(hostButton); joinButton.AddEventListener(Event.TOUCH_END, joinGameEvent); hostButton.AddEventListener(Event.TOUCH_END, hostGameEvent); }
public override void Load() { bgContainer = new Sprite(); bgLayers = new Sprite[3]; AddChild(bgContainer); for (int i = 0; i < 3; ++i) { bgLayers[i] = new Sprite(); var bmp1 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true)); var bmp2 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true)); bmp2.X = bmp1.Width; bgLayers[i].AddChild(bmp1); bgLayers[i].AddChild(bmp2); bgContainer.AddChild(bgLayers[i]); } // GUI guiContainer = new Sprite(); AddChild(guiContainer); NetPeerConfiguration config = new NetPeerConfiguration("multiplanes-network"); client = new NetClient(config); client.Start(); client.DiscoverLocalPeers(14242); client.DiscoverKnownPeer(GameClient.NET_ADRESS, GameClient.NET_PORT); nick = NickGenerator.GenerateNick(client.UniqueIdentifier); var screenNameLabel = new TextField(); screenNameLabel.font = Assets.GetFont("assets/MainFont"); screenNameLabel.text = "HOST GAME"; screenNameLabel.X = GameMain.ScreenWidth / 2 - screenNameLabel.Width / 2; screenNameLabel.Y = 10 / GameMain.mainScale; guiContainer.AddChild(screenNameLabel); var roomNameLabel = new TextField(); roomNameLabel.font = screenNameLabel.font; roomNameLabel.text = "Room name: " + nick; roomNameLabel.X = GameMain.ScreenWidth * 0.1f; roomNameLabel.Y = GameMain.ScreenHeight / 2 - roomNameLabel.Height / 2; roomNameLabel.ScaleX = roomNameLabel.ScaleY = 0.5f; guiContainer.AddChild(roomNameLabel); waitLabel = new TextField(); waitLabel.font = roomNameLabel.font; waitLabel.text = "Waiting for other player to connect. . ."; waitLabel.X = roomNameLabel.X; waitLabel.Y = roomNameLabel.Y + roomNameLabel.Height; waitLabel.ScaleX = waitLabel.ScaleY = 0.25f; guiContainer.AddChild(waitLabel); }
public Bullet(float x, float y, float rotation, bool isLocal) { X = x; Y = y; Rotation = rotation; var bmp = new Bitmap(Assets.GetBitmapData("assets/bullet", true)); bmp.X = -bmp.Width / 2; bmp.Y = -bmp.Height / 2; AddChild(bmp); this.isLocal = isLocal; this.lifeTime = MAX_LIFETIME; }
public override void Load() { var background = new MenuBackground(); AddChild(background); float ActualWidth = stage.StageWidth / GameMain.mainScale / 2f; float ActualHeight = stage.StageHeight / GameMain.mainScale / 2f; Levels = new Bitmap[CountLevels]; float widthBitmap = GiveCurrentData(); float heightBitmap = stage.StageHeight / 4; for (int k = 0; k < Levels.Length; k++) { Bitmap bmp = new Bitmap(Assets.GetBitmapData(String.Format("{0}", k + 1))); bmp.ScaleX = widthBitmap / bmp.Width / GameMain.mainScale; bmp.ScaleY = widthBitmap / bmp.Height / GameMain.mainScale; bmp.X = (leftContain + (widthBitmap + space) * k) / GameMain.mainScale; bmp.Y = 200 / GameMain.mainScale; AddChild(bmp); Levels[k] = bmp; bmp.AddEventListener(Event.TOUCH_END, levelButtonClick); } logoSelectLevel = new Bitmap(Assets.GetBitmapData("selectLevelLogo")); logoSelectLevel.ScaleX = logoSelectLevel.ScaleY = 1.25f; logoSelectLevel.X = stage.StageWidth / GameMain.mainScale / 2f - logoSelectLevel.Width / 2f; logoSelectLevel.Y = 5; AddChild(logoSelectLevel); buttonBack = new TextField(); buttonBack.text = "Back"; buttonBack.font = Assets.GetFont("MainFont"); buttonBack.ScaleX = buttonBack.ScaleY = 2f; buttonBack.X = logoSelectLevel.X + logoSelectLevel.Width / 2 - buttonBack.Width / 2; buttonBack.Y = Levels[0].Y + Levels[0].Height + 50f / GameMain.mainScale; AddChild(buttonBack); buttonBack.AddEventListener(Event.TOUCH_END, backToMenu); }
public Tile(int xpos = 0, int ypos = 0, byte type = 0) { this.x_pos = xpos; this.y_pos = ypos; this.type = (int)(type & 0x0F); if (this.type != 0) { var bmp = new Bitmap(Assets.GetBitmapData("assets/levels/" + (type >> 4) + "/" + this.type)); AddChild(bmp); } this.ScaleX = this.ScaleY = Level.TILE_SIZE / this.Width; this.X = Level.TILE_SIZE * xpos; this.Y = Level.TILE_SIZE * y_pos; // this.visible = false; }
public override void Load() { ActualWidth = stage.StageWidth / GameMain.mainScale / 2f; ActualHeight = stage.StageHeight / GameMain.mainScale / 2f; //Фон /*BitmapData backGr = Assets.GetBitmapData("Image"); Bitmap bitmap1 = new Bitmap(backGr); AddChild(bitmap1); // Center bitmap bitmap1.X = 0; bitmap1.Y = 0; //bitmap1.ScaleX = stage.StageWidth / (bitmap1.Width * GameMain.mainScale); bitmap1.ScaleY = stage.StageHeight / (bitmap1.Height * GameMain.mainScale); bitmap1.ScaleX = bitmap1.ScaleY;*/ var background = new MenuBackground(); AddChild(background); //Логотип BitmapData texture = Assets.GetBitmapData("Logo"); bitmap = new Bitmap(texture); AddChild(bitmap); // Center bitmap bitmap.ScaleX = bitmap.ScaleY = 0.1f; bitmap.X = ActualWidth;// - bitmap.Width / 2f; bitmap.Y = ActualHeight;// - bitmap.Height / 2f; //Старт гейм joinButton = new TextField(); joinButton.font = Assets.GetFont("MainFont"); joinButton.text = "Start game"; joinButton.textColor = Color.White; //joinButton.ScaleX = joinButton.ScaleY = 2f / GameMain.mainScale; joinButton.X = ActualWidth - joinButton.Width / 2; joinButton.Y = ActualHeight * 2;//ActualHeight + joinButton.Height AddChild(joinButton); joinButton.AddEventListener(Event.TOUCH_END, changeLevels); }
public Player(string nick = "NoName", bool isLocal = false) { string planeColor = (isLocal) ? "red" : "blue"; HP = MAX_HP; bmp = new Bitmap(Assets.GetBitmapData("assets/plane_" + planeColor, false)); bmp.X = -bmp.Width / 2; bmp.Y = -bmp.Height / 2; AddChild(bmp); this.isLocal = isLocal; this.nick = nick; name = new TextField(); name.font = Assets.GetFont("assets/MainFont"); name.text = nick; name.ScaleX = name.ScaleY = 0.3f; name.X = bmp.X - (name.Width / 2); name.Y = bmp.Y - bmp.Height - name.Height; // AddChild(name); }
private void Initialize(Event e) { RemoveEventListener(Event.ADDED_TO_STAGE, Initialize); fire = new Bitmap(Assets.GetBitmapData("fire")); left = new Bitmap(Assets.GetBitmapData("left")); right = new Bitmap(Assets.GetBitmapData("right")); up = new Bitmap(Assets.GetBitmapData("up")); AddChild(fire); fire.X = stage.StageWidth / GameMain.mainScale - fire.Width / GameMain.mainScale - 20; fire.Y = stage.StageHeight / GameMain.mainScale - fire.Height / GameMain.mainScale - 13; AddChild(left); left.X = 10; left.Y = fire.Y; AddChild(right); right.X = left.X + left.Width + 10; right.Y = fire.Y; AddChild(up); up.X = fire.X - up.Width / GameMain.mainScale - 20; up.Y = fire.Y; // AddEventListener(Event.ENTER_FRAME, Update); }
void LoadBackground(int levelNumber) { levelNumber += 1; if (levelNumber > 4) throw new IndexOutOfRangeException(); // Удаляем старый фон for (int i = 0; i < 3; ++i) { bgContainer.RemoveChild(bgLayers[i]); bgLayers[i] = null; } for (int i = 0; i < 3; ++i) { bgLayers[i] = new Sprite(); BitmapData bmpData = Assets.GetBitmapData("assets/background/" + levelNumber + "/"+ (i + 1).ToString(), true); var bmp1 = new Bitmap(bmpData); var bmp2 = new Bitmap(bmpData); bmp2.X = bmp1.Width; bgLayers[i].AddChild(bmp1); bgLayers[i].AddChild(bmp2); bgContainer.AddChild(bgLayers[i]); } }
public override void Load() { worldContainer = new Sprite(); AddChild(worldContainer); bullets = new List<Bullet>(); reloadTime = 0; // Фон bgLayers = new Sprite[3]; bgContainer = new Sprite(); worldContainer.AddChild(bgContainer); LoadBackground(levelNumber); // Игра gameContainer = new Sprite(); worldContainer.AddChild(gameContainer); localPlayer = new Player(localNick, true); remotePlayer = new Player(remoteNick, false); if (isHost) { localPlayer.X = localPlayer.Y = remotePlayer.Y = 10; remotePlayer.X = WORLD_WIDTH - GameMain.ScreenWidth / 2; remotePlayer.Rotation = 180; remotePlayer.ScaleY = -1; } else { remotePlayer.X = remotePlayer.Y = localPlayer.Y = 10; localPlayer.X = WORLD_WIDTH - GameMain.ScreenWidth / 2; localPlayer.Rotation = 180; localPlayer.ScaleY = -1; } gameContainer.AddChild(localPlayer); gameContainer.AddChild(remotePlayer); // Интерфейс guiContainer = new Sprite(); AddChild(guiContainer); #if __MOBILE__ // Кнопка тормоза decelerateButton = new Bitmap(Assets.GetBitmapData("assets/ui/down")); decelerateButton.Y = GameMain.ScreenHeight - decelerateButton.Height; guiContainer.AddChild(decelerateButton); decelerateButton.AddEventListener(Event.TOUCH_MOVE, onDecelerateBegin); decelerateButton.AddEventListener(Event.TOUCH_END, onDecelerateEnd); // Кнопка вправо rightButton = new Bitmap(Assets.GetBitmapData("assets/ui/right")); rightButton.X = GameMain.ScreenWidth - rightButton.Width; rightButton.Y = decelerateButton.Y; guiContainer.AddChild(rightButton); rightButton.AddEventListener(Event.TOUCH_MOVE, onRotateBegin); rightButton.AddEventListener(Event.TOUCH_END, onRotateEnd); // Кнопка вправо leftButton = new Bitmap(Assets.GetBitmapData("assets/ui/left")); leftButton.X = rightButton.X - leftButton.Width; leftButton.Y = rightButton.Y; guiContainer.AddChild(leftButton); leftButton.AddEventListener(Event.TOUCH_MOVE, onRotateBegin); leftButton.AddEventListener(Event.TOUCH_END, onRotateEnd); // Кнопка стрельбы fireButton = new Bitmap(Assets.GetBitmapData("assets/ui/fire")); fireButton.X = decelerateButton.X + decelerateButton.Width; fireButton.Y = decelerateButton.Y; guiContainer.AddChild(fireButton); fireButton.AddEventListener(Event.TOUCH_END, onFireBegin); leftButton.color = rightButton.color = decelerateButton.color = fireButton.color = new Color(Color.DarkGray, 20); #endif if (isHost) ChangeLevel(); resultLabel = new TextField(); resultLabel.font = Assets.GetFont("assets/MainFont"); resultLabel.visible = false; countLabel = new TextField(); countLabel.font = resultLabel.font; countLabel.visible = false; guiContainer.AddChild(resultLabel); guiContainer.AddChild(countLabel); }
public override void Unload() { joinButton.RemoveEventListener(Event.TOUCH_END, joinGameEvent); hostButton.RemoveEventListener(Event.TOUCH_END, hostGameEvent); bgLayers = null; logo = null; time = 0; }
public override void Load() { // Background bgContainer = new Sprite(); bgLayers = new Sprite[3]; AddChild(bgContainer); for (int i = 0; i < 3; ++i) { bgLayers[i] = new Sprite(); var bmp1 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true)); var bmp2 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true)); bmp2.X = bmp1.Width; bgLayers[i].AddChild(bmp1); bgLayers[i].AddChild(bmp2); bgContainer.AddChild(bgLayers[i]); } // GUI guiContainer = new Sprite(); AddChild(guiContainer); hosts = new List<HostLabel>(); font = Assets.GetFont("assets/MainFont"); var screenNameLabel = new TextField(); screenNameLabel.font = font; screenNameLabel.text = "JOIN GAME"; screenNameLabel.X = GameMain.ScreenWidth / 2 - screenNameLabel.Width / 2; screenNameLabel.Y = 10 / GameMain.mainScale; guiContainer.AddChild(screenNameLabel); pointerLabel = new TextField(); pointerLabel.font = screenNameLabel.font; pointerLabel.text = "Select a game to join"; pointerLabel.ScaleX = pointerLabel.ScaleY = 0.4f; pointerLabel.X = GameMain.ScreenWidth / 2 - pointerLabel.Width / 2; pointerLabel.Y = screenNameLabel.Y + screenNameLabel.Height; guiContainer.AddChild(pointerLabel); connectButton = new TextField(); connectButton.font = font; connectButton.text = "Connect"; connectButton.ScaleX = connectButton.ScaleY = 0.5f; connectButton.X = GameMain.ScreenWidth * 0.25f - connectButton.Width / 2; connectButton.Y = GameMain.ScreenHeight - connectButton.Height; connectButton.textColor = Color.DarkGray; guiContainer.AddChild(connectButton); refreshButton = new TextField(); refreshButton.font = font; refreshButton.text = "Refresh"; refreshButton.ScaleX = refreshButton.ScaleY = 0.5f; refreshButton.X = GameMain.ScreenWidth * 0.75f - refreshButton.Width / 2; refreshButton.Y = connectButton.Y; guiContainer.AddChild(refreshButton); connectButton.AddEventListener(Event.TOUCH_END, onButtonDown); refreshButton.AddEventListener(Event.TOUCH_END, onButtonDown); NetPeerConfiguration config = new NetPeerConfiguration("multiplanes-network"); client = new NetClient(config); client.Start(); nick = NickGenerator.GenerateNick((client.UniqueIdentifier)); client.DiscoverLocalPeers(14242); client.DiscoverKnownPeer(GameClient.NET_ADRESS, GameClient.NET_PORT); }