
-----------------------------------
ThgilFoDrol
Thu Nov 08, 2012 11:56 am

Help with Collision and platform generation in Turing
-----------------------------------
Hey, trying to make a game where you control a ball using arrow keys or any other keys to stay alive by bouncing off the platforms that generate. So far, I have the platforms randomly generating, and I'm planning to add commands to make the ball actually move. How would I be able to use forloops and counting loops to make about 7-8 platforms generate and be on the screen at any given moment, and allow the platforms to move up? What commands are there to make collision physics with platforms you don't exactly know the locations of it? Also, the platforms seem to be getting thinner as they progress, any fixes? Thanks!






setscreen ("noecho")
var x, y, r1, r2, c : int
x := 175
y := 300
r1 := 15
r2 := 15

var platformx, platformy, platformx2, platformy2 : int

put "Choose the colour of your player."
get c


randint (platformx, 0, 400)
randint (platformy, 0, 0)
randint (platformx2, platformx, 400)
randint (platformy2, platformy, 40)


loop
drawfilloval (x, y, r1, r2, c)    
drawfillbox (platformx, platformy, platformx2, platformy2, 255)
    randint (platformx, platformx, platformx2)
    randint (platformy, platformy, platformy2)
    randint (platformx2, platformx, 400)
    randint (platformy2, platformy2, platformy2+50)
    delay (750)
    cls
end loop





-----------------------------------
QuantumPhysics
Thu Nov 08, 2012 9:33 pm

Re: Help with Collision and platform generation in Turing
-----------------------------------
Well I am not sure this will work in turing the same as it does with Allegro and C++, but hell, it should - You can just use if statements by simply saying
if (player >= (platformY2 + 5) && player > platformX1 && player < platformX2){
player = platformY2 + 5;
}

using that format you can make the ball, or player, or whatever you use to move never go beneath the platform (NOTE: It must be in that same order no different)

You set the boundaries for the player. It will not leave the boundaries once it hits the platform, unless the player falls off.

in turing the if statements are if-then format, so you would just write if (player >= (platformY2 + 5) && player > platformX1 && player < platformX2) then

ignore the "{}" they are used in C++ instead of then.

Do you get the explanation? Does it answer your question for the "physics"

RE: Also, be sure to read into View.Update(), by just typing it into the search bar on this forums. In turing it is apparently used to stop the flickering when shapes are drawn over and over again really fast (usually in loops)

-----------------------------------
jr5000pwp
Fri Nov 09, 2012 12:49 am

Re: Help with Collision and platform generation in Turing
-----------------------------------
I'm assuming you are using a rectangle to represent the ball? If so, then it isn't too hard to do collision. The way I would do it would be as such: 

%Set the movement distances to be the maximum the player can move this frame.
var minX : int := moveThisFrameX
var minY : int := moveThisFrameY
%Loop through all your blocks (You can do some more advanced checks to only check possible tile collisions.)
for i : 1 .. rectangles.Count
     %This is the distance to the currently iterated block.
     var distance : int
     %If the player is moving down, you only need to check the top side, if your moving up, you only need to check the bottom.
     if(moveThisFrameY