Beispiel #1
0
func main() {
	s1 := new(generals.Soldier)
	s1.Pt.X = 100
	s1.Pt.Y = 200

	s2 := new(generals.Soldier)
	s2.Pt.X = 95
	s2.Pt.Y = 200
	s2.InFront = s1

	d, err := display.NewDisplay(width, height, border, heading, "Soldier")
	if err != nil {
		log.Fatal(err)
	}

	s1.P = d.NewParticle(s1.Pt.X, s1.Pt.Y, 2, generals.FrontColor)
	s2.P = d.NewParticle(s2.Pt.X, s2.Pt.Y, 2, generals.RankColor)

	tick := time.Tick(500 * time.Millisecond)
	timer := time.Tick(time.Second)
	timerEnd := time.Tick(time.Minute)
	orders := KeyOrders(d)

	ctr := 0
	fps := 0
	for {
		<-tick
		s1.Step()
		s2.Step()
		s1.Update()
		s2.Update()
		d.Frame()
		ctr++
		select {
		case <-timer:
			fps = ctr
			d.SetHeadingText(fmt.Sprint("FPS: ", fps))
			ctr = 0
		case <-timerEnd:
			return
		case o := <-orders:
			s1.Orders(o)
			s2.Orders(o)
		default:
		}
	}
}
Beispiel #2
0
func main() {
	defer glog.Flush()

	d, err := display.NewDisplay(width, height, border, heading, "Soldier")
	if err != nil {
		glog.Fatal(err)
	}

	c := generals.NewCompany(d, complex(float64(100), float64(200)),
		complex(float64(1), float64(0)), 24, generals.FourCol)

	tick := time.Tick(500 * time.Millisecond)
	timer := time.Tick(time.Second)
	timerEnd := time.Tick(2 * time.Second)
	orders := KeyOrders(d)

	ctr := 0
	fps := 0
	for {
		<-tick
		c.Step()
		c.Update()
		d.Frame()
		ctr++
		select {
		case <-timer:
			fps = ctr
			d.SetHeadingText(fmt.Sprint("FPS: ", fps))
			ctr = 0
		case <-timerEnd:
			return
		case o := <-orders:
			if o == generals.Quit {
				return
			}
			if o == generals.PrintForm {
				c.PrintFormation()
				break
			}
			c.Orders(o)
		default:
		}
	}
}