Voici en exclusivité (tadaaaa) les plate-formes qu'utiliseront les protagonistes de mon futur jeu : les WhiteBoxes !
Code : Tout sélectionner
; 26/07/07 by ATHOW
; Some 3D effects in a 2D scrolling :)
; --- White Box ---
;{- Introduction
If InitSprite()=0 Or InitKeyboard()=0 Or InitSprite3D()=0
MessageRequester("Error", "Verify that DirectX is installed correctly.", 0)
End
EndIf
If OpenWindowedScreen(OpenWindow(0,0,0,800, 600,"WhiteBox Effect",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget),0,0,800, 600,0,0,0) = 0
MessageRequester("Error", "Unable to open a 800x600 screen", 0)
End
EndIf
KeyboardMode(1)
;}
;{- Constants
; Sprites
Enumeration
#SPR_WHITESQUARE
#SPR_GRAYSQUARE
EndEnumeration
;Others
#SCREEN_WIDTH = 800
#SCREEN_HEIGHT = 600
#K = 10 ; the random magic3D effect constant
;}
;{- Structures
Structure box3D
x.w
y.w
width.w
height.w
EndStructure
;}
;{- Sprites
; The white square sprite3D for displaying the box3Ds
CreateSprite(#SPR_WHITESQUARE,256,256,#PB_Sprite_Texture)
TransparentSpriteColor(#SPR_WHITESQUARE, RGB(255,0,255))
CreateSprite(#SPR_GRAYSQUARE,256,256,#PB_Sprite_Texture)
TransparentSpriteColor(#SPR_GRAYSQUARE, RGB(255,0,255))
StartDrawing(SpriteOutput(#SPR_WHITESQUARE))
For i.w = 0 To 127
color.w = 150+Int(i/2)
If(color > 255)
color = 255
EndIf
Box(i,i,256-i,256-i,RGB(color,color,color))
Next
StopDrawing()
StartDrawing(SpriteOutput(#SPR_GRAYSQUARE))
For i.w = 0 To 255
color.w = 180+Int(i/2)
If(color > 255)
color = 255
EndIf
Line(0,i,256,0,RGB(color,color,color))
Next
StopDrawing()
CreateSprite3D(#SPR_WHITESQUARE,#SPR_WHITESQUARE)
CreateSprite3D(#SPR_GRAYSQUARE,#SPR_GRAYSQUARE)
;}
;{- Global Variables, Constants & Enumeration
; nothing for now :)
;}
;{- Procedure Tools
; nothing for now :)
;}
;{- Graphical Effects
Procedure displayBox3D(x.w,y.w,width.w,height.w)
; E______________________F
; /| /|
;A /_|_________________B__/ |
; | | | |
; | |H___________________|_|G
; |/_____________________|/
; D C
; The dot(x,y) is the middle of the edge [A,E]
; AB = EF = width
; AD = EH = height
; All the vertex are computed with the vertex E
ex.w = ((#SCREEN_WIDTH/2) / #K) - (x / #K) + x
ey.w = -((#SCREEN_HEIGHT/10) / #K + y / #K - y)
ax.w = 2 * x - ex
ay.w = 2 * y - ey
bx.w = ax + width
by.w = ay
cx.w = bx
cy.w = by + height
dx.w = ax
dy.w = cy
fx.w = ex + width
fy.w = ey
gx.w = fx
gy.w = fy + height
hx.w = ex
hy.w = gy
Start3D()
; display the left face
TransformSprite3D(#SPR_GRAYSQUARE,ex,ey,ax,ay,dx,dy,hx,hy)
DisplaySprite3D(#SPR_GRAYSQUARE,0,0,230)
; display the right face
TransformSprite3D(#SPR_GRAYSQUARE,bx,by,fx,fy,gx,gy,cx,cy)
DisplaySprite3D(#SPR_GRAYSQUARE,0,0,230)
; display the top face
TransformSprite3D(#SPR_WHITESQUARE,ex,ey,fx,fy,bx,by,ax,ay)
DisplaySprite3D(#SPR_WHITESQUARE,0,0)
; display the front face
TransformSprite3D(#SPR_GRAYSQUARE,ax,ay,bx,by,cx,cy,dx,dy)
DisplaySprite3D(#SPR_GRAYSQUARE,0,0,230)
Stop3D()
EndProcedure
;}
;{- Screens & Menus
Procedure Main()
Repeat
FlipBuffers()
ClearScreen(RGB(255,255,255))
x=WindowMouseX(0)
y=WindowMouseY(0)
displayBox3D(x,y,200,300)
ExamineKeyboard()
Event = WindowEvent()
Delay(2)
Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow
EndProcedure
;}
;{- Main routine
Main()
;}
Rien de nouveau là-dedans, mais comme c'est la première fois que je manipule ces machins, je suis content de moi...
J'y retourne.