Abderrahmane Faiz преди 4 седмици
родител
ревизия
1b0592c753
променени са 2 файла, в които са добавени 104 реда и са изтрити 46 реда
  1. BIN
      bin/game
  2. 104 46
      cmd/game/main.go

BIN
bin/game


+ 104 - 46
cmd/game/main.go

@@ -3,6 +3,7 @@ package main
 import (
 	"log"
 	"strings"
+	"time"
 
 	"github.com/gdamore/tcell/v3"
 	"github.com/gdamore/tcell/v3/color"
@@ -30,8 +31,7 @@ func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string
 }
 
 
-func main() {
-	var title string = `                                                                 
+var title_idle string = `                                                                 
 
 ⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀
@@ -67,7 +67,60 @@ func main() {
 |__/  |__/ \_______/    \_/    \_______/|__/  |__/   \___/   \______/ |__/       \_______/|_______/ 
 `
 
-	lines := strings.Split(title, "\n")
+var title_blinking string = `                                                                 
+
+⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀
+⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀
+⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀
+⠀⠀⠀⠀⠀⣾⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀
+⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀
+⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣠⣤⣤⣼⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀
+⠀⠀⠀⢀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀
+⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀
+⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀⠀
+⠀⠀⠀⠀⣿⣿⣿⣿⣿⣤⣤⣤⣤⣼⣿⣿⣿⣿⣧⣤⣤⣤⣤⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
+⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀
+⢀⣀⣀⣀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣤⠤⢤⣤⡄
+⠈⠉⠉⢉⣙⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⣀⣀⣀⡀⠀
+⠐⠚⠋⠉⢀⣬⡿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣥⣀⡀⠈⠀⠈⠛
+⠀⠀⠴⠚⠉⠀⠀⠀⠉⠛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⠋⠁⠀⠀⠀⠉⠛⠢⠀⠀
+⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ /$$    /$$                    /$$ /$$ /$$
+⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀| $$   | $$                   |__/| $$| $$
+⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀| $$   | $$ /$$$$$$  /$$$$$$$  /$$| $$| $$  /$$$$$$ 
+⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀|  $$ / $$/|____  $$| $$__  $$| $$| $$| $$ |____  $$
+⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀ \  $$ $$/  /$$$$$$$| $$  \ $$| $$| $$| $$  /$$$$$$$
+⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀  \  $$$/  /$$__  $$| $$  | $$| $$| $$| $$ /$$__  $$
+⠀⠀⠀⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀   \  $/  |  $$$$$$$| $$  | $$| $$| $$| $$|  $$$$$$$
+⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀    \_/    \_______/|__/  |__/|__/|__/|__/ \_______/
+                                                                                                    
+  /$$$$$$        /$$                                 /$$                                            
+ /$$__  $$      | $$                                | $$                                            
+| $$  \ $$  /$$$$$$$ /$$    /$$ /$$$$$$  /$$$$$$$  /$$$$$$   /$$   /$$  /$$$$$$   /$$$$$$   /$$$$$$$
+| $$$$$$$$ /$$__  $$|  $$  /$$//$$__  $$| $$__  $$|_  $$_/  | $$  | $$ /$$__  $$ /$$__  $$ /$$_____/
+| $$__  $$| $$  | $$ \  $$/$$/| $$$$$$$$| $$  \ $$  | $$    | $$  | $$| $$  \__/| $$$$$$$$|  $$$$$$ 
+| $$  | $$| $$  | $$  \  $$$/ | $$_____/| $$  | $$  | $$ /$$| $$  | $$| $$      | $$_____/ \____  $$
+| $$  | $$|  $$$$$$$   \  $/  |  $$$$$$$| $$  | $$  |  $$$$/|  $$$$$$/| $$      |  $$$$$$$ /$$$$$$$/
+|__/  |__/ \_______/    \_/    \_______/|__/  |__/   \___/   \______/ |__/       \_______/|_______/ 
+`
+var cats = [][]string{
+	strings.Split(title_idle, "\n"),
+	strings.Split(title_blinking, "\n")}
+
+
+
+func drawTitle(s tcell.Screen, x, frame int, style tcell.Style) int{
+	lines := cats[frame]
+	frame = (frame + 1) % 2
+	// Draw Title
+	xmax, ymax := s.Size()
+	for l:= range lines{
+		drawText(s,x, l, xmax, ymax, style, lines[l])
+	}
+	return len(lines)
+}
+
+
+func main() {
 	defStyle := tcell.StyleDefault.Background(color.Reset).Foreground(color.NewHexColor(0xf3e5ab))
 
 	// Initialize screen
@@ -108,69 +161,74 @@ func main() {
 	menu := true
 	gap_title_menu := 3
 	credits := false
+	frame := 0
+	ticker := time.NewTicker(500 * time.Millisecond)
+	defer ticker.Stop()
+	
 	// Event loop
 	for {
 		s.Clear()
-		
-		// Draw Title
-		xmax, ymax := s.Size()
-		for l:= range lines{
-			drawText(s,10, l, xmax, ymax, defStyle, lines[l])
-		}
-
+		title_size := drawTitle(s, 10, frame, defStyle)
+		frame = (frame + 1) % 2
+		xmax,ymax := s.Size()
 		// Draw Menu
 		if menu {
-			drawText(s, 10, len(lines)+gap_title_menu, xmax, ymax, defStyle,   "Arrows to navigate. Press ENTER to select")
+			drawText(s, 10, title_size+gap_title_menu, xmax, ymax, defStyle,   "Use arrows to navigate. Press ENTER to select")
 			switch curr_menu_item {
 			case 0:
-				drawText(s, 10, len(lines)+gap_title_menu+2, xmax, ymax, defStyle,   "▶ Start New Game")
-				drawText(s, 10, len(lines)+gap_title_menu+3, xmax, ymax, defStyle, "  Level Selector")
-				drawText(s, 10, len(lines)+gap_title_menu+4, xmax, ymax, defStyle, "  Credits")
+				drawText(s, 10, title_size+gap_title_menu+2, xmax, ymax, defStyle,   "▶ Start New Game")
+				drawText(s, 10, title_size+gap_title_menu+3, xmax, ymax, defStyle, "  Level Selector")
+				drawText(s, 10, title_size+gap_title_menu+4, xmax, ymax, defStyle, "  Credits")
 			case 1:
-				drawText(s, 10, len(lines)+gap_title_menu+2, xmax, ymax, defStyle,   "  Start New Game")
-				drawText(s, 10, len(lines)+gap_title_menu+3, xmax, ymax, defStyle, "▶ Level Selector")
-				drawText(s, 10, len(lines)+gap_title_menu+4, xmax, ymax, defStyle, "  Credits")
+				drawText(s, 10, title_size+gap_title_menu+2, xmax, ymax, defStyle,   "  Start New Game")
+				drawText(s, 10, title_size+gap_title_menu+3, xmax, ymax, defStyle, "▶ Level Selector")
+				drawText(s, 10, title_size+gap_title_menu+4, xmax, ymax, defStyle, "  Credits")
 			case 2:
-				drawText(s, 10, len(lines)+gap_title_menu+2, xmax, ymax, defStyle,   "  Start New Game")
-				drawText(s, 10, len(lines)+gap_title_menu+3, xmax, ymax, defStyle, "  Level Selector")
-				drawText(s, 10, len(lines)+gap_title_menu+4, xmax, ymax, defStyle, "▶ Credits")
+				drawText(s, 10, title_size+gap_title_menu+2, xmax, ymax, defStyle,   "  Start New Game")
+				drawText(s, 10, title_size+gap_title_menu+3, xmax, ymax, defStyle, "  Level Selector")
+				drawText(s, 10, title_size+gap_title_menu+4, xmax, ymax, defStyle, "▶ Credits")
 			}
 		}
 		
 		if credits {
-			drawText(s, 10, len(lines)+gap_title_menu, xmax,ymax, defStyle, "Abderrahmane Faiz")
-			drawText(s, 10, len(lines)+gap_title_menu+1, xmax,ymax, defStyle, "\u001B]8;;https://afaiz.dev\u001B\\https://afaiz.dev\u001B]8;;\u001B\\")
-			drawText(s, 10, len(lines)+gap_title_menu+2, xmax,ymax, defStyle, "\u001B]8;;mailto:learn_in_public@afaiz.dev\u001B\\learn_in_public@afaiz.dev\u001B]8;;\u001B\\")
-			drawText(s, 10, len(lines)+gap_title_menu+3, xmax,ymax, defStyle, "2026")
-			drawText(s, 10, len(lines)+gap_title_menu+5, xmax,ymax, defStyle, "Press ENTER to go back to the menu")
+			drawText(s, 10, title_size+gap_title_menu, xmax,ymax, defStyle, "Abderrahmane Faiz")
+			drawText(s, 10, title_size+gap_title_menu+1, xmax,ymax, defStyle, "\u001B]8;;https://afaiz.dev\u001B\\https://afaiz.dev\u001B]8;;\u001B\\")
+			drawText(s, 10, title_size+gap_title_menu+2, xmax,ymax, defStyle, "ASCII Art found on https://emojicombos.com/cat")
+			drawText(s, 10, title_size+gap_title_menu+4, xmax,ymax, defStyle, "Press ENTER to go back to the menu")
 		}
 		
 		// Update screen
 		s.Show()
 
 		// Poll event (this can be in a select statement as well)
-		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.KeyUp && menu {
-				if curr_menu_item == 0 {
-					curr_menu_item = 2
-				} else {
-					curr_menu_item = curr_menu_item - 1
+		select{
+			case <- ticker.C:
+			continue
+			case ev := <-s.EventQ():
+			// Process event
+			switch ev := ev.(type) {
+			default:
+				continue
+			case *tcell.EventResize:
+				s.Sync()
+			case *tcell.EventKey:
+				if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
+					return
+				} else if ev.Key() == tcell.KeyUp && menu {
+					if curr_menu_item == 0 {
+						curr_menu_item = 2
+					} else {
+						curr_menu_item = curr_menu_item - 1
+					}
+				} else if ev.Key() == tcell.KeyDown && menu {
+					curr_menu_item = (curr_menu_item + 1) % 3
+				} else if ev.Key() == tcell.KeyEnter && credits {
+					credits = false
+					menu = true
+				}  else if ev.Key() == tcell.KeyEnter && curr_menu_item == 2 {
+					menu = false
+					credits = true
 				}
-			} else if ev.Key() == tcell.KeyDown && menu {
-				curr_menu_item = (curr_menu_item + 1) % 3
-			} else if ev.Key() == tcell.KeyEnter && credits {
-				credits = false
-				menu = true
-			}  else if ev.Key() == tcell.KeyEnter && curr_menu_item == 2 {
-				menu = false
-				credits = true
 			}
 		}
 	}