Simple collision question 2D
Blitz3D Forums/Blitz3D Beginners Area/Simple collision question 2D
| ||
how to handel 2D collsion like a rpg game ? I use this If ImagesCollide(sprite1,x%,y%,a%,berg1,200,200,0) but than the moving object is hanging in a tree. I thought mmm then I change the x and y -1 or +1 but that's not working because you can walk arround the tree. There is no function to reset the Collision. ;some code here wend ;some code here Collide() ;move If KeyDown(205) Then ;right x%=x%+1 a%=3 End If If KeyDown(203) Then ;left x%=x%-1 a%=9 End If If KeyDown(200) Then ;up y%=y%-1 a%=0 End If If KeyDown(208) Then ;down y%=y%+1 a%=6 End If DrawImage sprite1,x%,y%,(sprite1_frm+a%) a% = "" ;idle Flip Wend End Function Collide() If ImagesCollide(sprite1,x%,y%,a%,berg1,200,200,0) Then Text 250,250,"Now i Stop walking :) and i can't move again stuck in a tree" ;But I want to walk again EndIf End Function |
| ||
You allow the player to move before checking for collision. You should (pseudo)... do Check input from player Check if this would cause a collision Collision = true then don't move player. Collision = false then move player. Display player loop |
| ||
damn yea, where is my fantasy. Sorry for all these stupid questions. |
| ||
Where can I find some good 2D RPG source examples? That's better then ask everything here. Thanks, |
| ||
Just keep asking your questions here. Good chance your probably helping out someone else reading these :o) |
| ||
And when I post here again , my topic is first again ;) ---- But I understand that people will ignore my question's if I ask many stupid questions. So people:does someone have a super basic RPG source code. I have found the design here: http://www.blitzbasic.com/Community/posts.php?topic=42222 By WolRon /-------------------------------------------------------------------\ | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | \-------------------------------------------------------------------/ Thanks for helping |
| ||
That was a joke post, so don't take anything from it seroiusly ;) |
| ||
yea haha I hope you understand that I know that :) That design was a joke. |
| ||
lol, good. With some ppl around here, u just don't know ;) |
| ||
i know I think 50% is 12 years old and like me asking super super stupid questions. |
| ||
Oke now its enough, I see some example on blitzcoder and blitzbasic , I asked here but I still don't have a super basic example :( :( : ( I have made an easy picture so its easy to see what I mean. [img /img] I only want a simple ImagesCollide() example with a moving player that's stop's moving when hit the rock. As you can see on the picture I have that but when people press for example up and right then he goes through the rock. And sometimes the players is acting strang because I use this: If coll = 208 y%=y%-1 EndIf .... Graphics 800,600,32,2 SetBuffer BackBuffer() Global x% = 400 Global y% = 400 Global a% = 0 Global coll,coll2 Global sprite1,berg1 ;load tiles backgrd = LoadImage("tiles/grass1.png") berg1 = LoadImage("tiles/berg1.png") ;load sprite sprite1 = LoadAnimImage("sprites/sprite1.png",24,32,0,12) MaskImage sprite1,32,156,0 While Not KeyHit(1) Cls TileBlock backgrd DrawImage berg1,500,500 If MilliSecs() > tmrSprite + 200 Then tmrSprite =MilliSecs() sprite1_frm=(sprite1_frm+1) Mod 3 End If DrawImage sprite1,0,0,sprite1_frm DrawImage sprite1,30,0,(sprite1_frm+3) DrawImage sprite1,60,0,(sprite1_frm+6) DrawImage sprite1,90,0,(sprite1_frm+9) Rect 30,30,660,560,0 ;move If KeyDown(205) Then ;right x%=x%+1 a%=3 coll=205 If KeyDown(208) Or KeyDown(200) Then coll2 = True EndIf EndIf If KeyDown(203) Then ;left x%=x%-1 a%=9 coll=203 If KeyDown(208) Or KeyDown(200) Then coll2 = True EndIf EndIf If KeyDown(200) Then ;up y%=y%-1 a%=0 coll=200 If KeyDown(205) Or KeyDown(203) Then coll2 = True EndIf EndIf If KeyDown(208) Then ;down y%=y%+1 a%=6 coll=208 If KeyDown(205) Or KeyDown(203) Then coll2 = True EndIf EndIf DrawImage sprite1,x%,y%,(sprite1_frm+a%) a% = "" ;idle If CheckCollide() = True If coll2 = False If coll = 208 y%=y%-1 EndIf If coll = 200 y%=y%+1 EndIf If coll = 203 x%=x%+1 EndIf If coll = 205 x%=x%-1 EndIf EndIf EndIf ;debug Text 50,50,"x:"+x% Text 50,60,"y:"+y% Text 50,70,"coll:"+coll Text 50,80,"coll2:"+coll2 Flip Wend End Function CheckCollide() If ImagesCollide(sprite1,x%,y%,a%,berg1,500,500,0) Then Return True Else coll = 0 coll2= False Return False EndIf End Function |
| ||
flush keys after any movement |
| ||
;28-11-2004, version 1.0 ;//////////////////////////////////////////////////////////////////////// ;nom de l'application AppTitle "collision bloc 1" ;//////////////////////////////////////////////////////////////////////// ;variable du mode graphique Const Resolution00%=640;X Const Resolution01%=480;Y Const Resolution02%=16;profondeur des couleurs Const Resolution03%=2;mode graphique ;//////////////////////////////////////////////////////////////////////// ;initialisation du mode graphique Graphics Resolution00,Resolution01,Resolution02,Resolution03 .VarCollision ;//////////////////////////////////////////////////////////////////////// ;variable, collisions ;image 0, dimension Const C00%=128;taille, X Const C01%=128;taille, Y ;image 0, dimension collision [0] Const C02%=64;taille, X Const C03%=64;taille, Y Const C04%=((C00-C02)/2);espace, X Const C05%=((C01-C03)/2);espace, Y ;image 1, dimension Const C10%=64;taille, X Const C11%=64;taille, Y .VarJoueur ;//////////////////////////////////////////////////////////////////////// ;variable, joueur J00#=100.0;position, X J01#=100.0;position, Y J02#=J00;position, X tampon J03#=J01;position, Y tampon .VarDecor ;//////////////////////////////////////////////////////////////////////// ;variable, decor D00%=288;position, X D01%=208;position, Y ;***************** ;* boucle du jeu * ;***************** ;//////////////////////////////////////////////////////////////////////// ;initialise le tampon secondaire SetBuffer BackBuffer() ;//////////////////////////////////////////////////////////////////////// ;tant que "echappe" n'a pas ete presse While Not KeyDown(1) ;//////////////////////////////////////////////////////////////////////// ;efface le tampon secondaire Cls .L00 ;//////////////////////////////////////////////////////////////////////// ;collision If RectsOverlap (Floor#(J00+C04),Floor#(J01+C05),C02,C03,D00,D01,C10,C11) Text 0,00,"Collision !!!" ;haut If Floor#((J03+C05)+C03)<=D01 ;mise a jour J01=Floor#((D01-C05)-C03) ;saute au pointeur Goto P_Collision00 EndIf ;bas If Floor#(J03+C05)>=(D01+C11) ;mise a jour J01=Floor#((D01+C11)-C05) ;saute au pointeur Goto P_Collision00 EndIf ;gauche If Floor#(J02+C04+C02)<=D00 ;mise a jour J00=Floor#((D00-C04)-C02) ;saute au pointeur Goto P_Collision00 EndIf ;droite If Floor#(J02+C04)>=(D00+C10) ;mise a jour J00=Floor#((D00+C10)-C04) ;saute au pointeur Goto P_Collision00 EndIf EndIf ;pointeur .P_Collision00 .L01 ;//////////////////////////////////////////////////////////////////////// ;dessin Color 0,255,255 Rect Floor#(J00+C04),Floor#(J01+C05),C02,C03,1 ;dessin Color 0,0,255 Rect D00,D01,C10,C11,1 .L02 ;//////////////////////////////////////////////////////////////////////// ;texte Text 0,10,"J02 "+J02 Text 0,20,"D00 "+D00 .L03 ;//////////////////////////////////////////////////////////////////////// ;mise a jour J02=J00;position, X tampon J03=J01;position, Y tampon ;//////////////////////////////////////////////////////////////////////// ;basculement des tampons Flip ;//////////////////////////////////////////////////////////////////////// ;haut If KeyDown(200) J01=(J01-4.0);position, Y EndIf ;bas If KeyDown(208) J01=(J01+4.0);position, Y EndIf ;gauche If KeyDown(203) J00=(J00-4.0);position, X EndIf ;droite If KeyDown(205) J00=(J00+4.0);position, X EndIf ;//////////////////////////////////////////////////////////////////////// ;fin de la boucle Wend ;//////////////////////////////////////////////////////////////////////// ;fin du programme End >the first square (player) has a second square inside for the collision. |
| ||
@ Duckstab[o] & Réno ----------------------------- -Thank You Very Much- ----------------------------- This is working :) |