File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 66	"time" 
77
88	tea "github.com/charmbracelet/bubbletea" 
9+ 	"github.com/charmbracelet/lipgloss" 
910)
1011
1112type  moveMsg  struct {}
3536type  player  struct  {
3637	body  []vector 
3738	dir   vector 
39+ 	style  lipgloss.Style 
3840}
3941
4042func  (p  * player ) move (m  model , foodPos  vector ) {
@@ -60,6 +62,7 @@ func (p player) headChar() rune {
6062
6163type  model  struct  {
6264	foodPos  vector 
65+ 	foodStyle  lipgloss.Style 
6366	player   player 
6467}
6568
@@ -133,16 +136,16 @@ func (m model) View() string {
133136			for  i , b  :=  range  m .player .body  {
134137				if  b .x  ==  x  &&  b .y  ==  y  {
135138					if  i  ==  0  {
136- 						s  +=  string (m .player .headChar ())
139+ 						s  +=  m . player . style . Render ( string (m .player .headChar () ))
137140					} else  {
138- 						s  +=  "*" 
141+ 						s  +=  m . player . style . Render ( "*" ) 
139142					}
140143					drew  =  true 
141144				}
142145			}
143146			if  ! drew  {
144147				if  x  ==  m .foodPos .x  &&  y  ==  m .foodPos .y  {
145- 					s  +=  "0" 
148+ 					s  +=  m . foodStyle . Render ( "0" ) 
146149					drew  =  true 
147150				}
148151			}
@@ -164,9 +167,11 @@ func initialModel() tea.Model {
164167			x : rand .IntN (20 ),
165168			y : rand .IntN (20 ),
166169		},
170+ 		foodStyle : lipgloss .NewStyle ().Foreground (lipgloss .Color ("#ff0000" )),
167171		player : player {
168172			body : []vector {{6 , 6 }},
169173			dir :  dirRight ,
174+ 			style : lipgloss .NewStyle ().Foreground (lipgloss .Color ("32" )),
170175		},
171176	}
172177}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments