コード例 #1
0
func initCritterSprites(width, height int32) {
	// The factor .75/64. should yield the same size as the original game
	// for a 1920x1080 display
	radius := int32(math32.Sqrt(float32(width*height)) * (.75 / 64.))
	const frameCount = 60
	for k := range critterSeq {
		critterSeq[k] = sprite.MakeAnimation(int(radius), k == 0, frameCount)
	}
}
コード例 #2
0
// Update state of live aliens
func updateLive(dt float32) {
	x0, y0 := Zoo[0].Sx, Zoo[0].Sy
	for k := 1; k < len(Zoo); k++ {
		c := &Zoo[k]
		// Update S and v
		bounce(&c.Sx, &c.vx, xSize-1, dt)
		bounce(&c.Sy, &c.vy, ySize-1, dt)
		// Update Progress
		c.Progress += c.fallRate * dt
		// Update health
		if c.health > 0 {
			// Healthy alien
			if c.Progress >= 1 {
				// Alien reached full power!
				if !isPractice {
					gameState = GameLose
				}
				// Mark alien for culling
				c.health = deathThreshold
				continue
			}
			dx := c.Sx - x0
			dy := c.Sy - y0
			if dx*dx+dy*dy <= killRadius2 {
				const killTime = 0.1
				c.health -= healthType(dt * (float32(initialHealth) / killTime))
				if c.health <= 0 {
					c.health = -1 // Transition to death sequence
					sound.Play(sound.Twang, alienPitch[c.Id])
				}
				c.Show = true
			} else {
				c.Show = showAlways
			}
		} else {
			// Dying alien
			c.health -= 1
			c.Show = true
		}
		// Update amplitude
		if c.health > 0 {
			c.Amplitude = math32.Sqrt(c.Progress)
		} else {
			c.Amplitude -= dt * (1 / amplitudeDieTime)
			if c.Amplitude < 0 {
				// Alien croaked.  Mark as dead
				c.health = deathThreshold
				if !isPractice {
					TallyKill()
				}
			}
		}
	}
}
コード例 #3
0
ファイル: main.go プロジェクト: ArchRobison/FrequonInvaders
func (context) Init(width, height int32) {
	if width < 640 || height < 400 {
		panic(fmt.Sprintf("screen size of %v x %v is too small!", width, height))
	}
	screenWidth, screenHeight = width, height
	nShade := int32(math32.Round(math32.Sqrt(float32(width*height)) * (32. / 1440)))
	initCritterSprites(width, height)
	pastels = coloring.PastelPalette(universe.MaxCritter, nShade)
	teletype.Init("Characters.png")
	if benchmarking {
		bootSequencePeriod = 0
		setMode(modeTraining)
	} else {
		setMode(modeSplash) // N.B. also causes partitionScreen to be called
		if devConfig {
			teletype.Print("[debug mode]\n")
		}
	}
}
コード例 #4
0
ファイル: menu.go プロジェクト: ArchRobison/FrequonInvaders
// Items for "Ratings" menu
var (
	highScores *menu.SimpleItem
	cpuSpeed   = menu.MakeSimpleItem("CPU Speed", func() {
		teletype.Reset()
		teletype.PrintUpper(fmt.Sprintf("HFT SPEED = %.1f GFlops\n", fourier.Benchmark()*1E-9))
	})
)

// State of stationary/moving radio buttons on the "Invaders" menu.
var letFrequonsMove = menu.RadioState{OnSelect: func(value int) {
	if value == 0 {
		universe.SetVelocityMax(0)
	} else {
		universe.SetVelocityMax(30. / 1440. * math32.Sqrt(float32(screenWidth*screenHeight)))
	}
}}

// State of "maximum number of Frequons" buttons on the "Invaders" menu.
var maxFrequon = menu.RadioState{Value: 1, OnSelect: func(value int) {
	universe.SetNLiveMax(value)
}}

// Entry for "Color" menu
type colorSchemeItem struct {
	name    string              // Name of scheme
	missing coloring.SchemeBits // Aspect that is missing from the color scheme
}

var colorSchemeInfo = []colorSchemeItem{