Snake Saver

Красивый червячок анимируется на экране. По сути это подобие скринмейта.

Платформы: Windows, Linux
Автор: Mysoft

snakesaver.png

#DEFINE FBC -s gui
#INCLUDE "fbgfx.bi"
#IFDEF __FB_WIN32__
#INCLUDE "windows.bi"
#ENDIF

Using fb
Declare Sub VSYNC ()
Declare Sub DOSNAKEBOX()

' ******************** Constantes de op‡oes ******************
Const MAXCO = 99   ' Numero de angulos
Const DIS = 15     ' Distancia (varia por num de angulos)
Const MAXR = 7     ' Velocidade maxima de rota‡ao de cada angulo
Const TAIL = 1000  ' Tamanho da cobra (varia pelo maxr)
Const BOXX = 25    ' Tamanho dos boxes

' ******************** Constantes fixas ***********************
Const PI = 3.141593/180

' ***************  Matrizes e variaveis iniciais **************
Dim As Double Ang(MAXCO), ANGS(MAXCO)
Dim LST((BOXX+BOXX+22)*(BOXX+BOXX+22)+5) As Integer
Dim Shared As Any Ptr SNK
'dim shared SNAKE(((BOXX*4)+2)*((BOXX*4)+2)+5) as integer
Dim Shared MAXX As Uinteger,MAXY As Uinteger
Dim As Integer ULX,ULY,FPMAX,FPC
Dim As Integer ScrWidth, ScrHeight, hScreen
Dim Shared As Integer LSX,LSY,PPX,PPY,PPXX,PPYY,COUNT
Dim Shared As Integer XVY,PX,PY,X,Y,ATUTAIL,PS,FPS
Dim As Integer TEX,TEY
Dim Shared As Uinteger CORS(255),BACKCOR
Dim As Ubyte PALR,PALG,PALB,BITS
Dim As Ubyte ATTR(15),ATTG(15),ATTB(15)
Dim Shared As Double TIM,SNC,SPD,PXX,PYY,LMF
Dim As Uinteger GETPNT,RGBPNT
Dim As Uinteger RRGGBB
Dim Shared As Integer APX(TAIL), APY(TAIL), COR(TAIL)
Dim Shared As Integer CX(TAIL), CY(TAIL), CXX(TAIL), CYY(TAIL)

Screencontrol(GET_DESKTOP_SIZE,TEX,TEY)
BITS = 32
Screenres TEX,TEY,BITS,,GFX_SHAPED_WINDOW
Screenlock
Screencontrol(GET_TRANSPARENT_COLOR,BACKCOR)
Line(0,0)-(TEX-1,TEY-1),BACKCOR,bf
Screenunlock

#IFDEF __FB_WIN32__
Dim As hwnd MYWIN
Screencontrol(GET_WINDOW_HANDLE,*Cast(Integer Ptr,@MYWIN))
SetWindowPos(MYWIN,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE Or SWP_NOMOVE)
#ENDIF

' *************** Iniciando dispositivos *************
Randomize Timer
MAXX = TEX
MAXY = TEY
XVY = (MAXY / MAXX) * 1.33333
PX = MAXX / 2
PY = MAXY / 2
SPD = 1
For X = 0 To 15
    Read ATTR(X),ATTG(X),ATTB(X)
Next X
SNK = Imagecreate(46,46)
For Y = 0 To 179
    Read CORS(Y)
Next Y
For Y = 0 To 45
    For X = 0 To 45
        Read COUNT
        Pset SNK,(X,Y),CORS(COUNT)
    Next X
Next Y
COUNT = 0
For X = 0 To 15
    For Y = 0 To 15
        PALR = ((ATTR(X)/15) * (15-Y)) + ((ATTR((X+1) And 15)/15) * (Y))
        PALG = ((ATTG(X)/15) * (15-Y)) + ((ATTG((X+1) And 15)/15) * (Y))
        PALB = ((ATTB(X)/15) * (15-Y)) + ((ATTB((X+1) And 15)/15) * (Y))
        CORS(COUNT) = Rgb(PALR,PALG,PALB)
        COUNT += 1
    Next Y
Next X

' *************** Posicoes e cores iniciais ****************
For X = 0 To MAXCO
    ANGS(X) = -MAXR + Rnd * (MAXR * 2)
    Ang(X) = Rnd * 360
Next X
For X = 0 To TAIL
    COR(X) = X And 255
    APX(X) = 10
    APY(X) = 10
Next X
ATUTAIL = 0
PS = 1

' ************************* Ake comeca a acao :D ********************
SNC = Timer:TIM = Timer

Do
    ' *********** Atualiza dados e cores da cobra em nova posicao *************
    For Y = 0 To 1
        For X = 1 To ATUTAIL
            APX(X - 1) = APX(X)
            APY(X - 1) = APY(X)
        Next X
        PXX = PX: PYY = PY
        For X = 0 To MAXCO
            PXX = PXX + (Sin(PI * Ang(X)) * DIS)
            PYY = PYY - ((Cos(PI * Ang(X)) * DIS) * XVY)
            Ang(X) += ANGS(X) * SPD
            If Ang(X) > 359 Then Ang(X) -= 360
            If Ang(X) < 0 Then Ang(X) += 360
        Next X
        APX(ATUTAIL + PS) = PXX
        APY(ATUTAIL + PS) = PYY
    Next Y

    Screenlock
    DOSNAKEBOX()
    Screenunlock
    VSYNC
    FPC += 1

    ' ********************** Finais e fim do loop ************
    LSX = Cint(APX(0)):LSY = Cint(APY(0))
    If Timer - SNC >= 1 Then FPMAX = FPC:FPC=0:SNC=Timer
    FPS = (1 / (Timer-TIM)) * 2
    TIM = Timer
    SPD = (60/FPS)/2
    If SPD > 2.5 Then SPD = 2.5
    If ATUTAIL < TAIL Then ATUTAIL = ATUTAIL + 1
    If ATUTAIL = TAIL Then PS = 0

Loop Until Inkey$ <> ""


' ********************* Fim do programa ******************
End

' ********************** Desenho de cobra com boxes *********************
Sub DOSNAKEBOX()
    PPX = LSX-BOXX-10
    PPY = LSY-BOXX-10
    PPXX = LSX+BOXX+10
    PPYY = LSY+BOXX+10
    If PPX < 0 Then PPX = 0
    If PPY < 0 Then PPY = 0
    If PPXX >= MAXX Then PPXX = MAXX - 1
    If PPYY >= MAXY Then PPYY = MAXY - 1
    If PPXX < 0 Then PPXX = 0
    If PPYY < 0 Then PPYY = 0
    If PPX >= MAXX Then PPX = MAXX - 1
    If PPY >= MAXY Then PPY = MAXY - 1
    Line (PPX,PPY)-(PPXX,PPYY),BACKCOR,bf
    For X = 0 To ATUTAIL - 1
        Circle (Cint(APX(X)), Cint(APY(X))), BOXX, CORS(COR(X)) ,,,,F
    Next X
    PPX = Cint(APX(X))-BOXX + ((BOXX*2-46)/2)
    PPY = Cint(APY(X))-BOXX + ((BOXX*2-46)/2)
    Put (PPX, PPY),SNK,Trans
End Sub

Sub VSYNC
    Sleep 1
    Screensync
End Sub

