Lyhensin koodia 235 riviin. ei muuta.
Code: Select all
Const img_char_w = 26
Const img_char_h = 21
Const img_chars = 55
Dim imgchartbl(48)
Type codefall
Field x#
Field y#
Field speed#
Field xoff#
Field memsize%
Field memque%
Field rpl_counter%
Field rpl_at%
Field rpl_turbulence%
Field rpl_maxjmp%
Field gen_counter%
Field gen_at%
Field gen_turbulence%
Field dmo_at%
EndType
Function DrawLetter(x%, y%, ind%, fade% = 0)
imgW% = ImageWidth(imgchartbl(0))
row% = ind / (imgW / img_char_w)
colum% = ind - row * (imgW / img_char_w)
If row >= 4 Then a = 1 'korjataan kuvan virhettä..
DrawImageBox imgchartbl(fade), x, y, colum*img_char_w, a + row*img_char_h, img_char_w, img_char_h
EndFunction
Color 0,255,0
Text ScreenWidth()/2 - TextWidth("Looking for best graphics mode..") /2, ScreenHeight()/2, "Looking for best graphics mode.."
DrawScreen
// Etsitään suurin (toivottavasti) tuettu grafiikka tila. Parametrilla /w Ohjelma käynnistyy
// 800x600 kokoisessa ikkunassa.
If Trim(CommandLine()) = "/w"
SCREEN 800,600
Else
modew = 0
modeh = 0
For y=0 To 2000 Step 2
For x=0 To 2000 Step 2
If GFXModeExists(x,y,32) Then
If modew < x Then modew = x
If modey < y Then modeh = y
EndIf
Next x
Next y
SCREEN modew,modeh,0,0
EndIf
Color 0,255,0
Text ScreenWidth()/2 - TextWidth("Loading awesome graphics..") /2, ScreenHeight()/2, "Loading awesome graphics.."
DrawScreen
// Ladataan kuva ja
m_imgchars% = LoadImage("matrix_code.png")
For i = 0 To 48
imgchartbl(i) = ImageBrightness(m_imgchars, -6*i + 30)
Next i
rndposwc% = ScreenWidth() / img_char_w
rndposhc% = ScreenHeight() / img_char_h
fall_gen_counter% = 0
fall_gen_at% = 400
m_x% = MouseX()
m_y% = MouseY()
Randomize Timer()
// Näytetään demo.
ApplyDemo()
Repeat
If fall_gen_counter > fall_gen_at
fall_gen_counter = 0
fall_gen_at = Rand(1, 4)
// generoidaan uusi koodipötkö:
nque.codefall = New(codefall)
nque\x = Rand(rndposwc) * img_char_w + Rand(-1,1) * (img_char_w/2)
nque\y = -img_char_h
// kaikki pötkön generoimis parametrit riippuvat sen nopeudesta..
nque\speed = Rand(1, img_char_h) + Rnd(-0.5, 1.0)
nque\xoff = (1 - 2*Rand(1)) * Rnd(nque\speed*3)
// Arvotaan pötkön pituus. (Min 2 merkkiä, koska muuten MemCopy ei toimi!)
quesize% = 2 + ((Rand(3, rndposhc) / nque\speed))
nque\memque = MakeMEMBlock(quesize)
nque\gen_at% = 1+(randposhc / quesize) + Int(img_char_h / nque\speed) / 2
nque\gen_turbulence = Rand(1, nque\gen_at / 2) * (1 - 2*Rand(1))
// jos pötkö liikuu hitaasti tapahtuu siinä paljon "virheitä"
nque\rpl_maxjmp = Rand(0, quesize-1)
nque\rpl_turbulence = Rand(nque\rpl_maxjmp / 6)
nque\rpl_at = Int(nque\speed * 0.75)
EndIf
fall_gen_counter + 1
TheMatrixCodefall()
If KeyHit(cbkeyspace)
ApplyDemo()
fall_gen_at = 10
EndIf
If KeyDown(cbkeyf) Then Text 0,0,"FPS:"+FPS()
// Suljetaan ohjelma jos hiiri liikkuu tarpeeksi.
If Distance(MouseX(),MouseY(),m_x,m_y) > 10 Then End
DrawScreen
Forever
End
Function TheMatrixCodefall()
For cf.codefall = Each codefall
cf\y = cf\y + cf\speed
cf\gen_counter = cf\gen_counter + 1
cf\rpl_counter = cf\rpl_counter + 1
If cf\memsize = 0
PokeByte cf\memque, 0, Rand(img_chars)
cf\memsize = 1
EndIf
If cf\gen_counter > cf\gen_at + cf\gen_turbulence + cf\dmo_at
cf\dmo_at = 0
cf\gen_counter = 0
cf\gen_turbulence = Rand(1, cf\gen_at / 2) * (1 - 2*Rand(1))
// siirrä merkki pötköä muistipalassa..
If MEMBlockSize(cf\memque)-1 < cf\memsize Then cf\memsize = cf\memsize - 1
MemCopy cf\memque, 0, cf\memque, 1, cf\memsize
cf\memsize = cf\memsize + 1
// arvo keulaan uusi merkki
PokeByte cf\memque, 0, Rand(img_chars)
cf\y = cf\y + img_char_h '/ 2
EndIf
If cf\rpl_counter > cf\rpl_at + cf\dmo_at
// Koravataan jokin merkki, pötkön 'hännässä' on epätodennäköisepää
// että merkki korvautuu.
cf\rpl_counter = 0
pos% = cf\rpl_maxjmp
Repeat
If Rand(pos) = 0
PokeByte cf\memque, Int(Min(MEMBlockSize(cf\memque)-1, pos + Rand(cf\rpl_turbulence))), Rand(img_chars)
Exit
EndIf
pos = pos - 1
Until pos < 0
EndIf
// Piirretään koodipötkö.
For i = 0 To cf\memsize-1
y# = cf\y - i * img_char_h
If y < ScreenHeight()
x# = cf\x+(Float(cf\y)/Float(ScreenHeight()))*cf\xoff
fade% = Max(0, (i / Max(1, Float(cf\memsize-1))) * 48)
DrawLetter(x, y, PeekByte(cf\memque, i), fade)
EndIf
Next i
// jos koko pötkö tipahti ulos ruudusta, se poistetaan.
If (cf\y - cf\memsize * img_char_h) > ScreenHeight()
DeleteMEMBlock cf\memque
Delete cf
EndIf
Next cf
EndFunction
// CBSDK:n Vastaavan nimiminen, nopeampi funktio.
Function ImageBrightness(pic%, bright%)
iw = ImageWidth(pic)
ih = ImageHeight(pic)
modified = MakeImage(iw,ih)
MaskImage modified, Int(Max(0, bright)),int(Max(0, bright)),int(Max(0, bright))
Lock Image(pic)
Lock Image(modified)
For j = 0 To ih-1
For i = 0 To iw-1
pixel% = GetPixel2(i,j,Image(pic))
r = Max(Min((pixel Shl 8) Shr 24 + bright, 255),0)
g = Max(Min((pixel Shl 16) Shr 24 + bright, 255),0)
b = Max(Min((pixel Shl 24) Shr 24 + bright, 255),0)
PutPixel2 i,j,b + (g Shl 8) + (r Shl 16), Image(modified)
Next i
Next j
Unlock Image(modified)
Unlock Image(pic)
Return modified
EndFunction
Function ApplyDemo()
// Luodaan kuvan merkeistä nipin napin tunnistettava "The Matrix codefall"
// Merkit ON valittu luovasti vapaalla silmällä. ;)
q.codefall = NULL
// ensin 19 pötköä..
For i = 1 To 19
nque.codefall = New(codefall)
// Keskitetään merkit n. ruudun keskelle.
nque\x = ((ScreenWidth() / img_char_w)/2 - 9 + i) * img_char_w
nque\y = -img_char_h
nque\speed = 1
nque\xoff = (1 - 2*Rand(1)) * Rnd(nque\speed*2)
quesize% = 2 + ((Rand(3, rndposhc) / nque\speed))
nque\memque = MakeMEMBlock(quesize)
nque\gen_at% = 2+(randposhc / quesize) + Int(img_char_h / nque\speed)
nque\dmo_at% = 400 'demo jono ..
nque\gen_turbulence = Rand(1, nque\gen_at / 2) * (1 - 2*Rand(1))
nque\rpl_maxjmp = rand(0, quesize-1)
nque\rpl_turbulence = Rand(1, nque\rpl_maxjmp / 6)
nque\rpl_at = Int(nque\speed * 0.75)
// lisäämme jokaiseen ainakin yhden merkin!
nque\memsize = 1
If i = 1 Then q = nque
Next i
// kirjoitetaan viesti.. : P
message$ = "13,49,31,19,11,20,13,49,16,54,19,10,8,4,31,50,20,32,32"
chars% = CountWords(message,",")
For i = 1 To chars
PokeByte q\memque, 0, GetWord(message, i, ",")
q = After(q)
Next i
EndFunction