示例#1
0
func endGame() {
	teletype.Reset()
	n := universe.NKill()
	if n >= 64 {
		teletype.PrintUpper(grammar.Generate(rune('W')) + "\n")
	}
	if vanity.IsWorthyScore(records, uint8(n)) {
		setMode(modeName)
	} else {
		setMode(modeVanity)
	}
}
示例#2
0
func (context) KeyDown(k nimble.Key) {
	switch k {
	case nimble.KeyEscape:
		switch currentMode {
		case modeSplash, modeVanity:
			nimble.Quit()
		case modeTraining, modeGame:
			youLose()
		case modeName:
			// FIXME - ask for confirmation
			nimble.Quit()
		}
	}
	if currentMode == modeName {
		if 0x20 <= k && k < 0x7F {
			teletype.PrintCharUpper(rune(k))
		} else {
			switch k {
			case nimble.KeyReturn:
				acceptScore(uint8(universe.NKill()), teletype.CursorLine())
			case nimble.KeyBackspace, nimble.KeyDelete:
				teletype.Backup()
			}
		}
	}

	if devConfig {
		// Shortcuts for debugging
		switch k {
		case 'b':
			// Begin game
			bootSequencePeriod = 0
			setMode(modeGame)
		case 'e':
			// End game
			youLose()
		case 'r':
			// Reset score file
			records = make([]vanity.Record, 0)
			vanity.WriteToFile(records)
		case 's':
			// Score a point
			universe.TallyKill()
		case 't':
			// Begin training
			bootSequencePeriod = 0
			setMode(modeTraining)
		}
	}
}
示例#3
0
func setMode(m mode) {
	fourierIsVisible = false
	fallIsVisible = false
	radarIsVisible = false
	scoreIsVisible = false
	dividerCount = 0
	switch m {
	case modeSplash:
		teletype.PrintUpper(title + "\n")
		teletype.PrintUpper(edition + "\n")
		teletype.PrintUpper("By Arch D. Robison\n")
		var err error
		records, err = vanity.ReadFromFile()
		if err != nil {
			if devConfig {
				teletype.Print(err.Error())
			}
		}
	case modeName:
		teletype.Reset()
		teletype.PrintUpper(grammar.GenerateWithNumber(rune('H'), universe.NKill()) + "\n")
		teletype.PrintUpper("Please enter your name:\n")
		teletype.DisplayCursor(true)
	case modeTraining, modeGame:
		universe.BeginGame(m == modeTraining)
		// Temporarily set NLiveMax to 0.  End of boot sequence will set it to 1.
		universe.SetNLiveMax(0)
		startBootSequence()
	case modeVanity:
		teletype.Reset()
		teletype.DisplayCursor(false)
		teletype.PrintUpper("Supreme Freqs\n\nScore Player\n")
		for _, r := range records {
			teletype.PrintUpper(fmt.Sprintf("%5d %s\n", r.Score, r.Name))
		}
	}
	currentMode = m
	setMenus(m)
}
示例#4
0
func (context) Render(pm nimble.PixMap) {
	dt := updateClock()

	// Advance the boot sequence
	advanceBootSequence(dt)

	// Draw dividers
	for i, r := range divider {
		if i < dividerCount {
			pm.DrawRect(r, nimble.White)
		} else {
			pm.DrawRect(r, nimble.Black)
		}
	}

	if fourierIsVisible {
		// Update universe
		xf, yf := fourierPort.RelativeToLeftTop(mouseX, mouseY)
		switch universe.Update(dt, xf, yf) {
		case universe.GameWin:
			youWin()
		case universe.GameLose:
			youLose()
		}
		updateZoom(dt)

		// Fourier view
		if rollPhase.Value {
			updatePhaseRoll(dt)
		}
		drawFrequonsFourier(pm.Intersect(fourierPort))
		drawFrequonsSpatial(pm.Intersect(fourierPort), xf, yf)
		tallyFourierFrame()
	} else {
		// Teletype view
		teletype.Draw(pm.Intersect(fourierPort))
	}

	// Fall view
	if fallIsVisible {
		inv := invStorage[:len(universe.Zoo)-1]
		for k := range inv {
			c := &universe.Zoo[k+1]
			inv[k] = fall.Invader{
				Progress:  c.Progress,
				Amplitude: c.Amplitude,
				Color:     pastels.Pixel(0, int32(c.Id)),
			}
		}
		fall.Draw(pm.Intersect(fallPort), inv)
	} else {
		pm.DrawRect(fallPort, nimble.Black)
	}

	// Radar view
	if radarIsVisible {
		radar.Draw(pm.Intersect(radarPort), universe.Scheme(), radarIsRunning)
	} else {
		pm.DrawRect(radarPort, nimble.Black)
	}

	// Score
	if scoreIsVisible {
		score.Draw(pm.Intersect(scorePort), universe.NKill())
	} else {
		pm.DrawRect(scorePort, nimble.Black)
	}

	// Menu bar
	if len(menuBar) > 0 {
		menu.DrawMenuBar(pm, menuBar)
	}

	// Cursor
	showCursor := true
	switch currentMode {
	case modeGame:
		showCursor = false
	case modeTraining:
		showCursor = !fourierPort.Contains(mouseX, mouseY)
	}
	if showCursor != cursorIsVisible {
		nimble.ShowCursor(showCursor)
		cursorIsVisible = showCursor
	}
}