you can make bombs again

slack
Jordan Orelli 10 years ago
parent 4ecc4c2952
commit ac92962ef8

@ -44,3 +44,33 @@ func (b *Bomb) Tick(frame int64) {
func (b *Bomb) String() string { func (b *Bomb) String() string {
return fmt.Sprintf("[bomb from: %v to: %v lived: %s]", b.origin, b.target, time.Since(b.start)) return fmt.Sprintf("[bomb from: %v to: %v lived: %s]", b.origin, b.target, time.Since(b.start))
} }
type MakeBombState struct {
CommandSuite
*System
start int64
}
func MakeBomb(s *System) ConnectionState {
m := &MakeBombState{System: s}
return m
}
func (m *MakeBombState) Enter(c *Connection) {
c.Printf("Making a bomb...\n")
}
func (m *MakeBombState) Tick(c *Connection, frame int64) ConnectionState {
if m.start == 0 {
m.start = frame
}
if framesToDur(frame-m.start) >= options.makeBombTime {
return Idle(m.System)
}
return m
}
func (m *MakeBombState) Exit(c *Connection) {
c.bombs += 1
c.Printf("Done! You now have %v bombs.\n", c.bombs)
}

@ -53,6 +53,11 @@ func Idle(sys *System) ConnectionState {
arity: 0, arity: 0,
handler: i.scan, handler: i.scan,
}, },
Command{
name: "make",
help: "makes things",
handler: i.maek,
},
} }
return i return i
} }
@ -131,3 +136,12 @@ func (i *IdleState) scan(c *Connection, args ...string) {
c.Printf("Scanning the galaxy for signs of life...\n") c.Printf("Scanning the galaxy for signs of life...\n")
currentGame.Register(NewScan(i.System)) currentGame.Register(NewScan(i.System))
} }
func (i *IdleState) maek(c *Connection, args ...string) {
switch args[0] {
case "bomb":
c.SetState(MakeBomb(i.System))
default:
c.Printf("I don't know how to make a %v.\n", args[0])
}
}

@ -17,6 +17,7 @@ var options struct {
frameRate int frameRate int
frameLength time.Duration frameLength time.Duration
lightSpeed float64 lightSpeed float64
makeBombTime time.Duration
moneyMean float64 moneyMean float64
moneySigma float64 moneySigma float64
playerSpeed float64 playerSpeed float64
@ -114,4 +115,5 @@ func init() {
flag.BoolVar(&options.debug, "debug", false, "puts the game in debug mode") flag.BoolVar(&options.debug, "debug", false, "puts the game in debug mode")
flag.StringVar(&options.speckPath, "speck-path", "/projects/exo/expl.speck", "path to exoplanet speck file") flag.StringVar(&options.speckPath, "speck-path", "/projects/exo/expl.speck", "path to exoplanet speck file")
flag.DurationVar(&options.respawnTime, "respawn-time", 60*time.Second, "time for player respawn") flag.DurationVar(&options.respawnTime, "respawn-time", 60*time.Second, "time for player respawn")
flag.DurationVar(&options.makeBombTime, "bomb-time", 5*time.Second, "time it takes to make a bomb")
} }

Loading…
Cancel
Save