コード例 #1
0
ファイル: player.go プロジェクト: RookieGameDevs/surviveler
/*
 * Repair sets the player as 'moving' and defines its macro-path, taking him to
 * the building to repair.
 *
 * The player action stack is emptied, effectively cancelling any previous
 * player action, and replaced with a 'move' action on top of a 'repair'
 * action, that will immediately start once the player will be in contact
 * with the target building
 */
func (p *Player) Repair(b Building, path Path) {
	// empty action stack, this cancel any current action(s)
	p.emptyActions()
	// fill the player action stack
	p.actions.Push(actions.New(actions.BuildId, actions.Build{}))
	p.actions.Push(actions.New(actions.MoveId, struct{}{}))
	p.curBuilding = b
	p.lastBPinduced = time.Time{}
	p.SetPath(path)
}
コード例 #2
0
ファイル: player.go プロジェクト: RookieGameDevs/surviveler
/*
 * Operate sets the player as 'moving' and defines its macro-path, taking him to
 * the interactive object to operate.
 *
 * The player action stack is emptied, effectively cancelling any previous
 * player action, and replaced with a 'move' action on top of an 'operate'
 * action, that will immediately start once the player will be in contact
 * with the target interactive object.
 */
func (p *Player) Operate(o Object, path Path) {
	// empty action stack, this cancel any current action(s)
	p.emptyActions()

	var action *actions.Action

	switch o.Type() {
	case CoffeeMachineObject:
		action = actions.New(actions.DrinkCoffeeId, actions.DrinkCoffee{})
		p.lastCoffeeDrink = time.Time{}
	default:
		log.WithField("type", o.Type).Error("Player.Operate not implemented for this type of game object")
		return
	}

	// fill the player action stack
	p.actions.Push(action)
	p.actions.Push(actions.New(actions.MoveId, struct{}{}))
	p.curObject = o
	p.SetPath(path)
}
コード例 #3
0
ファイル: player.go プロジェクト: RookieGameDevs/surviveler
func (p *Player) Attack(e Entity) {
	log.Debug("Player.Attack")

	// directly search for path
	p.findPath(e.Position())
	p.lastAttack = time.Time{}

	// setup the actions in the stack
	p.emptyActions()
	p.actions.Push(actions.New(actions.AttackId, actions.Attack{}))
	p.target = e

}
コード例 #4
0
ファイル: player.go プロジェクト: RookieGameDevs/surviveler
/*
 * NewPlayer creates a new player and set its initial position and speed
 */
func NewPlayer(g *Game, spawn d2.Vec2, entityType EntityType,
	speed, totalHP float32, buildPower, combatPower uint16) *Player {
	p := &Player{
		entityType:  entityType,
		buildPower:  buildPower,
		combatPower: combatPower,
		totalHP:     totalHP,
		curHP:       totalHP,
		g:           g,
		gamestate:   g.State(),
		world:       g.State().World(),
		id:          InvalidID,
		actions:     *actions.NewStack(),
		Movable:     NewMovable(spawn, speed),
	}
	// place an idle action as the bottommost item of the action stack item.
	// This should never be removed as the player should remain idle if he
	// has nothing better to do
	p.actions.Push(actions.New(actions.IdleId, actions.Idle{}))
	return p
}
コード例 #5
0
ファイル: player.go プロジェクト: RookieGameDevs/surviveler
/*
 * Move sets the player current action as 'moving' and define its macro-path.
 *
 * The player action stack is emptied, effectively cancelling any previous
 * player action, and defines its macro path.
 */
func (p *Player) Move(path Path) {
	// empty action stack, this cancel any current action(s)
	p.emptyActions()
	p.actions.Push(actions.New(actions.MoveId, struct{}{}))
	p.SetPath(path)
}