Exemple #1
0
 public override IEnumerable<Message> Handle(Model model)
 {
     foreach (var entry in q) {
         model.Terrain[entry.Key.X, entry.Key.Y] = entry.Value;
     }
     return null;
 }
Exemple #2
0
 public override IEnumerable<Message> Handle(Model model)
 {
     var e = model.FindEntity(id);
     if (e.Get<PushComponent>() == null)
         e.Set<PushComponent>(new PushComponent());
     e.Get<PushComponent>().Push(v);
     return null;
 }
Exemple #3
0
 public override System.Collections.Generic.IEnumerable<Message> Handle(Model model)
 {
     var e = model.FindEntity(id);
     if (e == null)
         yield return new GetEntity(id);
     else
         e.Get<HealthComponent>().Health += dhp;
 }
Exemple #4
0
 public SceneView(ClientView clientView)
 {
     this.clientView = clientView;
     this.client = clientView.client;
     this.model = clientView.model;
     terrain = model.Terrain;
     camera = client.Camera;
 }
        public override void Update(Model model, double dt)
        {
            base.Update(model, dt);

            foreach (var e in Entities) {
                Vec2 xy = e.Get<PositionComponent>().Position.XY;
                e.Get<PositionComponent>().Position = new Vec3(xy.X, xy.Y, model.Terrain.GetHeight(xy.X, xy.Y));
            }
        }
Exemple #6
0
 public override System.Collections.Generic.IEnumerable<Message> Handle(Model model)
 {
     var e = model.FindEntity(entityId);
     if (e == null)
         yield return new GetEntity(entityId);
     else {
         e.Get<WeaponComponent>().UpdateWeapon(weapon);
     }
 }
Exemple #7
0
 public override IEnumerable<Message> Handle(Model model)
 {
     UpdateTerrain reply = new UpdateTerrain();
     for (int i = fromX; i <= toX; i++)
         for (int j = fromY; j <= toY; j++) {
             reply[i, j] = model.Terrain[i, j];
         }
     yield return reply;
 }
Exemple #8
0
 public override void Render(Model model)
 {
     base.Render(model);
     foreach (var e in Entities) {
         var weapon = e.Get<WeaponComponent>().Weapon;
         if (weapon != null)
             weapon.Render();
     }
 }
 public override void UpdateOnce(Model model, double dt)
 {
     base.UpdateOnce(model, dt);
     foreach (var e in Entities) {
         if (e.Get<PushComponent>() == null) {
             e.Set<PushComponent>(new PushComponent());
         }
         e.Get<PushComponent>().UpdateOnce(dt);
     }
 }
Exemple #10
0
 public override void Update(Model model, double dt)
 {
     base.Update(model, dt);
     foreach (var e in Entities) {
         if (e.Get<HealthComponent>().Health <= 0) {
             if (model.Server != null) {
                 model.Server.RemoveEntity(e);
             }
         }
     }
 }
Exemple #11
0
 public override void UpdateOnce(Model model, double dt)
 {
     base.UpdateOnce(model, dt);
     nextBroadcast -= dt;
     if (nextBroadcast < 0) {
         nextBroadcast = Server.LAG;
         foreach (var e in Entities) {
             model.Server.AddToBroadcast(new Messages.MovementUpdate(e));
         }
     }
 }
Exemple #12
0
 public override void Update(Model model, double dt)
 {
     base.Update(model, dt);
     foreach (var e in Entities) {
         e.Get<MovementComponent>().Update(dt);
         var p = e.Get<PushComponent>();
         if (p != null) {
             p.Update(dt);
         }
     }
 }
Exemple #13
0
 public override void Update(Model model, double dt)
 {
     base.Update(model, dt);
     foreach (var e in Entities) {
         var weapon = e.Get<WeaponComponent>().Weapon;
         if (weapon != null) {
             weapon.Update(dt);
             if (e.Local)
                 weapon.CheckFire();
         }
     }
 }
Exemple #14
0
 public override void UpdateOnce(Model model, double dt)
 {
     base.UpdateOnce(model, dt);
     if (model.Server == null)
         return;
     nextBroadcast -= dt;
     if (nextBroadcast < 0) {
         nextBroadcast = Server.LAG;
         foreach (var e in Entities) {
             model.Server.AddToBroadcast(Messages.UpdateComponent.Create(e.Get<HealthComponent>()));
         }
     }
 }
