Пример #1
0
func (m *Maze) New(w *ecs.World) {
	ActiveMazeSystem = m
	m.System = ecs.NewSystem()
	m.World = w

	tilePlayer = helpers.GenerateSquareComonent(tilePlayerColor, tilePlayerColor, tileWidth, tileHeight, engi.MiddleGround)
	tileWall = helpers.GenerateSquareComonent(tileWallColor, tileWallColor, tileWidth, tileHeight, engi.ScenicGround+1)
	tileBlank = helpers.GenerateSquareComonent(tileBlankColor, tileBlankColor, tileWidth, tileHeight, engi.ScenicGround+2)
	tileGoal = helpers.GenerateSquareComonent(tileGoalColor, tileGoalColor, tileWidth, tileHeight, engi.ScenicGround+3)
	tileRoute = helpers.GenerateSquareComonent(tileRouteColor, tileRouteColor, tileWidth, tileHeight, engi.ScenicGround+4)

	m.levels = LoadLevels(m.LevelDirectory)

	engi.Mailbox.Listen("MazeMessage", func(msg engi.Message) {
		mazeMsg, ok := msg.(MazeMessage)
		if !ok {
			return
		}
		m.cleanup()

		if mazeMsg.Sequence == SequenceDescending {
			m.sequenceIndex = len(m.levels) - 1
		}

		m.sequence = mazeMsg.Sequence
		m.initialize(mazeMsg.LevelName)
	})
}
Пример #2
0
func (ds *DeathSystem) New(*ecs.World) {
	ds.System = ecs.NewSystem()
	// Subscribe to ScoreMessage
	engi.Mailbox.Listen("ScoreMessage", func(message engi.Message) {
		collision, isCollision := message.(engi.CollisionMessage)
		if isCollision {
			log.Println(collision, message)
			log.Println("DEAD")
		}
	})

}
Пример #3
0
func (ms *SpeedSystem) New(*ecs.World) {
	ms.System = ecs.NewSystem()
	engi.Mailbox.Listen("CollisionMessage", func(message engi.Message) {
		log.Println("collision")
		collision, isCollision := message.(engi.CollisionMessage)
		if isCollision {
			var speed *SpeedComponent
			if !collision.Entity.Component(&speed) {
				return
			}

			speed.X *= -1
		}
	})
}
Пример #4
0
func (sc *ScoreSystem) New(*ecs.World) {
	sc.upToDate = true
	sc.System = ecs.NewSystem()
	engi.Mailbox.Listen("ScoreMessage", func(message engi.Message) {
		scoreMessage, isScore := message.(ScoreMessage)
		if !isScore {
			return
		}

		sc.scoreLock.Lock()
		if scoreMessage.Player != 1 {
			sc.PlayerOneScore += 1
		} else {
			sc.PlayerTwoScore += 1
		}
		log.Println("The score is now", sc.PlayerOneScore, "vs", sc.PlayerTwoScore)
		sc.upToDate = false
		sc.scoreLock.Unlock()
	})
}
Пример #5
0
func (as *AudioSystem) New(*ecs.World) {
	as.System = ecs.NewSystem()

	if as.HeightModifier == 0 {
		as.HeightModifier = defaultHeightModifier
	}

	if err := al.OpenDevice(); err != nil {
		log.Println("Error initializing AudioSystem:", err)
		return
	}

	Mailbox.Listen("CameraMessage", func(msg Message) {
		_, ok := msg.(CameraMessage)
		if !ok {
			return
		}

		// Hopefully not that much of an issue, when we receive it before the CameraSystem does
		// TODO: but it is when the CameraMessage is not Incremental (i.e. the changes are big)
		al.SetListenerPosition(al.Vector{cam.X() / Width(), cam.Y() / Height(), cam.Z() * as.HeightModifier})
	})
}
Пример #6
0
func (c *Calibrate) New(w *ecs.World) {
	ActiveCalibrateSystem = c
	c.System = ecs.NewSystem()
	c.World = w

	var err error

	c.Connection, err = gobci.Connect("")
	if err != nil {
		log.Fatal(err)
	}

	err = c.Connection.FlushData()
	if err != nil {
		log.Fatal("FlushData error: ", err)
	}

	// Get latest header info
	c.Header, err = c.Connection.GetHeader()
	if err != nil {
		log.Fatal("GetHeader error: ", err)
	}

	for i := uint32(0); i < c.Header.NChannels; i++ {
		e := ecs.NewEntity([]string{c.Type(), "RenderSystem"})
		espace := &engi.SpaceComponent{engi.Point{0, float32(i * (3*dpi + 10))}, 0, 0}
		e.AddComponent(espace)

		if c.Visualize {
			e.AddComponent(&CalibrateComponent{i})
		}

		c.AddEntity(e)
		c.World.AddEntity(e)
	}
}
Пример #7
0
func (rs *RenderSystem) New(w *ecs.World) {
	rs.renders = make(map[PriorityLevel][]*ecs.Entity)
	rs.System = ecs.NewSystem()
	rs.world = w
	rs.ShouldSkipOnHeadless = true

	if !headless {
		if !Shaders.setup {
			Shaders.def.Initialize(Width(), Height())

			hud := &HUDShader{}
			hud.Initialize(Width(), Height())
			for i := HUDGround; i <= HighestGround; i++ {
				Shaders.Register(i, hud)
			}

			Shaders.setup = true
		}
	}

	Mailbox.Listen("renderChangeMessage", func(m Message) {
		rs.changed = true
	})
}
Пример #8
0
func (f *FPS) New(w *ecs.World) {
	f.System = ecs.NewSystem()
	f.World = w

	f.AddEntity(ecs.NewEntity([]string{f.Type()}))
}
Пример #9
0
func (a *MovementSystem) New(*ecs.World) {
	a.System = ecs.NewSystem()
}
Пример #10
0
func (as *AudioSystem) New(*ecs.World) {
	as.System = ecs.NewSystem()

	log.Println("Warning: audio is not yet implemented on Windows")
}
Пример #11
0
func (cs *CollisionSystem) New(*ecs.World) {
	cs.System = ecs.NewSystem()
}
Пример #12
0
func (h *Hud) New(*ecs.World) {
	h.System = ecs.NewSystem()
}
Пример #13
0
func (ns *NilSystem) New() {
	ns.System = ecs.NewSystem()
}
Пример #14
0
func (s *HideSystem) New(*ecs.World) {
	s.System = ecs.NewSystem()
}
Пример #15
0
func (m *MenuListener) New(w *ecs.World) {
	m.System = ecs.NewSystem()
	m.AddEntity(ecs.NewEntity([]string{m.Type()}))
}
Пример #16
0
func (bs *BallSystem) New(*ecs.World) {
	bs.System = ecs.NewSystem()
}
Пример #17
0
func (rock *RockSpawnSystem) New(w *ecs.World) {
	rock.System = ecs.NewSystem()
	rock.world = w
}
Пример #18
0
func (m *Menu) New(w *ecs.World) {
	m.System = ecs.NewSystem()
	m.World = w

	specificLevel := &MenuItem{Text: "Play specific level ..."}

	callbackGenerator := func(l *Level) func() {
		msg := MazeMessage{LevelName: l.Name}

		return func() {
			engi.SetSceneByName("BCIGame", true)
			engi.Mailbox.Dispatch(msg)
		}
	}

	specificLevel.Callback = func() {
		specificLevel.SubItems = make([]*MenuItem, 0)
		for _, l := range ActiveMazeSystem.levels {
			specificLevel.SubItems = append(specificLevel.SubItems, &MenuItem{Text: l.Name,
				Callback: callbackGenerator(&l)})
		}
	}

	e := ecs.NewEntity([]string{m.Type()})

	m.AddEntity(e)
	m.items = []*MenuItem{
		{Text: "Random Level", Callback: func() {
			engi.SetSceneByName("BCIGame", true)
		}},
		specificLevel,
		{Text: "Start Experiment", Callback: func() {
			engi.SetSceneByName("BCIGame", true)
			var msg MazeMessage
			if rand.Intn(2) == 0 {
				msg.Sequence = SequenceAscending
			} else {
				msg.Sequence = SequenceDescending
			}
			engi.Mailbox.Dispatch(msg)
		}},
		{Text: "Calibrate", Callback: func() {
			engi.SetSceneByName("CalibrateScene", false)
		}},
		{Text: "Exit", Callback: func() {
			engi.Exit()
		}},
	}

	// TODO: handle resizing of window
	menuWidth := (engi.Width() - 2*menuPadding)

	m.focusBackground = helpers.GenerateSquareComonent(
		MenuColorItemBackgroundFocus, MenuColorItemBackgroundFocus,
		menuWidth-2*menuItemPadding, menuItemHeight,
		engi.HUDGround+2,
	)

	m.defaultBackground = helpers.GenerateSquareComonent(
		MenuColorItemBackground, MenuColorItemBackground,
		menuWidth-2*menuItemPadding, menuItemHeight,
		engi.HUDGround+2,
	)

	m.openMenu()
}
Пример #19
0
func (fs *FallingSystem) New(*ecs.World) {
	fs.System = ecs.NewSystem()
	//engi.Mailbox.Listen("CollisionMessage", fs)

}
Пример #20
0
func (c *ControlSystem) New(*ecs.World) {
	c.System = ecs.NewSystem()
}
Пример #21
0
func (s *ScaleSystem) New(*ecs.World) {
	s.System = ecs.NewSystem()
}
Пример #22
0
func (s *SceneSwitcherSystem) New(*ecs.World) {
	s.System = ecs.NewSystem()
	s.System.AddEntity(ecs.NewEntity([]string{s.Type()}))
}
Пример #23
0
// New initializes the MouseSystem
func (m *MouseSystem) New(*ecs.World) {
	m.System = ecs.NewSystem()
}