func (c *ControlSystem) Update(entity *ecs.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 (fs *FallingSystem) Update(entity *ecs.Entity, dt float32) { var space *engi.SpaceComponent if !entity.Component(&space) { return } space.Position.Y += 200 * dt }
func (bs *BallSystem) Update(entity *ecs.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 (a *MovementSystem) Update(entity *ecs.Entity, dt float32) { var move *MovementComponent if !entity.Component(&move) { return } if !move.started { move.started = true move.timeLeft = float32(move.In.Seconds()) move.speedX = (move.From.X - move.To.X) / move.timeLeft move.speedY = (move.From.Y - move.To.Y) / move.timeLeft } move.timeLeft -= dt var space *engi.SpaceComponent if !entity.Component(&space) { return } space.Position.X -= move.speedX * dt space.Position.Y -= move.speedY * dt if move.timeLeft < 0 { // Because we might move more than needed space.Position.X -= move.speedX * move.timeLeft space.Position.Y -= move.speedY * move.timeLeft move.timeLeft = 0 } if move.timeLeft == 0 { entity.RemoveComponent(move) move.Callback() } }
func (ms *SpeedSystem) Update(entity *ecs.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 *ecs.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 *ecs.Entity, dt float32) { var mouse *engi.MouseComponent if !entity.Component(&mouse) { return } if mouse.Enter { engi.SetCursor(engi.Hand) } else if mouse.Leave { engi.SetCursor(engi.Arrow) } }
func (c *ControlSystem) Update(entity *ecs.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 *ScoreSystem) Update(entity *ecs.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.SetDrawable(basicFont.Render(render.Label)) width := len(render.Label) * 20 space.Position.X = float32(400 - (width / 2)) } }
func (c *ScaleSystem) Update(e *ecs.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 } newScale := render.Scale() newScale.AddScalar(mod) render.SetScale(newScale) }
func (control *ControlSystem) Update(entity *ecs.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 } }