Je vous expose ici même un petit défi personnel que je m'impose à titre de "repos cérébral" et purement pour le fun.
Je trouve ça très sympa de voir les gens partager leurs oeuvres par balises "Code", sans qu'il soit nécessaire de télécharger quoi que ce soit. Aussi, pour me faire la main sur PB, j'ai envie, dans le fun le plus total et sans aucune prise de choux, de développer, en live et avec vous, un petit jeu dont le seul objectif est d'être diffusable par forum. Toutes les ressources seront générées par algo, pour que vous n'ayez pas à télécharger quoi que ce soit

Voici donc le premier jet du soir! Attention, rien n'est jouable, c'est sans intérêt pour le moment, il n'y a pas de démonstration de code là dedant, c'est cours quitte à être moche voir sale. Juste qu'il faut un premier post.

Code : Tout sélectionner
Structure Player
x.f
y.f
dx.f
dy.f
spd.f
EndStructure
Global Dim World(32,32)
Global hero, eye, wall, halo
Global Play.Player
AngX.f : AngY.f : AngZ.f
WindowWidth = 800
WindowHeight = WindowWidth*9/16
InitKeyboard() : InitSprite()
hWnd = OpenWindow(0, 32, 32, WindowWidth, WindowHeight, "Test")
OpenWindowedScreen (WindowID(0),0 , 0, WindowWidth, WindowsHeight,0, 0, 0, #PB_Screen_WaitSynchronization)
hdc = GetDC_(hWnd)
pfd.PIXELFORMATDESCRIPTOR
; Il faudra écrire un pixel format descriptor, un miracle que ça marche en l'état
pixformat = ChoosePixelFormat_(hdc, pfd) ; Error check?
SetPixelFormat_(hdc, pixformat, pfd) ; Error check?
hrc = wglCreateContext_(hdc) ; Error check?
wglMakeCurrent_(hdc,hrc) ; Error check?
glMatrixMode_(#GL_MODELVIEW)
gluPerspective_(70.0, WindowWidth/WindowHeight, 1.0, 100.0)
glViewport_(0, 0, WindowWidth, WindowHeight)
glTranslatef_(0, 0, -8.0)
glEnable_(#GL_CULL_FACE)
glEnable_(#GL_TEXTURE_2D)
glEnable_(#GL_BLEND)
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
Procedure Clamp(i.i)
If i<0 : i=0 : EndIf
If i>255 : i=255 : EndIf
ProcedureReturn i
EndProcedure
Procedure MyBindTexture(w.i, h.i, buffer)
glGenTextures_(1, @tex.l)
If Not(glGetError_())
glBindTexture_(#GL_TEXTURE_2D, tex)
If Not(glGetError_())
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
glTexImage2D_(#GL_TEXTURE_2D, 0, 4, w, h, 0, #GL_RGBA, #GL_UNSIGNED_BYTE, buffer)
EndIf
EndIf
FreeMemory(buffer) ; Caca total mais ça raccourci le code à passer au forum
ProcedureReturn tex
EndProcedure
Procedure CreateHero()
w=128 : h=128 : xc=w/2: yc=h/2
buffer=AllocateMemory(w*h*4, #PB_Memory_NoClear)
buf=buffer
For u=0 To h-1
For n=0 To w-1
PokeB(buf+0, 0)
PokeB(buf+1, 0)
PokeB(buf+2, 255-2*Sqr(Pow(xc-n,2)+Pow(yc-u,2)))
PokeB(buf+3, Clamp(512-4*Sqr(Pow(xc-n,2)+Pow(yc-u,2))))
buf+4
Next
Next
ProcedureReturn MyBindTexture(w,h,buffer) ; Attention, proc free buffer
EndProcedure
Procedure CreateEye()
w=32 : h=32 : xc=w/2: yc=h/2
buffer=AllocateMemory(w*h*4, #PB_Memory_NoClear)
buf=buffer
For u=0 To h-1
For n=0 To w-1
C=Clamp(640-48*Sqr(Pow(xc-n,2)+Pow(yc-u,2)))
PokeB(buf+0, C)
PokeB(buf+1, C)
PokeB(buf+2, C)
PokeB(buf+3, Clamp(2550-172*Sqr(Pow(xc-n,2)+Pow(yc-u,2))))
buf+4
Next
Next
ProcedureReturn MyBindTexture(w,h,buffer) ; Attention, proc free buffer
EndProcedure
Procedure CreateWall()
w=128 : h=128 : xc=w/2: yc=h/2
buffer=AllocateMemory(w*h*4, #PB_Memory_NoClear)
buf=buffer
For u=0 To h-1
For n=0 To w-1
G=Clamp(-1024+14*Sqr(Pow(xc-n,2)+Pow(yc-u,2)))
RB=Clamp(G+2*Sqr(Pow(xc-n,2)+Pow(yc-u,2)))
PokeB(buf+0, RB)
PokeB(buf+1, G)
PokeB(buf+2, RB)
PokeB(buf+3, Clamp(4*Sqr(Pow(xc-n,2)+Pow(yc-u,2))))
buf+4
Next
Next
ProcedureReturn MyBindTexture(w,h,buffer) ; Attention, proc free buffer
EndProcedure
Procedure CreateHalo()
w=32 : h=32 : xc=w/2: yc=h/2
buffer=AllocateMemory(w*h*4, #PB_Memory_NoClear)
buf=buffer
For u=0 To h-1
For n=0 To w-1
C=Clamp(255-16*Sqr(Pow(xc-n,2)+Pow(yc-u,2)))
PokeB(buf+0, C)
PokeB(buf+1, C)
PokeB(buf+2, C)
PokeB(buf+3, 255)
buf+4
Next
Next
ProcedureReturn MyBindTexture(w,h,buffer) ; Attention, proc free buffer
EndProcedure
Procedure DisplayWorld()
glPushMatrix_()
glMatrixMode_(#GL_MODELVIEW)
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
glBindTexture_(#GL_TEXTURE_2D, Wall)
glBegin_(#GL_QUADS) ; Un mur
glColor4ub_(255,255,255,255)
For j=0 To 31
For i=0 To 31
If World(i,j)=1
glTexCoord2f_(0.0, 0.0) : glVertex3f_( 0.0+i, 1.0-j, 0)
glTexCoord2f_(0.0, 1.0) : glVertex3f_( 0.0+i, 0.0-j, 0)
glTexCoord2f_(1.0, 1.0) : glVertex3f_( 1.0+i, 0.0-j, 0)
glTexCoord2f_(1.0, 0.0) : glVertex3f_( 1.0+i, 1.0-j, 0)
EndIf
Next
Next
glEnd_()
glPopMatrix_()
EndProcedure
Procedure DisplayWorldLight(Ang.f)
glPushMatrix_()
glMatrixMode_(#GL_MODELVIEW)
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE)
glBindTexture_(#GL_TEXTURE_2D, Halo)
glBegin_(#GL_QUADS) ; Un mur
For j=0 To 31
For i=0 To 31
If World(i,j)=1
glColor4ub_(255,0,255,42+Cos(Sin(i*10+j*140-Ang/86)*60-Cos(j*10+i*132+Ang/100)*48+Ang)*12) ; Un peu d'aléatoire
glTexCoord2f_(0.0, 0.0) : glVertex3f_(-1.5+i, 2.5-j, 0)
glTexCoord2f_(0.0, 1.0) : glVertex3f_(-1.5+i,-1.5-j, 0)
glTexCoord2f_(1.0, 1.0) : glVertex3f_( 2.5+i,-1.5-j, 0)
glTexCoord2f_(1.0, 0.0) : glVertex3f_( 2.5+i, 2.5-j, 0)
EndIf
Next
Next
glEnd_()
glPopMatrix_()
EndProcedure
Procedure DisplayHero()
glPushMatrix_()
glMatrixMode_(#GL_MODELVIEW)
glTranslatef_(Play\x, -Play\y, 0)
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
glBindTexture_(#GL_TEXTURE_2D, Hero)
glBegin_(#GL_QUADS) ; Corp du hero
glColor4ub_(255,255,255,255)
glTexCoord2f_(0.0, 0.0) : glVertex3f_( 0.0, 1.0, 0)
glTexCoord2f_(0.0, 1.0) : glVertex3f_( 0.0, 0.0, 0)
glTexCoord2f_(1.0, 1.0) : glVertex3f_( 1.0, 0.0, 0)
glTexCoord2f_(1.0, 0.0) : glVertex3f_( 1.0, 1.0, 0)
glEnd_()
glBindTexture_(#GL_TEXTURE_2D, eye)
glBegin_(#GL_QUADS) ; Eyes
glTexCoord2f_(0.0, 0.0) : glVertex3f_( 0.1, 0.5, 0)
glTexCoord2f_(0.0, 1.0) : glVertex3f_( 0.1, 0.2, 0)
glTexCoord2f_(1.0, 1.0) : glVertex3f_( 0.4, 0.2, 0)
glTexCoord2f_(1.0, 0.0) : glVertex3f_( 0.4, 0.5, 0)
glTexCoord2f_(0.0, 0.0) : glVertex3f_( 0.6, 0.5, 0)
glTexCoord2f_(0.0, 1.0) : glVertex3f_( 0.6, 0.2, 0)
glTexCoord2f_(1.0, 1.0) : glVertex3f_( 0.9, 0.2, 0)
glTexCoord2f_(1.0, 0.0) : glVertex3f_( 0.9, 0.5, 0)
glEnd_()
glPopMatrix_()
EndProcedure
Procedure DisplayHeroLight()
glPushMatrix_()
glMatrixMode_(#GL_MODELVIEW)
glTranslatef_(Play\x, -Play\y, 0)
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE)
glBindTexture_(#GL_TEXTURE_2D, Halo)
glBegin_(#GL_QUADS) ; Corp du hero
glColor4ub_(0,0,255,80)
glTexCoord2f_(0.0, 0.0) : glVertex3f_(-1.0, 2.0, 0)
glTexCoord2f_(0.0, 1.0) : glVertex3f_(-1.0,-1.0, 0)
glTexCoord2f_(1.0, 1.0) : glVertex3f_( 2.0,-1.0, 0)
glTexCoord2f_(1.0, 0.0) : glVertex3f_( 2.0, 2.0, 0)
glEnd_()
glPopMatrix_()
EndProcedure
hero = CreateHero()
eye = CreateEye()
wall = CreateWall()
halo = CreateHalo()
; Création d'un monde à la con BOUH BOUH BOUH!!!
For i=0 To 31
World(i,0)=1 : World(i,31)=1 : World(0,i)=1 : World(31,i)=1
World(i/4,3)=1 : World(i/3+10,10)=1 : World(i/4+12,12)=1 : World(i/3+5,6)=1 : World(i/3+20,6)=1 : World(i/4+13,14)=1
World(14,i/4)=1 : World(7,i/3+10)=1 : World(2,i/4+8)=1 : World(9,i/3+5)=1 : World(15,i/3+20)=1 : World(17,i/4+10)=1
Next
;Placement du joueur
Play\x=9 : Play\dx=Play\x
Play\y=3 : Play\dy=Play\y
Play\Spd=0.05
Repeat
glClear_ (#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glPushMatrix_()
glMatrixMode_(#GL_MODELVIEW)
glRotatef_ (Cos(AngX)*5, 1.0, 0, 0)
glRotatef_ (Sin(AngY)*5, 0, 1.0, 0)
;glRotatef_ (AngZ, 0, 0, 1.0)
glTranslatef_(-Play\x-0.5, Play\y-0.5, Cos(AngZ)*2)
AngX+0.003 : AngY+0.004 : AngZ+0.002
DisplayWorld()
DisplayHero()
DisplayWorldLight(AngZ*5)
DisplayHeroLight()
glPopMatrix_()
glFinish_()
SwapBuffers_(hdc)
ExamineKeyboard()
If (Play\x=Play\dx) And (Play\y=Play\dy)
If KeyboardPushed(#PB_Key_Left) : If World(Int(Play\x-1),Int(Play\y))=0 : Play\dx-1 : EndIf : EndIf
If KeyboardPushed(#PB_Key_Right) : If World(Int(Play\x+1),Int(Play\y))=0 : Play\dx+1 : EndIf : EndIf
If KeyboardPushed(#PB_Key_Up) : If World(Int(Play\x),Int(Play\y-1))=0 : Play\dy-1 : EndIf : EndIf
If KeyboardPushed(#PB_Key_Down) : If World(Int(Play\x),Int(Play\y+1))=0 : Play\dy+1 : EndIf : EndIf
If KeyboardPushed(#PB_Key_Escape) : Quit=1 : EndIf
EndIf
If (Play\dx) > (Play\x) : Play\x+Play\Spd : If Abs(Play\x-Play\dx)<Play\Spd*0.9 : Play\x=Play\dx : EndIf : EndIf
If (Play\dx) < (Play\x) : Play\x-Play\Spd : If Abs(Play\x-Play\dx)<Play\Spd*0.9 : Play\x=Play\dx : EndIf : EndIf
If (Play\dy) > (Play\y) : Play\y+Play\Spd : If Abs(Play\y-Play\dy)<Play\Spd*0.9 : Play\y=Play\dy : EndIf : EndIf
If (Play\dy) < (Play\y) : Play\y-Play\Spd : If Abs(Play\y-Play\dy)<Play\Spd*0.9 : Play\y=Play\dy : EndIf : EndIf
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Event=0
Delay(1000/120)
Until Quit = 1
glDeleteTextures_(1, @hero)
glDeleteTextures_(1, @eye)
glDeleteTextures_(1, @wall)
glDeleteTextures_(1, @halo)