Help with colliding objects in an array
Author |
Message |
huzaifahmian
|
Posted: Tue May 09, 2017 8:47 pm Post subject: Help with colliding objects in an array |
|
|
What is it you are trying to achieve?
i am trying to make a platformer where the user is a ball and the platforms are boxes.
What is the problem you are having?
i cannot seem to figure out code that gets the ball to collide with the boxes. the boxes are randomly generated and their coordinates are stored inside an array
Describe what you have tried to solve this problem
ive tried absolutely everything that i know of
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
var mainArray : array 1.. 32, 1.. 40 of int % Platform Array
var chars : array char of boolean % KeyBoard Key Detection
var jump, slam : boolean := false % Booleans
var ballx, bally, vy, slamy : real := 0 % Real Numbers
var iRadius, iGround : int % Integers
const gravity := 0. 1
iGround := 15
iRadius := 10
ballx := maxx div 2
bally := 100
background (255)
for x: 1.. 32
for y: 1.. 40
% Difficulty
mainArray (x,y ):= Rand.Int (0, 30)
if mainArray (x,y ) = 1 then
% Platforms
drawbox (x* 20, y* 10, x* 20+ 40, y* 10+ 10, red)
end if
end for
end for
proc controller
Input.KeyDown (chars )
% Jump Key Detection
if chars (KEY_UP_ARROW) and jump = false then
jump := true
vy := 5
end if
% Moving Right
if chars (KEY_RIGHT_ARROW) then
ballx + = 3
end if
% Moving Left
if chars (KEY_LEFT_ARROW) then
ballx - = 3
end if
% Slam Key Detection
if chars (KEY_DOWN_ARROW) and slam = false then
slam := true
slamy := 6
end if
% Jump
if jump = true then
bally + = vy
vy - = gravity
if bally <= 15 then
jump := false
end if
end if
% Slam
if slam = true then
bally - = slamy
if bally <= 15 then
slam := false
end if
end if
% Drawing the Player
drawfilloval (round (ballx ), round (bally ), iRadius, iRadius, red)
delay (10)
View.Update
drawfilloval (round (ballx ), round (bally ), iRadius, iRadius, black)
end controller
proc collider
end collider
loop
controller
end loop
|
Please specify what version of Turing you are using
im using the open turing editor on tristan.hume.ca |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|