-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
1485 lines (1322 loc) · 49.4 KB
/
Copy pathmain.lua
File metadata and controls
1485 lines (1322 loc) · 49.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- SNAKE / BRUTALISM
-- Estetica brutalista unificada. Serpiente con diseno brutalista propio.
local CELL = 20
local COLS = 30
local ROWS = 25
local HUD = 52
local MARGIN = 14 -- brutalist frame around the board
local BOARD_X = MARGIN
local BOARD_Y = HUD + MARGIN
local WIDTH = CELL * COLS + MARGIN * 2
local HEIGHT = CELL * ROWS + HUD + MARGIN * 2 + 22 -- +22 para footer
-- Paleta brutalista
local B = {
black = {0.04, 0.04, 0.04},
paper = {0.90, 0.89, 0.85},
red = {0.95, 0.16, 0.13},
redDark = {0.62, 0.10, 0.08},
gray = {0.55, 0.54, 0.52},
darkGray = {0.13, 0.13, 0.13},
}
-- Colores Purple (ex-Ekans)
local EK = {
yellow = {1.000, 0.792, 0.024},
darkPurple = {0.247, 0.098, 0.302},
midPurple = {0.420, 0.000, 0.494},
}
-- Colores estilo piton de jungla (verde oliva + ambar)
local JG = {
amber = {0.86, 0.62, 0.20}, -- cabeza ambar
olive = {0.36, 0.45, 0.22}, -- verde oliva
darkGreen = {0.18, 0.28, 0.14}, -- verde oscuro
eye = {0.95, 0.78, 0.10}, -- ojo amarillo hipnotico
}
-- Colores Quetzalcoatl (serpiente emplumada: esmeralda, oro, turquesa)
local QZ = {
emerald = {0.06, 0.58, 0.40}, -- verde quetzal
gold = {0.95, 0.74, 0.16}, -- oro
teal = {0.10, 0.42, 0.45}, -- turquesa profundo
crimson = {0.78, 0.16, 0.20}, -- detalle rojo
}
-- ===== Skins disponibles =====
local SKINS = {
{
id = "brutal",
name = "BRUTAL",
head = B.red,
bodyA = B.paper,
bodyB = B.gray,
eye = B.black,
border = B.black,
},
{
id = "purple",
name = "PURPLE",
head = EK.yellow,
bodyA = EK.midPurple,
bodyB = EK.darkPurple,
eye = B.black,
border = EK.darkPurple,
},
{
id = "jungle",
name = "JUNGLE",
head = JG.amber,
bodyA = JG.olive,
bodyB = JG.darkGreen,
eye = JG.eye,
border = JG.darkGreen,
},
{
id = "quetzal",
name = "QUETZAL",
head = QZ.gold,
bodyA = QZ.emerald,
bodyB = QZ.teal,
eye = QZ.crimson,
border = QZ.gold,
},
}
local selectedSkin = 1 -- indice en SKINS
local skinCursor = 1 -- cursor en la pantalla de seleccion
-- ===== Modos de juego =====
local MODES = {
{ id = "classic", name = "CLASSIC", desc = "STANDARD SNAKE" },
{ id = "obstacles", name = "OBSTACLES", desc = "WALLS APPEAR AS YOU LEVEL UP" },
}
local gameMode = "classic" -- modo activo
local modeCursor = 1 -- cursor en pantalla de modos
-- ===== Ajustes de partida =====
local settings = {
speedUp = true, -- aumentar velocidad cada 30 puntos
powerups = false, -- aparicion de power-ups
special = false, -- aparicion de comida especial
noWalls = false, -- atravesar bordes (wrap-around)
}
local configCursor = 1 -- 1=speedUp, 2=powerups, 3=special, 4=noWalls, 5=START
local snake, dir, nextDir, food, score, hiScore, state, timer, speed
local foodTimer = 0
local countdown = 0 -- segundos restantes de cuenta regresiva
local resumeAfter = false -- si la cuenta regresiva vuelve a "playing" tras pausa
local particles = {} -- particulas activas al comer
local shake = 0 -- intensidad actual del screen shake
-- Power-ups
local powerup = nil -- {x, y, life} o nil
local powerupTimer = 0 -- cuenta hacia la proxima aparicion
local powerupNext = 10 -- segundos hasta el proximo power-up
local slowTime = 0 -- segundos restantes del efecto ralentizar
-- Comida especial
local special = nil -- {x, y, life, maxLife} o nil
local specialTimer = 0 -- cuenta hacia la proxima aparicion
local specialNext = 12 -- segundos hasta la proxima comida especial
local SPECIAL_POINTS = 50 -- puntos que otorga
-- Obstaculos (modo OBSTACLES)
local obstacles = {} -- lista de {x, y}
local obstacleSet = {} -- lookup "x,y" -> true para colisiones rapidas
local obsLevel = 0 -- nivel actual alcanzado (cada 40 pts sube)
local OBS_PER_LEVEL = 3 -- obstaculos que aparecen por nivel
local F = {} -- fuentes
local SFX = {} -- efectos de sonido
local function newFood()
local occupied = {}
for _, s in ipairs(snake) do
occupied[s.x .. "," .. s.y] = true
end
-- evitar obstaculos
for _, o in ipairs(obstacles) do
occupied[o.x .. "," .. o.y] = true
end
local x, y
repeat
x = math.random(1, COLS)
y = math.random(1, ROWS)
until not occupied[x .. "," .. y]
return {x = x, y = y}
end
-- Genera 'count' obstaculos nuevos en celdas libres, lejos de la cabeza
local function spawnObstacles(count)
local occupied = {}
for _, s in ipairs(snake) do occupied[s.x..","..s.y] = true end
for _, o in ipairs(obstacles) do occupied[o.x..","..o.y] = true end
if food then occupied[food.x..","..food.y] = true end
if powerup then occupied[powerup.x..","..powerup.y] = true end
if special then occupied[special.x..","..special.y] = true end
local head = snake[1]
local placed = 0
local attempts = 0
while placed < count and attempts < 400 do
attempts = attempts + 1
local x = math.random(2, COLS - 1) -- no pegados al borde
local y = math.random(2, ROWS - 1)
local key = x .. "," .. y
-- zona segura: no dentro de 4 celdas de la cabeza ni en su fila/columna inmediata
local distHead = math.abs(x - head.x) + math.abs(y - head.y)
if not occupied[key] and distHead > 4 then
occupied[key] = true
obstacleSet[key] = true
table.insert(obstacles, {x = x, y = y})
placed = placed + 1
end
end
end
-- coordenada de celda a pixel (con marco)
local function cellPx(gx, gy)
return BOARD_X + (gx - 1) * CELL, BOARD_Y + (gy - 1) * CELL
end
-- Genera una explosion de cuadritos brutalistas en (px,py)
local function spawnParticles(px, py, color)
local count = 14
for i = 1, count do
local angle = math.random() * math.pi * 2
local sp = 60 + math.random() * 140 -- velocidad
table.insert(particles, {
x = px, y = py,
vx = math.cos(angle) * sp,
vy = math.sin(angle) * sp,
life = 0.4 + math.random() * 0.3, -- duracion
maxLife = 0.7,
size = 3 + math.random() * 5, -- cuadrito
rot = math.random() * math.pi,
vrot = (math.random() - 0.5) * 12,
color = color,
})
end
end
local function updateParticles(dt)
for i = #particles, 1, -1 do
local p = particles[i]
p.life = p.life - dt
if p.life <= 0 then
table.remove(particles, i)
else
p.x = p.x + p.vx * dt
p.y = p.y + p.vy * dt
p.vx = p.vx * 0.90 -- friccion (frenan rapido = brutalista)
p.vy = p.vy * 0.90
p.rot = p.rot + p.vrot * dt
end
end
end
local function drawParticles()
for _, p in ipairs(particles) do
local alpha = math.min(1, p.life / 0.3) -- desvanece al final
love.graphics.push()
love.graphics.translate(p.x, p.y)
love.graphics.rotate(p.rot)
love.graphics.setColor(p.color[1], p.color[2], p.color[3], alpha)
love.graphics.rectangle("fill", -p.size/2, -p.size/2, p.size, p.size)
love.graphics.pop()
end
end
local function reset()
local cx = math.floor(COLS / 2)
local cy = math.floor(ROWS / 2)
snake = {
{x = cx, y = cy},
{x = cx - 1, y = cy},
{x = cx - 2, y = cy},
}
dir = {x = 1, y = 0}
nextDir = {x = 1, y = 0}
score = 0
timer = 0
speed = 0.13
food = newFood()
particles = {}
shake = 0
-- Reiniciar power-ups
powerup = nil
powerupTimer = 0
powerupNext = 8 + math.random() * 7 -- primer power-up entre 8-15s
slowTime = 0
-- Reiniciar comida especial
special = nil
specialTimer = 0
specialNext = 10 + math.random() * 8 -- primera entre 10-18s
-- Reiniciar obstaculos
obstacles = {}
obstacleSet = {}
obsLevel = 0
-- Arranca directo a jugar (la cuenta regresiva solo aparece al reanudar de pausa)
state = "playing"
end
function love.load()
love.window.setTitle("SNAKE / BRUTALISM")
love.window.setMode(WIDTH, HEIGHT, {resizable = false, vsync = true})
math.randomseed(os.time())
F.display = love.graphics.newFont("fonts/Anton-Regular.ttf", 64)
F.huge = love.graphics.newFont("fonts/Anton-Regular.ttf", 160)
F.displaySm= love.graphics.newFont("fonts/Anton-Regular.ttf", 40)
F.heavy = love.graphics.newFont("fonts/ArchivoBlack-Regular.ttf", 18)
F.heavySm = love.graphics.newFont("fonts/ArchivoBlack-Regular.ttf", 13)
F.mono = love.graphics.newFont("fonts/SpaceMono-Bold.ttf", 14)
F.monoSm = love.graphics.newFont("fonts/SpaceMono-Bold.ttf", 11)
-- ===== Sintesis de sonidos 8-bit (ondas cuadradas brutalistas) =====
-- parts: lista de {f0, f1, wave, vol}; genera un Source estatico
local function synth(parts, duration)
local rate = 44100
local n = math.floor(rate * duration)
local data = love.sound.newSoundData(n, rate, 16, 1)
for i = 0, n - 1 do
local t = i / rate
local prog = i / n
local sample = 0
for _, p in ipairs(parts) do
local freq = p.f0 + (p.f1 - p.f0) * prog
local phase = freq * t * 2 * math.pi
local s
if p.wave == "square" then
s = (math.sin(phase) >= 0) and 1 or -1
elseif p.wave == "noise" then
s = math.random() * 2 - 1
else
s = math.sin(phase)
end
sample = sample + s * p.vol
end
-- Envelope: ataque rapido, decaimiento lineal (evita clicks)
local attack = 0.01
local env
if prog < attack then
env = prog / attack
else
env = 1 - (prog - attack) / (1 - attack)
end
sample = sample * env
if sample > 1 then sample = 1 elseif sample < -1 then sample = -1 end
data:setSample(i, sample)
end
return love.audio.newSource(data, "static")
end
-- EAT: blip cuadrado ascendente y brillante
SFX.eat = synth({{f0=440, f1=880, wave="square", vol=0.35}}, 0.10)
-- SELECT: beep limpio corto para menus
SFX.select = synth({{f0=660, f1=660, wave="square", vol=0.30}}, 0.05)
-- DIE: tono grave descendente + ruido (golpe seco)
SFX.die = synth({
{f0=300, f1=60, wave="square", vol=0.30},
{f0=200, f1=40, wave="noise", vol=0.20},
}, 0.45)
-- POWERUP: arpegio ascendente brillante (recoger ralentizar)
SFX.power = synth({
{f0=523, f1=1046, wave="square", vol=0.28},
{f0=659, f1=1318, wave="sine", vol=0.18},
}, 0.25)
hiScore = 0
state = "menu"
end
-- Reproduce un efecto reiniciandolo (permite repeticion rapida)
local function playSFX(src)
if src then
src:stop()
src:play()
end
end
function love.update(dt)
foodTimer = foodTimer + dt
-- Particulas y screen shake se actualizan siempre
updateParticles(dt)
if shake > 0 then
shake = shake - dt * 18 -- decae rapido
if shake < 0 then shake = 0 end
end
-- Cuenta regresiva: descuenta y pasa a jugar al llegar a 0
if state == "countdown" then
countdown = countdown - dt
-- countdown va de 3.0 a -0.5 (el tramo negativo muestra "GO")
if countdown <= -0.5 then
state = "playing"
end
return
end
if state ~= "playing" then return end
-- Efecto ralentizar: descuenta su tiempo
if slowTime > 0 then
slowTime = slowTime - dt
if slowTime < 0 then slowTime = 0 end
end
-- Power-ups: aparicion y expiracion (si estan activados en ajustes)
if settings.powerups then
if powerup then
-- el power-up activo en el tablero tiene vida limitada
powerup.life = powerup.life - dt
if powerup.life <= 0 then
powerup = nil
powerupTimer = 0
powerupNext = 8 + math.random() * 7
end
else
powerupTimer = powerupTimer + dt
if powerupTimer >= powerupNext then
-- generar power-up en una celda libre
local occupied = {}
for _, s in ipairs(snake) do occupied[s.x..","..s.y] = true end
occupied[food.x..","..food.y] = true
if special then occupied[special.x..","..special.y] = true end
for _, o in ipairs(obstacles) do occupied[o.x..","..o.y] = true end
local px, py
repeat
px = math.random(1, COLS)
py = math.random(1, ROWS)
until not occupied[px..","..py]
powerup = {x = px, y = py, life = 6.0} -- visible 6s
end
end
end
-- Comida especial: aparicion y expiracion (si esta activada)
if settings.special then
if special then
special.life = special.life - dt
if special.life <= 0 then
special = nil
specialTimer = 0
specialNext = 10 + math.random() * 8
end
else
specialTimer = specialTimer + dt
if specialTimer >= specialNext then
local occupied = {}
for _, s in ipairs(snake) do occupied[s.x..","..s.y] = true end
occupied[food.x..","..food.y] = true
if powerup then occupied[powerup.x..","..powerup.y] = true end
for _, o in ipairs(obstacles) do occupied[o.x..","..o.y] = true end
local px, py
repeat
px = math.random(1, COLS)
py = math.random(1, ROWS)
until not occupied[px..","..py]
local lifeDur = 5.0 -- visible 5s
special = {x = px, y = py, life = lifeDur, maxLife = lifeDur}
end
end
end
-- Velocidad efectiva: el doble de lento si el efecto esta activo
local effSpeed = speed
if slowTime > 0 then effSpeed = speed * 2 end
timer = timer + dt
if timer < effSpeed then return end
timer = 0
if not (nextDir.x == -dir.x and nextDir.y == -dir.y) then
dir = nextDir
end
local head = snake[1]
local nx = head.x + dir.x
local ny = head.y + dir.y
-- Paredes: con noWalls se envuelve al lado opuesto; si no, matan
if nx < 1 or nx > COLS or ny < 1 or ny > ROWS then
if settings.noWalls then
if nx < 1 then nx = COLS elseif nx > COLS then nx = 1 end
if ny < 1 then ny = ROWS elseif ny > ROWS then ny = 1 end
else
state = "dead"
shake = 1.0
playSFX(SFX.die)
if score > hiScore then hiScore = score end
return
end
end
for i = 1, #snake do
if snake[i].x == nx and snake[i].y == ny then
state = "dead"
shake = 1.0
playSFX(SFX.die)
if score > hiScore then hiScore = score end
return
end
end
-- Colision con obstaculos (modo OBSTACLES)
if obstacleSet[nx .. "," .. ny] then
state = "dead"
shake = 1.0
playSFX(SFX.die)
if score > hiScore then hiScore = score end
return
end
table.insert(snake, 1, {x = nx, y = ny})
local grew = false -- si la serpiente crecio este turno (no quitar cola)
-- Recoger power-up (ralentizar tiempo)
if powerup and nx == powerup.x and ny == powerup.y then
slowTime = 5.0 -- 5 segundos de tiempo lento
playSFX(SFX.power)
local ppx, ppy = cellPx(powerup.x, powerup.y)
spawnParticles(ppx + CELL/2, ppy + CELL/2, {0.3, 0.7, 1.0}) -- particulas azules
powerup = nil
powerupTimer = 0
powerupNext = 8 + math.random() * 7
end
-- Recoger comida especial (mas puntos, hace crecer)
if special and nx == special.x and ny == special.y then
score = score + SPECIAL_POINTS
grew = true
playSFX(SFX.power)
local spx, spy = cellPx(special.x, special.y)
spawnParticles(spx + CELL/2, spy + CELL/2, {1.0, 0.79, 0.05}) -- particulas doradas
special = nil
specialTimer = 0
specialNext = 10 + math.random() * 8
-- Tambien puede subir velocidad si toca multiplo de 30
if settings.speedUp and score % 30 == 0 and speed > 0.06 then
speed = speed - 0.01
end
end
if nx == food.x and ny == food.y then
score = score + 10
grew = true
playSFX(SFX.eat)
-- Particulas brutalistas en la posicion de la comida
local fpx, fpy = cellPx(food.x, food.y)
spawnParticles(fpx + CELL/2, fpy + CELL/2, SKINS[selectedSkin].head)
-- Aumentar velocidad cada 30 puntos (si el ajuste esta activo)
if settings.speedUp and score % 30 == 0 and speed > 0.06 then
speed = speed - 0.01
end
food = newFood()
end
if not grew then
table.remove(snake) -- mover: quitar cola si no crecio
end
-- Modo OBSTACLES: subir de nivel cada 40 puntos genera muros nuevos
if gameMode == "obstacles" then
local newLevel = math.floor(score / 40)
if newLevel > obsLevel then
for _ = obsLevel + 1, newLevel do
spawnObstacles(OBS_PER_LEVEL)
end
obsLevel = newLevel
playSFX(SFX.select) -- pequeno aviso al aparecer muros
end
end
end
function love.keypressed(key)
if key == "escape" then love.event.quit() end
if key == "p" then
if state == "playing" then
state = "paused"
playSFX(SFX.select)
elseif state == "paused" then
-- Reanudar con una cuenta regresiva corta
countdown = 1.5
state = "countdown"
playSFX(SFX.select)
end
return
end
-- Durante la cuenta regresiva ignoramos el resto de inputs
if state == "countdown" then return end
if state == "paused" then
if key == "m" then
state = "menu"
playSFX(SFX.select)
end
return
end
if state == "dead" then
if key == "return" or key == "space" then
playSFX(SFX.select)
reset()
elseif key == "m" then
state = "menu"
playSFX(SFX.select)
end
return
end
if state == "menu" then
if key == "return" or key == "space" then
playSFX(SFX.select)
reset()
elseif key == "g" then
modeCursor = 1
for i, m in ipairs(MODES) do
if m.id == gameMode then modeCursor = i end
end
state = "modes"
playSFX(SFX.select)
elseif key == "s" then
skinCursor = selectedSkin
state = "skins"
playSFX(SFX.select)
end
return
end
if state == "modes" then
if key == "left" or key == "a" then
modeCursor = modeCursor - 1
if modeCursor < 1 then modeCursor = #MODES end
playSFX(SFX.select)
elseif key == "right" or key == "d" then
modeCursor = modeCursor + 1
if modeCursor > #MODES then modeCursor = 1 end
playSFX(SFX.select)
elseif key == "return" or key == "space" then
gameMode = MODES[modeCursor].id
configCursor = 1
state = "config"
playSFX(SFX.select)
elseif key == "m" then
state = "menu"
playSFX(SFX.select)
end
return
end
if state == "config" then
if key == "up" or key == "w" then
configCursor = configCursor - 1
if configCursor < 1 then configCursor = 5 end
playSFX(SFX.select)
elseif key == "down" or key == "s" then
configCursor = configCursor + 1
if configCursor > 5 then configCursor = 1 end
playSFX(SFX.select)
elseif key == "left" or key == "right" or key == "a" or key == "d" then
if configCursor == 1 then
settings.speedUp = not settings.speedUp
playSFX(SFX.select)
elseif configCursor == 2 then
settings.powerups = not settings.powerups
playSFX(SFX.select)
elseif configCursor == 3 then
settings.special = not settings.special
playSFX(SFX.select)
elseif configCursor == 4 then
settings.noWalls = not settings.noWalls
playSFX(SFX.select)
end
elseif key == "return" or key == "space" then
if configCursor == 1 then
settings.speedUp = not settings.speedUp
playSFX(SFX.select)
elseif configCursor == 2 then
settings.powerups = not settings.powerups
playSFX(SFX.select)
elseif configCursor == 3 then
settings.special = not settings.special
playSFX(SFX.select)
elseif configCursor == 4 then
settings.noWalls = not settings.noWalls
playSFX(SFX.select)
else
-- START: arrancar partida
playSFX(SFX.select)
reset()
end
elseif key == "m" then
state = "modes"
playSFX(SFX.select)
end
return
end
if state == "skins" then
if key == "left" or key == "a" then
skinCursor = skinCursor - 1
if skinCursor < 1 then skinCursor = #SKINS end
playSFX(SFX.select)
elseif key == "right" or key == "d" then
skinCursor = skinCursor + 1
if skinCursor > #SKINS then skinCursor = 1 end
playSFX(SFX.select)
elseif key == "return" or key == "space" then
selectedSkin = skinCursor
state = "menu"
playSFX(SFX.select)
elseif key == "m" then
state = "menu"
playSFX(SFX.select)
end
return
end
if state ~= "playing" then return end
if (key == "up" or key == "w") and dir.y ~= 1 then nextDir = {x=0, y=-1}
elseif (key == "down" or key == "s") and dir.y ~= -1 then nextDir = {x=0, y=1}
elseif (key == "left" or key == "a") and dir.x ~= 1 then nextDir = {x=-1, y=0}
elseif (key == "right" or key == "d") and dir.x ~= -1 then nextDir = {x=1, y=0}
end
end
local function drawCell(gx, gy, r, g, b)
love.graphics.setColor(r, g, b)
local px, py = cellPx(gx, gy)
love.graphics.rectangle("fill", px + 1, py + 1, CELL - 2, CELL - 2)
end
-- ===== Pie de pagina (compartido por todas las pantallas) =====
local function drawFooter()
love.graphics.setFont(F.monoSm)
love.graphics.setColor(B.gray)
love.graphics.printf("SNAKE.BRUTALISM // LUA + LOVE2D", 0, HEIGHT - 18, WIDTH, "center")
end
-- ===== HUD (shared) =====
local function drawHUD()
love.graphics.setColor(B.black)
love.graphics.rectangle("fill", 0, 0, WIDTH, HUD)
love.graphics.setColor(B.red)
love.graphics.setLineWidth(3)
love.graphics.line(0, HUD, WIDTH, HUD)
-- Decorative red block
love.graphics.setColor(B.red)
love.graphics.rectangle("fill", 0, 0, 50, 8)
local labelY = 10 -- label row
local valueY = 28 -- value row (below label)
-- Helper: draws a stacked label/value block centered on x
-- mode: "left" anchors x at left edge, "center" centers on x, "right" anchors x at right edge
local function stack(label, value, x, mode)
local lw = F.heavySm:getWidth(label)
local vw = F.mono:getWidth(value)
local blockW = math.max(lw, vw)
local bx
if mode == "left" then
bx = x
elseif mode == "right" then
bx = x - blockW
else -- center
bx = x - blockW / 2
end
-- Label (red) centered within the block
love.graphics.setFont(F.heavySm)
love.graphics.setColor(B.red)
love.graphics.print(label, bx + (blockW - lw) / 2, labelY)
-- Value (paper) centered within the block
love.graphics.setFont(F.mono)
love.graphics.setColor(B.paper)
love.graphics.print(value, bx + (blockW - vw) / 2, valueY)
end
-- SCORE (left)
stack("SCORE", tostring(score), 14, "left")
-- SPEED (center)
local spd = string.format("%.0f", (0.13 - speed) / 0.01 + 1)
stack("SPEED", spd, WIDTH / 2, "center")
-- BEST (right)
stack("BEST", tostring(hiScore), WIDTH - 14, "right")
end
-- ===== Marco brutalista del tablero =====
local function drawBoardFrame()
-- Borde rojo grueso alrededor del area de juego
love.graphics.setColor(B.red)
love.graphics.setLineWidth(5)
love.graphics.rectangle("line", BOARD_X - 4, BOARD_Y - 4,
CELL * COLS + 8, CELL * ROWS + 8)
end
local function drawGrid()
love.graphics.setColor(B.darkGray)
love.graphics.setLineWidth(1)
for x = 0, COLS do
love.graphics.line(BOARD_X + x * CELL, BOARD_Y,
BOARD_X + x * CELL, BOARD_Y + ROWS * CELL)
end
for y = 0, ROWS do
love.graphics.line(BOARD_X, BOARD_Y + y * CELL,
BOARD_X + COLS * CELL, BOARD_Y + y * CELL)
end
end
-- Dibuja los muros/obstaculos (bloques de peligro brutalistas)
local function drawObstacles()
for _, o in ipairs(obstacles) do
local px, py = cellPx(o.x, o.y)
-- bloque gris oscuro solido
love.graphics.setColor(0.20, 0.20, 0.22)
love.graphics.rectangle("fill", px + 1, py + 1, CELL - 2, CELL - 2)
-- borde rojo grueso (peligro)
love.graphics.setColor(B.red)
love.graphics.setLineWidth(2)
love.graphics.rectangle("line", px + 2, py + 2, CELL - 4, CELL - 4)
-- rayas diagonales de peligro
love.graphics.setColor(B.red[1], B.red[2], B.red[3], 0.5)
love.graphics.setLineWidth(1)
love.graphics.line(px + 4, py + CELL - 4, px + CELL - 4, py + 4)
end
end
-- ===== S brutalista para el menu =====
local function drawSnakeS(cx, cy)
local S = 13
local G = 2
local step = S + G
local segs = {
{2,0},{1,0},{0,0},
{0,1},
{0,2},{1,2},{2,2},
{2,3},
{2,4},{1,4},{0,4},
}
local offX = cx - step
local offY = cy - step * 2
for i, seg in ipairs(segs) do
local px = offX + seg[1] * step
local py = offY + seg[2] * step
if i == 1 then
love.graphics.setColor(B.red)
else
love.graphics.setColor(B.paper)
end
love.graphics.rectangle("fill", px, py, S, S)
end
-- Ojo: cuadro rojo sobre cabeza roja -> usamos negro
local hx = offX + segs[1][1] * step
local hy = offY + segs[1][2] * step
love.graphics.setColor(B.black)
love.graphics.rectangle("fill", hx + S - 5, hy + 3, 3, 3)
end
-- ===== Serpiente brutalista (usa skin seleccionada) =====
local function drawSnakeBody()
local sk = SKINS[selectedSkin]
for i, seg in ipairs(snake) do
local px, py = cellPx(seg.x, seg.y)
if i == 1 then
-- CABEZA color principal de la skin
love.graphics.setColor(sk.head)
love.graphics.rectangle("fill", px + 1, py + 1, CELL - 2, CELL - 2)
-- borde interno (look brutalista)
love.graphics.setColor(sk.border)
love.graphics.setLineWidth(2)
love.graphics.rectangle("line", px + 3, py + 3, CELL - 6, CELL - 6)
-- Ojo cuadrado segun direccion
love.graphics.setColor(sk.eye)
local e = 4
local ex, ey = px + CELL/2 - e/2, py + CELL/2 - e/2
ex = ex + dir.x * 4
ey = ey + dir.y * 4
love.graphics.rectangle("fill", ex, ey, e, e)
else
-- CUERPO: alterna los dos colores de la skin (efecto franja)
if i % 2 == 0 then
love.graphics.setColor(sk.bodyA)
else
love.graphics.setColor(sk.bodyB)
end
love.graphics.rectangle("fill", px + 1, py + 1, CELL - 2, CELL - 2)
-- barra central de borde (cebra brutalista)
love.graphics.setColor(sk.border)
if dir and i == 2 and (dir.x ~= 0) then
love.graphics.rectangle("fill", px + 1, py + CELL/2 - 1, CELL - 2, 3)
else
love.graphics.rectangle("fill", px + CELL/2 - 1, py + 1, 3, CELL - 2)
end
end
end
end
-- ===== Dibuja una serpiente de muestra (para la pantalla de skins) =====
-- Dibuja horizontalmente 5 segmentos a partir de (x,y) con tamano cell
local function drawSkinPreview(skin, x, y, cell)
local segs = 5
-- Dibujamos de cola (izq) a cabeza (der)
for i = 1, segs do
local px = x + (i - 1) * cell
local isHead = (i == segs)
if isHead then
love.graphics.setColor(skin.head)
love.graphics.rectangle("fill", px + 1, y + 1, cell - 2, cell - 2)
love.graphics.setColor(skin.border)
love.graphics.setLineWidth(2)
love.graphics.rectangle("line", px + 3, y + 3, cell - 6, cell - 6)
-- ojo mirando a la derecha
love.graphics.setColor(skin.eye)
local e = 4
love.graphics.rectangle("fill", px + cell/2 - e/2 + 4, y + cell/2 - e/2, e, e)
else
if i % 2 == 0 then
love.graphics.setColor(skin.bodyA)
else
love.graphics.setColor(skin.bodyB)
end
love.graphics.rectangle("fill", px + 1, y + 1, cell - 2, cell - 2)
love.graphics.setColor(skin.border)
love.graphics.rectangle("fill", px + cell/2 - 1, y + 1, 3, cell - 2)
end
end
end
-- ===== Comida animada =====
local function drawFood()
local px, py = cellPx(food.x, food.y)
local cx, cy = px + CELL/2, py + CELL/2
-- Animacion: rotacion + pulso de escala
local t = foodTimer
local pulse = 1 + 0.12 * math.sin(t * 6) -- escala pulsante
local rot = t * 1.5 -- rotacion lenta
local sz = (CELL - 6) * 0.5 * pulse
love.graphics.push()
love.graphics.translate(cx, cy)
love.graphics.rotate(rot)
-- Diamante rojo brutalista (cuadrado rotado)
love.graphics.setColor(B.red)
love.graphics.rectangle("fill", -sz, -sz, sz * 2, sz * 2)
-- Cuadro interior negro
love.graphics.setColor(B.black)
love.graphics.setLineWidth(2)
love.graphics.rectangle("line", -sz * 0.5, -sz * 0.5, sz, sz)
love.graphics.pop()
-- Halo parpadeante (marco rojo fino alrededor de la celda)
local glow = 0.5 + 0.5 * math.sin(t * 6)
love.graphics.setColor(B.red[1], B.red[2], B.red[3], glow * 0.6)
love.graphics.setLineWidth(1)
love.graphics.rectangle("line", px + 2, py + 2, CELL - 4, CELL - 4)
end
-- Dibuja el power-up de ralentizar (reloj/cristal azul) si existe
local function drawPowerup()
if not powerup then return end
local px, py = cellPx(powerup.x, powerup.y)
local cx, cy = px + CELL/2, py + CELL/2
local t = foodTimer
local blue = {0.30, 0.70, 1.00}
-- Parpadeo cuando esta por desaparecer (ultimo 1.5s)
local visible = true
if powerup.life < 1.5 then
visible = (math.floor(t * 8) % 2 == 0)
end
if not visible then return end
local pulse = 1 + 0.15 * math.sin(t * 8)
local sz = (CELL - 4) * 0.5 * pulse
-- Bloque azul con borde grueso negro (brutalista)
love.graphics.setColor(blue)
love.graphics.rectangle("fill", cx - sz, cy - sz, sz * 2, sz * 2)
love.graphics.setColor(B.black)
love.graphics.setLineWidth(2)
love.graphics.rectangle("line", cx - sz, cy - sz, sz * 2, sz * 2)
-- Simbolo de reloj (manecillas) en negro
love.graphics.setLineWidth(2)
love.graphics.line(cx, cy, cx, cy - sz * 0.55)
love.graphics.line(cx, cy, cx + sz * 0.45, cy)
end
-- Dibuja la comida especial (estrella dorada) con barra de tiempo descontando
local function drawSpecial()
if not special then return end
local px, py = cellPx(special.x, special.y)
local cx, cy = px + CELL/2, py + CELL/2
local t = foodTimer
local gold = {1.0, 0.79, 0.05}
-- Parpadeo en el ultimo segundo
local visible = true
if special.life < 1.0 then
visible = (math.floor(t * 10) % 2 == 0)
end
if visible then
-- Bloque dorado rotando con borde negro grueso (diamante brutalista doble)
local pulse = 1 + 0.12 * math.sin(t * 7)
local sz = (CELL - 4) * 0.5 * pulse
love.graphics.push()
love.graphics.translate(cx, cy)
love.graphics.rotate(t * 2)
love.graphics.setColor(gold)
love.graphics.rectangle("fill", -sz, -sz, sz*2, sz*2)
love.graphics.setColor(B.black)
love.graphics.setLineWidth(2)
love.graphics.rectangle("line", -sz*0.5, -sz*0.5, sz, sz)
love.graphics.pop()
end
-- Barra de tiempo brutalista justo encima de la celda
local frac = special.life / special.maxLife
local barW = CELL + 6
local barX = px - 3
local barY = py - 8
-- fondo de la barra
love.graphics.setColor(B.black)
love.graphics.rectangle("fill", barX, barY, barW, 5)
-- relleno dorado descontando
love.graphics.setColor(gold)
love.graphics.rectangle("fill", barX, barY, barW * frac, 5)
end