Ooops
September 28, 2020, 03:54:34 AM

Author Topic: Doom Fire  (Read 130 times)

Offline ricardo_sdl

  • Jr. Member
  • **
  • Posts: 10
Doom Fire
« on: August 20, 2020, 11:53:57 PM »
Doom Fire (https://fabiensanglard.net/doom_fire_psx/). Faster on release mode!
Code: [Select]
Strict
Global width:Int = 640
Global height = 480
Global Palette:Int[37]
Global Pixels:UInt[width * height]

Global ScreenPixMap:TPixmap

Function Setup()
  FillPalette()
  ScreenPixMap = CreatePixmap(Width, Height, PF_RGB888)
  ClearPixels(ScreenPixMap, $0)
 
  For Local i = 0 To (Width * Height) - 2
    Pixels[0] = 0
  Next
  For Local x = 0 To Width - 1
    Pixels[(Height - 1) * Width + x] = 36
  Next

EndFunction

Function RGB:Int(Red, Green, Blue)
  Local Alpha = $ff
  Return (Alpha Shl 24) | (Red Shl 16) | (Green Shl 8) | Blue
EndFunction

Function FillPalette()
  Palette[0] = RGB(7, 7,7)
  Palette[1] = RGB(31, 7,7)
  Palette[2] = RGB(47, 15,7)
  Palette[3] = RGB(71, 15,7)
  Palette[4] = RGB(87, 23,7)
  Palette[5] = RGB(103, 31,7)
  Palette[6] = RGB(119, 31,7)
  Palette[7] = RGB(143, 39,7)
  Palette[8] = RGB(159, 47,7)
  Palette[9] = RGB(175, 63,7)
  Palette[10] = RGB(191, 71,7)
  Palette[11] = RGB(199, 71,7)
  Palette[12] = RGB(223, 79,7)
  Palette[13] = RGB(223, 87,7)
  Palette[14] = RGB(223, 87,7)
  Palette[15] = RGB(215, 95,7)
  Palette[16] = RGB(215, 95,7)
  Palette[17] = RGB(215, 103,15)
  Palette[18] = RGB(207, 111,15)
  Palette[19] = RGB(207, 119,15)
  Palette[20] = RGB(207, 127,15)
  Palette[21] = RGB(207, 135,23)
  Palette[22] = RGB(199, 135,23)
  Palette[23] = RGB(199, 143,23)
  Palette[24] = RGB(199, 151,31)
  Palette[25] = RGB(191, 159,31)
  Palette[26] = RGB(191, 159,31)
  Palette[27] = RGB(191, 167,39)
  Palette[28] = RGB(191, 167,39)
  Palette[29] = RGB(191, 175,47)
  Palette[30] = RGB(183, 175,47)
  Palette[31] = RGB(183, 183,47)
  Palette[32] = RGB(183, 183,55)
  Palette[33] = RGB(207, 207,111)
  Palette[34] = RGB(223, 223,159)
  Palette[35] = RGB(239, 239,199)
  Palette[36] = RGB(255, 255,255)
EndFunction

Function DoFire()
  Local MaxSrc = Width * Height - 1
  For Local Src = Width To MaxSrc
    Local Pixel:Int = Pixels[Src]
    If Pixel = 0
      Pixels[Src - Width] = 0
    Else
      Local RandIdx = Rand(0, 3)
      Local Dst = Src - RandIdx + 1
      If (Dst - Width) >= 0
        Dst :- Width
      Else
        Dst = 0
      EndIf
      Pixels[Dst] = Pixel - (RandIdx & 1)
    EndIf
  Next
EndFunction

Function Draw()
  Local Before = MilliSecs()
  For Local x = 0 To Width - 1
    For Local y = 0 To Height - 1
      'Local Color = Palette[Pixels[y * Width + x]]
      'SetColor(Color & $00ff0000, Color & $0000ff00, Color & $000000ff)
      'Plot(x, y)
      WritePixel(ScreenPixMap, x, y, Palette[Pixels[y * Width + x]])
    Next
  Next
  Local After = MilliSecs()
  Print After - Before
EndFunction



'--Create a quick Graphics window
Graphics(Width, Height, 0)

Setup()

' - - - - - - - - - - L o o p   S t a r t - - - - - - - - - - - - -

While Not KeyDown(Key_Escape)   ' This loop is equal to repeat except the condition is at the top.
  DoFire()
  Draw()
  DrawPixmap(ScreenPixMap, 0, 0)
  Flip;Cls
Wend


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal