slack
Jordan Orelli 10 years ago
parent 69c0706be4
commit b03b607235

@ -130,6 +130,8 @@ func (i *IdleState) maek(c *Connection, args ...string) {
case "colony": case "colony":
MakeColony(c, i.System) MakeColony(c, i.System)
return return
case "shield":
MakeShield(c, i.System)
default: default:
c.Printf("I don't know how to make a %v.\n", args[0]) c.Printf("I don't know how to make a %v.\n", args[0])
} }

@ -21,6 +21,7 @@ var options struct {
lightSpeed float64 lightSpeed float64
makeBombTime time.Duration makeBombTime time.Duration
makeColonyTime time.Duration makeColonyTime time.Duration
makeShieldTime time.Duration
moneyMean float64 moneyMean float64
moneySigma float64 moneySigma float64
playerSpeed float64 playerSpeed float64
@ -126,4 +127,5 @@ func init() {
flag.DurationVar(&options.makeColonyTime, "colony-time", 15*time.Second, "time it takes to make a colony") flag.DurationVar(&options.makeColonyTime, "colony-time", 15*time.Second, "time it takes to make a colony")
flag.IntVar(&options.startBombs, "start-bombs", 0, "number of bombs a player has at game start") flag.IntVar(&options.startBombs, "start-bombs", 0, "number of bombs a player has at game start")
flag.IntVar(&options.startMoney, "start-money", 1000, "amount of money a player has to start") flag.IntVar(&options.startMoney, "start-money", 1000, "amount of money a player has to start")
flag.DurationVar(&options.makeShieldTime, "shield-time", 15*time.Second, "time it takes to make a shield")
} }

@ -0,0 +1,70 @@
package main
import (
"fmt"
)
func MakeShield(c *Connection, s *System) {
m := &MakeShieldState{
System: s,
CommandSuite: CommandSet{
balCommand,
BroadcastCommand(s),
helpCommand,
NearbyCommand(s),
playersCommand,
},
}
c.SetState(m)
}
type MakeShieldState struct {
CommandSuite
*System
start int64
}
func (m *MakeShieldState) Enter(c *Connection) {
c.Printf("Making shield on %v...\n", m.System)
}
func (m *MakeShieldState) Tick(c *Connection, frame int64) ConnectionState {
if m.start == 0 {
m.start = frame
}
if framesToDur(frame-m.start) >= options.makeShieldTime {
return Idle(m.System)
}
return m
}
func (m *MakeShieldState) Exit(c *Connection) {
c.Printf("Done! System %v is now shielded.\n", m.System)
m.System.Shield = new(Shield)
}
func (m *MakeShieldState) String() string {
return fmt.Sprintf("Making shield on %v", m.System)
}
type Shield struct {
energy float64
}
func (s *Shield) Tick(frame int64) {
if s.energy < 1000 {
s.energy += (1000 - s.energy) * 0.0005
}
}
func (s *Shield) Hit() bool {
if s.energy > 750 {
s.energy -= 750
return true
}
return false
}
func (s *Shield) Dead() bool {
return false
}

@ -15,6 +15,7 @@ var (
) )
type System struct { type System struct {
*Shield
id int id int
x, y, z float64 x, y, z float64
planets int planets int
@ -46,6 +47,9 @@ func (s *System) Tick(frame int64) {
s.colonizedBy.Deposit(1) s.colonizedBy.Deposit(1)
s.money -= 1 s.money -= 1
} }
if s.Shield != nil {
s.Shield.Tick(frame)
}
} }
func (s *System) Dead() bool { func (s *System) Dead() bool {
@ -166,6 +170,17 @@ func (s *System) Distances() []Ray {
} }
func (s *System) Bombed(bomber *Connection, frame int64) { func (s *System) Bombed(bomber *Connection, frame int64) {
if s.Shield != nil {
if s.Shield.Hit() {
s.EachConn(func(conn *Connection) {
conn.Printf("A bomb has hit %v but it was stopped by the system's shield.\n", s)
conn.Printf("Shield remaining: %v.\n", s.energy)
conn.Printf("Shield is recharing....\n")
})
return
}
}
s.EachConn(func(conn *Connection) { s.EachConn(func(conn *Connection) {
conn.Die(frame) conn.Die(frame)
bomber.MadeKill(conn) bomber.MadeKill(conn)

Loading…
Cancel
Save