Exemplo n.º 1
0
func NewChestEntity(location EntityRegion, x, y float64) *ChestEntity {
	chest := new(ChestEntity)
	chest.PerformanceMixin = *performance.NewPerfMixin()
	chest.id = NextEntityID()
	chest.closing = make(chan bool, 1)
	chest.receiver = make(chan *events.Event, 128)
	chest.location = location

	chest.inventory = NewInventory(chest, CHEST_INV_SIZE)

	chest.x, chest.y = x, y

	go func() {
		for {
			select {
			case <-chest.closing:
				chest.closing <- true
				return
			case event := <-chest.receiver:
				chest.handle(event)
			}
		}
	}()

	return chest
}
Exemplo n.º 2
0
func NewPotEntity(location EntityRegion, type_ int, x, y float64) *PotEntity {
	pot := new(PotEntity)
	pot.PerformanceMixin = *performance.NewPerfMixin()
	pot.id = NextEntityID()
	pot.closing = make(chan bool, 1)
	pot.receiver = make(chan *events.Event, 128)
	pot.location = location
	pot.type_ = type_
	pot.item = ""
	pot.entity = ""

	pot.x, pot.y = x, y

	go func() {
		for {
			select {
			case <-pot.closing:
				pot.closing <- true
				return
			case event := <-pot.receiver:
				pot.handle(event)
			}
		}
	}()

	return pot
}
Exemplo n.º 3
0
func NewItemEntity(code string, from EntityThatCanThrow) *ItemEntity {
	item := NewItemEntityInstance(code)
	item.PerformanceMixin = *performance.NewPerfMixin()

	item.location = from.Location()

	fromX, fromY := from.BlockingPosition()
	fromDirX, fromDirY := from.Direction()
	item.x, item.y = fromX+float64(fromDirX), fromY+float64(fromDirY)

	return item
}
Exemplo n.º 4
0
func NewPlayer(conn *websocket.Conn) *Player {
	if conn == nil {
		panic("WebSocket connection required")
	}

	outbound := make(chan *events.Event, SOCKET_BUFFER_SIZE)
	outbound_raw := make(chan string, SOCKET_BUFFER_SIZE)
	closing := make(chan bool, 1)

	// Get the region and make it active.
	reg := regions.GetRegion(terrain.WORLD_OVERWORLD, terrain.REGIONTYPE_FIELD, 0, 0)
	// Let the region know to stay alive.
	reg.KeepAlive <- true

	player := Player{
		*performance.NewPerfMixin(),

		conn, reg,
		outbound, outbound_raw, closing,

		entities.NextEntityID(),
		float64(reg.Terrain.Width) / 2, float64(reg.Terrain.Height) / 2, 0, 0, 0, 1,
		time.Now().UnixNano(),
		PLAYER_MAX_HEALTH,
		"",
		nil,
		make([][2]float64, 0),
		false,
		0,
	}
	reg.AddEntity(&player)

	// Set up the player's inventory
	player.inventory = entities.NewInventory(&player, PLAYER_INV_SIZE)
	player.inventory.Give("wsw.sharp.12")
	player.inventory.Give("f5")
	player.inventory.Give("f5")

	go player.startPinging()
	go player.gameTick()

	// Send the player the initial level
	outbound_raw <- "lev{" + reg.String() + "}"

	return &player
}
func NewVirtualEntity(entityName string) *VirtualEntity {
	ent := new(VirtualEntity)
	ent.PerformanceMixin = *performance.NewPerfMixin()

	ent.id = NextEntityID()

	ent.closing = make(chan bool, 1)
	ent.receiver = make(chan *events.Event, VIRTUAL_ENTITY_QUEUE_SIZE)
	ent.taskQueue = make(chan func(), VIRTUAL_ENTITY_TASK_QUEUE_SIZE)

	ent.width, ent.height = 1, 1

	ent.EntityVM = *GetEntityVM(entityName)
	ent.vm.Set("ID", ent.id)

	setUpPathing(ent)

	return ent
}