March 05, 2021, 07:48:28 AM

Author Topic: [bb] Spinning, exploding titles demo by big10p [ 1+ years ago ]  (Read 769 times)

Offline BlitzBot

Title : Spinning, exploding titles demo
Author : big10p
Posted : 1+ years ago

Description : Game title made up from cubes spins in a star field and randomly explodes before reconstructing and continuing.

Code :
Code: BlitzBasic
  1. ;
  2. ; Spinning, exploding, reconstructing titles demo
  3. ;
  4. ; by big10p (A.K.A. Chris Chadwick) 2003.
  5. ;
  6. ; Written with Blitz3D v1.83
  7. ;
  8.  
  9.         Graphics3D 800,600,16
  10.  
  11.         SetBuffer BackBuffer()
  12.  
  13.         SeedRnd MilliSecs()
  14.        
  15.         Type grid_pix
  16.                 Field ent
  17.                 Field x#,y#,z#
  18.                 Field rot#
  19.         End Type
  20.  
  21.         Type part
  22.                 Field ent
  23.                 Field x#,y#,z#
  24.         End Type
  25.  
  26.         Const TOTAL_STARS = 400 ; Number of stars in star field.
  27.         Const EXPLODE% = 400    ; Number of frames to explode before imploding.
  28.                        
  29.         Global frame_count%
  30.         Global fps%
  31.         Global fps_timeout%
  32.         Global frame_time%
  33.         Global slowest_frame%
  34.         Global frame_start%
  35.  
  36.         Global title_state% = 3
  37.         Global explode_count%
  38.                
  39.         Global cam = CreateCamera()
  40.         PositionEntity cam,0,0,-14
  41.        
  42.         Global light = CreateLight()
  43.  
  44.         Global spiv = CreatePivot()
  45.         Global piv = CreatePivot()
  46.  
  47.         ; Master entity the title grid is constructed from.
  48.         Global title_ent = CreateCube()
  49.         EntityShininess title_ent,1
  50.         HideEntity title_ent
  51.        
  52.         ; Blur sprite.
  53.         sprite = CreateSprite(cam)
  54.         PositionEntity sprite,0,0,1.1
  55.         ScaleSprite sprite,1.5,1
  56.         SpriteViewMode sprite,1
  57.         EntityAlpha sprite,.124
  58.         EntityColor sprite,0,0,0
  59.         EntityBlend sprite,1
  60.         EntityFX sprite,1
  61.         EntityOrder sprite,1
  62.         Dither False
  63.         CameraClsMode cam,0,1
  64.        
  65.         make_titles()  
  66.         make_stars()
  67.  
  68.         ; Main loop.
  69.         While Not KeyHit(1)
  70.                 frame_start = MilliSecs()
  71.  
  72.                 update_titles()
  73.                 update_stars()
  74.                
  75.                 UpdateWorld
  76.                 CopyRect 0,0,800,600,0,0,FrontBuffer(),BackBuffer()
  77.                 RenderWorld
  78.  
  79.                 frame_time = MilliSecs() - frame_start 
  80.                 ;show_info()           
  81.  
  82.                 Flip(1)
  83.         Wend
  84.        
  85.         kill_titles()
  86.         kill_stars()
  87.        
  88.         ClearWorld
  89.                
  90.         End
  91.  
  92.  
  93. ;
  94. ; Update title animation.
  95. ;
  96. Function update_titles()
  97.  
  98.         Local y#
  99.        
  100.         Select title_state
  101.                 Case 0  ; Prepare title pixels for exploding...
  102.  
  103.                         title_state = 1
  104.                         explode_count = EXPLODE
  105.                        
  106.                         For this.grid_pix = Each grid_pix
  107.                                 thisx = Rnd(-1,1)
  108.                                 thisy = Rnd(-1,1)
  109.                                 thisz = Rnd(-1,1)
  110.                                 this
  111. ot = Rnd(-1,1)
  112.                         Next           
  113.  
  114.                 Case 1  ; Explode title pixels...
  115.  
  116.                         For this.grid_pix = Each grid_pix
  117.                                 TranslateEntity thisent,thisx,thisy,thisz
  118.                                
  119.                                 ; Pitch, yaw and roll rotations must be done separately so that
  120.                                 ; we can reverse the process correctly when reconstructing!
  121.                                 TurnEntity thisent,this
  122. ot,0,0
  123.                                 TurnEntity thisent,0,this
  124. ot,0
  125.                                 TurnEntity thisent,0,0,this
  126. ot
  127.                         Next
  128.                        
  129.                         explode_count = explode_count - 1
  130.  
  131.                         If explode_count = 0
  132.                                 title_state = 2
  133.                                 explode_count = EXPLODE
  134.                         EndIf          
  135.  
  136.                 Case 2  ; Implode/reconstruct exploded title...
  137.  
  138.                         For this.grid_pix = Each grid_pix
  139.                                 TranslateEntity thisent,-thisx,-thisy,-thisz
  140.                                
  141.                                 ; Do pitch, yaw and roll rotations separately and in REVERSE order
  142.                                 ; from explosion so pixels reconstruct correctly!
  143.                                 TurnEntity thisent,0,0,-this
  144. ot
  145.                                 TurnEntity thisent,0,-this
  146. ot,0
  147.                                 TurnEntity thisent,-this
  148. ot,0,0
  149.                         Next
  150.                        
  151.                         TurnEntity piv,0,-1,0
  152.                        
  153.                         explode_count = explode_count - 1
  154.                         If explode_count = 0 Then title_state = 3                              
  155.  
  156.                 Case 3  ; Spin the title...
  157.  
  158.                         ; Spin faster when showing back and slower when showing front.
  159.                         y = Abs(EntityYaw(piv))/2.0
  160.                         TurnEntity piv,0,-(.3 + (Sin(y) * (y/20))),0
  161.                        
  162.                         ; Randomly explode title.
  163.                         If Rand(1,400) = 100 Then title_state = 0
  164.         End Select
  165.        
  166. End Function
  167.  
  168.  
  169. ;
  170. ; Create the game title grid.
  171. ;
  172. Function make_titles()
  173.  
  174.         Local title_rows% = 0
  175.         Local title_cols% = 0
  176.         Local grid_row$, datum$
  177.         Local pix.grid_pix
  178.         Local grid_step#
  179.         Local tl_x#, tl_y#
  180.         Local title_width# = 18.0
  181.         Local title_height#
  182.         Local pix_size#
  183.                        
  184.         ; Find width and height of title grid from DATA
  185.         Restore TITLE_DATA
  186.         Read grid_row$
  187.         title_cols = Len(grid_row$)
  188.         Repeat
  189.                 title_rows = title_rows + 1
  190.                 Read grid_row$
  191.         Until grid_row$ = "."
  192.        
  193.         title_height = title_rows * (title_width/title_cols)
  194.  
  195.         grid_step = title_width/(title_cols-1)
  196.         tl_x = -title_width/2.0
  197.         tl_y = title_height/2.0
  198.  
  199.         pix_size# = grid_step/2.0 - 0.04
  200.         ScaleEntity piv,pix_size,pix_size,pix_size
  201.        
  202.         Restore TITLE_DATA
  203.          
  204.         For r = 1 To title_rows
  205.                 Read grid_row$
  206.  
  207.                 For c = 1 To title_cols
  208.                         datum$ = Mid$(grid_row$,c,1)
  209.  
  210.                         If datum$ <> " "
  211.                                 pix = New grid_pix
  212.                                 pixent = CopyEntity(title_ent,piv)
  213.                                
  214.                                 PositionEntity pixent,tl_x + ((c-1)*grid_step),tl_y - ((r-1)*grid_step),0,True
  215.  
  216.                                 Select datum$
  217.                                         Case "1"
  218.                                                 EntityColor pixent,150,50,0
  219.                                                 ScaleEntity pixent,1,1,4
  220.                                         Case "2"
  221.                                                 EntityColor pixent,0,150,0
  222.                                                 ScaleEntity pixent,1,1,6
  223.                                         Case "3"
  224.                                                 EntityColor pixent,150,150,0
  225.                                                 ScaleEntity pixent,1,1,2
  226.                                         Case "4"
  227.                                                 EntityColor pixent,150,0,0
  228.                                                 ScaleEntity pixent,1,1,4
  229.                                         Default
  230.                                                 EntityColor pixent,100,50,0
  231.                                 End Select
  232.                         EndIf
  233.                 Next
  234.         Next
  235.                
  236. End Function
  237.  
  238.  
  239. ;
  240. ; Free all mem used by title.
  241. ;
  242. Function kill_titles()
  243.  
  244.         For this.grid_pix = Each grid_pix
  245.                 FreeEntity thisent
  246.                 Delete this
  247.         Next
  248.  
  249. End Function
  250.  
  251.  
  252. ;
  253. ; Show debug info
  254. ;
  255. Function show_info()
  256.        
  257.         frame_count = frame_count + 1
  258.  
  259.         If MilliSecs() > fps_timeout Then
  260.                 fps_timeout = MilliSecs() + 1000
  261.                 fps = frame_count
  262.                 frame_count = 0
  263.         EndIf
  264.        
  265.         If frame_time > slowest_frame Then slowest_frame = frame_time
  266.        
  267.         Color 0,0,100
  268.         Rect 0,0,200,80,1
  269.         Color 255,255,255
  270.        
  271.         Text 10,10," Triangles: " + TrisRendered()
  272.         Text 10,25," Millisecs: " + frame_time
  273.         Text 10,40,"   slowest: " + slowest_frame
  274.         Text 10,55,"       FPS: " + fps
  275.  
  276. End Function
  277.  
  278.  
  279. ;
  280. ; Create and initialize stars.
  281. ;
  282. Function make_stars()
  283.  
  284.         For n = 1 To TOTAL_STARS
  285.                 this.part = New part
  286.                
  287.                 thisent = CreateSprite()
  288.                 EntityColor thisent,255,255,255
  289.                 EntityAutoFade thisent,200,500
  290.        
  291.                 init_star(this)
  292.                 update_stars()
  293.         Next
  294.  
  295. End Function
  296.  
  297.  
  298. ;
  299. ; Free all mem used by stars.
  300. ;
  301. Function kill_stars()
  302.  
  303.         For this.part = Each part
  304.                 FreeEntity thisent
  305.                 Delete this
  306.         Next
  307.  
  308. End Function
  309.  
  310.  
  311. ;
  312. ; Update star field.
  313. ;
  314. Function update_stars()
  315.  
  316.         For this.part = Each part
  317.  
  318.                 If Not EntityInView(thisent,cam)
  319.                         init_star(this)
  320.                 Else
  321.                         TranslateEntity thisent,thisx,thisy,thisz
  322.                 EndIf
  323.         Next
  324.  
  325. End Function
  326.  
  327.  
  328. ;
  329. ; Spawn/re-spawn star.
  330. ;
  331. Function init_star(star.part)
  332.  
  333.         r#=Rnd(0.0,360.0)
  334.         starx = Cos(r)/2.0
  335.         stary = Sin(r)/2.0
  336.         starz = -Rnd(.01,.5)
  337.  
  338.         PositionEntity starent,starx*50,stary*50,500
  339.  
  340. End Function
  341.  
  342.  
  343. .TITLE_DATA
  344. Data " ttttttttttttttttttttttttttttttttttttttttt "
  345. Data "t                                         t"
  346. Data "t 111 111 111 111 111     111 1 1   1 111 t"
  347. Data "t 1   1 1 1 1 1   1        1  1 11 11 1   t"
  348. Data "t 111 111 111 1   11  111  1  1 1 1 1 11  t"
  349. Data "t   1 1   1 1 1   1        1  1 1   1 1   t"
  350. Data "t 111 1   1 1 111 111      1  1 1   1 111 t"
  351. Data "t                 2222                    t"
  352. Data "t 1 1  1 1   1  22222222  11  111 111 111 t"
  353. Data "t 1 11 1 1   1 2244224422 1 1 1   1 1 1   t"
  354. Data "t 1 1 11  1 1  2222222222 1 1 11  11  111 t"
  355. Data "t 1 1  1  1 1    22  22   1 1 1   1 1   1 t"
  356. Data "t 1 1  1   1    22 22 22  111 111 1 1 111 t"
  357. Data "t              2        2                 t"
  358. Data " ttttttttttttt      3     tttttttttttttttt "
  359. Data "                   3                       "
  360. Data "                    3                      "
  361. Data "                   3                       "
  362. Data "."


Comments :


CodeD(Posted 1+ years ago)

 Cooooooool.


simonh(Posted 1+ years ago)

 Awesome! Would be interesting to see how this would look if combined with Tokamak to make the little blocks realistically collapse.


wedoe(Posted 1+ years ago)

 Kewl :)


Olive(Posted 1+ years ago)

 Even faster with a quad instead of a sprite, also what the "Copyrect" between update and renderworld is for ????here is the code with the quad        ; Blur sprite.        ; Create a fullscreen sprite        sprite          = CreateMesh(Cam)        sf              = CreateSurface(sprite)                ; Make a quad        AddVertex   sf, -1, 1, 0, 0, 0        AddVertex   sf,  1, 1, 0, .1, 0        AddVertex   sf, -1,-1, 0, 0, .1        AddVertex   sf,  1,-1, 0, .1, .1                        AddTriangle sf, 0, 1, 2        AddTriangle sf, 3, 2, 1        PositionEntity sprite,0,0,1.01        ScaleEntity sprite,1.5,1.5,1        EntityAlpha sprite,.124        EntityColor sprite,0,0,0        EntityBlend sprite,1        EntityFX sprite,1+8        EntityOrder sprite,1        Dither False        CameraClsMode cam,0,1and i removed the Copyrect....don't know why it's here...


Olive(Posted 1+ years ago)

 I forgot :   Good job big10p !!!


Danny(Posted 1+ years ago)

 Absolute gem!  nice one!


Neuro(Posted 1+ years ago)

 Ooooooooh.....


big10p(Posted 1+ years ago)

 Cheers all - glad you like!Olive: basically, without that copyrect, the blur doesnt work correctly and appears too harsh.


Tri|Ga|De(Posted 1+ years ago)

 Niice work big10P!


IPete2(Posted 1+ years ago)

 Great stuff big10p!  Looks pretty awesome to me!No external files either!  Great!IPete2.


BlitzSupport(Posted 1+ years ago)

 Love it!


Kozmi(Posted 1+ years ago)

 This would make a nice credits thingy in a game.... It is a different approch!Excellent work man!


Rook Zimbabwe(Posted 1+ years ago)

 Flat out GROOVY!!!


semar(Posted 1+ years ago)

 Wonderful !Sergio.


Panno(Posted 1+ years ago)

 nice !


Blitzplotter(Posted 1+ years ago)

 Very impressive....  marvlious... nice bit of code.


Buggy(Posted 1+ years ago)

 Droool... amazing.


Trader3564(Posted 1+ years ago)

 ye its fun :)


_33(Posted 1+ years ago)

 Modified version of Exploding Title :PFirst you need to make an include file.BLOOMFILTER.bb:
Code: [Select]
;Bloom / Glow post-process filter by Bouncer
;Using SSwift's excellent texture blurring routine
;Use at your own risk :) may contain bugs
;Warning ... this filter uses LOT of fillrate so it's not for the old gfx-cards

;V1.2
;Fixed camera bug...


;SSwifts blur routine ---------------------
; This is the location in the world where the camera will reside.
; This location should be far from any other geometry you have in your world.
Const BLUR_CAM_X# = 65536.0
Const BLUR_CAM_Y# = 65536.0
Const BLUR_CAM_Z# = 0.0

;Modified to additive blend in the same time as blur.
;Also modified the copyrecting... so that multiple passes don't cause texture drifting.
;this is just a quick fix... don't actually get why tex texture drifts...
; -------------------------------------------------------------------------------------------------------------------
; This function blurs a texture using a technique that takes advantage of 3D acceleration.  
;
; * You MUST hide all other cameras before calling this function!
; * You MUST reset your texture's blending mode, scale, and position after calling this function!
;
; Texture is the texture you want blurred.
;
; Blur_Quality defines the quality of the blur.  1 = 4 passes, 2 = 8 passes, 3 = 12 passes, etc.
;
; (The reason that the passes are in multiples of four is because interference artifacts are created when
; the number of passes is not a multiple of four... meaning that ten passes will actually look far worse
; than eight.)
;
; Blur_Radius# defines the radius of the blur, in pixels, assuming a map size of 256x256.
;
;(Ie, a radius of 16 will be the same width regardless of whether the texture is 16x16 or 512x512.  It will
; only be exactly 16 pixels wide if the map is 256x256.)
; -------------------------------------------------------------------------------------------------------------------
Function BlurTexture(Texture, Blur_Quality, Blur_Radius#)
Local BlurMesh[16*4] ; This is used for temporary storage of the meshes used for soft shadow blurring.

   ; If blurring is enabled...
   If Blur_Quality > 0
      Blur_Cam = CreateCamera()
      ; Set the camera's range to be very small so as to reduce the possiblity of extra objects making it into the scene.
      CameraRange Blur_Cam, 0.1, 100

      ; Set the camera to zoom in on the object to reduce perspective error from the object being too close to the camera.
      CameraZoom Blur_Cam, 16.0

      ; Aim camera straight down.
      RotateEntity Blur_Cam, 90, 0, 0, True

      ; Set the camera viewport to the same size as the texture.
      CameraViewport Blur_Cam, 0, 0, TextureWidth(Texture), TextureHeight(Texture)

      ; Set the camera so it clears the color buffer before rendering the texture.
      CameraClsColor Blur_Cam, 0,0,0
      CameraClsMode  Blur_Cam, True, True

      ; Position the blur camera far from other entities in the world.
      PositionEntity Blur_Cam, BLUR_CAM_X#, BLUR_CAM_Y#, BLUR_CAM_Z#

      ; Create the sprites to use for blurring the shadow maps.
      For Loop = 0 To (Blur_Quality*4)-1
         BlurMesh[Loop] = CreateSprite()
         EntityBlend BlurMesh[Loop],3
      Next

      ; Scale the texture down because we scale the sprites up so they fill a larger area of the
      ; screen.  (Otherwise the edges of the texture are darker than the middle because they don't
      ; get covered.
      ScaleTexture    Texture, 0.5, 0.5
      PositionTexture Texture, 0.5, 0.5

      ; Blur texture by blitting semi-transparent copies of it on top of it.
      BlurRadius# = Blur_Radius# * (1.0 / 256.0)
      BlurAngleStep# = 360.0 / Float(Blur_Quality*4)

      ; Normally we would just divide 255 by the number of passes so that adding all the passes
      ; together would not exceed 256.  However, if we did that, then we could not have a number of
      ; passes which does not divide 256 evenly, or else the error would result in the white part of
      ; the image being slightly less than white.  So we round partial values up to ensure that
      ; white will always be white, even if it ends up being a little whiter than white as a result
      ; when all the colors are added, since going higher than white just clamps to white.
      BlurShade = Ceil(255.0 / Float(Blur_Quality*4))

      ; Place each of the blur objects around a circle of radius blur_radius.
      For Loop = 0 To (Blur_Quality*4)-1
         EntityTexture BlurMesh[Loop], Texture
         EntityFX BlurMesh[Loop], 1+8
         EntityAlpha BlurMesh[Loop], 1.0 / Float(Loop+1)
         ScaleSprite BlurMesh[Loop], 2, 2
         BlurAngle# = BlurAngleStep# * Float(Loop) + 180.0*(Loop Mod 2)

         Xoff# = BlurRadius# * Cos(BlurAngle#)
         Yoff# = BlurRadius# * Sin(BlurAngle#)

         PositionEntity BlurMesh[Loop], BLUR_CAM_X# + Xoff#, BLUR_CAM_Y# - 16.0, BLUR_CAM_Z# + Yoff#, True
      Next

      ; Render the new texture.
      RenderWorld

      ; Copy the new texture from the screen buffer to the texture buffer.
      CopyRect 1, 1, TextureWidth(Texture)-1, TextureHeight(Texture)-1, 0, 0, BackBuffer(), TextureBuffer(Texture)

      ; Free the blur entities.
      For Loop = 0 To (Blur_Quality*4)-1
         FreeEntity BlurMesh[Loop]
      Next

      ; Free the blur camera.
      FreeEntity Blur_Cam

   EndIf

End Function
;---------------------------------------------------



;GLOW VARIABLES
Global GL_cam
Global GL_scenecam ;This stores the pointer to your scene camera
Global GL_offset = 65536 ;Offset for the glow camera
Global GL_texsize = 256 ;Glow texture resolution (128 or 256 recommended)
Global GL_camzoom# = 1.0 ;Change this value if your camzoom differs from the default

Global GL_sprite
Global GL_tex,GL_texbuffer

Global GL_sprite_scene
Global GL_timer=1


;Initializes the filter
;--------------------------

;camera - your main scene camera
;NOTE - do not change camera rotation before calling this init function.
Function InitGlow(camera)
   GL_scenecam = camera

   ;SET GLOW CAMERA
   GL_cam = CreateCamera()
   PositionEntity GL_cam,GL_offset,0,0
   CameraProjMode GL_cam,2
   CameraRange GL_Cam, 1, 100
   CameraClsMode GL_cam,0,1
   CameraViewport GL_cam,0,0,GL_texsize,GL_texsize
   HideEntity GL_cam

   ;SET GLOW SPRITE 1 (FOR DARKENING PASSES)
   GL_sprite = CreateSprite()
   GL_tex = CreateTexture(GL_texsize,GL_texsize,256+16+32)
   GL_texbuffer = TextureBuffer(GL_tex)
   EntityTexture GL_sprite,GL_tex
   PositionEntity GL_sprite,GL_offset,0,1
   EntityOrder GL_sprite,-999
   EntityFX GL_sprite,1

   ;SET GLOW SPRITE 2  (FINAL  OVERLAY)
   GL_sprite_scene = CreateSprite()
   EntityTexture GL_sprite_scene,GL_tex
   ScaleSprite GL_sprite_scene,2*(1.0/GL_camzoom),2*(1.0/GL_camzoom)
   PositionEntity GL_sprite_scene,EntityX(GL_scenecam),EntityY(GL_scenecam),EntityZ(GL_scenecam)+2
   EntityParent GL_sprite_scene,GL_scenecam
   EntityOrder GL_sprite_scene,-999
   EntityFX GL_sprite_scene,1
End Function



;Renders the filter
;--------------------------

;fade - initial fade value for the scene
;dark_passes - how many multiply passes (darkening)
;glow_passes - how many blur / glow passes
;glare_size - blur radius

;just play with the values until you find a good combination.


;IMPORTANT NOTES
;* The scene camera will be hidden automatically...
; but you must hide every other camera you might be using Before calling this Function.
;* Also if you want to turn the blurring off you MUST HIDE the GL_sprite_scene object and stop calling this function (obviously :)
;* The more dark_passes and glow_passes - the slower the function is ... so beware.
; Also switching to smaller texture size will boost performance.
Function RenderGlow(fade#=0.15,dark_passes=2,glow_passes=3,glare_size#=4)
   ;RENDER THE SCENE WITH MAIN CAMERA AND COPY TO TEXTURE
   ;Also apply the fade filter
   HideEntity GL_sprite
   EntityBlend GL_sprite_scene,1
   EntityColor GL_sprite_scene,0,0,0
   EntityAlpha GL_sprite_scene,fade

   CameraViewport GL_scenecam,0,0,GL_texsize,GL_texsize
   RenderWorld
   CopyRect 1,1,GL_texsize-1,GL_texsize-1,0,0,BackBuffer(),GL_texbuffer
   CameraViewport GL_scenecam,0,0,GraphicsWidth(),GraphicsHeight()

   ShowEntity GL_sprite
   EntityColor GL_sprite_scene,255,255,255
   EntityAlpha GL_sprite_scene,1

   ;SWITCH TO GLOW CAMERA AND HIDE MAIN CAMERA
   HideEntity GL_scenecam
   ShowEntity GL_cam

   ;MULTIPLY BLEND WITH BACKBUFFER TO MAKE THE CONTRAST HIGHER
   ;(RESERVE THE LUMINATED AREAS)
   EntityBlend GL_sprite,2
   For i=1 To dark_passes
      RenderWorld
   Next
   CopyRect 1,0,GL_texsize-1,GL_texsize,0,0,BackBuffer(),GL_texbuffer
   EntityBlend GL_sprite,1
   HideEntity GL_sprite

   ;BLUR AND PUT SOME GLOW ON THE TEXTURE
   ;MORE PASSES - MORE GLOW
   HideEntity GL_cam
   For i=1 To glow_passes
      blurtexture(GL_tex,1,glare_size)
   Next
   ScaleTexture GL_tex, 1,1
   PositionTexture GL_tex,0,0
   TextureBlend GL_tex, 2

   ;SWITCH BACK TO NORMAL CAMERA
   ShowEntity GL_scenecam

   ;BLEND WITH ADDITIVE BLENDING WITH THE SCENE
   EntityBlend GL_sprite_scene,3
End Function
Exploding_title2.bb:
Code: [Select]
Include "BLOOMFILTER.bb"

;
; Spinning, exploding, reconstructing titles demo
;
; by big10p (A.K.A. Chris Chadwick) 2003.
;
; Written with Blitz3D v1.83
;

Graphics3D 1024,768,32,1

SetBuffer BackBuffer()

SeedRnd MilliSecs()

Type grid_pix
Field ent
Field x#,y#,z#
Field rot#
End Type

Type part
Field ent
Field x#,y#,z#
End Type

Const TOTAL_STARS = 250 ; Number of stars in star field.
Const EXPLODE% = 360 ; Number of frames to explode before imploding.

Global frame_count%
Global fps%
Global fps_timeout%
Global frame_time%
Global slowest_frame%
Global frame_start%

Global explode_count%

Global cam = CreateCamera()
PositionEntity cam,0,0,-14

Global light = CreateLight()

    Dim piv(2)
piv(1) = CreatePivot()
piv(2) = CreatePivot()

; Master entity the title grid is constructed from.
Global title_ent = CreateSphere()
EntityShininess title_ent,0
HideEntity title_ent

Global title_ent2 = CreateCube()
EntityShininess title_ent2,1
HideEntity title_ent2

; Blur sprite.
sprite = CreateSprite(cam)
PositionEntity sprite,0,0,1.1
ScaleSprite sprite,1.5,1
SpriteViewMode sprite,1
EntityAlpha sprite,.124
EntityColor sprite,0,0,0
EntityBlend sprite,1
EntityFX sprite,1
EntityOrder sprite,1
Dither False
CameraClsMode cam,0,1

make_stars()
    initglow(cam)


Dim title_state%(2)
title_state%(1) = 4
title_state%(2) = 5
    Global current_title = 1
Global timer360# = 0

make_title(current_title)
;make_title(2)

; Main loop.
While Not KeyHit(1)
frame_start = MilliSecs()

update_title(current_title)
;update_title(2)
update_stars()

UpdateWorld

renderglow(0.69,2,4,5)
CopyRect 0,0,GraphicsWidth(),GraphicsHeight(),0,0,FrontBuffer(),BackBuffer()

RenderWorld

frame_time = MilliSecs() - frame_start
show_info()

Flip
Cls

timer360 = timer360 + 0.25 : If timer360 > 359 Then timer360 = 0
Wend

kill_titles(current_title)
kill_stars()

ClearWorld

End


;
; Update title animation.
;
Function update_title(title_page)

    Local s# = title_state(title_page)

Local y#
Select s#
Case 0 ; Prepare title pixels for exploding...

title_state(title_page) = 1
explode_count = EXPLODE

For this.grid_pix = Each grid_pix
thisx = Rnd(-1,1)
thisy = Rnd(-1,1)
thisz = Rnd(-1,1)
thisot = Rnd(-1,1)
Next

Case 1 ; Explode title pixels...

For this.grid_pix = Each grid_pix
TranslateEntity thisent,thisx,thisy,thisz

; Pitch, yaw and roll rotations must be done separately so that
; we can reverse the process correctly when reconstructing!
TurnEntity thisent,thisot,0,0
TurnEntity thisent,0,thisot,0
TurnEntity thisent,0,0,thisot
Next

explode_count = explode_count - 1

If explode_count = 0
title_state(title_page) = 5
explode_count = EXPLODE
EndIf

Case 2 ; Implode/reconstruct exploded title...

For this.grid_pix = Each grid_pix
TranslateEntity thisent,-thisx,-thisy,-thisz

; Do pitch, yaw and roll rotations separately and in REVERSE order
; from explosion so pixels reconstruct correctly!
TurnEntity thisent,0,0,-thisot
TurnEntity thisent,0,-thisot,0
TurnEntity thisent,-thisot,0,0
Next

TurnEntity piv(title_page),0,-4,0
TurnEntity cam,0,-2,0

explode_count = explode_count - 1
If explode_count = 0 Then title_state(title_page) = 3 : timer360 = 0

Case 3 ; Spin the title...

; Spin faster when showing back and slower when showing front.
y = Abs(EntityYaw(piv(title_page)))/2.0
TurnEntity piv(title_page),0,-(.3 + (Sin(y) * (y/20))),0

; Is it time to explode again?
If timer360 = 359 Then title_state(title_page) = 0

Case 4  ; Introduce title

If timer360 = 0 Then
PositionEntity piv(title_page),0,0,360 * 2
            Else
If timer360 <= 45 Then
MoveEntity piv(title_page),0,0,-4
TurnEntity piv(title_page),0,0,title_page * 4
TurnEntity cam,0,0,4 - title_page * 2
Else
title_state(title_page) = 3
timer360 = 0
EndIf
EndIf

Case 5  ; switch title screen
If current_title = title_page Then
If current_title = 1 Then current_title = 2 Else current_title = 1
kill_titles(title_page)
make_title(current_title)
title_state(current_title) = 4
timer360 = 0
update_title(current_title)
PointEntity(piv(current_title), cam)
TurnEntity(piv(current_title),180,0,0)
TurnEntity(piv(current_title),0,0,180)
EndIf


End Select

End Function


;
; Create the game title grid.
;
Function make_title(title_page)

Local title_rows% = 0
Local title_cols% = 0
Local grid_row$, datum$
Local pix.grid_pix
Local grid_step#
Local tl_x#, tl_y#
Local title_width# = 18.0
Local title_height#
Local pix_size#

; Find width and height of title grid from DATA
If title_page = 1 Then
Restore TITLE_DATA
Else
Restore TITLE_DATA2
    EndIf
Read grid_row$
title_cols = Len(grid_row$)
Repeat
title_rows = title_rows + 1
Read grid_row$
Until grid_row$ = "."

title_height = title_rows * (title_width/title_cols)

grid_step = title_width/(title_cols-1)
tl_x = -title_width/2.0
tl_y = title_height/2.0

pix_size# = grid_step/2.0 - 0.04
ScaleEntity piv(title_page),pix_size,pix_size,pix_size

If title_page = 1 Then
Restore TITLE_DATA
Else
Restore TITLE_DATA2
    EndIf

For r = 1 To title_rows
Read grid_row$

For c = 1 To title_cols
datum$ = Mid$(grid_row$,c,1)

If datum$ <> " "
pix = New grid_pix

Select datum$
Case "1"
pixent = CopyEntity(title_ent2,piv(title_page))
PositionEntity pixent,tl_x + ((c-1)*grid_step),tl_y - ((r-1)*grid_step),0,True
EntityColor pixent,64,64,64
ScaleEntity pixent,1,1,1
Case "2"
pixent = CopyEntity(title_ent2,piv(title_page))
PositionEntity pixent,tl_x + ((c-1)*grid_step),tl_y - ((r-1)*grid_step),0,True
EntityColor pixent,127,127,127
ScaleEntity pixent,1,1,1
Case "3"
pixent = CopyEntity(title_ent2,piv(title_page))
PositionEntity pixent,tl_x + ((c-1)*grid_step),tl_y - ((r-1)*grid_step),0,True
EntityColor pixent,255,127,64
ScaleEntity pixent,1.1,1.1,1.1
Case "4"
pixent = CopyEntity(title_ent2,piv(title_page))
PositionEntity pixent,tl_x + ((c-1)*grid_step),tl_y - ((r-1)*grid_step),0,True
EntityColor pixent,192,192,192
ScaleEntity pixent,1,1,1
Default
pixent = CopyEntity(title_ent,piv(title_page))
PositionEntity pixent,tl_x + ((c-1)*grid_step),tl_y - ((r-1)*grid_step),0,True
EntityColor pixent,64,127,255
End Select
EndIf
Next
Next

End Function


;
; Free all mem used by title.
;
Function kill_titles(title_page)

For this.grid_pix = Each grid_pix
FreeEntity thisent
Delete this
Next
;piv(title_page)

End Function

;
; Backup all mem used by title.
;
;Function backup_titles()
; For this.grid_pix = Each grid_pix
; CopyEntity thisent
; Next
;End Function

;
; Show debug info
;
Function show_info()

frame_count = frame_count + 1

If MilliSecs() > fps_timeout Then
fps_timeout = MilliSecs() + 1000
fps = frame_count
frame_count = 0
EndIf

If frame_time > slowest_frame Then slowest_frame = frame_time

Color 0,0,100
Rect 0,0,200,80,1
Color 255,255,255

Text 10,10," Triangles: " + TrisRendered()
Text 10,25," Millisecs: " + frame_time
Text 10,40,"   slowest: " + slowest_frame
Text 10,55,"       FPS: " + fps

End Function


;
; Create and initialize stars.
;
Function make_stars()

For n = 1 To TOTAL_STARS
this.part = New part

thisent = CreateSprite()
bright_level = Rnd(32,255)
EntityColor thisent,bright_level,bright_level,bright_level
EntityAutoFade thisent,200,500

init_star(this)
update_stars()
Next

End Function


;
; Free all mem used by stars.
;
Function kill_stars()

For this.part = Each part
FreeEntity thisent
Delete this
Next

End Function


;
; Update star field.
;
Function update_stars()

For this.part = Each part

If Not EntityInView(thisent,cam)
init_star(this)
Else
TranslateEntity thisent,thisx,thisy,thisz
EndIf
Next

End Function


;
; Spawn/re-spawn star.
;
Function init_star(star.part)

r#=Rnd(0.0,360.0)
starx = Cos(r)/2.0
stary = Sin(r)/2.0
starz = -Rnd(.1,3)

PositionEntity starent,starx*50,stary*50,500

End Function


.TITLE_DATA
Data " ttttttttttttttttttttttttttttttttttttttttt "
Data "ttttttttttttttttttttttttttttttttttttttttttt"
Data "tt                                       tt"
Data "tt                                       tt"
Data "tt                                       tt"
Data "tt     33 33   33333  3333333 3333333    tt"
Data "tt    333 333 33   33     33  33         tt"
Data "tt    33 3 33 3333333   333   3333       tt"
Data "tt    33   33 33   33  33     33         tt"
Data "tt    33   33 33   33 3333333 3333333    tt"
Data "tt                                       tt"
Data "tt     33333   33333   33 33  3333333    tt"
Data "tt    33   33 33   33 333 333 33         tt"
Data "tt    33      3333333 33 3 33 3333       tt"
Data "tt    33 3333 33   33 33   33 33         tt"
Data "tt     333333 33   33 33   33 3333333    tt"
Data "tt                                       tt"
Data "tt                                       tt"
Data "tt                                       tt"
Data "ttttttttttttttttttttttttttttttttttttttttttt"
Data " ttttttttttttttttttttttttttttttttttttttttt "
Data "."

.TITLE_DATA2
Data "     t     ttt      tt        ttt          "
Data "333333t3333333t3333333t3333333t3333333333t3"
Data "3333333t3333333t3333333tt3333t3333333333t33"
Data "33 t    tt      ttt      tttt     t    t 33"
Data "33 t                               tttt  33"
Data "33  t 111111  11   11   44444444444      33"
Data "33  t 11   11  11 11    44444444444      33"
Data "33  t 111111    111              44      33"
Data "33 t  11   11   111            444444    33"
Data "33t   111111    111             4444     33"
Data "33     44                        44      33"
Data "33    4444            222222  222222     33"
Data "33   444444               222     222    33"
Data "33     44               2222    2222     33"
Data "33     444444444          222     222    33"
Data "33     444444444      222222  222222     33"
Data "33      t                                33"
Data "33    tt t    ttt        tt             t33"
Data "33333t3333333t3333333333t33333333333333t333"
Data "3333t3333333t333333333tt333333333333ttt3333"
Data " ttt      tt      t tt           ttt       "
Data "."



big10p(Posted 1+ years ago)

 Pretty nice, _33. I only get 20fps on my old crate, tho.P.S. Can you put your code into code boxes, please (use 'codebox' tag, instead of just 'code').


_33(Posted 1+ years ago)

 Sorry Chris!  I left the resolution at 1360x1024!  I've lowered to 1024x768 and put the code in the right format.Cheers.


Blitzplotter(Posted 1+ years ago)

 Just ran the first post version of this - awesome, wow this was penned (typed) a good 11 years ago - still rocks! ;)


big10p(Posted 1+ years ago)

 Cheers. 11 years. Wowsers...


BlitzSupport(Posted 1+ years ago)

 Wow, looks even cooler in 1080p!


Hotshot2005(Posted 1+ years ago)

 Amazing !!!!


RemiD(Posted 8 months ago)

 wrong thread, sorry... [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal