• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ecs.NewEntity函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/paked/engi/ecs.NewEntity函数的典型用法代码示例。如果您正苦于以下问题:Golang NewEntity函数的具体用法?Golang NewEntity怎么用?Golang NewEntity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewEntity函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Setup

func (pong *PongGame) Setup(w *ecs.World) {
	engi.SetBg(0x2d3739)
	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&engi.CollisionSystem{})
	w.AddSystem(&SpeedSystem{})
	w.AddSystem(&ControlSystem{})
	w.AddSystem(&BallSystem{})
	w.AddSystem(&ScoreSystem{})

	basicFont = (&engi.Font{URL: "Roboto-Regular.ttf", Size: 32, FG: color.NRGBA{255, 255, 255, 255}})
	if err := basicFont.CreatePreloaded(); err != nil {
		log.Fatalln("Could not load font:", err)
	}

	ball := ecs.NewEntity([]string{"RenderSystem", "CollisionSystem", "SpeedSystem", "BallSystem"})
	ballTexture := engi.Files.Image("ball.png")
	ballRender := engi.NewRenderComponent(ballTexture, engi.Point{2, 2}, "ball")
	ballSpace := &engi.SpaceComponent{engi.Point{(engi.Width() - ballTexture.Width()) / 2, (engi.Height() - ballTexture.Height()) / 2}, ballTexture.Width() * ballRender.Scale().X, ballTexture.Height() * ballRender.Scale().Y}
	ballCollision := &engi.CollisionComponent{Main: true, Solid: true}
	ballSpeed := &SpeedComponent{}
	ballSpeed.Point = engi.Point{300, 100}

	ball.AddComponent(ballRender)
	ball.AddComponent(ballSpace)
	ball.AddComponent(ballCollision)
	ball.AddComponent(ballSpeed)
	w.AddEntity(ball)

	score := ecs.NewEntity([]string{"RenderSystem", "ScoreSystem"})

	scoreRender := engi.NewRenderComponent(basicFont.Render(" "), engi.Point{1, 1}, "YOLO <3")

	scoreSpace := &engi.SpaceComponent{engi.Point{100, 100}, 100, 100}
	score.AddComponent(scoreRender)
	score.AddComponent(scoreSpace)
	w.AddEntity(score)

	schemes := []string{"WASD", ""}
	for i := 0; i < 2; i++ {
		paddle := ecs.NewEntity([]string{"RenderSystem", "CollisionSystem", "ControlSystem"})
		paddleTexture := engi.Files.Image("paddle.png")
		paddleRender := engi.NewRenderComponent(paddleTexture, engi.Point{2, 2}, "paddle")
		x := float32(0)
		if i != 0 {
			x = 800 - 16
		}

		paddleSpace := &engi.SpaceComponent{engi.Point{x, (engi.Height() - paddleTexture.Height()) / 2}, paddleRender.Scale().X * paddleTexture.Width(), paddleRender.Scale().Y * paddleTexture.Height()}
		paddleControl := &ControlComponent{schemes[i]}
		paddleCollision := &engi.CollisionComponent{Main: false, Solid: true}
		paddle.AddComponent(paddleRender)
		paddle.AddComponent(paddleSpace)
		paddle.AddComponent(paddleControl)
		paddle.AddComponent(paddleCollision)
		w.AddEntity(paddle)
	}
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:57,代码来源:pong.go


示例2: Setup

func (game *Game) Setup(w *ecs.World) {
	engi.SetBg(0x2d3739)

	// Add all of the systems
	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&engi.CollisionSystem{})
	w.AddSystem(&DeathSystem{})
	w.AddSystem(&FallingSystem{})
	w.AddSystem(&ControlSystem{})
	w.AddSystem(&RockSpawnSystem{})

	// Create new entity subscribed to all the systems!
	guy := ecs.NewEntity([]string{"RenderSystem", "ControlSystem", "RockSpawnSystem", "CollisionSystem", "DeathSystem"})
	texture := engi.Files.Image("icon.png")
	render := engi.NewRenderComponent(texture, engi.Point{4, 4}, "guy")
	// Tell the collision system that this player is solid
	collision := &engi.CollisionComponent{Solid: true, Main: true}

	width := texture.Width() * render.Scale().X
	height := texture.Height() * render.Scale().Y

	space := &engi.SpaceComponent{engi.Point{(engi.Width() - width) / 2, (engi.Height() - height) / 2}, width, height}

	guy.AddComponent(render)
	guy.AddComponent(space)
	guy.AddComponent(collision)

	w.AddEntity(guy)
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:29,代码来源:falling.go


示例3: generateBackground

// generateBackground creates a background of green tiles - might not be the most efficient way to do this
func generateBackground() *ecs.Entity {
	rect := image.Rect(0, 0, int(worldWidth), int(worldHeight))
	img := image.NewNRGBA(rect)
	c1 := color.RGBA{102, 153, 0, 255}
	c2 := color.RGBA{102, 173, 0, 255}
	for i := rect.Min.X; i < rect.Max.X; i++ {
		for j := rect.Min.Y; j < rect.Max.Y; j++ {
			if i%40 > 20 {
				if j%40 > 20 {
					img.Set(i, j, c1)
				} else {
					img.Set(i, j, c2)
				}
			} else {
				if j%40 > 20 {
					img.Set(i, j, c2)
				} else {
					img.Set(i, j, c1)
				}
			}
		}
	}
	bgTexture := engi.NewImageObject(img)
	field := ecs.NewEntity([]string{"RenderSystem"})
	fieldRender := engi.NewRenderComponent(engi.NewTexture(bgTexture), engi.Point{1, 1}, "Background1")
	fieldRender.SetPriority(engi.Background)
	fieldSpace := &engi.SpaceComponent{engi.Point{0, 0}, worldWidth, worldHeight}
	field.AddComponent(fieldRender)
	field.AddComponent(fieldSpace)
	return field
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:32,代码来源:escroller.go


示例4: CreateEntity

func (game *GameWorld) CreateEntity() *ecs.Entity {
	entity := ecs.NewEntity([]string{"MouseSystem", "RenderSystem", "ControlSystem"})

	entity.AddComponent(generateBackground())
	entity.AddComponent(&engi.MouseComponent{})
	entity.AddComponent(&engi.SpaceComponent{engi.Point{0, 0}, boxWidth, boxHeight})

	return entity
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:9,代码来源:mouse.go


示例5: Setup

func (game *Game) Setup(w *ecs.World) {
	engi.SetBg(0xFFFFFF)

	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&engi.AudioSystem{})

	backgroundMusic := ecs.NewEntity([]string{"AudioSystem"})
	backgroundMusic.AddComponent(&engi.AudioComponent{File: "326488.wav", Repeat: true, Background: true})

	w.AddEntity(backgroundMusic)
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:11,代码来源:audio.go


示例6: BenchmarkEntity1000

// BenchmarkEntity1000 creates 1000 `Entity`s which all depend on the `NilSystem`
func BenchmarkEntity1000(b *testing.B) {
	const count = 1000

	preload := func() {}
	setup := func(w *ecs.World) {
		w.AddSystem(&NilSystem{})
		for i := 0; i < count; i++ {
			w.AddEntity(ecs.NewEntity([]string{"NilSystem"}))
		}
	}
	Bench(b, preload, setup)
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:13,代码来源:benchmarks_test.go


示例7: CreateEntity

func (game *GameWorld) CreateEntity(point *engi.Point, spriteSheet *engi.Spritesheet, action *engi.AnimationAction) *ecs.Entity {
	entity := ecs.NewEntity([]string{"AnimationSystem", "RenderSystem", "ControlSystem"})

	space := &engi.SpaceComponent{*point, 150, 150}
	render := engi.NewRenderComponent(spriteSheet.Cell(action.Frames[0]), engi.Point{3, 3}, "hero")
	animation := engi.NewAnimationComponent(spriteSheet.Drawables(), 0.1)
	animation.AddAnimationActions(actions)
	animation.SelectAnimationByAction(action)
	entity.AddComponent(render)
	entity.AddComponent(space)
	entity.AddComponent(animation)

	return entity
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:14,代码来源:anim.go


示例8: NewRock

func NewRock(position engi.Point) *ecs.Entity {
	rock := ecs.NewEntity([]string{"RenderSystem", "FallingSystem", "CollisionSystem", "SpeedSystem"})

	texture := engi.Files.Image("rock.png")
	render := engi.NewRenderComponent(texture, engi.Point{4, 4}, "rock")
	space := &engi.SpaceComponent{position, texture.Width() * render.Scale().X, texture.Height() * render.Scale().Y}
	collision := &engi.CollisionComponent{Solid: true}

	rock.AddComponent(render)
	rock.AddComponent(space)
	rock.AddComponent(collision)

	return rock
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:14,代码来源:falling.go


示例9: generateHUDBackground

// generateHUDBackground creates a violet HUD on the left side of the screen - might be inefficient
func generateHUDBackground(width, height float32) *ecs.Entity {
	rect := image.Rect(0, 0, int(width), int(height))
	img := image.NewNRGBA(rect)
	c1 := color.RGBA{255, 0, 255, 180}
	for i := rect.Min.X; i < rect.Max.X; i++ {
		for j := rect.Min.Y; j < rect.Max.Y; j++ {
			img.Set(i, j, c1)
		}
	}
	bgTexture := engi.NewImageObject(img)
	field := ecs.NewEntity([]string{"RenderSystem"})
	fieldRender := engi.NewRenderComponent(engi.NewTexture(bgTexture), engi.Point{1, 1}, "HUDBackground1")
	fieldRender.SetPriority(hudBackgroundPriority)
	fieldSpace := &engi.SpaceComponent{engi.Point{-1, -1}, width, height}
	field.AddComponent(fieldRender)
	field.AddComponent(fieldSpace)
	return field
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:19,代码来源:hud.go


示例10: Setup

func (game *GameWorld) Setup() {
	engi.SetBg(0x2d3739)

	game.AddSystem(&engi.RenderSystem{})

	gameMap := ecs.NewEntity([]string{"RenderSystem"})
	tilemap := engi.NewTilemap(
		[][]string{
			{"0", "2", "0"},
			{"4", "5", "1"},
			{"2", "3", "4"},
			{"5", "1", "2"}},
		engi.Files.Image("sheet"), 16)

	mapRender := engi.NewRenderComponent(tilemap, engi.Point{1, 1}, "map")
	mapSpace := &engi.SpaceComponent{engi.Point{100, 100}, 0, 0}
	gameMap.AddComponent(mapRender)
	gameMap.AddComponent(mapSpace)

	game.AddEntity(gameMap)
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:21,代码来源:tilemap.go


示例11: Setup

func (game *GameWorld) Setup(w *ecs.World) {
	engi.SetBg(0x2d3739)

	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&HideSystem{})

	guy := ecs.NewEntity([]string{"RenderSystem", "HideSystem"})
	texture := engi.Files.Image("rock.png")
	render := engi.NewRenderComponent(texture, engi.Point{8, 8}, "guy")
	collision := &engi.CollisionComponent{Solid: true, Main: true}

	width := texture.Width() * render.Scale().X
	height := texture.Height() * render.Scale().Y

	space := &engi.SpaceComponent{engi.Point{(engi.Width() - width) / 2, (engi.Height() - height) / 2}, width, height}

	guy.AddComponent(render)
	guy.AddComponent(space)
	guy.AddComponent(collision)

	w.AddEntity(guy)
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:22,代码来源:hide.go


示例12: Setup

func (game *GameWorld) Setup(w *ecs.World) {
	engi.SetBg(0x2d3739)

	w.AddSystem(&engi.RenderSystem{})

	// Create an entity part of the Render and Scale systems
	guy := ecs.NewEntity([]string{"RenderSystem", "ScaleSystem"})
	// Retrieve a texture
	texture := engi.Files.Image("icon.png")

	// Create RenderComponent... Set scale to 8x, give lable "guy"
	render := engi.NewRenderComponent(texture, engi.Point{8, 8}, "guy")

	width := texture.Width() * render.Scale().X
	height := texture.Height() * render.Scale().Y

	space := &engi.SpaceComponent{engi.Point{0, 0}, width, height}

	guy.AddComponent(render)
	guy.AddComponent(space)

	w.AddEntity(guy)
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:23,代码来源:entity.go


示例13: Setup

func (game *RockScene) Setup(w *ecs.World) {
	engi.SetBg(0x2d3739)

	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&ScaleSystem{})
	w.AddSystem(&SceneSwitcherSystem{NextScene: "IconScene", WaitTime: time.Second * 3})

	guy := ecs.NewEntity([]string{"RenderSystem", "ScaleSystem"})
	texture := engi.Files.Image("rock.png")
	render := engi.NewRenderComponent(texture, engi.Point{8, 8}, "rock")
	collision := &engi.CollisionComponent{Solid: true, Main: true}

	width := texture.Width() * render.Scale().X
	height := texture.Height() * render.Scale().Y

	space := &engi.SpaceComponent{engi.Point{(engi.Width() - width) / 2, (engi.Height() - height) / 2}, width, height}

	guy.AddComponent(render)
	guy.AddComponent(space)
	guy.AddComponent(collision)

	w.AddEntity(guy)
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:23,代码来源:scenes.go


示例14: New

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)
	}
}
开发者ID:EtienneBruines,项目名称:bcigame,代码行数:36,代码来源:calibrate.go


示例15: New

func (s *SceneSwitcherSystem) New(*ecs.World) {
	s.System = ecs.NewSystem()
	s.System.AddEntity(ecs.NewEntity([]string{s.Type()}))
}
开发者ID:EtienneBruines,项目名称:engi,代码行数:4,代码来源:scenes.go


示例16: New

func (f *FPS) New(w *ecs.World) {
	f.System = ecs.NewSystem()
	f.World = w

	f.AddEntity(ecs.NewEntity([]string{f.Type()}))
}
开发者ID:EtienneBruines,项目名称:bcigame,代码行数:6,代码来源:fps.go


示例17: New

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()
}
开发者ID:EtienneBruines,项目名称:bcigame,代码行数:66,代码来源:menu.go


示例18: openMenu

func (m *Menu) openMenu() {
	m.menuFocus = 0

	// Create the visual menu
	// - background
	backgroundWidth := engi.Width()
	backgroundHeight := engi.Height()

	menuBackground := helpers.GenerateSquare(
		MenuColorBackground, MenuColorBackground,
		backgroundWidth, backgroundHeight,
		0, 0,
		engi.HUDGround,
		"AudioSystem",
	)
	//menuBackground.AddComponent(&engi.UnpauseComponent{})
	menuBackground.AddComponent(&engi.AudioComponent{File: "click_x.wav", Repeat: false, Background: true})
	m.menuEntities = append(m.menuEntities, menuBackground)
	m.World.AddEntity(menuBackground)

	// - box
	menuWidth := (engi.Width() - 2*menuPadding)
	menuHeight := (engi.Height() - 2*menuPadding)

	menuEntity := helpers.GenerateSquare(
		MenuColorBox, MenuColorBox,
		menuWidth, menuHeight,
		menuPadding, menuPadding,
		engi.HUDGround+1,
	)
	//menuEntity.AddComponent(&engi.UnpauseComponent{})
	m.menuEntities = append(m.menuEntities, menuEntity)
	m.World.AddEntity(menuEntity)

	// - items - font
	itemFont := (&engi.Font{URL: "Roboto-Regular.ttf", Size: 64, FG: MenuColorItemForeground})
	if err := itemFont.CreatePreloaded(); err != nil {
		log.Fatalln("Could not load font:", err)
	}
	labelFontScale := float32(36 / itemFont.Size)

	// - items - entities
	offsetY := float32(menuPadding + menuItemPadding)

	var itemList []*MenuItem
	if m.itemSelected == nil {
		itemList = m.items
	} else {
		itemList = m.itemSelected.SubItems
	}

	for itemID, item := range itemList {
		item.menuBackground = ecs.NewEntity([]string{"RenderSystem"})
		if itemID == m.menuFocus {
			item.menuBackground.AddComponent(m.focusBackground)
		} else {
			item.menuBackground.AddComponent(m.defaultBackground)
		}
		item.menuBackground.AddComponent(&engi.SpaceComponent{
			engi.Point{menuItemOffsetX, offsetY}, menuWidth - 2*menuItemPadding, menuItemHeight})
		//item.menuBackground.AddComponent(&engi.UnpauseComponent{})
		m.menuEntities = append(m.menuEntities, item.menuBackground)
		m.World.AddEntity(item.menuBackground)

		item.menuLabel = ecs.NewEntity([]string{"RenderSystem"})
		menuItemLabelRender := &engi.RenderComponent{
			Display:      itemFont.Render(item.Text),
			Scale:        engi.Point{labelFontScale, labelFontScale},
			Transparency: 1,
			Color:        color.RGBA{255, 255, 255, 255},
		}
		menuItemLabelRender.SetPriority(engi.HUDGround + 3)
		item.menuLabel.AddComponent(menuItemLabelRender)
		item.menuLabel.AddComponent(&engi.SpaceComponent{
			Position: engi.Point{
				menuItemOffsetX + (menuItemHeight-float32(itemFont.Size)*labelFontScale)/2,
				offsetY + menuItemFontPadding + (menuItemHeight-float32(itemFont.Size)*labelFontScale)/2,
			}})
		//item.menuLabel.AddComponent(&engi.UnpauseComponent{})
		m.menuEntities = append(m.menuEntities, item.menuLabel)
		m.World.AddEntity(item.menuLabel)

		offsetY += menuItemHeight + menuItemPadding
	}

	m.menuActive = true
}
开发者ID:EtienneBruines,项目名称:bcigame,代码行数:87,代码来源:menu.go


示例19: GenerateSquare

// GenerateSquare creates a square, alternating two colors, with given size and priority level
func GenerateSquare(c1, c2 color.NRGBA, w, h float32, offX, offY float32, priority engi.PriorityLevel, requirements ...string) *ecs.Entity {
	field := ecs.NewEntity(append([]string{"RenderSystem"}, requirements...))
	field.AddComponent(GenerateSquareComonent(c1, c2, w, h, priority))
	field.AddComponent(&engi.SpaceComponent{engi.Point{offX, offY}, w, h})
	return field
}
开发者ID:EtienneBruines,项目名称:bcigame,代码行数:7,代码来源:bg.go


示例20: initialize

func (m *Maze) initialize(level string) {
	m.active = true

	if len(level) == 0 {
		switch m.sequence {
		case SequenceAscending:
			if m.sequenceIndex >= len(m.levels) {
				return // we're done
			}
			m.currentLevel = m.levels[m.sequenceIndex]
			m.sequenceIndex++
		case SequenceDescending:
			if m.sequenceIndex < 0 {
				return // we're done
			}
			m.currentLevel = m.levels[m.sequenceIndex]
			m.sequenceIndex--
		case SequenceNone:
			m.currentLevel = NewRandomLevel(randomMinWidth, randomMaxWidth, randomMinHeight, randomMaxHeight)
		}
	} else {
		for lvlId := range m.levels {
			if m.levels[lvlId].Name == level {
				m.currentLevel = m.levels[lvlId].Copy()
				break
			}
		}
	}

	if m.currentLevel.ID == emptyLevel.ID {
		if len(m.levels) > 0 {
			m.currentLevel = m.levels[rand.Intn(len(m.levels))].Copy()
		} else {
			return
		}
	}

	if ActiveCalibrateSystem != nil {
		ActiveCalibrateSystem.Connection.PutEvent("Started Level", m.currentLevel.Name)
	}

	// Create world
	engi.WorldBounds.Max = engi.Point{float32(m.currentLevel.Width) * tileWidth, float32(m.currentLevel.Height) * tileHeight}

	engi.Mailbox.Dispatch(engi.CameraMessage{engi.XAxis, float32(m.currentLevel.Width) * tileWidth / 2, false})
	engi.Mailbox.Dispatch(engi.CameraMessage{engi.YAxis, float32(m.currentLevel.Height) * tileHeight / 2, false})

	// Initialize the tiles
	m.currentLevel.GridEntities = make([][]*ecs.Entity, len(m.currentLevel.Grid))
	for rowNumber, tileRow := range m.currentLevel.Grid {
		m.currentLevel.GridEntities[rowNumber] = make([]*ecs.Entity, len(tileRow))
		for columnNumber, tile := range tileRow {
			e := ecs.NewEntity([]string{"RenderSystem"})
			e.AddComponent(&engi.SpaceComponent{engi.Point{float32(columnNumber) * tileWidth, float32(rowNumber) * tileHeight}, tileWidth, tileHeight})

			switch tile {
			case TilePlayer:
				// set player location
				m.currentLevel.PlayerX, m.currentLevel.PlayerY = columnNumber, rowNumber
				fallthrough
			case TileBlank:
				e.AddComponent(tileBlank)
			case TileWall:
				e.AddComponent(tileWall)
			case TileGoal:
				e.AddComponent(tileGoal)
			case TileRoute:
				e.AddComponent(tileRoute)
			case TileError:
				e.AddComponent(tileRoute)
			case TileHiddenError:
				e.AddComponent(tileBlank)
			}

			m.currentLevel.GridEntities[rowNumber][columnNumber] = e
			m.World.AddEntity(e)
		}
	}

	// Draw the player
	m.playerEntity = ecs.NewEntity([]string{"RenderSystem", "MovementSystem", m.Type()})
	m.playerEntity.AddComponent(tilePlayer)
	m.playerEntity.AddComponent(&engi.SpaceComponent{engi.Point{float32(m.currentLevel.PlayerX) * tileWidth, float32(m.currentLevel.PlayerY) * tileHeight}, tileWidth, tileHeight})
	m.World.AddEntity(m.playerEntity)

	// Initialize the controller
	m.Controller.New()
}
开发者ID:EtienneBruines,项目名称:bcigame,代码行数:88,代码来源:maze.go



注:本文中的github.com/paked/engi/ecs.NewEntity函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ecs.NewSystem函数代码示例发布时间:2022-05-28
下一篇:
Golang engi.World类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap