コード例 #1
0
ファイル: Player.cs プロジェクト: Trayus/cpgd_diskwars
        public Player(Vector2[] spawn, int num, GameState gameState)
        {
            this.num = num;
            this.spawn = spawn;
            this.gameState = gameState;
            switch (num)
            {
                case 1:
                    animation = Animation.createSingleFrameAnimation("player/redplayer", spawn[num-1], 0.9f);
                    disk = new Disk(this, "player/reddisk", spawn[num - 1] + new Vector2(0, 20), new Color(0.8f, 0.1f, 0.1f));
                    playerlight = new Light(new Color(1f, 0.2f, 0.2f), animation.position, Constants.PLAYERLIGHTPOWER * 2, Constants.PLAYERLIGHTSIZE);
                    break;
                case 2:
                    animation = Animation.createSingleFrameAnimation("player/yellowplayer", spawn[num - 1], 0.9f);
                    disk = new Disk(this, "player/yellowdisk", spawn[num - 1] + new Vector2(0, 20), new Color(0.8f, 0.8f, 0.1f));
                    playerlight = new Light(new Color(1f, 1f, 0.2f), animation.position, Constants.PLAYERLIGHTPOWER, Constants.PLAYERLIGHTSIZE);
                    break;
                case 3:
                    animation = Animation.createSingleFrameAnimation("player/greenplayer", spawn[num - 1], 0.9f);
                    disk = new Disk(this, "player/greendisk", spawn[num - 1] + new Vector2(0, 20), new Color(0.1f, 0.8f, 0.1f));
                    playerlight = new Light(new Color(0.2f, 1f, 0.2f), animation.position, Constants.PLAYERLIGHTPOWER, Constants.PLAYERLIGHTSIZE);
                    break;
                case 4:
                    animation = Animation.createSingleFrameAnimation("player/blueplayer", spawn[num - 1], 0.9f);
                    disk = new Disk(this, "player/bluedisk", spawn[num - 1] + new Vector2(0, 20), new Color(0.1f, 0.1f, 0.8f));
                    playerlight = new Light(new Color(0.2f, 0.2f, 1f), animation.position, Constants.PLAYERLIGHTPOWER * 2, Constants.PLAYERLIGHTSIZE);
                    break;
            }
            speedPUAnimation = Animation.createSingleFrameAnimation("player/orangepowerup", spawn[num - 1], 0.95f);
            speedPUAnimation.setVisible(false);

            shieldPUAnimation = Animation.createSingleFrameAnimation("player/shieldpu", spawn[num - 1], 1.0f);
            shieldPUAnimation.setVisible(false);
            shieldPUAnimation.setScale(20f);

            animation.setScale(Constants.PLAYERSCALE);
            disk.setScale(Constants.PLAYERSCALE);
            speedPUAnimation.setScale(Constants.PLAYERSCALE);
            shieldPUAnimation.setScale(Constants.PLAYERSCALE);
            powerUps = new List<PowerUp>();
            random = new Random(num);
        }
コード例 #2
0
ファイル: Disk.cs プロジェクト: Trayus/cpgd_diskwars
        public bool collide(Disk other)
        {
            if (Vector2.Distance(animation.position, other.animation.position) < 2 * diskRadius)
            {
                if (!this.stopped && !diskPierce)
                {
                    Vector2 axis = animation.position - other.animation.position;
                    axis.Normalize();
                    Vector3 midden = Vector3.Cross(new Vector3(axis, 0), Vector3.UnitZ);
                    Vector2 mid = new Vector2(midden.X, midden.Y);

                    float speed = this.velocity.Length();
                    this.velocity = this.velocity * Vector2.Dot(this.velocity, axis) + mid * Vector2.Dot(this.velocity, mid);
                    if (this.velocity.X != 0 && this.velocity.Y != 0)
                    {
                        this.velocity.Normalize();
                        this.velocity *= speed;
                    }
                }
                if (!other.stopped)
                {
                    Vector2 axis = other.animation.position - animation.position;
                    axis.Normalize();
                    Vector3 midden = Vector3.Cross(new Vector3(axis, 0), Vector3.UnitZ);
                    Vector2 mid = new Vector2(midden.X, midden.Y);

                    float speed = other.velocity.Length();
                    other.velocity = other.velocity * Vector2.Dot(other.velocity, axis) + mid * Vector2.Dot(other.velocity, mid);
                    if (other.velocity.X != 0 && other.velocity.Y != 0)
                    {
                        other.velocity.Normalize();
                        other.velocity *= speed;
                    }
                }
                SoundManager.PlaySound("sound/dw_diskhit");
                return true;
            }
            return false;
        }
