|
|
@@ -16,6 +16,37 @@ type coords struct {
|
|
|
x, y int
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+var fallingQuotes = []string{
|
|
|
+ "IT DESCENDS.",
|
|
|
+ "The sky provides.",
|
|
|
+ "I sense tuna.",
|
|
|
+ "Ah yes. The prophecy.",
|
|
|
+ "Rain harder.",
|
|
|
+ "Something edible approaches.",
|
|
|
+}
|
|
|
+
|
|
|
+var catchQuotes = []string{
|
|
|
+ "Mine.",
|
|
|
+ "Calculated.",
|
|
|
+ "Too easy.",
|
|
|
+ "As foretold.",
|
|
|
+ "Nom.",
|
|
|
+ "You may drop another.",
|
|
|
+}
|
|
|
+
|
|
|
+var missQuotes = []string{
|
|
|
+ "This is sabotage.",
|
|
|
+ "The sky betrayed me.",
|
|
|
+ "I meant to let that one go.",
|
|
|
+ "It lacked seasoning.",
|
|
|
+ "Unacceptable.",
|
|
|
+}
|
|
|
+
|
|
|
+func randomQuote(pool []string) string {
|
|
|
+ return pool[rand.Intn(len(pool))]
|
|
|
+}
|
|
|
+
|
|
|
//go:embed assets/title/title_idle.txt
|
|
|
var title_idle string
|
|
|
|
|
|
@@ -181,16 +212,28 @@ func DrawCat(s tcell.Screen, x1,y1,x2,y2 int, style tcell.Style, direction rune)
|
|
|
// x1,y2 ------- x2,y2
|
|
|
func GetFoodPositions(x1,y1,x2,y2,level int) []*coords{
|
|
|
var res []*coords
|
|
|
- nb_food := 5*level
|
|
|
- for range nb_food {
|
|
|
+ nb_food := 5 + level
|
|
|
+ for i := range nb_food {
|
|
|
x := rand.Intn((x2-1)-(x1+1)) + (x1+1)
|
|
|
- y := y1
|
|
|
+ y := y1 - i*3
|
|
|
food_pos := coords{x: x, y: y}
|
|
|
res = append(res, &food_pos)
|
|
|
}
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
+func DrawFood(s tcell.Screen, y1, y2 int, food_positions []*coords, defStyle tcell.Style) {
|
|
|
+ xmax, ymax := s.Size()
|
|
|
+ for _, food_pos := range food_positions {
|
|
|
+ if food_pos.y > y1 && food_pos.y < (y2-1) {
|
|
|
+ drawText(s,food_pos.x,food_pos.y,xmax,ymax,defStyle,"@")
|
|
|
+ }
|
|
|
+ if food_pos.y < (y2-1) {
|
|
|
+ food_pos.y += 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
func main() {
|
|
|
// Initialize screen
|
|
|
@@ -226,6 +269,8 @@ func main() {
|
|
|
x_offset := 0
|
|
|
new_level := true
|
|
|
var food_positions []*coords
|
|
|
+ speed := 0
|
|
|
+ message := randomQuote(fallingQuotes)
|
|
|
game_loop:
|
|
|
go_to_menu := false
|
|
|
for {
|
|
|
@@ -251,10 +296,6 @@ game_loop:
|
|
|
y2 := 4*ymax/length_factor
|
|
|
length_map := y2 - y1 + 1
|
|
|
|
|
|
- // Draw UI
|
|
|
- drawText(s, x1, y1 - 5, xmax, ymax, defStyle, "Use arrows or AD to move. Press q to return to Main Menu.")
|
|
|
- drawText(s, x1, y1 - 3, xmax, ymax, defStyle, fmt.Sprintf("Level: %d", level))
|
|
|
- drawText(s, x1, y1 - 2, xmax, ymax, defStyle, fmt.Sprintf("Score: %d", score))
|
|
|
|
|
|
// Draw Game Map Borders
|
|
|
// upper border
|
|
|
@@ -275,43 +316,82 @@ game_loop:
|
|
|
}
|
|
|
|
|
|
position_cat_x := (x2 + x1)/2 + x_offset
|
|
|
+ speed = 2 + (level * 0)
|
|
|
DrawCat(s, position_cat_x, y2 - 3, xmax,ymax,defStyle, direction)
|
|
|
if (new_level){
|
|
|
food_positions = GetFoodPositions(x1,y1,x2,y2,level)
|
|
|
new_level = false
|
|
|
}
|
|
|
- for i, food_pos := range food_positions {
|
|
|
- drawText(s,food_pos.x,food_pos.y,xmax,ymax,defStyle,"@")
|
|
|
- if i == rand.Intn(len(food_positions)) && food_pos.y < (y2-1) {
|
|
|
- food_pos.y += 1
|
|
|
- }
|
|
|
- }
|
|
|
- s.Show()
|
|
|
+
|
|
|
+ DrawFood(s,y1,y2,food_positions,defStyle)
|
|
|
|
|
|
- ev := <- s.EventQ()
|
|
|
- // Process event
|
|
|
- switch ev := ev.(type) {
|
|
|
- case *tcell.EventResize:
|
|
|
+
|
|
|
+ // Draw UI
|
|
|
+ drawText(s, x1, y1 - 6, xmax, ymax, defStyle, "Use arrows or AD to move. Use Up Arrow or W to speed up")
|
|
|
+ drawText(s, x1, y1 - 5, xmax, ymax, defStyle, "Press P to Pause.")
|
|
|
+ drawText(s, x1, y1 - 3, xmax, ymax, defStyle, fmt.Sprintf("Level: %d", level))
|
|
|
+ drawText(s, x1, y1 - 2, xmax, ymax, defStyle, fmt.Sprintf("Score: %d", score))
|
|
|
+ drawText(s, x1, y2 + 1, xmax, ymax, defStyle, fmt.Sprintf("Vanilla: \"%s\"", message))
|
|
|
+
|
|
|
+ s.Show()
|
|
|
+ ticker := time.NewTicker((1000) * time.Millisecond)
|
|
|
+ defer ticker.Stop()
|
|
|
+ select{
|
|
|
+ case <- ticker.C:
|
|
|
+ DrawFood(s,y1,y2,food_positions,defStyle)
|
|
|
s.Sync()
|
|
|
- case *tcell.EventKey:
|
|
|
- if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
|
|
|
+ case ev := <- s.EventQ():
|
|
|
+ // Process event
|
|
|
+ switch ev := ev.(type) {
|
|
|
+ case *tcell.EventResize:
|
|
|
+ s.Sync()
|
|
|
+ case *tcell.EventKey:
|
|
|
+ if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
|
|
|
return
|
|
|
- } else if (ev.Key() == tcell.KeyRight || ev.Str() == "d" || ev.Str() == "D") {
|
|
|
- direction = 'r'
|
|
|
- if (position_cat_x + 1 < (x2-6)){
|
|
|
- x_offset += 1
|
|
|
+ } else if (ev.Key() == tcell.KeyRight || ev.Str() == "d" || ev.Str() == "D") {
|
|
|
+ direction = 'r'
|
|
|
+ if (position_cat_x + speed < (x2-7)){
|
|
|
+ x_offset += speed
|
|
|
+ } else {
|
|
|
+ x_offset = x2 - 7 - (x2 + x1)/2
|
|
|
+ }
|
|
|
+ } else if (ev.Key() == tcell.KeyLeft || ev.Str() == "a" || ev.Str() == "A") {
|
|
|
+ direction = 'l'
|
|
|
+ if (position_cat_x - speed > (x1+1)){
|
|
|
+ x_offset -= speed
|
|
|
+ } else {
|
|
|
+ x_offset = (x1+1) - (x2 + x1)/2
|
|
|
+ }
|
|
|
+ } else if (ev.Key() == tcell.KeyUp || ev.Str() == "w" || ev.Str() == "W") {
|
|
|
+ direction = 'n'
|
|
|
+ } else if (ev.Str() == "p" || ev.Str() == "P"){
|
|
|
+ go_to_menu = true
|
|
|
}
|
|
|
- } else if (ev.Key() == tcell.KeyLeft || ev.Str() == "a" || ev.Str() == "A") {
|
|
|
- direction = 'l'
|
|
|
- if (position_cat_x + 1 > (x1 + 2)){
|
|
|
- x_offset -= 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // collect_food
|
|
|
+ for _, food_pos := range food_positions{
|
|
|
+ if (food_pos.y == y2 - 2){
|
|
|
+ if (position_cat_x <= food_pos.x && food_pos.x <= position_cat_x + 7) {
|
|
|
+ message = randomQuote(catchQuotes)
|
|
|
+ score++
|
|
|
+ } else {
|
|
|
+ message = randomQuote(missQuotes)
|
|
|
}
|
|
|
- } else if (ev.Key() == tcell.KeyUp || ev.Str() == "w" || ev.Str() == "W") {
|
|
|
- direction = 'n'
|
|
|
- } else if (ev.Str() == "q" || ev.Str() == "Q"){
|
|
|
- go_to_menu = true
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ new_level = true
|
|
|
+ level++
|
|
|
+ for _,food_pos := range food_positions{
|
|
|
+ if food_pos.y < y2-3{
|
|
|
+ level--
|
|
|
+ new_level = false
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
start_game = DrawMainMenu(s, defStyle, true)
|
|
|
if (start_game){
|