j'ai essayer pas mal de truc mais rien de bien conveincant...
c'est pour un rpg 2d avec deplacement a la sourie
merci d'avance

Code : Tout sélectionner
`-----------------------------
`--- Collisions Glissantes ---
`--- By T£rsAk£n Studio ---
`-----------------------------
`---- Je Remecie Dri ---------
`-----------------------------
`------------
`--- Init ---
`------------
Set Display Mode 640,480,16
Sync On : Sync Rate 30
Hide Mouse
`-----------------
`--- Variables ---
`-----------------
Dim Map(10,10) : LoadMap()
GloBal Angle#,Move
GloBal Y_Perso# = 240.0
Global X_Perso# = 320.0
Global X_Old#,Y_Old#
`-------------------------
`--- Boucle Principale ---
`-------------------------
Do
Cls
Controle()
Collision()
Affiche()
Sync
Loop
`-----------------
`--- Fonctions ---
`-----------------
Function Collision()
Detection()
if X_Perso#=X_Old# and Y_Perso#=Y_Perso#
inc X_Perso#, move*cos(Angle#-45)
endif
Detection()
if X_Perso#=X_Old# and Y_Perso#=Y_Perso#
inc Y_Perso#, move*sin(Angle#-45)
endif
Detection() : Move = 0
endfunction 0
`-------------------------------------------
Function Affiche()
`Carte.
for yloop = 0 to 9 : for xloop = 0 to 9
Ink rgb(0,0,255),0
If Map(xloop,yloop) <> 0 : Box xloop*64,yloop*48,xloop*64+64,yloop*48+48 : endif
next xloop : next yloop
`Personnage.
ink rgb(255,0,0),0
Line X_perso#,Y_Perso#,X_Perso#+20*cos(wrapvalue(Angle#)),Y_Perso#+20*sin(Angle#)
ink rgb(0,255,0),0
Line X_Perso#,Y_Perso#,X_Perso#+20*cos(WrapValue(Angle#-90)),Y_Perso#+20*sin(WrapValue(Angle#-90))
endfunction 0
`------------------------------------------
Function Controle()
X_Old# = X_Perso# : Y_Old# = Y_Perso#
Inc Angle#,( Rightkey() - LeftKey() ) * 3
Angle# = WrapValue(Angle#)
move = ( downkey()-upkey() ) * 3
inc X_Perso#, Move*cos(Angle#-45)
inc Y_Perso#, Move*sin(Angle#-45)
EndFunction 0
`------------------------------------------
Function LoadMap()
for yloop = 0 to 9 : for xloop = 0 to 9
read map(xloop,yloop)
next xloop : next yloop
endfunction 0
`-------------------------------------------
Function Detection()
if Map( Int ( X_Perso#/64.0 ), Int( Y_Perso#/48.0 ) ) <> 0
X_Perso# = X_Old# : Y_Perso# = Y_Old#
endif
EndFunction 0
`-------------------------------------------
`------------------
`--- Etiquettes ---
`------------------
Carte:
Data 1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,0,1,1,1,0,1
Data 1,1,0,0,0,0,0,1,0,1
Data 1,1,0,0,0,0,0,1,0,1
Data 1,1,0,0,0,0,0,1,0,1
Data 1,1,1,1,0,1,1,1,0,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,1,1
Data 0,0,0,0,0,0,0,0,0,0
Code : Tout sélectionner
;-Initialisation
#ScreenWidth = 800
#ScreenHeight = 600
#ScreenDepth = 16
If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester( "Erreur" , "Impossible d'initialiser DirectX 7 Ou plus" , 0 )
End
ElseIf OpenScreen( #ScreenWidth , #ScreenHeight , #ScreenDepth , "Demo PlateForme" ) = 0
MessageRequester( "Erreur" , "Impossible d'ouvrir l'écran " , 0 )
End
EndIf
;/ Structures
Structure sprite
x.l
y.l
Width.l
Height.l
EndStructure
Structure joueur
x.f
y.f
Width.l
Height.l
Sens.w
EndStructure
NewList mur.sprite()
Global Joueur.joueur
Global player1_move.f,player1_speed.f
;/Les sprites
;Joueur
CreateSprite(0,16,16)
StartDrawing(SpriteOutput(0))
Circle(SpriteWidth(0)/2,SpriteHeight(0)/2,SpriteWidth(0)/2,RGB(255,255,55))
StopDrawing()
Joueur\x = 100
Joueur\y = 50
Joueur\Width = SpriteWidth(0)
Joueur\Height = SpriteHeight(0)
;mur
CreateSprite(1,32,32)
StartDrawing(SpriteOutput(1))
Box(0,0,SpriteWidth(1),SpriteHeight(1),RGB(55,155,155))
StopDrawing()
;- procedures
Procedure InitGameTimer()
Shared _GT_DevCaps.TIMECAPS
timeGetDevCaps_(_GT_DevCaps,SizeOf(TIMECAPS))
timeBeginPeriod_(_GT_DevCaps\wPeriodMin)
EndProcedure
Procedure StopGameTimer()
Shared _GT_DevCaps.TIMECAPS
timeEndPeriod_(_GT_DevCaps\wPeriodMin)
EndProcedure
Procedure Readmap()
Restore map
For b = 0 To 15
For a = 0 To 19
Read c
If c
AddElement(mur())
mur()\Width = SpriteWidth(1)
mur()\Height = SpriteHeight(1)
mur()\x = a * mur()\Width
mur()\y = b * mur()\Height
EndIf
Next a
Next b
EndProcedure
Procedure Affmap()
ForEach mur()
DisplaySprite(1,mur()\x,mur()\y)
Next
EndProcedure
Procedure collision()
ForEach mur()
If SpriteCollision(0,Joueur\x,Joueur\y,1,mur()\x,mur()\y)
;corrige la position du perso
Ecartx = Joueur\x - mur()\x
Ecarty = Joueur\y - mur()\y
If Ecartx < 0
decalX = Abs(Ecartx) - Joueur\Width
Else
decalX = mur()\Width - Ecartx
EndIf
If Ecarty < 0
decalY = Abs(Ecarty) - Joueur\Height
Else
decalY = mur()\Height - Ecarty
EndIf
If Random(1) ; pas terrible ça saccade , mais je ne sais pas comment faire autrement pour l'instant
If Abs(decalX)>= Abs(decalY)
decalX = 0
Else
decalY = 0
EndIf
Else
If Abs(decalX)> Abs(decalY)
decalX = 0
Else
decalY = 0
EndIf
EndIf
Joueur\x + decalX
Joueur\y + decalY
collision()
Break
EndIf
Next
EndProcedure
Vitesse = 3
Readmap()
player1_speed.f = 0.250
; timer initialisieren
InitGameTimer()
StartTime = TimeGetTime_()
;StartTime = GetTickCount_()
time= StartTime
Repeat
; calculate multiplicator
multiplicator.f = StartTime
StartTime = TimeGetTime_()
;StartTime = GetTickCount_()
multiplicator = StartTime - multiplicator
; calc framerate
If TimeGetTime_()-time >= 1000
;If GetTickCount_()-time >= 1000
time = TimeGetTime_()
;time = GetTickCount_()
FPS = Frames-1
Frames = 1
Else
Frames+1
EndIf
ClearScreen(0,0,0)
; show framerate
StartDrawing(ScreenOutput())
DrawingMode(1):FrontColor($80,$FF,$00)
Locate(50,50):DrawText("FrameRate: "+Str(FPS))
StopDrawing()
; calc move-step for player1
player1_move = player1_speed * multiplicator
Affmap()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
Joueur\y - player1_move
ElseIf KeyboardPushed(#PB_Key_Down)
Joueur\y + player1_move
EndIf
If KeyboardPushed(#PB_Key_Left)
Joueur\x - player1_move
ElseIf KeyboardPushed(#PB_Key_Right)
Joueur\x + player1_move
EndIf
collision()
DisplaySprite(0,Joueur\x,Joueur\y)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
DataSection
map:
Data.l 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data.l 1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1
Data.l 1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,1
Data.l 1,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,0,1
Data.l 1,0,1,0,0,0,0,0,1,0,1,0,0,1,0,0,0,1,0,1
Data.l 1,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,0,1
Data.l 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1
Data.l 1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1
Data.l 1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data.l 1,0,0,0,1,1,1,0,0,1,0,1,0,1,1,1,0,0,0,1
Data.l 1,0,1,0,0,0,1,0,0,1,0,1,0,1,0,0,0,0,0,1
Data.l 1,0,1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1
Data.l 1,0,1,1,0,0,1,0,1,1,1,1,0,1,0,0,0,0,0,1
Data.l 1,0,0,1,1,0,1,0,1,1,1,1,1,1,1,1,0,0,0,1
Data.l 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data.l 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
EndDataSection