Exemple #15
0
 public override void UpdateOnce(Model model, double dt)
 {
     base.UpdateOnce(model, dt);
     nextBroadcast -= dt;
     if (nextBroadcast < 0) {
         nextBroadcast = Server.LAG;
         foreach (var e in Entities) {
             var msg = new Messages.WeaponUpdate(e);
             if (model.Server != null)
                 model.Server.AddToBroadcast(msg);
             if (model.Client != null)
                 model.Client.AddToSend(msg);
         }
     }
 }
Exemple #16
0
 public override void Render(Model model)
 {
     base.Render(model);
     var entities = new List<Entity>(Entities);
     entities.Sort((Entity a, Entity b) => {
         Vec2 pa = Vec2.Rotate(a.Get<PositionComponent>().Position.XY, -model.Client.Camera.Rotation);
         Vec2 pb = Vec2.Rotate(b.Get<PositionComponent>().Position.XY, -model.Client.Camera.Rotation);
         return -pa.Y.CompareTo(pb.Y);
     });
     foreach (var e in entities) {
         RenderState.Push();
         RenderState.Translate(e.Get<PositionComponent>().Position);
         RenderState.FaceCam();
         e.Get<RenderComponent>().Render();
         RenderState.Pop();
     }
 }
Exemple #17
0
 public override void Render(Model model)
 {
     base.Render(model);
     foreach (var e in Entities) {
         RenderState.Push();
         RenderState.Translate(e.Get<PositionComponent>().Position);
         RenderState.FaceCam();
         RenderState.Translate(0, 1.7);
         RenderState.Scale(1, 0.1);
         RenderState.Origin(0.5, 0.5);
         RenderState.Color = Color.Red;
         Draw.Quad();
         RenderState.Scale(e.Get<HealthComponent>().Health / e.Get<HealthComponent>().MaxHealth, 1);
         RenderState.Color = Color.Green;
         Draw.Quad();
         RenderState.Pop();
     }
 }
        public override void Update(Model model, double dt)
        {
            base.Update(model, dt);
            foreach (var e in Entities) {
                if (e.Get<PushComponent>() == null) {
                    e.Set<PushComponent>(new PushComponent());
                }
                e.Get<PushComponent>().Update(dt);
            }
            foreach (var m1 in Entities) {
                foreach (var m2 in Entities) {
                    if (m1 == m2)
                        continue;
                    Vec3 dr = m2.Get<PositionComponent>().Position - m1.Get<PositionComponent>().Position;
                    if (dr.Length < m1.Get<PhysicsComponent>().Size + m2.Get<PhysicsComponent>().Size) {
                        var n = dr.Unit;
                        dr = n * (m1.Get<PhysicsComponent>().Size + m2.Get<PhysicsComponent>().Size - dr.Length) / 2;
                        if (!m1.Local || !m2.Local)
                            dr = Vec3.Clamp(dr, dt * MAX_PUSH_PER_SEC);
                        m1.Get<PushComponent>().Push(-dr);
                        m2.Get<PushComponent>().Push(+dr);

                        var dv = Vec3.Zero;
                        if (m2.Local)
                            dv += m2.Get<MovementComponent>().Velocity;
                        if (m1.Local)
                            dv -= m1.Get<MovementComponent>().Velocity;
                        var dvn = Vec3.Dot(dv, n);
                        if (dvn < 0) {
                            if (m1.Local)
                                m1.Get<MovementComponent>().Velocity += n * dvn;
                            if (m2.Local)
                                m2.Get<MovementComponent>().Velocity -= n * dvn;
                        }
                    }
                }
            }
        }
Exemple #19
0
 public virtual void Render(Model model)
 {
 }
Exemple #20
0
 public ClientView(string address, int port)
 {
     client = new Client(address, port);
     model = client.Model;
     Background = new SceneView(this);
 }
Exemple #21
0
 public override void Update(Model model, double dt)
 {
     base.Update(model, dt);
     foreach (var e in Entities)
         e.Get<RenderComponent>().Update(dt);
 }
Exemple #22
0
 public virtual void UpdateOnce(Model model, double dt)
 {
     entities.Refresh();
 }