func (fs *FallingSystem) Update(entity *engi.Entity, dt float32) { var space *engi.SpaceComponent if !entity.Component(&space) { return } space.Position.Y += 200 * dt }
func (c *ControlSystem) Update(entity *engi.Entity, dt float32) { //Check scheme // -Move entity based on that var control *ControlComponent var space *engi.SpaceComponent if !entity.Component(&space) || !entity.Component(&control) { return } up := false down := false if control.Scheme == "WASD" { up = engi.Keys.Get(engi.W).Down() down = engi.Keys.Get(engi.S).Down() } else { up = engi.Keys.Get(engi.ArrowUp).Down() down = engi.Keys.Get(engi.ArrowDown).Down() } if up { space.Position.Y -= 800 * dt } if down { space.Position.Y += 800 * dt } }
func (bs *BallSystem) Update(entity *engi.Entity, dt float32) { var space *engi.SpaceComponent var speed *SpeedComponent if !entity.Component(&space) || !entity.Component(&speed) { return } if space.Position.X < 0 { engi.Mailbox.Dispatch(ScoreMessage{1}) space.Position.X = 400 - 16 space.Position.Y = 400 - 16 speed.X = 800 * rand.Float32() speed.Y = 800 * rand.Float32() } if space.Position.Y < 0 { space.Position.Y = 0 speed.Y *= -1 } if space.Position.X > (800 - 16) { engi.Mailbox.Dispatch(ScoreMessage{2}) space.Position.X = 400 - 16 space.Position.Y = 400 - 16 speed.X = 800 * rand.Float32() speed.Y = 800 * rand.Float32() } if space.Position.Y > (800 - 16) { space.Position.Y = 800 - 16 speed.Y *= -1 } }
func (ms *SpeedSystem) Update(entity *engi.Entity, dt float32) { var speed *SpeedComponent var space *engi.SpaceComponent if !entity.Component(&speed) || !entity.Component(&space) { return } space.Position.X += speed.X * dt space.Position.Y += speed.Y * dt }
func (c *HideSystem) Update(e *engi.Entity, dt float32) { var render *engi.RenderComponent if !e.Component(&render) { return } if rand.Int()%10 == 0 { render.SetPriority(engi.Hidden) } else { render.SetPriority(engi.MiddleGround) } }
func (c *ControlSystem) Update(entity *engi.Entity, dt float32) { var a *engi.AnimationComponent if !entity.Component(&a) { return } if engi.Keys.Get(engi.ArrowRight).Down() { a.SelectAnimationByAction(WalkAction) } else if engi.Keys.Get(engi.Space).Down() { a.SelectAnimationByAction(SkillAction) } else { a.SelectAnimationByAction(StopAction) } }
func (c *ScaleSystem) Update(e *engi.Entity, dt float32) { var render *engi.RenderComponent if !e.Component(&render) { return } var mod float32 if rand.Int()%2 == 0 { mod = 0.1 } else { mod = -0.1 } if render.Scale.X+mod >= 15 || render.Scale.X+mod <= 1 { mod *= -1 } render.Scale.AddScalar(mod) }
func (c *ScoreSystem) Update(entity *engi.Entity, dt float32) { var render *engi.RenderComponent var space *engi.SpaceComponent if !entity.Component(&render) || !entity.Component(&space) { return } if !c.upToDate { c.scoreLock.RLock() render.Label = fmt.Sprintf("%v vs %v", c.PlayerOneScore, c.PlayerTwoScore) c.upToDate = true c.scoreLock.RUnlock() render.Display = basicFont.Render(render.Label) width := len(render.Label) * 20 space.Position.X = float32(400 - (width / 2)) } }
func (control *ControlSystem) Update(entity *engi.Entity, dt float32) { var space *engi.SpaceComponent if !entity.Component(&space) { return } speed := 400 * dt if engi.Keys.Get(engi.A).Down() { space.Position.X -= speed } if engi.Keys.Get(engi.D).Down() { space.Position.X += speed } if engi.Keys.Get(engi.W).Down() { space.Position.Y -= speed } if engi.Keys.Get(engi.S).Down() { space.Position.Y += speed } }