Data 255,255,255,255,128,128,128,255,128,128,128,255,255,255,128
Data 255,128,255,128,255,255,255,0,128,128,255,0,0,128,255
Data 255,255,0,250,0,250,0,255,255,255,0,0,0,255,0,0,0,255
Data 0,8,526336,526344,1052672,1052696,1579008,2105344,2105368,2105384
Data 2631680,2631688,2631704,2631728,3155968,3158016,3158024,3158040,3158048
Data 3158064,3684352,3684376,4208640,4210688,4210712,4210728,4737024,5263360
Data 6316032,6316128,6316144,6842368,6842384,6842392,6842400,6842424,6842448
Data 7366656,7366672,7368704,7368736,7368744,7368760,7368784,7892992,7895040
Data 8681472,8684544,8684684,9208832,9208888,9210880,9211028,9735168,9737216
Data 9737348,10261504,10261512,10263552,10263576,10263616,10263624,10263716
Data 10787840,10789888,11314176,11314208,11316224,11316280,11316288,11316328
Data 11840512,11842560,11842576,11842656,11842664,11844804,12366848,12366856
Data 12366864,12366920,12368896,12368904,12368960,12369016,12893184,12893208
Data 12893240,12893264,12895232,12895264,12895280,12895288,12895372,13419520
Data 13419536,13419560,13419568,13419576,13421568,13421600,13421648,13421700
Data 13421748,13945856,13945864,13945896,13945928,13947904,13947984,14472192
Data 14474240,14474256,14474288,14998528,14998536,14998560,15000576,15000584
Data 15000600,15000740,15524864,15524880,15524888,15524936,15524968,15526912
Data 15526928,15526936,15526952,15526960,15527060,16051200,16051216,16051248
Data 16053248,16053256,16053288,16053312,16053320,16053328,16053336,16053404
Data 16053412,16053428,16711935,16577536,16577552,16577568,16577576,16577592
Data 16577600,16577608,16577616,16577624,16579584,16579592,16579600,16579608
Data 16579616,16579624,16579632,16579640,16579648,16579656,16579664,16579672
Data 16579680,16579688,16579696,16579704,16579716,16579724,16579732,16579740
Data 16579748,16579756,16579764,16579772,16579780
Data 145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145
Data 145,145,174,172,172,172,170,168,169,141,141,141,138,130,130,145
Data 145,145,145,145,145,145,145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,176
Data 175,175,174,172,172,172,170,169,168,141,141,153,138,130,130,129
Data 119,119,145,145,145,145,145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,178,178,177,177,176
Data 175,176,174,174,172,172,170,169,168,167,141,152,138,134,134,123
Data 115,115,111,110,145,145,145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,178,178,177,177,176
Data 176,175,174,172,174,172,170,168,169,154,153,153,138,134,134,123
Data 115,115,110,110,145,145,145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,178,178,178,178,178,177,177
Data 176,176,175,174,172,172,171,168,169,154,152,152,138,137,137,127
Data 117,117,117,108,104,104,104,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,178,178,178,178,178,178,178,177
Data 176,177,175,174,174,172,171,168,169,167,152,152,162,148,148,126
Data 126,126,111,111,104,104,89,89,85,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,178,178,178,178,178,178,178,177
Data 176,177,175,174,174,172,171,169,168,154,152,152,138,148,148,127
Data 117,126,114,111,104,104,89,85,89,145,145,145,145,145
Data 145,145,145,145,145,145,178,178,178,178,178,178,178,178,178,178
Data 177,176,176,174,175,172,171,169,169,154,152,152,162,147,148,126
Data 126,126,121,110,104,104,104,85,85,85,145,145,145,145
Data 145,145,145,145,145,177,178,177,178,178,178,178,178,178,178,178
Data 177,177,177,175,175,172,172,169,169,154,152,163,160,147,147,126
Data 126,126,121,117,104,110,94,85,85,85,145,145,145,145
Data 145,145,145,145,145,177,178,178,178,178,178,178,178,178,178,178
Data 177,177,177,174,175,172,172,169,169,154,163,152,160,147,147,135
Data 126,132,117,111,104,110,94,85,85,85,145,145,145,145
Data 145,145,145,177,176,177,177,177,178,178,178,178,178,178,178,178
Data 178,177,177,175,176,174,171,169,169,154,163,163,160,147,136,135
Data 126,126,126,114,110,110,108,85,94,81,77,77,145,145
Data 145,145,145,175,176,176,176,177,177,177,177,178,178,178,178,178
Data 178,178,178,176,176,174,172,169,169,154,163,163,148,135,135,135
Data 135,132,126,111,110,110,104,85,89,85,77,77,77,145
Data 145,145,172,175,175,175,175,176,176,177,177,177,178,178,178,179
Data 144,144,84,84,84,142,172,169,169,154,113,106,73,108,108,135,135
Data 135,126,121,104,110,104,85,89,85,77,77,71,145
Data 145,145,174,175,174,175,176,175,177,177,177,177,178,178,178,179
Data 144,120,93,84,84,142,172,169,169,154,113,113,73,108,104,135,135
Data 135,135,121,104,110,108,89,89,85,77,77,71,145
Data 145,145,172,172,174,174,174,174,175,176,175,177,177,120,120,43
Data 8,8,18,36,36,131,171,168,168,153,59,59,23,4,4,23,56,56,117,117
Data 111,110,104,89,85,85,77,77,71,145
Data 171,171,172,172,171,172,172,172,174,174,175,175,143,8,8,0,0,0
Data 25,143,131,174,171,167,168,163,137,137,71,2,2,0,0,0,31,121,104
Data 110,104,85,89,77,77,77,71,71
Data 171,171,171,172,172,172,174,172,174,175,174,175,143,8,12,0,0,0
Data 25,143,131,174,171,167,168,163,137,148,67,2,2,0,0,0,31,117,111
Data 110,104,85,89,85,77,77,71,71
Data 170,170,170,170,170,171,171,171,172,172,172,174,70,0,0,0,3,3,9
Data 70,70,172,169,154,153,162,136,136,15,0,0,0,5,5,18,114,104,110
Data 94,85,89,77,77,71,71,71
Data 168,168,125,168,168,169,169,170,170,171,171,172,74,0,0,3,29,29
Data 48,102,93,169,167,163,163,148,135,135,20,0,0,19,48,48,55,111,104
Data 104,94,85,85,85,71,77,71,71
Data 168,168,168,169,168,169,170,169,170,171,170,172,74,0,0,5,29,29
Data 48,102,102,169,167,163,163,148,135,135,20,0,0,19,48,48,55,111
Data 104,104,94,85,85,81,77,71,71,71
Data 154,141,141,141,167,167,167,167,168,168,168,169,169,21,24,13,62
Data 62,103,169,169,154,163,137,137,135,135,135,71,3,3,30,76,76,107
Data 111,104,108,89,85,85,77,77,71,71,71
Data 140,140,140,141,152,124,68,68,140,154,154,154,167,141,141,101
Data 125,125,154,152,152,138,148,135,135,135,135,135,135,108,104,100
Data 116,116,111,104,104,89,89,65,65,46,71,71,71,71
Data 140,140,139,141,152,124,68,68,140,154,154,154,167,141,141,101
Data 125,125,141,152,152,138,148,135,136,135,135,135,135,104,108,100
Data 116,116,110,104,104,94,89,65,65,46,71,71,71,71
Data 138,130,124,150,138,91,0,0,87,163,163,163,163,163,163,163,138
Data 138,162,137,137,136,135,135,135,135,135,135,135,126,126,126,111
Data 117,110,108,89,89,85,37,31,0,66,66,71,67
Data 130,130,130,134,134,137,38,32,33,162,160,137,137,148,148,148,147
Data 147,136,135,135,135,135,135,135,135,135,135,126,126,121,117,110
Data 110,104,104,89,89,71,20,22,35,92,92,71,65
Data 116,116,119,123,123,127,122,122,26,112,112,136,135,135,135,135
Data 135,135,135,135,135,135,135,135,135,135,126,126,121,111,121,104
Data 104,104,104,85,85,77,49,21,24,101,78,78,65,71
Data 116,116,119,123,123,147,122,119,26,112,112,136,135,135,135,135
Data 135,135,135,135,135,135,135,135,135,126,126,126,121,114,117,111
Data 104,104,104,85,85,77,49,21,24,101,78,71,65,71
Data 112,112,112,117,112,121,126,126,71,28,28,135,135,135,135,135,135
Data 135,135,135,135,135,132,126,126,126,121,121,111,111,110,104,108
Data 104,89,85,64,63,22,60,60,86,65,71,71,65
Data 145,145,104,104,110,111,121,117,126,56,56,54,135,132,135,126,132
Data 126,132,126,126,126,121,121,121,111,111,111,110,104,104,104,89
Data 89,85,71,28,28,50,91,96,65,71,65,71,71
Data 145,145,104,110,110,111,121,117,126,56,54,54,135,132,135,126,126
Data 126,126,126,126,126,121,121,121,121,111,111,110,104,104,104,89
Data 89,85,71,28,28,50,91,96,65,71,65,71,65
Data 145,145,108,104,108,104,110,110,121,111,121,49,71,117,126,126
Data 121,126,121,121,121,121,111,111,111,111,104,110,104,104,104,89
Data 85,89,78,44,40,40,87,77,71,71,65,71,65,145
Data 145,145,145,89,89,104,108,104,108,111,111,111,44,56,56,111,121
Data 117,111,111,111,111,110,104,104,104,104,104,94,89,89,85,71,65
Data 37,34,87,87,77,65,71,65,71,71,65,145
Data 145,145,145,89,94,104,104,104,104,111,111,111,44,56,56,111,121
Data 117,111,114,114,111,111,104,111,104,104,94,104,89,89,85,65,67
Data 37,34,87,92,71,71,65,71,71,65,71,145
Data 145,145,145,89,89,89,89,89,104,104,104,104,108,45,45,37,71,77
Data 104,104,104,104,104,108,104,104,89,89,85,77,71,53,27,27,41,87
Data 78,78,65,71,71,65,71,65,71,145
Data 145,145,145,145,145,85,85,85,85,89,89,94,104,105,108,57,10,10
Data 26,51,49,64,65,56,58,58,53,53,39,20,20,11,61,61,92,78,65,71,71
Data 65,71,71,65,71,145,145
Data 145,145,145,145,145,85,81,77,85,85,85,85,85,89,85,105,73,73,33
Data 16,16,7,7,4,4,7,7,7,17,42,42,80,90,90,71,65,71,65,71,71,65,71
Data 145,145,145,145
Data 145,145,145,145,145,85,81,77,85,85,81,85,85,89,89,95,73,73,33
Data 21,16,7,7,4,6,7,7,7,17,42,42,80,90,87,71,71,65,71,71,65,71,71
Data 145,145,145,145
Data 145,145,145,145,145,145,145,145,77,77,77,77,81,77,85,77,85,85
Data 95,106,106,98,80,68,69,88,101,101,107,90,90,71,65,71,65,71,71
Data 65,71,65,71,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,77,71,77,71,77,77,78,77,77,77
Data 78,77,77,78,78,79,78,78,71,78,65,71,65,71,65,71,65,71,65,71,71
Data 145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,77,71,77,71,77,77,78,71,77,77
Data 71,77,77,77,78,79,79,78,78,71,71,71,71,65,71,71,65,71,71,65,71
Data 145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,71,71,71,71,71,71
Data 71,71,71,71,71,71,71,71,67,65,71,65,71,65,71,71,65,71,71,65,71
Data 145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,145,71,71,71,71,71
Data 71,71,71,71,67,71,71,67,65,71,71,65,71,71,65,71,65,71,145,145
Data 145,145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,145,71,71,71,71,71
Data 67,71,71,67,71,65,71,71,65,71,65,71,71,65,71,71,65,71,145,145
Data 145,145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,71
Data 67,71,65,71,65,71,71,65,71,71,65,71,71,65,71,65,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145
Data 145,65,65,65,65,65,65,65,65,65,65,65,65,65,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145
Data 145,145,145,145,145,145,145,145,145,145,145,145,145,145