J'ai un peu avancé le projet de la page précédente : on peut maintenant gérer un scrolling et plusieurs boite indépendante.
Baladez vous avec la souris et cliquez de temps en temps pour voir un effet interdit au moins de 16 ans
Code : Tout sélectionner
; © ATHOW
; Au-Delà Project
;{- Global Variables, Constants & Enumeration
; sprites, sound effects, musics...
Enumeration
#SPR_WHITESQUARE
#SPR_GRAYSQUARE
EndEnumeration
;Others
; screen size
#SCREEN_WIDTH = 1024
#SCREEN_HEIGHT = 768
; gravity
#Gravity = 10
; depth of the platforms
#K = 10
; global variables for the scrolling
Global firstX.w
Global firstY.w
Global worldWidth.w
Global worldHeight.w
Global heroPosX.w
Global heroPosY.w
;}
;{- Structures
Structure blood
diam.f
x.f
y.f
dx.f
dy.f
depth.b
EndStructure
Structure box3D
x.w
y.w
width.w
height.w
spriteLeft.l
spriteRight.l
spriteTop.l
spriteFace.l
k.w
EndStructure
Structure level
levelFileName.s
enemyFileName.s
width.w
height.w
EndStructure
;}
;{- Global Lists & Dims
Global NewList bloodList.blood()
Global NewList boxes3DList.box3D()
;}
;{- Windows
UsePNGImageDecoder()
If InitSprite()=0 Or InitKeyboard()=0 Or InitSprite3D()=0 Or InitMouse() = 0
MessageRequester("Error", "Au-Delà was unable to launch. Verify that DirectX is installed correctly.", 0)
End
EndIf
;If OpenWindowedScreen(OpenWindow(0,0,0,#SCREEN_WIDTH, #SCREEN_HEIGHT,"Au-Delà",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget),0,0,#SCREEN_WIDTH, #SCREEN_HEIGHT,0,0,0) = 0
If OpenScreen(#SCREEN_WIDTH,#SCREEN_HEIGHT,32,"Au-Delà") = 0
MessageRequester("Error", "Unable to open a 800x600 screen", 0)
End
EndIf
KeyboardMode(1)
;}
;{- Sprites
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 = 170+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 = 130+Int(i/4)
If(color > 255)
color = 255
EndIf
Line(0,i,256,0,RGB(color,color,color))
Next
StopDrawing()
;}
;{- Tools
Procedure.w Max(Value1.f,Value2.f)
If Value1 > Value2
ProcedureReturn Value1
Else
ProcedureReturn Value2
EndIf
EndProcedure
Procedure.w randInt(max.w)
ProcedureReturn Int(Random(max))
EndProcedure
;}
;{- Graphical Effects
Procedure addBlood(x.f,y.f,powerX.f,powerY.f)
nbBlood.b = Int(50+Abs(powerX*powerY))
For i.b = 0 To nbBlood
AddElement(bloodList())
bloodList()\diam = Max(1,Random(4))
bloodList()\x = x + Random(10)
bloodList()\y = y + Random(10)
bloodList()\dx = (Random(bloodList()\diam))*powerX+(Random(bloodList()\diam))
bloodList()\dy = (Random(bloodList()\diam))*powerY+(Random(bloodList()\diam))
Next
EndProcedure
Procedure displayBlood()
ResetList(bloodList())
StartDrawing(ScreenOutput())
While NextElement(bloodList())
Ellipse(Int(bloodList()\x) - firstX,Int(bloodList()\y) - firstY,Int(bloodList()\diam),Int(bloodList()\diam)+randInt(2),RGB(160,0,0))
Wend
StopDrawing()
EndProcedure
Procedure updateBlood()
ResetList(bloodList())
While NextElement(bloodList())
bloodList()\x = bloodList()\x + bloodList()\dx
bloodList()\y = bloodList()\y + bloodList()\dy
bloodList()\dy = bloodList()\dy + #Gravity/10
bloodList()\dx = bloodList()\dx
If bloodList()\x - firstX<0 Or bloodList()\x - firstX>worldWidth Or bloodList()\y - firstY>worldHeight
DeleteElement(bloodList())
Else ; collision with the Boxes ?
ResetList(boxes3DList())
While(NextElement(boxes3DList()))
; collision with the left face :
If (bloodList()\x - bloodList()\dx < boxes3DList()\x) And (bloodList()\x >= boxes3DList()\x) And (bloodList()\y >= boxes3DList()\y) And (bloodList()\y <= boxes3DList()\y + boxes3DList()\height) And (randInt(10) > 4)
StartDrawing(SpriteOutput(boxes3DList()\spriteLeft))
argX.w = randInt(256)
argY.w = Int(256 * (bloodList()\y - boxes3DList()\y) / boxes3DList()\height)
argRadiusX.w = 3*Int(bloodList()\diam)
argRadiusY.w = Int(512 / boxes3DList()\height) * Int(bloodList()\diam) + randInt(3)
Ellipse(argX,argY,argRadiusX,argRadiusY,RGB(140,0,0))
StopDrawing()
DeleteElement(bloodList())
Break
EndIf
; collision with the right face :
If (bloodList()\x - bloodList()\dx >= boxes3DList()\x + boxes3DList()\width) And (bloodList()\x < boxes3DList()\x + boxes3DList()\width) And (bloodList()\y >= boxes3DList()\y) And (bloodList()\y <= boxes3DList()\y + boxes3DList()\height) And (randInt(10) > 4)
StartDrawing(SpriteOutput(boxes3DList()\spriteRight))
argX.w = randInt(256)
argY.w = Int(256 * (bloodList()\y - boxes3DList()\y) / boxes3DList()\height)
argRadiusX.w = 3*Int(bloodList()\diam)
argRadiusY.w = Int(512 / boxes3DList()\height) * Int(bloodList()\diam) + randInt(3)
Ellipse(argX,argY,argRadiusX,argRadiusY,RGB(140,0,0))
StopDrawing()
DeleteElement(bloodList())
Break
EndIf
; collision with the top face :
If (bloodList()\y + bloodList()\dy >= boxes3DList()\y) And (bloodList()\y < boxes3DList()\y) And (bloodList()\x >= boxes3DList()\x) And (bloodList()\x <= boxes3DList()\x + boxes3DList()\width) And (randInt(10) > 4)
StartDrawing(SpriteOutput(boxes3DList()\spriteTop))
argX.w = Int(256 * (bloodList()\x - boxes3DList()\x) / boxes3DList()\width)
argY.w = randInt(256)
argRadiusX.w = Int(768 / boxes3DList()\width) * Int(bloodList()\diam) + randInt(3)
argRadiusY.w = 3*Int(bloodList()\diam)
Ellipse(argX,argY,argRadiusX,argRadiusY,RGB(140,0,0))
StopDrawing()
DeleteElement(bloodList())
Break
EndIf
; collision with the bottom face (no blood paint):
If (bloodList()\y + bloodList()\dy < boxes3DList()\y + boxes3DList()\height) And (bloodList()\y >= boxes3DList()\y + boxes3DList()\height) And (bloodList()\x >= boxes3DList()\x) And (bloodList()\x <= boxes3DList()\x + boxes3DList()\width) And (randInt(10) > 3)
DeleteElement(bloodList())
Break
EndIf
; collision with the front face :
If (bloodList()\y >= boxes3DList()\y) And (bloodList()\y <= boxes3DList()\y + boxes3DList()\height) And (bloodList()\x >= boxes3DList()\x) And (bloodList()\x <= boxes3DList()\x + boxes3DList()\width) And (randInt(10) > 5)
StartDrawing(SpriteOutput(boxes3DList()\spriteFace))
argX.w = Int(256 * (bloodList()\x - boxes3DList()\x) / boxes3DList()\width)
argY.w = Int(256 * (bloodList()\y - boxes3DList()\y) / boxes3DList()\height)
argRadiusX.w = Int(512 / boxes3DList()\width) * Int(bloodList()\diam) + randInt(3)
argRadiusY.w = Int(768 / boxes3DList()\height) * Int(bloodList()\diam) + randInt(5)
Ellipse(argX,argY,argRadiusX,argRadiusY,RGB(140,0,0))
StopDrawing()
DeleteElement(bloodList())
Break
EndIf
Wend
EndIf
Wend
EndProcedure
Procedure displayBox3D(x.w,y.w,width.w,height.w, spriteLeft,spriteRight,spriteTop,spriteFace)
CreateSprite3D(0,spriteLeft)
CreateSprite3D(1,spriteRight)
CreateSprite3D(2,spriteTop)
CreateSprite3D(3,spriteFace)
ex.w = ((#SCREEN_WIDTH/2) / #K) - (x / #K) + x
ey.w = -((#SCREEN_HEIGHT/10) / #K + y / #K - y)
bx.w = (((#SCREEN_WIDTH/2) - x - width) / - #K) + x + width
by.w = 2 * y - ey
ax.w = 2 * x - ex
ay.w = by
cx.w = bx
cy.w = by + height
dx.w = ax
dy.w = cy
fx.w = 2 * x + 2 * width - bx
fy.w = ey
gx.w = fx
gy.w = fy + height
hx.w = ex
hy.w = gy
; display the left face
TransformSprite3D(0,ex,ey,ax,ay,dx,dy,hx,hy)
DisplaySprite3D(0,0,0,230)
; display the right face
TransformSprite3D(1,bx,by,fx,fy,gx,gy,cx,cy)
DisplaySprite3D(1,0,0,230)
; display the top face
TransformSprite3D(2,ex,ey,fx,fy,bx,by,ax,ay)
DisplaySprite3D(2,0,0)
; display the front face
TransformSprite3D(3,ax,ay,bx,by,cx,cy,dx,dy)
DisplaySprite3D(3,0,0,230)
EndProcedure
Procedure addBox3D(x.w,y.w,width.w,height.w)
AddElement(boxes3DList())
boxes3DList()\x = x
boxes3DList()\y = y
boxes3DList()\width = width
boxes3DList()\height = height
boxes3DList()\spriteLeft = CopySprite(#SPR_GRAYSQUARE,#PB_Any,#PB_Sprite_Texture)
boxes3DList()\spriteRight = CopySprite(#SPR_GRAYSQUARE,#PB_Any,#PB_Sprite_Texture)
boxes3DList()\spriteTop = CopySprite(#SPR_WHITESQUARE,#PB_Any,#PB_Sprite_Texture)
boxes3DList()\spriteFace = CopySprite(#SPR_GRAYSQUARE,#PB_Any,#PB_Sprite_Texture)
EndProcedure
Procedure displayAllBoxes3D()
Start3D()
ResetList(boxes3DList())
While NextElement(boxes3DList())
displayBox3D(boxes3DList()\x - firstX,boxes3DList()\y - firstY,boxes3DList()\width,boxes3DList()\height,boxes3DList()\spriteLeft,boxes3DList()\spriteRight,boxes3DList()\spriteTop,boxes3DList()\spriteFace)
Wend
Stop3D()
StartDrawing(ScreenOutput())
Circle(heroPosX - firstX, heroPosY - firstY, 10, RGB(255,0,0))
StopDrawing()
EndProcedure
;}
;-{ Game Procedures
Procedure updateScroll()
firstX = heroPosX - Int(#SCREEN_WIDTH / 2)
If firstX < 0
firstX = 0
EndIf
If firstX > worldWidth - Int(#SCREEN_WIDTH)
firstX = worldWidth - Int(#SCREEN_WIDTH)
EndIf
firstY = heroPosY - Int(#SCREEN_HEIGHT / 2)
If firstY < 0
firstY = 0
EndIf
If firstY > worldHeight - Int(#SCREEN_HEIGHT)
firstY = worldHeight - Int(#SCREEN_HEIGHT)
EndIf
EndProcedure
Procedure createWorld()
worldWidth = 1600
worldHeight = 1000
heroPosX = 30
heroPosY = 500
addBox3D(20,500,400,50)
addBox3D(1000,300,300,100)
addBox3D(100,100,20,200)
EndProcedure
;{- Menus and screens
Procedure Test()
createWorld()
click.b = 0
Repeat
FlipBuffers()
ClearScreen(RGB(255,255,255))
ExamineKeyboard()
ExamineMouse()
heroPosX + MouseDeltaX()
If heroPosX < 0
heroPosX = 0
EndIf
If heroPosX > worldWidth
heroPosX = worldWidth
EndIf
heroPosY + MouseDeltaY()
If heroPosY < 0
heroPosY = 0
EndIf
If heroPosY > worldHeight
heroPosY = worldHeight
EndIf
updateScroll()
If MouseButton(1)
If click = 1
click = 2
EndIf
If click = 0
click = 1
EndIf
Else
If click <> 0
click = 0
EndIf
EndIf
If click = 1
addBlood(heroPosX,heroPosY,randInt(20) - 10,randInt(20) - 10)
EndIf
displayAllBoxes3D()
displayBlood()
updateBlood()
Delay(20)
Until KeyboardPushed(#PB_Key_Escape)
EndProcedure
;}
;{- Main routine
Test()
;}