本文整理汇总了Golang中core.NewEntity函数的典型用法代码示例。如果您正苦于以下问题:Golang NewEntity函数的具体用法?Golang NewEntity怎么用?Golang NewEntity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewEntity函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Setup
func (self *TexturedCube) Setup() {
self.theCube = core.NewEntity()
self.theCube.Name = "Textured Cube"
self.theCube.AddComponent(new(components.Visual))
self.colorCube = core.NewEntity()
self.colorCube.Name = "Colored Cube"
self.colorCube.AddComponent(&components.Visual{
MaterialName: "only_color",
MeshName: "ColorIndexCube",
})
transform := components.GetTransform(self.theCube)
transform.Position = math3d.Vector{0, 0, -10}
transform.Scale = math3d.Vector{2, 2, 2}
transform.Speed = math3d.Vector{5, 5, 5}
transform = components.GetTransform(self.colorCube)
transform.Position = math3d.Vector{0, 0, -5}
// transform.MoveRelativeToRotation = true
// self.theCube.AddComponent(&components.Input{
// Mapping: FPSMapping,
// })
skybox := factories.SkyBox("stevecube", self.game.Camera)
self.game.RegisterEntity(skybox)
self.game.RegisterEntity(self.theCube)
self.game.RegisterEntity(self.colorCube)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:31,代码来源:textured_cube.go
示例2: Generate
func (self *Level) Generate() *core.Entity {
// A square arena with walls
self.volume = &volume.FunctionVolume{
func(x, y, z float32) float32 {
if y > 5 && (x > 3 && x < 47) && (z > 3 && z < 47) {
return -1
} else {
return 1
}
},
}
volumeMesh := volume.MarchingCubes(self.volume, math3d.Vector{50, 10, 50}, 0.5)
volumeMesh.Name = "Level Mesh"
self.entity = core.NewEntity()
self.entity.Name = "Level Geometry"
self.entity.AddComponent(&components.Visual{
Mesh: volumeMesh,
MaterialName: "only_color",
})
transform := components.GetTransform(self.entity)
transform.Position = math3d.Vector{-25, -10, -25}
return self.entity
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:27,代码来源:level.go
示例3: Test_TopDownCamera_TracksEntities
func Test_TopDownCamera_TracksEntities(t *testing.T) {
camera := NewTopDownCamera(core.NewCamera())
entity := core.NewEntity()
camera.TrackEntity(entity)
assert.Equal(t, entity, camera.trackingEntity)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:7,代码来源:top_down_camera_test.go
示例4: Test_Update_PassesInputEventsToComponentsWhoWantThem
func Test_Update_PassesInputEventsToComponentsWhoWantThem(t *testing.T) {
input, queue, entityDb := getTestInput()
testMappingQuitCalled := false
var testMappingQuitCalledEntity components.ComponentHolder
testMapping := components.InputEventMap{
events.Quit: func(entity components.ComponentHolder, event events.Event) {
testMappingQuitCalledEntity = entity
testMappingQuitCalled = true
},
}
entity := core.NewEntity()
entity.AddComponent(&components.Input{
Mapping: testMapping,
})
entityDb.RegisterEntity(entity)
queue.Events = append(queue.Events, events.Event{EventType: events.Quit})
input.Update(0)
assert.True(t, testMappingQuitCalled)
assert.Equal(t, entity, testMappingQuitCalledEntity)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:26,代码来源:input_test.go
示例5: Test_Update_CopiesPositionFromLinkedEntity
func Test_Update_CopiesPositionFromLinkedEntity(t *testing.T) {
behavior, entityDb := getTestTransform()
entity := core.NewEntity()
entityDb.RegisterEntity(entity)
followee := core.NewEntity()
followeeTransform := components.GetTransform(followee)
followeeTransform.Position = math3d.Vector{10, 11, -12}
transform := components.GetTransform(entity)
transform.UsingPositionOf = followee
behavior.Update(1)
assert.Equal(t, math3d.Vector{10, 11, -12}, transform.Position)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:17,代码来源:transform_test.go
示例6: NewPlayer
func NewPlayer() *Player {
player := new(Player)
player.entity = core.NewEntity()
player.entity.Name = "The Player"
player.initializeComponents()
return player
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:8,代码来源:player.go
示例7: Setup
func (self *TopDownTestScene) Setup() {
self.game.RegisterEntity(factories.SkyBox("stevecube", self.game.Camera))
self.levelVolume = &volume.FunctionVolume{
func(x, y, z float32) float32 {
if y > 5 && (x > 3 && x < 47) && (z > 3 && z < 47) {
return -1
} else {
return 1
}
},
}
volumeMesh := volume.MarchingCubes(self.levelVolume, math3d.Vector{50, 10, 50}, 0.5)
volumeMesh.Name = "Level Mesh"
self.levelEntity = core.NewEntity()
self.levelEntity.Name = "Level Geometry"
self.levelEntity.AddComponent(&components.Visual{
Mesh: volumeMesh,
MaterialName: "only_color",
})
self.game.RegisterEntity(self.levelEntity)
self.game.Camera.AddComponent(&components.Input{
Mapping: FPSMapping,
})
// Get the camera facing downwards
cameraTransform := components.GetTransform(self.game.Camera.Entity)
cameraTransform.Position = math3d.Vector{25, 10, 25}
cameraTransform.CurrentPitch = 90
cameraTransform.Speed = math3d.Vector{8, 8, 8}
cameraTransform.MoveRelativeToRotation = false
// Our unit we'll control
self.playerCube = core.NewEntityAt(math3d.Vector{25, 6, 25})
self.playerCube.Name = "The Player"
self.playerCube.AddComponent(&components.Visual{})
playerTransform := components.GetTransform(self.playerCube)
playerTransform.Scale = math3d.Vector{0.25, 0.5, 0.25}
playerTransform.Speed = math3d.Vector{3, 3, 3}
playerTransform.MoveRelativeToRotation = false
self.topDownCamera = NewTopDownCamera(self.game.Camera)
self.topDownCamera.SetTrackingHeight(5)
self.topDownCamera.TrackEntity(self.playerCube)
self.game.RegisterEntity(self.playerCube)
self.game.Keyboard.OnKey(input.KeySpace, func(event events.Event) { self.SwapInput(event) })
// Start by controlling the player unit. Game defaults to controlling the camera
self.SwapInput(events.Event{Pressed: true})
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:57,代码来源:top_down_test_scene.go
示例8: Setup
func (self *VolumeScene) Setup() {
skybox := factories.SkyBox("stevecube", self.game.Camera)
self.game.RegisterEntity(skybox)
self.game.Camera.AddComponent(FPSInput)
self.game.Camera.SetSpeed(math3d.Vector{5, 5, 5})
self.game.Camera.LookAt(math3d.Vector{0, 0, -5})
self.game.Keyboard.OnKey(input.KeyJ, func(e events.Event) {
if e.Pressed {
self.marchingCubeSize -= 0.1
if self.marchingCubeSize <= 0 {
self.marchingCubeSize = 0.1
} else {
self.rebuildVolume()
}
}
})
self.game.Keyboard.OnKey(input.KeyK, func(e events.Event) {
if e.Pressed {
self.marchingCubeSize += 0.1
self.rebuildVolume()
}
})
self.cubeVolume = &volume.FunctionVolume{
// A sphere!
func(x, y, z float32) float32 {
// Translate to treat middle of the volume as 0,0,0
// Basically I want 0,0,0 of the volume to act like -25, -25, -25, so that
// the center point of the sphere is at 25, 25, 25 in the volume,
// then check the equation against the radius of the sphere.
tX := x - 25
tY := y - 25
tZ := z - 25
return -(tX*tX + tY*tY + tZ*tZ - 20)
},
}
self.volumeEntity = core.NewEntity()
self.volumeEntity.Name = "cube volume"
self.rebuildVolume()
// Move the volume into view of the starting camera
transform := components.GetTransform(self.volumeEntity)
transform.Position = math3d.Vector{-25, -25, -40}
self.game.RegisterEntity(self.volumeEntity)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:55,代码来源:volume_scene.go
示例9: Test_SetUpEntity_TellsRendererToLoadNewMeshFromVisual
func Test_SetUpEntity_TellsRendererToLoadNewMeshFromVisual(t *testing.T) {
graphical, renderer, entityDb := getTestGraphical()
mesh := &render.Mesh{}
entity := core.NewEntity()
entity.AddComponent(&components.Visual{Mesh: mesh})
entityDb.RegisterEntity(entity)
assert.Equal(t, mesh, renderer.loadedMesh)
assert.NotEqual(t, mesh, graphical.meshes[mesh.Name])
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:11,代码来源:graphical_test.go
示例10: Test_TearDownEntity_TellsRendererToUnload
func Test_TearDownEntity_TellsRendererToUnload(t *testing.T) {
_, renderer, entityDb := getTestGraphical()
mesh := &render.Mesh{}
entity := core.NewEntity()
entity.AddComponent(&components.Visual{Mesh: mesh})
entityDb.RegisterEntity(entity)
entity.Destroy()
assert.Equal(t, mesh, renderer.unloadedMesh)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:12,代码来源:graphical_test.go
示例11: Test_SetUpEntity_TellsQueueWhatEventsToPollFor
func Test_SetUpEntity_TellsQueueWhatEventsToPollFor(t *testing.T) {
_, queue, entityDb := getTestInput()
pollEvents := events.EventTypeList{events.Quit, events.TurnLeft}
entity := core.NewEntity()
entity.AddComponent(&components.Input{
Polling: pollEvents,
})
entityDb.RegisterEntity(entity)
assert.Equal(t, pollEvents, queue.pollingEvents)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:12,代码来源:input_test.go
示例12: Test_Update_AppliesEulerAngles
func Test_Update_AppliesEulerAngles(t *testing.T) {
behavior, entityDb := getTestTransform()
entity := core.NewEntity()
entityDb.RegisterEntity(entity)
transform := components.GetTransform(entity)
startingQuat := transform.Rotation
transform.CurrentPitch = 45
behavior.Update(1)
assert.NotEqual(t, startingQuat, transform.Rotation)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:13,代码来源:transform_test.go
示例13: Test_TearDownEntity_TurnsOffPollingForRelatedEvents
func Test_TearDownEntity_TurnsOffPollingForRelatedEvents(t *testing.T) {
_, queue, entityDb := getTestInput()
pollEvents := events.EventTypeList{events.Quit, events.TurnLeft}
entity := core.NewEntity()
entity.AddComponent(&components.Input{
Polling: pollEvents,
})
entityDb.RegisterEntity(entity)
entityDb.EntityDestroyed(entity)
assert.Equal(t, pollEvents, queue.unpollingEvents)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:13,代码来源:input_test.go
示例14: Test_Update_RemovesAFinishedOneTimeAnimation
func Test_Update_RemovesAFinishedOneTimeAnimation(t *testing.T) {
behavior, entityDb := getTestAnimation()
entity := core.NewEntity()
entity.AddComponent(
components.NewPositionAnimation(math3d.Vector{10, 10, 10}, 0.5, func() {}),
)
entityDb.RegisterEntity(entity)
behavior.Update(1)
assert.Nil(t, entity.GetComponent(components.ANIMATION))
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:13,代码来源:animation_test.go
示例15: Test_Update_AppliesSpeedToMovingDir
func Test_Update_AppliesSpeedToMovingDir(t *testing.T) {
behavior, entityDb := getTestTransform()
entity := core.NewEntity()
entityDb.RegisterEntity(entity)
transform := components.GetTransform(entity)
transform.Moving(math3d.Vector{1, 0, 0})
transform.Speed = math3d.Vector{2, 2, 2}
// Time passed? change!
behavior.Update(0.5)
assert.Equal(t, math3d.Vector{1, 0, 0}, transform.Position)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:14,代码来源:transform_test.go
示例16: Test_MouseMove
func Test_MouseMove(t *testing.T) {
event := events.Event{
MouseXDiff: 30,
MouseYDiff: 40,
}
entity := core.NewEntity()
transform := components.GetTransform(entity)
FPSMapping[events.MouseMove](entity, event)
assert.Equal(t, 15, transform.CurrentYaw)
assert.Equal(t, 20, transform.CurrentPitch)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:14,代码来源:fps_mapping_test.go
示例17: Test_MouseMove_ClampsPitch
func Test_MouseMove_ClampsPitch(t *testing.T) {
event := events.Event{
MouseXDiff: 0,
MouseYDiff: 40,
}
entity := core.NewEntity()
transform := components.GetTransform(entity)
transform.CurrentPitch = 80
FPSMapping[events.MouseMove](entity, event)
assert.Equal(t, 89, transform.CurrentPitch)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:14,代码来源:fps_mapping_test.go
示例18: Test_Update_UsesMeshLinkedToVisualIfExists
func Test_Update_UsesMeshLinkedToVisualIfExists(t *testing.T) {
graphical, renderer, entityDb := getTestGraphical()
mesh := &render.Mesh{}
entity := core.NewEntity()
entity.AddComponent(&components.Visual{Mesh: mesh})
entityDb.RegisterEntity(entity)
graphical.Update(core.NewCamera(), 0)
renderOp := renderer.queueRendered.RenderOperations()[0]
assert.Equal(t, mesh, renderOp.Mesh)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:14,代码来源:graphical_test.go
示例19: Test_MouseMove_ConstrainsYaw
func Test_MouseMove_ConstrainsYaw(t *testing.T) {
event := events.Event{
MouseXDiff: 40,
MouseYDiff: 0,
}
entity := core.NewEntity()
transform := components.GetTransform(entity)
transform.CurrentYaw = 350
FPSMapping[events.MouseMove](entity, event)
assert.Equal(t, 10, transform.CurrentYaw)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:14,代码来源:fps_mapping_test.go
示例20: Test_Update_CallsCompletionCallbackOnCompletion
func Test_Update_CallsCompletionCallbackOnCompletion(t *testing.T) {
behavior, entityDb := getTestAnimation()
callbackCalled := false
entity := core.NewEntity()
entity.AddComponent(
components.NewPositionAnimation(math3d.Vector{10, 10, 10}, 0.5, func() { callbackCalled = true }),
)
entityDb.RegisterEntity(entity)
behavior.Update(1)
assert.True(t, callbackCalled)
}
开发者ID:jasonroelofs,项目名称:slartibartfast,代码行数:15,代码来源:animation_test.go
注:本文中的core.NewEntity函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论