Exemple #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)
	})
}
Exemple #2
0
func BenchmarkSolidOne(b *testing.B) {
	engi.OpenHeadlessNoRun()

	c1 := color.NRGBA{255, 255, 255, 255}
	c2 := color.NRGBA{255, 255, 255, 255}
	w := float32(100)
	h := float32(100)
	priority := engi.Background
	var r *engi.RenderComponent

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		helpers.GenerateSquareComonent(c1, c2, w, h, priority)
	}
	fmt.Sprint(r)
}
Exemple #3
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()
}