News:

Function Finder  Find all the functions within source code files

Main Menu

Help with sliding collisions sprite/world

Started by reno, December 08, 2007, 05:26:48 AM

Previous topic - Next topic

reno

Hi !

Here are the commands :

- move camera : 8, 2, 4, 6 (num pad).
- move sprite : up, down, left, right.

Image to run the code :


Code (this is the last update) :



; PROJECT : Project2
; AUTHOR  : reno
; CREATED : 15/12/2007
; ---------------------------------------------------------------------

; PROJECT : Exemple_03
; AUTHOR  : 04072007
; CREATED : 28/11/2007
; EDITED  : 14/12/2007
; ---------------------------------------------------------------------

;titre
TitleScreen "THE REETEAM - exemple"
;syncro verticale
ScreenVsync On
;images par secondes
SetFPS 61

;////////////////
;variables
ForceDeclaration

Declaration
;x,y
a
image
objet1
objet2
monde
camera
EndDeclaration

image=10
objet1=20
objet2=30
monde=40
camera=1

;chargement
LoadFxImage "_avatar01.jpg",image

;////////////////
;monde
CreateWorld monde
CaptureToWorld monde

;monde1(0,0,640,480)

line 0,0,640,50
line 640,0,640,300
line 640,300,500,300
line 500,300,500,480
line 500,480,300,480
line 300,480,300,200
line 300,200,400,200
line 400,200,400,100
line 400,100,200,100
line 200,100,200,480
line 200,480,0,480
line 0,480,0,0

PartitionWorld monde,256

;////////////////
;cameras
CreateCamera camera

;////////////////
;creation des objets
CreateSprite objet1
SpriteImage objet1,image
CenterSpriteHandle objet1
SpriteDrawMode objet1,2
SpriteCollisionMode objet1,4
SpriteCollisionWorld objet1,monde
SpriteCollisionRadius objet1,32
SpriteCollisionDebug objet1,1
PositionSprite objet1,128.0,128.0

CreateSprite objet2
SpriteImage objet2,image
CenterSpriteHandle objet2
SpriteDrawMode objet2,2
SpriteCollisionMode objet2,4
SpriteCollisionWorld objet2,monde
SpriteCollisionRadius objet2,64
SpriteCollisionDebug objet2,1
PositionSprite objet2,(640-128.0),128.0


Repeat

;efface l'ecran
;Cls RGB(0,0,0)

;////////////////
;evenement

;mise a jour
Inc a
If a>360 Then a=0

;objet
If KeyState(200)=1 Then MoveSprite objet1,0.0,-8.0
If KeyState(208)=1 Then MoveSprite objet1,0.0,8.0
If KeyState(203)=1 Then MoveSprite objet1,-8.0,0.0
If KeyState(205)=1 Then MoveSprite objet1,8.0,0.0

RotateSprite objet1,a
;scalespritey 1,(a/100.0)

ScaleSpriteXY objet2,-1.0,1.0

;camera
If KeyState(72)=1 Then MoveCamera camera,0,-8.0
If KeyState(80)=1 Then MoveCamera camera,0,8.0
If KeyState(75)=1 Then MoveCamera camera,-8,0.0
If KeyState(77)=1 Then MoveCamera camera,8,0.0

;////////////////
;initialisation de la camera
CaptureToScene

;efface la camera
ClsScene

;////////////////
;camera, monde
CameraGrabWorld camera,monde

;dessin
DrawAllSprites

;camera
DrawCamera camera

;////////////////
;textes
Text 200,000,"-* demo *-"
Text 200,010,"angle rotation : "+Str$(a)
Text 200,020,"objet 1 dans camera : "+Str$(SpriteInCamera(objet1,camera))

Text 200,040,"position X : "+Str$(GetSpriteX(objet1))
Text 200,050,"position Y : "+Str$(GetSpriteY(objet1))

Text 200,070,"monde actif : "+Str$(GetWorldStatus(monde))
Text 200,080,"collision avec monde : "+Str$(GetSpriteWorldImpact(objet1))
Text 200,090,"collision objet : "+Str$(SpritesOverlap(objet1,objet2))


;basculement de tampon
Sync

; sortie de boucle
Until KeyState(1)=1

;fin du programme
End


function monde1(a1,a2,b1,b2)
line a1,a2,(a1+b1),a2
line (a1+b1),a2,(a1+b1),(a2+b2)
line (a1+b1),(a2+b2),a1,(a2+b2)
line a1,(a2+b2),a1,a2
endfunction



Thanks for help  ;)
More games ? Go to my website :)
http://www.thereeteam.com/

reno

More games ? Go to my website :)
http://www.thereeteam.com/

kevin


    Collision worlds can only be made up of line segments.  These lines are considered barriers to the collision engine, and are also one sided.   To define a box region we therefore need to draw the fore lines to define this region within the world as being hard (impassable).       

   For example, a box has four corner points (vertices)  bellow the points are labeled A,B,C,D in a clock wise order.     


     A-----B 
     |           |
     D------C


     To define this region within a collision world, we create a world,  redirect rendering via capturing to the world then draw four lines.  Line A->B,  Line B ->C,  Line C->D   & Line D->A.   

    This initializes the worlds cache, but we can't really use it for collision until the world has been partitioned.  Partitioning cuts the world into more mandible segments for the collision and display engine.   

     I'd also recommending reading notes under CreateWorld for more information.   


reno

Ok, thank you for the tip. It works now, but just if the sprite is inside a closed rectangle. But if I put another rectangle inside it, the collisions are strange again... I'm working on that... I'll post again if I can't find the probleme.
More games ? Go to my website :)
http://www.thereeteam.com/

reno

I understand how sliding collisions work now  :)

But I wonder if in the futur PB could use "the hard boundary lines" in the 2 sides ? Or the possibility to inverse the actual boundary line into the other face ?

(I hope you understand what I'm sayin Kevin  :P)

Other thing, It seems that "SpriteCollisionDebug" doesnt' folow the camera when drawing the sprites.

See the code on the first post, I've updated it.

Thanks !
More games ? Go to my website :)
http://www.thereeteam.com/

reno

Quote
Other thing, It seems that "SpriteCollisionDebug" doesnt' folow the camera when drawing the sprites.

Please, is it a "bug" of PB or did I miss something ?
More games ? Go to my website :)
http://www.thereeteam.com/

kevin

Quote from: reno on December 23, 2007, 10:27:42 AM
Quote
Other thing, It seems that "SpriteCollisionDebug" doesnt' folow the camera when drawing the sprites.

Please, is it a "bug" of PB or did I miss something ?

   If you're using PB1.7x or higher them this is a  bug. 
 

kevin


Quote
But I wonder if in the futur PB could use "the hard boundary lines" in the 2 sides ?

     It might be possible, although i have a feeling if both sides are visible sliding characters that are embedded on a segment with get pulling through or popped to the other side.


Quote
Or the possibility to inverse the actual boundary line into the other face ?

   If you want double sided walls,  you need to lay two lines in the same position (A-B and B-A).   You can control the visibility of any captured world item using   WorldElementVisible.  But you'll have to keep track of the Index of the captured items yourself. 

reno

More games ? Go to my website :)
http://www.thereeteam.com/