コード例 #3
0
ファイル: EntryPoint.cs プロジェクト: GigaGrunch/DiskWars
        async void ReadServerMessagesAsync()
        {
            StreamReader reader = new StreamReader(_networkStream);

            while (_networkListening)
            {
                Task <string> readTask = reader.ReadLineAsync();
                await         readTask;

                string json = readTask.Result;
                if (string.IsNullOrWhiteSpace(json))
                {
                    continue;
                }

                Debug.Log(json);

                NetworkMessage message = JsonUtility.FromJson <NetworkMessage>(json);

                switch (message.type)
                {
                case NetworkMessage.Type.Chat:
                    Debug.Log(message.chat.message);
                    break;

                case NetworkMessage.Type.DiskSpawn:
                    SpawnDisk(message.diskSpawn.diskName, message.diskSpawn.player);
                    break;

                case NetworkMessage.Type.DiskMove:
                    Disk disk = _disks[message.diskMove.diskID];
                    disk.Position       = message.diskMove.targetLocation;
                    disk.RemainingMoves = message.diskMove.remainingMoves;
                    GameObject    actor         = _actorByID[disk.ID];
                    FlapAnimation flapAnimation = new FlapAnimation
                    {
                        Actor          = actor,
                        TargetLocation = disk.Position
                    };
                    _flapQueue.Enqueue(flapAnimation);
                    break;

                case NetworkMessage.Type.InitializeClient:
                    _playerID = message.initializeClient.playerID;
                    break;

                case NetworkMessage.Type.PlayerTurnUpdateMessage:
                    _currentPlayer             = message.playerTurnUpdate.currentPlayer;
                    _currentPlayerDisplay.text = _currentPlayer == _playerID
                            ? "It's your turn!"
                            : $"Player {_currentPlayer}'s turn";
                    if (_currentPlayer == _playerID)
                    {
                        _diskGhost.SetActive(true);
                    }
                    break;

                default:
                    Debug.LogError($"{message.type} is not a valid value for {typeof(NetworkMessage.Type)}.");
                    break;
                }
            }
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: Trayus/cpgd_diskwars
        public bool check(Disk other)
        {
            if (Vector2.Distance(animation.position, other.animation.position) < Constants.DISKRADIUS + Constants.PLAYERRADIUS)
            {
                if (!pUShield)
                {
                    kill();
                    return true;
                }
                else
                {
                    Vector2 axis = other.animation.position - animation.position;
                    axis.Normalize();
                    Vector3 midden = Vector3.Cross(new Vector3(axis, 0), Vector3.UnitZ);
                    Vector2 mid = new Vector2(midden.X, midden.Y);

                    float speed = other.velocity.Length() * 1.5f;
                    other.velocity = other.velocity * Vector2.Dot(other.velocity, axis) + mid * Vector2.Dot(other.velocity, mid);
                    other.velocity.Normalize();
                    other.velocity *= speed;

                    pUShield = false;
                    shieldPUAnimation.setVisible(pUShield);
                    foreach (PowerUp pu in powerUps)
                    {
                        if (pu.type == PowerUp.TYPE.shield)
                            pu.activeTime = -1;
                    }
                }
            }
            return false;
        }