Making a Swinging Rope in a Platform game

BlitzMax Forums/BlitzMax Programming/Making a Swinging Rope in a Platform game

Rico(Posted 2010) [#1]
Hi i am writing a platform game, and its going well so far, but i would like to have a swinging rope in there, which the character can jump on. When i think of ropes in platform games i always thing of the one in Jet Set Willy which was made out of lots of dots/squares. How can i make such a rope?. i have never done one before and i am unsure how to go about it. can a rope be made from lines somehow? i would like the rope to have some thickness.

there used to be a routine i had called ColorRope i think which i got from the old Blitz 2D forum, however i lost that with my old computer. that drew a rope like i want.


ImaginaryHuman(Posted 2010) [#2]
You could use lines, you could have several vartical sections each of which starts on a given row and ends on a given row, then to make it wider you just add more lines to the sides of it.. it wouldn't be accurate but it'd be reasonable. You'd need some collisione detection in order to detect rope colliding with player. To get more advanced you'd need physics and textured polygon routines.


CGV(Posted 2010) [#3]
You're looking for this maybe?


Rico(Posted 2010) [#4]
thank you very much CGV, that looks great, how can i do collision detection with the rope - ie to see if the main character lands on it? thats a very nice routine though :) just what i was thinking of.


theHand(Posted 2010) [#5]
Rico I recommend you start learning Trigonometry now so that you will have it in the future (checkout a couple books on it at your local library). It's a great asset (look at that Cosine function on the rope, you will have a much better understanding of how it works and will be able to do many, many more fun things like the swingy rope)


Rico(Posted 2010) [#6]
Thank you, i will brush up on my trig. i know a little bit already. will it help me to detect collisions with the rope? i suppose i know the position of each individual segment of the rope, so i can use those for helping with collision detection. also if i use bitmaps for the rope segments i can use the built in collision detection as well.


theHand(Posted 2010) [#7]
Yes, it will absolutely help you detect collisions with the rope. To do so you must understand where the Function puts each "segment", and to do that you need math and probably a graphing calculator. :P

Edit: If you use bitmaps it has to access the object every time to check for collisions, whereas if you just store a center point for each segment and check for 'collision' with your Player object, you will do the same thing in half( at least!) of the work.


EOF(Posted 2010) [#8]
Rico,
I wrote that code some while ago but for collision detection you might want to consider the Dist() function below

You can check how 'close' your player is to say, the end of the rope. If the distance is relatively small (<=12 pixels for example) you can switch to a PLAYERSTATUS = ONROPE mode

Function Dist:Float(x1:Float,y1:Float,x2:Float,y2:Float)
	Local dx:Float=Abs(x1-x2)
	Local dy:Float=Abs(y1-y2)
	Return Sqr(dx*dx + dy*dy)
End Function



You can check the distance at the time of the Draw() routine:

Method Draw()
    For Local rad%=1 To length Step 7
    Local bend#=(angle-ropemid)/ropebend
    Local ang#=angle+bend*rad
    ropePX#=ropeX#+Cos(ang)*rad 
    ropePY#=ropeY#+Sin(ang)*rad
    DrawOval ropePX,ropePY,8,12
    ' the bottom End of the rope
    SetColor 10,50,10
    DrawOval ropepx,ropepy,10,11
    ' check distance between player and end of rope
    ' no need to check if player is already on the rope though
    If PLAYERSTATUS<>ONROPE
        If Dist(playerX,playerY,ropepx,ropepy)<12
            PLAYERSTATUS=ONROPE
        EndIf
    EndIf
End Method



Rico(Posted 2010) [#9]
Thank you Hand, i have a few ideas i can use now. Thanks very much Jim for the routine. That will be very useful too, it will come in handy for other things too :)

i found a few more rope routines on the forum using the search function but they are in old Blitz language so i need to convert them, i will look at those too to see which rope i prefer.