   `                                  DDD@33344DD4ODD4OCC4OCC4O3CDDD 333?CDDCDDC43C44C4CC                                @  4@C4DDC433C4DDC4@C4@C@  @DD433C4DD 4334334DD433C@DD@  4@C@C4 4C  4C @C44@C@  @DD433C4DDC4DCC433C44DC4D@C@  @  4@C4@CDC4D@C4@4C 4C  @ @  4@C4C@C44DC4DCC44C4@C@                                   3330DDDC333C333C333C333C333C333333 DDD333433343334333433343334                  
	
	            p|||p|||                                      4OCC4OCC4OCC4ODD4ODD4@333 DDD44C44C44CDDCDDC?C333DDD                                   ff `ff fff`fff  "  "  "" "ffffffffffffffff   "   "      " ffffffffffffffff  " " """  " ff  ff fff ff& "   "   "   "  C333C333C333C333C333C3330DDD 333333433343334333433343334DDD333                                                ADt||Dt||A                                                                                                                                       "  "  "  ""  "" """  "  "  "  " ""  " "" "" ""  "" "" " ""  "" "" ""  " ""  "" """""  "  "" "" """"""" "   c3 33 3 3   33 33  36 33 3 31   33 33  33 @DD033@DD033@DD 33  @ DDDDDDDDDDDDDDDD44440444 44         ADDA                                        c3 33 3 #  ! 3# 3#  36 33 3 21   23 23                                   "  ""  ""  ""  ""  ""  ""  " "" "" ""  "  "     "  "   " """ """"""""" "" ""  " "" "" " """"" "" "" "" "" 333333 33 3 3 3 33 333333 1  1  1                      33 33333313331333                                                                                                                                                                                                                                                         "  ""  ""  "" """ """ """""""  ""  " " """ "" ""  ""  ""   "  "  "  ""  "  "  "" "" " "" "" """""""""""""""""              
	                    p|||                                                                                                                                                  133a33131D3           3333333333                                                                                                                                                                                                                                                                                                                                                                                                                                                                1D41CDa3D13DA   @     DDD33 43D33D33DDD DDDDDD                                                                                                                                                                                                                                                                                                                                                                                                                                                                @DDD@DDD DDD DDD DDD @DD        DDDDDDDDDD DDDD D  @  @  @                                                                                                                                                                                                 '()*         '()*        '()* '()*         '()*        '()* '()*         '()*        '()* '()*         '()*        '()*                                                                                           789:         789:        789: 789:         789:        789: 789:         789:        789: 789:         789:        789:                                                                                           GHIJ     GHIJ    GHIJ GHIJ  GHIJ    GHIJ GHIJ     GHIJ    GHIJ GHIJ     GHIJ    GHIJ                                                                                                '()*          -()*            '()*      '()*            '()*       -()*            '()*          '()*                                                                                                      789:        +,789:            789:     12789:            789:   / +,789:            789:        QR789:                                                                                                      GHIJ        ;<GHIJ            GHIJ     ..GHIJ            GHIJ     ;>GHIJ            GHIJ  =     abGHIJ                                                                                                                                         =                                         =     =   KrK K                                                                                                               '()*                  '()*                  '()*            L     '()*                                                                                               '()*      '()*   789:     '()*      '()*   789:     '()*      '()*   789:     '()* = LK '()*   789:                                                                                           '()*    789:      789:   GHIJ '()*    789:      789:   GHIJ '()*    789:      789:   GHIJ '()*    789:L L  K789:   GHIJ                                                                                           789:    GHIJ  GHIJ        789:    GHIJ  GHIJ        789:    GHIJ  GHIJ        789:  = GHIJL GHIJ                                                                                                  GHIJ         '()*             GHIJ         '()*             GHIJ         '()*             GHIJ         '()*                                                                                                                    789:                      789:                      789:                      789:                                                                                                                GHIJ         '()*             GHIJ         '()*             GHIJ         '()*             GHIJ         '()*                                                                                                                    789:                          789:                          789:                          789:                                                                                                                    GHIJ                          GHIJ                          GHIJ                          GHIJ	                                                                                                                                    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  `    `   
 `    `    `    `    `    `    `    `    `       ` `    `    `    `   	 `    `   
 `    `   	 `    `    `    `    `    `   	 `    `   	 `    `    `    `    @   
 @   
 `    @    @    @	 @     @   
 `   	 @         @    @                                                                                                                                                                             	                                                                                                                                                     
                 	                                                             	    
        
              
 ` ` `	 ` `	 `	 ` ` ` `
 ` ` ` ` ` ` ` ` ` `
 ` ` `
 ` `
 ` ` ` ` `	 ` ` `	 ` `	 ` `
 `	 ` ` ` ` `
 `	 ` `
 ` ` ` ` ` `	 ` ` ` `	 ` `
 ` `	 ` ` `	 `2                                                                                                                                                                                                                                                                                                      
<? """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""",,"""",,",,""","",,"""","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""",",",""",""""",",""""""","",",""",""","","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""",","",""""",",,"""""",","",""""""","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""",",""""""""",,,,","""""",,"""",""","","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""",",",""",,",",,,""""",",","""","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           NDDNDDDDDDDDNDDNDDDDDDDDNDDNDD                          NDDNDDDDDDDDNDDNDDDDDDDDNDDNDD                          NDDNDDDDDDDDNDDNDDDDDDDDNDDNDD                          D43DND3CDD433333333CDD43DND3CDD433333333CDD43DND3CDD43DND3CD                          D43DND3CDD433333333CDD43DND3CDD433333333CDD43DND3CDD43DND3CD                          D43DND3CDD433333333CDD43DND3CDD433333333CDD43DND3CDD43DND3CD                          D43DDDDDD3CDD43DDDDDDND3CDD43DD43DDDDDD3CDD43DND3CDD433CDND3CD                          D43DDDDDD3CDD43DDDDDDND3CDD43DD43DDDDDD3CDD43DND3CDD433CDND3CD                          D43DDDDDD3CDD43DDDDDDND3CDD43DD43DDDDDD3CDD43DND3CDD433CDND3CD                          D433333333CDD43333333DD433CDD43DDD3CD3CDDDD3CDD43DDDD43D43DDD3CD                          D433333333CDD43333333DD433CDD43DDD3CD3CDDDD3CDD43DDDD43D43DDD3CD                          D433333333CDD43333333DD433CDD43DDD3CD3CDDDD3CDD43DDDD43D43DDD3CD                          D43DDDDDD3CDD43333333DD433CDD433333333CDND3CDD43DD43DDD3CD3CD                          D43DDDDDD3CDD43333333DD433CDD433333333CDND3CDD43DD43DDD3CD3CD                          D43DDDDDD3CDD43333333DD433CDD433333333CDND3CDD43DD43DDD3CD3CD                          D43DND3CDD43DDDDDDDND3CDD43DD43D43DDD3CDNDD433CDDD43DD433CD                          D43DND3CDD43DDDDDDDND3CDD43DD43D43DDD3CDNDD433CDDD43DD433CD                          D43DND3CDD43DDDDDDDND3CDD43DD43D43DDD3CDNDD433CDDD43DD433CD                          D43DND3CDD433333333CDD43DND3CDD43DDDND3CDD433CDD43DND3CD                          D43DND3CDD433333333CDD43DND3CDD43DDDND3CDD433CDD43DND3CD                          D43DND3CDD433333333CDD43DND3CDD43DDDND3CDD433CDD43DND3CD                          NDDNDDDDDDDDNDDNDDNDDNDD                          NDDNDDDDDDDDNDDNDDNDDNDD                          NDDNDDDDDDDDNDDNDDNDDNDD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 @ -- title: HexaVN
-- author: Hexabee Retro
-- desc: Step into the hexagonal domain of Hexa. In a world where honey isn't made the classic way, every decision stings. A minimalist visual novel experience crafted with 8-bit limitations and deterministic logic.
-- script: lua
-- saveid: hexavn
-- Licensed: EULA
-- Copyright 2026 Hexabee Retro


sira = 1
-- ✨ TYPEWRITER AYARLARI
tw_pozisyon = 0      -- Şu an ekranda kaç karakter var
tw_zamanlayici = 0   -- Kare sayacı
tw_hiz = 3           -- Karakter başına düşen kare sayısı (3 = ~20 karakter/sn)

local baslangic_idx = 1
local bitis_idx = 4 -- level1'de kaçıncı satıra kadar gidecek?
local su_an_calan = -1

-- 📖 SENARYO TABLOSU
senaryo = {
--- Level 1
  {ad="HEXA", metin="Hey, I'm Hexa. My hive, this place is a huge domain. Under our Queen Hoxa's lead, we don't make honey in the classic way here. This honey has a ...", baslik="EPISODE 01: IN THE BEGINNING"},
  {ad="HEXA", metin="... special power.", baslik=""},
  {ad="QUEEN HOXA", metin="Hello, Hexa. Let me explain: this venom we produce is actually in our nectar. It's not in the honey itself; it only passes into the honey. ", baslik=""},
  {ad="QUEEN HOXA", metin="There have been those who could destroy this venom, but not completely. ", baslik=""},
  {ad="HEXA", metin="When humans eat it, the entire venom spreads within 10 minutes and it's powerful enough to collapse one bodily function every second. ", baslik=""},
  {ad="HEXA", metin="Of course, the antidote is, ironically, with us.", baslik=""},
  {ad="QUEEN HOXA", metin="Look, this isn't just for humans. It's even more dire for bears. Since they dive in with their paws, it can finish them off in a few minutes without ...", baslik=""},
  {ad="QUEEN HOXA", metin="... even needing to eat it. To not die, they must stay away from us. Of course, that poor creature isn't quite that smart.", baslik=""},
  {ad="...", metin="10 minutes pass.", baslik=""},
  {ad="HEXA", metin="My Queen Hoxa. If humans can save themselves, why haven't they tried to save us?", baslik=""},
  {ad="QUEEN HOXA", metin="Humans are both ungrateful and intelligent. Look, this is heavily both contradictory and ironic in this matter. These creatures we call ...", baslik=""},
  {ad="QUEEN HOXA", metin="... humans can't stop experimenting on animals for the sake of health and beauty.", baslik=""},
  {ad="HEXA", metin="My Queen, do you think humans will ever reform?", baslik=""},
  {ad="...", metin="At that moment, a feeling comes to Hexa that a hungry bear is arriving. But she doesn't care.", baslik=""},
  {ad="QUEEN HOXA", metin="Humans don't know when they should stop. Then they blame the crimes on animals. They have gone mad.", baslik=""},
  {ad="HEXA", metin="My Queen, I believe you don't feel sorry for humans. But why do we poison the bears?", baslik=""},
  {ad="QUEEN HOXA", metin="Bears are actually innocent, but we have to produce venom for our survival. Life is short for ... ", baslik=""},
  {ad="QUEEN HOXA", metin="... us, but long for the bear. I feel sorry for these bears.", baslik=""},

-- LEVEL 2
  {ad="???", metin="I'M HUNGRY! I WANT FOOD! IS THERE ANY?!", baslik="EPISODE 02: THE ASSAULT"},
  {ad="...", metin="She spots a beehive on one of the trees. She approaches slowly.", baslik=""},
  {ad="BEA", metin="My name is Bea. Not like 'Bee' with a double E.", baslik=""},
  {ad="...", metin="She looks at the tree, raises her right leg. She kicks it with the full power of her massive frame. Red alerts start blaring in Hexa's sector.", baslik=""},
  {ad="...", metin="HEXA SECTOR", baslik=""},
  {ad="...", metin="When Hexa and her friends hear the alarm, everyone starts screaming. Panic takes over. Queen Hoxa waits until the chaos reaches a point ...", baslik=""},
  {ad="...", metin="... where no one can hear anything.", baslik=""},
  {ad="QUEEN HOXA", metin="EVERYONE SHUT UP AND GET IN LINE! NOW!", baslik=""},
  {ad="...", metin="Not a single sound is heard in the hive.", baslik=""},
  {ad="QUEEN HOXA", metin="Alright. We do not know the enemy before us, but looking at its movements, it's not hard to guess. A Bear. It will be difficult to ...", baslik=""},
  {ad="QUEEN HOXA", metin="... destroy it. CHARGE!", baslik=""},
  {ad="...", metin="All the bees unite and begin to fly toward the bear.", baslik=""},
-- LEVEL 3
  {ad="QUEEN HOXA", metin="I will lead the first strike.", baslik="EPISODE 03: THE SACRIFICE"},
  {ad="HIXA", metin="My name is Hixa. I am a girl cherished by the Queen. I am the legacy of my former Queen in this hive.", baslik=""},
  {ad="HIXA", metin="My Queen, I want to try.", baslik=""},
  {ad="QUEEN HOXA", metin="Go ahead and try.", baslik=""},
  {ad="BEA", metin="I'm going to eat honey.", baslik=""},
  {ad="QUEEN HOXA", metin="I wish I could explain to you that this is poisonous.", baslik=""},
  {ad="...", metin="Bea doesn't listen to them and as she begins to reach for the honey, Hixa sees her. She tries to sting the bear's paws.", baslik=""},
  {ad="...", metin="Just as she aims, Bea raises her hand. Hixa manages to escape without taking any damage by pure luck.", baslik=""},
  {ad="QUEEN HOXA", metin="Fine, it is my turn. I will attack its nose.", baslik=""},
  {ad="...", metin="As Queen Hoxa prepares to attack, the other bees see that she is charging. Simultaneously, they see the bear touching the honey.", baslik=""},
  {ad="QUEEN HOXA", metin="STOP!", baslik=""},
  {ad="...", metin="No one listens to her. For the sake of everyone, she rapidly aims for the bear's nose, stings it, and dies.", baslik=""},
  {ad="...", metin="Enraged by this, Bea angrily throws the honey to the ground. She leans down and continues to eat it from the earth.", baslik=""},
--- LEVEL 4
  {ad="...", metin="Queen Hoxa is dead. While everyone starts to wonder who will lead the hive, the bear begins to consume the venom. Hearing this, Hixa prepares ...", baslik="EPISODE 04: THE NEW REIGN"},
  {ad="...", metin=" ... herself.", baslik=""},
  {ad="HIXA", metin="Since our Queen is gone, I will not allow us to be leaderless. I shall be your Queen.", baslik=""},
  {ad="HEXA", metin="I won't listen to you. If our Queen is gone, then I am gone too.", baslik=""},
  {ad="QUEEN HIXA", metin="STOP! Have you lost your mind? The bear ate it; it will die within 1 or 2 minutes. We can start over.", baslik=""},
  {ad="HEXA", metin="We are racing against seconds. Maybe the bear will eat us too.", baslik=""},
  {ad="QUEEN HIXA", metin="Do you know the price of disobedience? My Queen trained me for these situations. So that I could take charge when necessary.", baslik=""},
  {ad="...", metin="Bea continues to eat her meal. But Hexa cannot bear it; she rapidly flies towards her.", baslik=""},
--- LEVEL 5
  {ad="...", metin="This time, Bea hears the buzzing and pushes them all away with her hands; Hixa is sent flying further into the air. In that moment, she loses ...", baslik="EPISODE 05: THE FINAL FALL"},
  {ad="...", metin="... half of the bees. Hexa is still alive.", baslik=""},
  {ad="HEXA", metin="She's mad... Don't expect me to say 'just die already.' I'm going to speed up and sting her.", baslik=""},
  {ad="QUEEN HIXA", metin="Hold your position! STOP!", baslik=""},
  {ad="...", metin="It's in vain; she won't stop. It is clear she is flying toward her death. Hexa aims for Bea's belly to sting her.", baslik=""},
  {ad="...", metin="Seeing this, the bear makes one last leap and falls upon them, killing everyone instantly.", baslik=""},
  {ad="...", metin="Bea is now poisoned by the honey she ate. She cannot even realize she is poisoned; as Queen Hoxa said, bears are not smart.", baslik=""},
  {ad="SYSTEM", metin="The game ends here. For the continuation of the story, wait for HexaVN 2.", baslik="THE END"}
}

function TIC()
TIC = baslangic
 baslangic()
end

local start_time = 0

function baslangic()
  if start_time == 0 then start_time = time() end
  local elapsed = time() - start_time
  
  cls() -- Temiz bir siyah zemin

  -- 🎨 SAHNE ÇİZİMLERİ (Her zamanki gibi altta dursun)
  spr(1, 58, 42, 0, 3) 
  spr(2, 80, 42, 0, 3)
  spr(17, 58, 65, 0, 3)
  spr(18, 80, 65, 0, 3)
  print("HEXABEE", 108, 50, 5, false, 2)
  print("RETRO", 108, 70, 4, false, 2)
  print("FROM KAYSERI/TURKIYE", 65, 95, 11)

  -- 🏁 NES STİLİ PANJUR EFEKTİ (Scanline Fade)
  -- Ekranı 8 piksellik şeritlere bölüp, zamanla bu şeritleri daraltıyoruz
  local perde_genisligi = math.max(0, 8 - (elapsed / 200)) -- 1.6 saniyede tamamen açılır
  
  if perde_genisligi > 0 then
    for y = 0, 136, 8 do
      -- Her 8 pikselde bir siyah bir "perde" çekiyoruz
      rect(0, y, 240, perde_genisligi, 0)
    end
  end

  -- 3.5 sn sonra title'a geçiş
  if elapsed >= 3500 then
    TIC = title
    music(0, true)
  end
end-- Global değişkenler (Dosyanın en başında, bir kez tanımla)
logo_y_offset = 120 -- Başlangıçta her şeyi 120 piksel aşağı kaydırıyoruz
logo_hedef_offset = 0 -- Hedefimiz orijinal yerleşimin (0 kayma) olduğu yer

function title()
	cls()
	
	-- 🚀 YUMUŞAK GEÇİŞ MANTIĞI
	-- Offset 0 olana kadar her karede 2 piksel azalır (her şey yukarı kayar)
	if logo_y_offset > logo_hedef_offset then
		logo_y_offset = logo_y_offset - 2
	end

	sira = 1
	arilar_olusturuldu = false


	-- 🖼️ LOGO (Senin orijinal koordinatlarına sadece offset ekledim, hiç bozulmaz)
	spr(20, 26, 35 + logo_y_offset, 0, 3)
	spr(21, 46, 35 + logo_y_offset, 0, 3)
	spr(21, 64, 35 + logo_y_offset, 0, 3)
	spr(21, 82, 35 + logo_y_offset, 0, 3)
	spr(21, 100, 35 + logo_y_offset, 0, 3)
	spr(21, 118, 35 + logo_y_offset, 0, 3)
	spr(21, 132, 35 + logo_y_offset, 0, 3)
	spr(21, 150, 35 + logo_y_offset, 0, 3)
	spr(21, 168, 35 + logo_y_offset, 0, 3)
	spr(22, 189, 35 + logo_y_offset, 0, 3)

	spr(52, 26, 50 + logo_y_offset, 0, 3)
	spr(53, 46, 50 + logo_y_offset, 0, 3)
	spr(53, 64, 50 + logo_y_offset, 0, 3)
	spr(53, 82, 50 + logo_y_offset, 0, 3)
	spr(53, 100, 50 + logo_y_offset, 0, 3)
	spr(53, 118, 50 + logo_y_offset, 0, 3)
	spr(53, 132, 50 + logo_y_offset, 0, 3)
	spr(53, 150, 50 + logo_y_offset, 0, 3)
	spr(53, 168, 50 + logo_y_offset, 0, 3)
	spr(54, 189, 50 + logo_y_offset, 0, 3)

	spr(4, 32, 43 + logo_y_offset, 0, 3)
	spr(5, 62, 43 + logo_y_offset, 0, 3)
	spr(6, 92, 43 + logo_y_offset, 0, 3)
	spr(7, 122, 43 + logo_y_offset, 0, 3)
	spr(8, 152, 43 + logo_y_offset, 0, 3)
	spr(9, 182, 43 + logo_y_offset, 0, 3)
	
	-- 📝 YAZILAR (Bunlar da aynı offsetle geliyor)
	print("HEXAGON VISUAL NOVEL", 60, 25 + logo_y_offset, 12)
	
	-- Logo yerine tam oturunca diğer bilgiler gelsin
	if logo_y_offset == logo_hedef_offset then
		if math.floor(time() / 500) % 2 == 0 then
			print("PRESS Z START", 48, 80, 12, false, 2)
		end
		
		print("COPYRIGHT 2026 - HEXABEE RETRO", 40, 110, 12)
		print("STORY TRANSLATED BY: GOOGLE GEMINI", 30, 130, 12)
		print("DEVELOPED, MUSIC, DESIGN BY: AGG1401", 26, 120, 12)
	end
	
	if btnp(4) then TIC = level1 end
end




-- 📦 KUTU AYARLARI (Sadece burayı kutuna göre 1 kez ayarla)
local KUTU = {
  x = 16,          -- Metin kutusunun sol iç kenarı
  y = 86,         -- Metin kutusunun üst iç kenarı
  genislik = 230,  -- Kutunun kullanılabilir iç genişliği (piksel)
  yukseklik = 32,  -- Kutunun kullanılabilir iç yüksekliği (piksel)
  satir_araligi = 8 -- Satırlar arası dikey boşluk
}
local FONT_W = 6   -- TIC-80 varsayılan font genişliği (scale 1 için)

function sprBox()
 spr(20, 10, 80, 0, 3)
	spr(21, 30, 80, 0, 3)
	spr(21, 50, 80, 0, 3)
	spr(21, 70, 80, 0, 3)
	spr(21, 90, 80, 0, 3)
	spr(21, 110, 80, 0, 3)
	spr(21, 130, 80, 0, 3)
	spr(21, 150, 80, 0, 3)
	spr(21, 170, 80, 0, 3)
	spr(21, 190, 80, 0, 3)
	spr(22, 210, 80, 0, 3)
	spr(36, 10, 90, 0, 3)
	spr(37, 30, 90, 0, 3)
	spr(37, 50, 90, 0, 3)
	spr(37, 70, 90, 0, 3)
	spr(37, 90, 90, 0, 3)
	spr(37, 110, 90, 0, 3)
	spr(37, 130, 90, 0, 3)
	spr(37, 150, 90, 0, 3)
	spr(37, 170, 90, 0, 3)
	spr(37, 190, 90, 0, 3)
	spr(38, 210, 90, 0, 3)
 spr(52, 10, 100, 0, 3)
	spr(53, 30, 100, 0, 3)
	spr(53, 50, 100, 0, 3)
	spr(53, 70, 100, 0, 3)
	spr(53, 90, 100, 0, 3)
	spr(53, 110, 100, 0, 3)
	spr(53, 130, 100, 0, 3)
	spr(53, 150, 100, 0, 3)
	spr(53, 170, 100, 0, 3)
	spr(53, 190, 100, 0, 3)
	spr(54, 210, 100, 0, 3)

local txt = "PRESS Z TO CONTINUE"
local x, y = 63, 128
-- Yazının arkasına tam oturan ince siyah bir dikdörtgen
rect(x - 2, y - 2, (#txt * 6) + 4, 9, 0) 
-- Üstüne parlak bir renk (Mesela 12 numara, o mavi/gri tonu)
print(txt, x, y, 12)
	
end

function typewriterord(hedef_tic)

  -- 1. SAHNE BİTİŞ KONTROLÜ (Müzik takılmasını önleyen yer)
  if not sira or sira < baslangic_idx then sira = baslangic_idx end
  
  if sira > bitis_idx or not senaryo[sira] then 
    tw_pozisyon = 0
    tw_zamanlayici = 0
    
    -- Eğer hedef bir fonksiyonsa (level2, level3 vb.)
    if type(hedef_tic) == "function" then
      -- Bir sonraki bölümün başlangıç indexini otomatik ayarla
      -- Bu sayede level fonksiyonlarının içinde sira = 19 gibi manuel işlere gerek kalmaz.
      sira = bitis_idx + 1 
      TIC = hedef_tic
    end
    
    -- KRİTİK: Bu karede daha fazla işlem yapma ki music() komutları tetiklenmesin.
    return 
  end

  local sahne = senaryo[sira]
  local metin = sahne.metin or ""
  local uzunluk = #metin
  
  -- ⌨️ TYPEWRITER HESAPLAMA
  if tw_pozisyon < uzunluk then
    tw_zamanlayici = tw_zamanlayici + 1
    if tw_zamanlayici >= tw_hiz then
      tw_pozisyon = tw_pozisyon + 1
      tw_zamanlayici = 0
      
      local karakter = string.sub(metin, tw_pozisyon, tw_pozisyon)
      if karakter ~= " " then
        sfx(0, "C-4", 6, 3, 5) 
      end
    end
  end

  -- 🧠 WORD-WRAP (Aynı kalıyor)
  local gosterilen = string.sub(metin, 1, tw_pozisyon)
  local satirlar = {}
  local mevcut_satir = ""
  
  for kelime in gosterilen:gmatch("%S+") do
    if (#mevcut_satir + #kelime + 1) * FONT_W <= KUTU.genislik then
      if mevcut_satir == "" then mevcut_satir = kelime
      else mevcut_satir = mevcut_satir .. " " .. kelime end
    else
      table.insert(satirlar, mevcut_satir)
      mevcut_satir = kelime
    end
  end
  table.insert(satirlar, mevcut_satir) 

  -- 🎨 ÇİZİMLER (İsim, Başlık, Metin - Aynı kalıyor)
  if sahne.ad and sahne.ad ~= "" then 
    local ad_genislik = (#sahne.ad * 12) + 12 
    rect(10, 60, ad_genislik, 16, 0)   
    rectb(10, 60, ad_genislik, 16, 15) 
    print(sahne.ad, 16, 63, 12, false, 2) 
  end

  if sahne.baslik and sahne.baslik ~= "" then 
    local bas_gen = (#sahne.baslik * 6) + 8
    rect(10, 15, bas_gen, 11, 0) 
    rectb(10, 15, bas_gen, 11, 12) 
    print(sahne.baslik, 14, 18, 13) 
  end

  local max_satir = math.floor(KUTU.yukseklik / KUTU.satir_araligi)
  for i = 1, math.min(#satirlar, max_satir) do
    print(satirlar[i], KUTU.x, KUTU.y + (i-1)*KUTU.satir_araligi, 4)
  end

  -- 🖱️ BUTON KONTROLÜ
  if btnp(4) then
    if tw_pozisyon < uzunluk then 
      tw_pozisyon = uzunluk
    else 
      tw_pozisyon = 0
      tw_zamanlayici = 0
      sira = sira + 1 
    end
  end
end

-- 🎵 MÜZİK ÇALICI (Daha güvenli yöntem)
function calMuzik(id)
  if su_an_calan ~= id then
    music(id, true)
    su_an_calan = id
  end
end

local arilar = {}
local arilar_olusturuldu = false

function arilari_serpistis()
for i=1, 10 do -- Ekranda 10 tane rastgele arı olsun
table.insert(arilar, {
id = math.random(13, 15), -- 13, 14 veya 15 numaralı sprite
x = math.random(20, 220),
y = math.random(20, 100),
hiz = math.random(1, 3) * 0.1 -- Hafif bir salınım için
})
end
arilar_olusturuldu = true
end


-- BÖLÜMLER
function level1()
  cls(); map(0,0)
  calMuzik(1) -- Müzik 1
  
if not arilar_olusturuldu then arilari_serpistis() end
for i, ari in ipairs(arilar) do
local y_salinim = math.sin(time()/500 + i) * 2
spr(ari.id, ari.x, ari.y + y_salinim, 0)
end
spr(30, 200, 40, 0, 2)

  sprBox()

  baslangic_idx, bitis_idx = 1, 18 
  typewriterord(level2)
end

function level2()
  cls(10); map(30,0,30,17,0,0,0)
  calMuzik(2) -- Müzik 2
  sprBox()
  baslangic_idx, bitis_idx = 19, 30
  typewriterord(level3)
end

function level3()
  cls(13); map(90,0,90,17,0,0,0)
  calMuzik(4) -- Müzik 3
  sprBox()
  baslangic_idx, bitis_idx = 31, 43
  typewriterord(level4)
end

function level4()
  cls(); map(60,0)
  calMuzik(3) -- Müzik 4 (Editörde 4. sekme dolu olmalı)
  sprBox()
  baslangic_idx, bitis_idx = 44, 51
  typewriterord(level5)
end

function level5()
  cls(); map(120,0)
  calMuzik(5) -- Müzik 5 (Editörde 5. sekme dolu olmalı)
  sprBox()
  baslangic_idx, bitis_idx = 52, 60
  typewriterord(title)
end
