var BOX_x1 :int:=500 var BOX_y1 :int:=128 var BOX_x2 :int:=550 var BOX_y2 :int:=175 var BOX1_x1 :int:=493 var BOX1_y1 :int:=175 var BOX1_x2 :int:=556 var BOX1_y2 :int:=185 var BOX2_x1 :int:=350 var BOX2_y1 :int:=275 var BOX2_x2 :int:=450 var BOX2_y2 :int:=300 var BOX3_x1 :int:=100 var BOX3_y1 :int:=225 var BOX3_x2 :int:=200 var BOX3_y2 :int:=250 var BOX4_x1 :int:=5 var BOX4_y1 :int:=300 var BOX4_x2 :int:=85 var BOX4_y2 :int:=20 var BOX5_x1 :int:=245 var BOX5_y1 :int:=250 var BOX5_x2 :int:=85 var BOX5_y2 :int:=20 var BOX6_x1 :int:=500 var BOX6_y1 :int:=350 var BOX6_x2 :int:=85 var BOX6_y2 :int:=20 var a1 :int:=1366 var a2 :int:=130 var a3 :int:=0 var a4 :int:=1000 var b1 :int:=1366 var b2 :int:=130 var b3 :int:=0 var b4 :int:=110 var c1 :int:=1366 var c2 :int:=109 var c3 :int:=0 var c4 :int:=0 var d1 :int:=1366 var d2 :int:=90 var d3 :int:=0 var d4 :int:=80 var e1 :int:=1366 var e2 :int:=60 var e3 :int:=0 var e4 :int:=50 var f1 :int:=500 var f2 :int:=550 var f3 :int:=85 var f4 :int:=20 var BOX7_x1 :int:=600 var BOX7_y1 :int:=225 var BOX7_x2 :int:=700 var BOX7_y2 :int:=250 var BOX8_x1 :int:=800 var BOX8_y1 :int:=350 var BOX8_x2 :int:=900 var BOX8_y2 :int:=375
var win :=Window.Open("graphics:1024;480") var chars :arraycharofboolean
var posx, posy :int var velx, vely :real
var health :real:=100 var damage :int:=1 var HPup :real:=1 var HPleft :real:=100 var HPminus :int:=1 var HPgain :real:=0.01 var changeX :int:=5
posx :=20
velx :=0
posy :=400
vely :=0 loop Input.KeyDown(chars) if chars ('q')then exit endif
if chars (KEY_LEFT_ARROW)then
velx := -RUN_SPEED
elsif chars (KEY_RIGHT_ARROW)then
velx := RUN_SPEED
else
velx :=0 endif
if posy = GROUND_HEIGHT then
ground :=true else
ground :=false endif if chars (KEY_UP_ARROW)then
vely := JUMP_SPEED
endif
if chars (KEY_UP_ARROW)and posy = BOX_y2 and posx > BOX_x1 and posx < BOX_x2 then
vely := JUMP_SPEED
endif
if posy = BOX7_y2 and posx > BOX7_x1 and posx < BOX7_x2 then
vely := JUMP_SPEED
endif
if chars (KEY_UP_ARROW)and posy = BOX1_y2 and posx > BOX1_x1 and posx < BOX1_x2 then
vely := JUMP_SPEED
endif
if chars (KEY_UP_ARROW)and posy = BOX2_y2 and posx > BOX2_x1 and posx < BOX2_x2 then
vely := JUMP_SPEED
endif
Please specify what version of Turing you are using
4.1.1
Sponsor Sponsor
Insectoid
Posted: Tue Mar 08, 2016 2:43 pm Post subject: RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform
First of all, you can put all of your platform coordinates into an array and loop over it to check for collisions/whatever. That should clean up your code quite a bit and make it easier to debug. If you treat the ground as one big platform, then you can eliminate all code that deals with the ground, which will simplify it even more.
ThePyroManiac
Posted: Tue Mar 08, 2016 7:51 pm Post subject: Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform
so how would i put the concordats in an array and how do i check for collisions?
Insectoid
Posted: Wed Mar 09, 2016 3:46 pm Post subject: RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform
I apologize; I accidentally submitted my post early, and while editing it, the power went out in my town. It didn't come back on for twelve hours!
Look up arrays in the Turing Walkthrough. They are incredibly useful and you'll see why in a minute.
Look at this line:
code:
if posy not= GROUND_HEIGHT and posy < BOX3_y2 and posx + 10 > BOX3_x1 and posx < BOX3_x2 then
posy := BOX3_y2
vely := 0
end if
In english, this says 'If the player is above the ground and below the platform, move the player on top of the platform'.
This is the line that's causing you to teleport when you jump. If you jump underneath the platform, then you are above the ground and below the platform, which satisfies that if statement.
I take it you want the player to move on top of the platform if he is inside of it, not just below it. You can check if the player is inside the platform using rectangular collision detection. You can find a tutorial about this in the Turing Walkthrough.
Now, you have this same section of code repeated almost exactly five times in your program, which means you need to fix it five times. If you move all your platforms to an array, you can put this code inside a for loop and it will check all of the platforms, but you only need to write the code once. This also makes it really, really easy to add more platforms. Try to get just one platform working properly before you bother with arrays though, or you'll just give yourself a headache.
ThePyroManiac
Posted: Wed Mar 09, 2016 4:43 pm Post subject: RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform
Thank you for you help and i'm sorry to hear about the power
ThePyroManiac
Posted: Wed Mar 23, 2016 7:50 pm Post subject: Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform
var BOX_x1 : int := 500
var BOX_y1 : int := 128
var BOX_x2 : int := 550
var BOX_y2 : int := 175
var BOX1_x1 : int := 493
var BOX1_y1 : int := 175
var BOX1_x2 : int := 556
var BOX1_y2 : int := 185
var BOX2_x1 : int := 350
var BOX2_y1 : int := 275
var BOX2_x2 : int := 450
var BOX2_y2 : int := 300
var BOX3_x1 : int := 100
var BOX3_y1 : int := 225
var BOX3_x2 : int := 200
var BOX3_y2 : int := 250
var BOX4_x1 : int := 5
var BOX4_y1 : int := 300
var BOX4_x2 : int := 85
var BOX4_y2 : int := 20
var BOX5_x1 : int := 245
var BOX5_y1 : int := 250
var BOX5_x2 : int := 85
var BOX5_y2 : int := 20
var BOX6_x1 : int := 500
var BOX6_y1 : int := 350
var BOX6_x2 : int := 85
var BOX6_y2 : int := 20
var a1 : int := 1366
var a2 : int := 130
var a3 : int := 0
var a4 : int := 1000
var b1 : int := 1366
var b2 : int := 130
var b3 : int := 0
var b4 : int := 110
var c1 : int := 1366
var c2 : int := 109
var c3 : int := 0
var c4 : int := 0
var d1 : int := 1366
var d2 : int := 90
var d3 : int := 0
var d4 : int := 80
var e1 : int := 1366
var e2 : int := 60
var e3 : int := 0
var e4 : int := 50
var f1 : int := 500
var f2 : int := 550
var f3 : int := 85
var f4 : int := 20
var BOX7_x1 : int := 600
var BOX7_y1 : int := 225
var BOX7_x2 : int := 700
var BOX7_y2 : int := 250
var BOX8_x1 : int := 790
var BOX8_y1 : int := 340
var BOX8_x2 : int := 890
var BOX8_y2 : int := 365
var win := Window.Open ("graphics:1024;480")
var chars : array char of boolean
var posx, posy : int
var velx, vely : real
posx := 20
velx := 0
posy := 400
vely := 0
loop
Input.KeyDown (chars)
if chars ('q') then
exit
end if
if chars (KEY_LEFT_ARROW) then
velx := -RUN_SPEED
elsif chars (KEY_RIGHT_ARROW) then
velx := RUN_SPEED
else
velx := 0
end if
if posy = GROUND_HEIGHT then
ground := true
else
ground := false
end if
if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT then
vely := JUMP_SPEED
end if
if chars (KEY_UP_ARROW) and posy = BOX_y2 and posx > BOX_x1 and posx < BOX_x2 then
vely := JUMP_SPEED
end if
if chars (KEY_UP_ARROW) and posy = BOX3_y2 and posx > BOX3_x1 and posx < BOX3_x2 then
vely := JUMP_SPEED
end if
if chars (KEY_UP_ARROW) and posy = BOX8_y2 and posx > BOX8_x1 and posx < BOX8_x2 then
vely := JUMP_SPEED
end if
if chars (KEY_UP_ARROW) and posy = BOX2_y2 and posx > BOX2_x1 and posx < BOX2_x2 then
vely := JUMP_SPEED
end if
if posy = BOX7_y2 and posx > BOX7_x1 and posx < BOX7_x2 then
vely := JUMP_SPEED+2
end if
if chars (KEY_UP_ARROW) and posy = BOX1_y2 and posx > BOX1_x1 and posx < BOX1_x2 then
vely := JUMP_SPEED
end if
if chars (KEY_UP_ARROW) and posy = BOX2_y2 and posx > BOX2_x1 and posx < BOX2_x2 then
vely := JUMP_SPEED
end if
if posy < GROUND_HEIGHT then
posy := GROUND_HEIGHT
vely := 0
end if
if posy not= GROUND_HEIGHT and posy < BOX1_y2 and posx + 10 > BOX1_x1 and posx < BOX1_x2 then
posy := BOX1_y2
vely := 0
end if
if posx > BOX3_x1 and BOX1_x1 < BOX2_x2 and BOX1_y2 > BOX2_y1 and BOX1_y1 < BOX2_y2 then
put ""
end if
if posy not= GROUND_HEIGHT and posy < BOX2_y2 and posx + 10 > BOX2_x1 and posx < BOX2_x2 then
posy := BOX2_y2
vely := 0
end if
if posy not= GROUND_HEIGHT and posy < BOX8_y2 and posx + 10 > BOX8_x1 and posx < BOX8_x2 then
posy := BOX8_y2
vely := 0
end if
if posy not= GROUND_HEIGHT and posy < BOX7_y2 and posx + 10 > BOX7_x1 and posx < BOX7_x2 then
posy := BOX7_y2
vely := 0
end if
if posy not= GROUND_HEIGHT and posy < BOX3_y2 and posx + 10 > BOX3_x1 and posx < BOX3_x2 then
posy := BOX3_y2
vely := 0
end if
I refined the code but couldn't figure out the tutorial. i don't want to sound rude but if you have time could you show me how you would put the coordinates in an array and the collision detection when the cube only has two coordinates "posx and posy". don't worry about it if you don't have time.[/code]
Dreadnought
Posted: Thu Mar 24, 2016 1:43 pm Post subject: Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform
The tutorial on arrays is decent, what you want is to convert the code in the section called "Problem 1" to the code in the section called "Problem 2". Here's a simpler example of how its done with an intermediate step.
put"Prime number 1 is: ", prime1
put"Prime number 2 is: ", prime2
put"Prime number 3 is: ", prime3
put"Prime number 4 is: ", prime4
put"Prime number 5 is: ", prime5
It works, but its ugly and will only get uglier if I decide to do it for the first 20 primes. So let's put every thing into an array
Turing:
var primes :array1..5ofint
primes(1):=2
primes(2):=3
primes(3):=5
primes(4):=7
primes(5):=11
put"Prime number 1 is: ", primes(1) put"Prime number 2 is: ", primes(2) put"Prime number 3 is: ", primes(3) put"Prime number 4 is: ", primes(4) put"Prime number 5 is: ", primes(5)
Aaaaaand it looks just as ugly. But that's okay because we can now shorten it like so
Turing:
var primes :array1..5ofint:=init(2,3,5,7,11)
for n:1..5 put"Prime number ", n, " is: ", primes(n) endfor
/* Note: good coding practices say:
1- Use a constant (perhaps called NUM_PRIMES) instead of 5
2- Use const instead of var since the values in the array will not change */
This is much nicer and can easily be scaled to many more primes.
Hopefully this helps you see how arrays and loops are an effective way of removing repetitive code.
In your case, you actually have variables that are related (i.e. BOX_x1, BOX_y1, BOX_x2 and BOX_y2 go together). One way of putting variables together is to use arrays of arrays, but a better way is to use records (you should read the tutorial on records).
ThePyroManiac
Posted: Wed Mar 30, 2016 12:34 pm Post subject: Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform
Could you show me how i would make an array
by demonstrate an array with this code
code:
var BOX8_x1 : int := 790
var BOX8_y1 : int := 340
var BOX8_x2 : int := 890
var BOX8_y2 : int := 365
Sponsor Sponsor
Dreadnought
Posted: Wed Mar 30, 2016 2:56 pm Post subject: Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform
ThePyroManiac wrote:
Could you show me how i would make an array
by demonstrate an array with this code
code:
var BOX8_x1 : int := 790
var BOX8_y1 : int := 340
var BOX8_x2 : int := 890
var BOX8_y2 : int := 365
What have you tried so far? You should try it on your own and see how far you get. If you run into issues we'll be happy to help.
As I mentioned, the best solution is to put all the information for a box into a record. Then if you want the same behaviour for many boxes you can put their records into an array to reduce repetitive code.
ThePyroManiac
Posted: Thu Mar 31, 2016 11:43 am Post subject: RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform
i do not under stand how i would wright the array it would really help if you could demonstrate an array
with BOX8 i dont want you to do them all i just want you to show me how to do it.
ThePyroManiac
Posted: Thu Mar 31, 2016 11:53 am Post subject: Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform
code:
var win := Window.Open ("graphics:1024;480")
var BOX8 : array 1..5 of int
BOX8(1) := 790
BOX8(2) := 340
BOX8(3) := 890
BOX8(4) := 365
drawfillbox (BOX8, BOX8, BOX8, BOX8, 138
this is what I've got so far but it doesn't work
?
ThePyroManiac
Posted: Thu Mar 31, 2016 12:45 pm Post subject: Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform
ok so i get how to make an array but now i dont get the collisions
var font1 : int
font1 := Font.New ("Eras Bold ITC:20:bold")
var font2 : int
font2 := Font.New ("Eras Bold ITC:10:bold")
var ground : boolean := true
var BOX_x1 : int := 500
var BOX_y1 : int := 128
var BOX_x2 : int := 550
var BOX_y2 : int := 175
var BOX1_x1 : int := 493
var BOX1_y1 : int := 175
var BOX1_x2 : int := 556
var BOX1_y2 : int := 185
var BOX2_x1 : int := 350
var BOX2_y1 : int := 275
var BOX2_x2 : int := 450
var BOX2_y2 : int := 300
var BOX3_x1 : int := 100
var BOX3_y1 : int := 225
var BOX3_x2 : int := 200
var BOX3_y2 : int := 250
var BOX4_x1 : int := 5
var BOX4_y1 : int := 300
var BOX4_x2 : int := 85
var BOX4_y2 : int := 20
var BOX5_x1 : int := 245
var BOX5_y1 : int := 250
var BOX5_x2 : int := 85
var BOX5_y2 : int := 20
var BOX6_x1 : int := 500
var BOX6_y1 : int := 350
var BOX6_x2 : int := 85
var BOX6_y2 : int := 20
var a1 : int := 1366
var a2 : int := 130
var a3 : int := 0
var a4 : int := 1000
var b1 : int := 1366
var b2 : int := 130
var b3 : int := 0
var b4 : int := 110
var c1 : int := 1366
var c2 : int := 109
var c3 : int := 0
var c4 : int := 0
var d1 : int := 1366
var d2 : int := 90
var d3 : int := 0
var d4 : int := 80
var e1 : int := 1366
var e2 : int := 60
var e3 : int := 0
var e4 : int := 50
var f1 : int := 500
var f2 : int := 550
var f3 : int := 85
var f4 : int := 20
var BOX7_1, BOX7_2, BOX7_3, BOX7_4 : int
BOX7_1 := 600
BOX7_2 := 225
BOX7_3 := 700
BOX7_4 := 250
var BOX8_1, BOX8_2, BOX8_3, BOX8_4 : int
BOX8_1 := 790
BOX8_2 := 340
BOX8_3 := 890
BOX8_4 := 365
var win := Window.Open ("graphics:1024;480")
var chars : array char of boolean
var posx, posy : int
var velx, vely : real
posx := 20
velx := 0
posy := 400
vely := 0
loop
Input.KeyDown (chars)
if chars ('q') then
exit
end if
Draw.Text ("GIVE ISAAC AN A+", 20, 20, font2, red)
if chars (KEY_LEFT_ARROW) then
velx := -RUN_SPEED
elsif chars (KEY_RIGHT_ARROW) then
velx := RUN_SPEED
else
velx := 0
end if
if posy = GROUND_HEIGHT then
ground := true
else
ground := false
end if
if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT then
vely := JUMP_SPEED
end if
if chars (KEY_UP_ARROW) and posy = BOX_y2 and posx > BOX_x1 and posx < BOX_x2 then
vely := JUMP_SPEED
end if
if chars (KEY_UP_ARROW) and posy = BOX3_y2 and posx > BOX3_x1 and posx < BOX3_x2 then
vely := JUMP_SPEED
end if
if chars (KEY_UP_ARROW) and posy = BOX8_4 and posx > BOX8_1 and posx < BOX8_3 then
vely := JUMP_SPEED
end if
if chars (KEY_UP_ARROW) and posy = BOX2_y2 and posx > BOX2_x1 and posx < BOX2_x2 then
vely := JUMP_SPEED
end if
if posy = BOX7_4 and posx > BOX7_1 and posx < BOX7_3 then
vely := JUMP_SPEED+2
end if
if chars (KEY_UP_ARROW) and posy = BOX1_y2 and posx > BOX1_x1 and posx < BOX1_x2 then
vely := JUMP_SPEED
end if
if chars (KEY_UP_ARROW) and posy = BOX2_y2 and posx > BOX2_x1 and posx < BOX2_x2 then
vely := JUMP_SPEED
end if
if posy < GROUND_HEIGHT then
posy := GROUND_HEIGHT
vely := 0
end if
if posy not= GROUND_HEIGHT and posy < BOX1_y2 and posx + 10 > BOX1_x1 and posx < BOX1_x2 then
posy := BOX1_y2
vely := 0
end if
if posx > BOX3_x1 and BOX1_x1 < BOX2_x2 and BOX1_y2 > BOX2_y1 and BOX1_y1 < BOX2_y2 then
put ""
end if
if posy not= GROUND_HEIGHT and posy < BOX2_y2 and posx + 10 > BOX2_x1 and posx < BOX2_x2 then
posy := BOX2_y2
vely := 0
end if
if posy not= GROUND_HEIGHT and posy < BOX8_4 and posx + 10 > BOX8_1 and posx < BOX8_3 then
posy := BOX8_4
vely := 0
end if
if posy not= GROUND_HEIGHT and posy < BOX7_4 and posx + 10 > BOX7_1 and posx < BOX7_3 then
posy := BOX7_4
vely := 0
end if
Posted: Thu Mar 31, 2016 1:23 pm Post subject: Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform
It looks like you renamed some variables, but I don't see an array. As for the collision problems, Insectoid already explained what your issue is.
Also, the collision problems are not related to using or not using arrays. We are simply suggesting that you use arrays to cut down on repetitive code.
ThePyroManiac
Posted: Thu Mar 31, 2016 1:59 pm Post subject: Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform
so how do i apply this code
code:
var primes : array 1..5 of int := init(2,3,5,7,11)
for n:1..5
put "Prime number ", n, " is: ", primes(n)
end for
to this
code:
var BOX8_1, BOX8_2, BOX8_3, BOX8_4 : int
BOX8_1 := 790
BOX8_2 := 340
BOX8_3 := 890
BOX8_4 := 365
Insectoid
Posted: Thu Mar 31, 2016 3:35 pm Post subject: RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform