Comme j'ai vu "partie bidon de jeu", comme d'hab je me suis lancé bêtement dans un jeu bidon. C'est du code source pur porc, mais le coeur y est ! Juste flèche gauche, flèche droite et la souris. Mais il n'y a même pas le tir... Libre à vous d'en faire un bel exemple.
Code : Tout sélectionner
Procedure aGray(x)
ProcedureReturn RGBA(x, x, x, x)
EndProcedure
Procedure transform(sp, z.d, x0, y0, x1, y1, x2, y2, x3, y3)
TransformSprite(sp, x0 * z, y0 * z, x1 * z, y1 * z, x2 * z, y2 * z, x3 * z, y3 * z)
EndProcedure
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
scW = DesktopWidth(0)
scH = DesktopHeight(0)
OpenScreen(scW, scH, 32, "", #PB_Screen_SmartSynchronization)
scBackC = RGB(32, 64, 128)
msCursZoom.d = 3.2
msCurs = CreateSprite(#PB_Any, 64, 64)
StartDrawing(SpriteOutput(msCurs) )
Box(0, 0, 64, 64, RGB(0, 0, 0) )
Box(10, 5, 50, 50, RGB(255, 255, 255) )
StopDrawing()
transform(msCurs, msCursZoom, 8, 8, 3, 8, 0, 12, 0, 0)
pen = CreateSprite(#PB_Any, 3, 3, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(pen) )
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0, 0, 3, 3, RGBA(0, 0, 0, 0) )
Box(0, 1, 3, 1, RGBA(255, 255, 255, 255) )
StopDrawing()
head = CreateSprite(#PB_Any, 32, 32, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(head) )
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0, 0, 32, 32, RGBA(0, 0, 0, 0) )
For i = 16 To 1 Step -1
Circle(16, 16, i, aGray(256 - Pow(i, 3/5) * 16) )
Next
StopDrawing()
Structure xy
x.d
y.d
EndStructure
Procedure pointCreate(x.d, y.d)
Protected *r.xy = AllocateMemory(SizeOf(xy) )
With *r
\x = x
\y = y
EndWith
ProcedureReturn *r
EndProcedure
Structure transform
A.xy
B.xy
ang.d
rad.d
an0.d
an1.d
an2.d
an3.d
rd0.d
pen.i
C.xy
D.xy
E.xy
F.xy
EndStructure
Procedure traceCreate()
Protected *r.transform = AllocateMemory(SizeOf(transform) )
ProcedureReturn *r
EndProcedure
Procedure trans(pen, *a.xy, *r.xy, ang.d, rad.d, thickness.d = 1.0)
Define.d ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy
Define.d an0, an1, an2, an3
Define.d rd
ax = *a\x
ay = *a\y
;rd = Sqr(2) * 1.5 * thickness ; 1.5 = spriteHeight (3) / 2
rd = Sqr(1) * 1.5 * thickness ; 1.5 = spriteHeight (3) / 2
bx = ax + Cos(ang) * rad
by = ay - Sin(ang) * rad
;an0 = ang + (3 * #PI / 4)
;an1 = ang + (1 * #PI / 4)
;an2 = ang - (1 * #PI / 4)
;an3 = ang - (3 * #PI / 4)
an0 = ang + (#PI / 2)
an1 = ang + (#PI / 2)
an2 = ang - (#PI / 2)
an3 = ang - (#PI / 2)
cx = ax + Cos(an0) * rd
cy = ay - Sin(an0) * rd
dx = bx + Cos(an1) * rd
dy = by - Sin(an1) * rd
ex = bx + Cos(an2) * rd
ey = by - Sin(an2) * rd
fx = ax + Cos(an3) * rd
fy = ay - Sin(an3) * rd
TransformSprite(pen, cx, cy, dx, dy, ex, ey, fx, fy)
DisplayTransparentSprite(pen, 0, 0, RGB(255, 0, 0) )
*r\x = bx
*r\y = by
ProcedureReturn *r
EndProcedure
Procedure.d max(a.d, b.d)
If a > b
ProcedureReturn a
Else
ProcedureReturn b
EndIf
EndProcedure
#pMax = 31
Global Dim *p.xy(#pMax)
Global Dim *gp.xy(63, #pMax)
Procedure guy(man, pen, head, j.d, timeScale.d, scW.d, scH.d)
For i = 0 To #pMax
If i <> pen
;*p(i) = *gp(man, i)
EndIf
Next
trans(pen, *p(0), *p(1), 3*#PI/2 + Cos(j) / 4 * timeScale, scW/32, 20)
trans(pen, *p(1), *p(2), 3*#PI/2 + (Cos(j) / 4 - ((1 - Cos(j) ) / 8) ) * timeScale, scW/32, 20)
trans(pen, *p(0), *p(4), 3*#PI/2 + Cos(j+#PI) / 4 * timeScale, scW/32, 20)
trans(pen, *p(4), *p(5), 3*#PI/2 + (Cos(j+#PI) / 4 - ((1 - Cos(j+#PI) ) / 8) ) * timeScale, scW/32, 20)
*p(8)\x = *p(0)\x
*p(8)\y = *p(0)\y - scW/32
trans(pen, *p(8), *p(12), 3*#PI/2 + Cos(j+#PI) / 4 * timeScale, scW/40, 16)
trans(pen, *p(12), *p(13), 3*#PI/2 + ((Cos(j+#PI) / 4) + ((1 + Cos(j+#PI) ) / 8 * (1 * timeScale) ) ) * timeScale, scW/40, 16)
trans(pen, *p(8), *p(9), 3*#PI/2 + Cos(j) / 4 * timeScale, scW/40, 16)
trans(pen, *p(9), *p(10), 3*#PI/2 + ((Cos(j) / 4) + ((1 + Cos(j) ) / 8 * (1 * timeScale) ) ) * timeScale, scW/40, 16)
*p(16)\x = *p(8)\x + (scW / 640) * Pow(timeScale, 2)
*p(16)\y = *p(8)\y
trans(head, *p(16), *p(17), #PI/2, scW/40, scW/160)
*p(0)\x + 3*Sqr(max((Cos(j) + 1), Cos(j + #PI) + 1) )*Pow(timeScale, 2)
For i = 0 To #pMax
;*gp(man, i) = *p(i)
Next
EndProcedure
Procedure released(x)
Static Dim stat(255)
k = KeyboardPushed(x)
If k And stat(x) = 0
stat(x) = k
ProcedureReturn 1
EndIf
stat(x) = k
EndProcedure
For i = 0 To #pMax
*p(i) = AllocateMemory(SizeOf(xy) )
Next
SpriteQuality(#PB_Sprite_BilinearFiltering)
*p(0)\x = scW / 2
*p(0)\y = scH / 2
timeScale.d = 0
Repeat
*p(0)\x - MouseDeltaX()
*p(0)\y - MouseDeltaY()
Delay(1)
ExamineKeyboard()
ExamineMouse()
ClearScreen(scBackC)
j.d = ElapsedMilliseconds() / 100 * timeScale
For i = 0 To 0
guy(0, pen, head, j, timeScale, scW, scH)
*p(20)\x = 0
*p(20)\y = scH / 2
trans(pen, *p(20), *p(21), 0, scW, 1)
*p(22)\x = scW / 2
*p(22)\y = 0
trans(pen, *p(22), *p(23), 3*#PI/2, scH, 1)
Next
If *p(0)\x > scW
*p(0)\x - scW
EndIf
If Released(#PB_Key_Right)
timeScale + 0.5
EndIf
If Released(#PB_Key_Left)
If timeScale >= 0.5
timeScale - 0.5
EndIf
EndIf
;DisplaySprite(msCurs, MouseX(), MouseY() )
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or MouseButton(#PB_MouseButton_Middle)