コード例 #1
0
 /// <summary>New user joined to the game as observer.</summary>
 /// <param name="realm">Realm.</param>
 /// <param name="user">User.</param>
 /// <returns>Aceept user to the game?</returns>
 public override bool Enter(IRealm realm, User user)
 {
     user["player"] = new Player {
         X = 64 * 3,
         Name = "Player_" + DateTime.Now.Millisecond,
         ClientSessionId = user.Session
     };
     realm.AddEntity(user["player"]);
     return true;
 }
コード例 #2
0
        /// <summary>User input.</summary>
        /// <param name="realm">Realm.</param>
        /// <param name="user">User.</param>
        /// <param name="state">Keys.</param>
        public override void Input(IRealm realm, User user, InputState state)
        {
            var player = (Player)user["player"];
            var aimAngle = state.Get<float>("aimAngle");
            var fire = state.Get<bool>("fire");
            var aimAngleRad = aimAngle / 180.0f * Math.PI;

            if (fire) {
                var vectorX = (float)Math.Cos(aimAngleRad);
                var vectorY = (float)Math.Sin(aimAngleRad);
                var bullet = new Bullet {
                    X = player.X + vectorX * 25, Y = player.Y + vectorY * 25,
                    VectorX = vectorX * 50,
                    VectorY = vectorY * 50
                };
                realm.AddEntity(bullet);
            }
        }
コード例 #3
0
        /// <summary>Realm has been started.</summary>
        /// <param name="realm">Realm.</param>
        public override void Start(IRealm realm)
        {
            // Creates decorations
            realm.AddEntity(new Decoration { X = 64 * 3, Y = 64 * 3 });
            realm.AddEntity(new Decoration { X = 64 * 6, Y = 64 * 3 });

            // Creates ground
            realm.AddEntity(Ground.CreateBlock(64 * 1, 64 * 2));
            realm.AddEntity(Ground.CreateBlock(64 * 0, 64 * 10));
            realm.AddEntity(Ground.CreateBlock(64 * 1, 64 * 1));
            realm.AddEntity(Ground.CreateBlock(64 * 1, 64 * 5));
            realm.AddEntity(Ground.CreateBlock(64 * 2, 64 * 5));
            realm.AddEntity(Ground.CreateBlock(64 * 3, 64 * 5));
            realm.AddEntity(Ground.CreateBlock(64 * 3, 64 * 6));
            realm.AddEntity(Ground.CreateBlock(64 * 4, 64 * 6));
            realm.AddEntity(Ground.CreateBlock(64 * 5, 64 * 6));
            realm.AddEntity(Ground.CreateBlock(64 * 6, 64 * 8));
            realm.AddEntity(Ground.CreateBlock(64 * 7, 64 * 8));
            realm.AddEntity(Ground.CreateBlock(64 * 8, 64 * 8));
            realm.AddEntity(Ground.CreateBlock(64 * 6, 64 * 5));
            realm.AddEntity(Ground.CreateBlock(64 * 0, 64 * 1));
            for (var i = 0; i < 20; ++i) {
                realm.AddEntity(Ground.CreateBlock(64 * i, 64 * 9));
                realm.AddEntity(Ground.CreateBlock(64 * 12, 64 * i));
            }

            realm.AddEntity(new Ball { X = 64 * 3, Y = 64 * 3 });
            realm.AddEntity(new Gate { X = 64 * 6, Y = 64 * 4 });

            /*_realm.AddEntity(new Ground(new[] {
                new Point(10, 100), new Point(290, 250), new Point(420, 450),  new Point(580, 350), new Point(620, 750), new Point(30, 790)
            }));*/
        }