Computer Science Canada

I cant figure out how to make it so that you don't teleport if you jump when your under a platform

Author:  ThePyroManiac [ Tue Mar 08, 2016 1:22 pm ]
Post subject:  I cant figure out how to make it so that you don't teleport if you jump when your under a platform

I cant figure out how to make it so that you don't teleport if you jump when your under a platform



Turing:


const GROUND_HEIGHT := 130
const RUN_SPEED := 10
const JUMP_SPEED := 15
const GRAVITY := 1.5

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_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 : array char of boolean


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
    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) 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 posy = BOX7_y2 and posx > BOX7_x1 and posx < BOX7_x2 then
        vely := JUMP_SPEED
    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


    \
    vely -= GRAVITY
    posx += round (velx)
    posy += round (vely)

   
    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 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
 
    drawfillbox (a1, a2, a3, a4, 79)
    drawfilloval (f1, f2, f3, f4, 0)
    drawfilloval (BOX6_x1, BOX6_y1, BOX6_x2, BOX6_y2, 0)
    drawfilloval (BOX5_x1, BOX5_y1, BOX5_x2, BOX5_y2, 0)
    drawfilloval (BOX4_x1, BOX4_y1, BOX4_x2, BOX4_y2, 0)
    drawfillbox (b1, b2, b3, b4, 10)
    drawfillbox (c1, c2, c3, c4, 67)
    drawfillbox (d1, d2, d3, d4, 65)
    drawfillbox (e1, e2, e3, e4, 65)
   
    if posy = GROUND_HEIGHT then
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
       
    elsif posy = BOX_y2 then
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
       
    else
 
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
    end if




    drawfillbox (BOX_x1, BOX_y1, BOX_x2, BOX_y2, 121)
    drawfillbox (BOX1_x1, BOX1_y1, BOX1_x2, BOX1_y2, 2)
    drawfillbox (BOX3_x1, BOX3_y1, BOX3_x2, BOX3_y2, 138)
    drawfillbox (BOX2_x1, BOX2_y1, BOX2_x2, BOX2_y2, 138)
    drawfillbox (BOX8_x1, BOX8_y1, BOX8_x2, BOX8_y2, 138)
    drawfillbox (BOX7_x1, BOX7_y1, BOX7_x2, BOX7_y2, 14)
    var font1 : int
    font1 := Font.New ("Eras Bold ITC:20:bold")
    Draw.Text ("SUPER JET PACK BROS", 220, 380, font1, red)

    View.Update
    delay (30)
end loop







Please specify what version of Turing you are using
4.1.1

Author:  Insectoid [ 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.

Author:  ThePyroManiac [ 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?

Author:  Insectoid [ 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.

Author:  ThePyroManiac [ 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

Author:  ThePyroManiac [ 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

code:

%BY ISAAC
%version 2.0
%08/03/2016
%Turing 4.1.1

const GROUND_HEIGHT := 130
const RUN_SPEED := 10
const JUMP_SPEED := 17
const GRAVITY := 1.5

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_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


   
    vely -= GRAVITY
    posx += round (velx)
    posy += round (vely)

   
    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
 
    drawfillbox (a1, a2, a3, a4, 79)
    drawfilloval (f1, f2, f3, f4, 0)
    drawfilloval (BOX6_x1, BOX6_y1, BOX6_x2, BOX6_y2, 0)
    drawfilloval (BOX5_x1, BOX5_y1, BOX5_x2, BOX5_y2, 0)
    drawfilloval (BOX4_x1, BOX4_y1, BOX4_x2, BOX4_y2, 0)
    drawfillbox (b1, b2, b3, b4, 10)
    drawfillbox (c1, c2, c3, c4, 67)
    drawfillbox (d1, d2, d3, d4, 65)
    drawfillbox (e1, e2, e3, e4, 65)
   
    if posy = GROUND_HEIGHT then
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
       
   
    else
 
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
    end if



    drawfillbox (BOX_x1, BOX_y1, BOX_x2, BOX_y2, 121)
    drawfillbox (BOX1_x1, BOX1_y1, BOX1_x2, BOX1_y2, 2)
    drawfillbox (BOX3_x1, BOX3_y1, BOX3_x2, BOX3_y2, 138)
    drawfillbox (BOX2_x1, BOX2_y1, BOX2_x2, BOX2_y2, 138)
    drawfillbox (BOX8_x1, BOX8_y1, BOX8_x2, BOX8_y2, 138)
    drawfillbox (BOX7_x1, BOX7_y1, BOX7_x2, BOX7_y2, 14)
    var font1 : int
    font1 := Font.New ("Eras Bold ITC:20:bold")
    Draw.Text ("SUPER JUMP BROS", 220, 380, font1, red)

    View.Update
    delay (30)
end loop


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]

Author:  Dreadnought [ 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.

Turing:
var prime1, prime2, prime3, prime4, prime5 : int
prime1 := 2
prime2 := 3
prime3 := 5
prime4 := 7
prime5 := 11

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 : array 1..5 of int
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 : array 1..5 of int := init(2,3,5,7,11)

for n:1..5
    put "Prime number ", n, " is: ", primes(n)
end for

/* 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).

Author:  ThePyroManiac [ 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

Author:  Dreadnought [ 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.

Author:  ThePyroManiac [ 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. Smile

Author:  ThePyroManiac [ 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
?
Sad

Author:  ThePyroManiac [ 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


code:
%BY ISAAC
%version 2.0
%08/03/2016
%Turing 4.1.1

const GROUND_HEIGHT := 130
const RUN_SPEED := 10
const JUMP_SPEED := 17
const GRAVITY := 1.5

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


   
    vely -= GRAVITY
    posx += round (velx)
    posy += round (vely)

   
    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
   
    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
    drawfillbox (a1, a2, a3, a4, 79)
    drawfilloval (f1, f2, f3, f4, 0)
    drawfilloval (BOX6_x1, BOX6_y1, BOX6_x2, BOX6_y2, 0)
    drawfilloval (BOX5_x1, BOX5_y1, BOX5_x2, BOX5_y2, 0)
    drawfilloval (BOX4_x1, BOX4_y1, BOX4_x2, BOX4_y2, 0)
    drawfillbox (b1, b2, b3, b4, 10)
    drawfillbox (c1, c2, c3, c4, 67)
    drawfillbox (d1, d2, d3, d4, 65)
    drawfillbox (e1, e2, e3, e4, 65)
   
    if posy = GROUND_HEIGHT then
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
       
   
    else
 
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
    end if



    drawfillbox (BOX_x1, BOX_y1, BOX_x2, BOX_y2, 121)
    drawfillbox (BOX1_x1, BOX1_y1, BOX1_x2, BOX1_y2, 2)
    drawfillbox (BOX3_x1, BOX3_y1, BOX3_x2, BOX3_y2, 138)
    drawfillbox (BOX2_x1, BOX2_y1, BOX2_x2, BOX2_y2, 138)
    drawfillbox (BOX8_1, BOX8_2, BOX8_3, BOX8_4, 138)
    drawfillbox (BOX7_1, BOX7_2, BOX7_3, BOX7_4, 14)
   
    Draw.Text ("SUPER JUMP BROS", 220, 380, font1, red)

    View.Update
    delay (30)
end loop



PLEASE help

Author:  Dreadnought [ 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.

Author:  ThePyroManiac [ 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

Author:  Insectoid [ 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

This is the sample Dreadnaught posted:
code:
var prime1, prime2, prime3, prime4, prime5 : int
prime1 := 2
prime2 := 3
prime3 := 5
prime4 := 7
prime5 := 11


This is your code:
code:
var BOX8_1, BOX8_2, BOX8_3, BOX8_4 : int
BOX8_1 := 790
BOX8_2 := 340
BOX8_3 := 890
BOX8_4 := 365


They're pretty much identical, no? So look at how the first example changed to an array, and make the same changes to your code.

Author:  Dreadnought [ Thu Mar 31, 2016 4:12 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

Maybe there is some confusion here. I'm not saying that placing the x1, x2, y1, y2 variables for a box into an array will reduce repeated code.

At the moment you are repeating code when you don't need to. For example:
Turing:

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

% Let's ignore the bouncy box since it behaves a little differently

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

Notice how you basically have the same 3 lines repeated with the only changes being which box you are checking.
What will happen if you add another 5 or 10 or 20 boxes? Will you just copy the lines and slightly modify each one? Well you can do things that way and I won't stop you.
What will happen if you want to modify the behaviour? Will you modify each copy? Again, you can do this and it will work. However, there is a good way to avoid all this repetitive code.

What exactly is it that changes in each group of three lines? It's the box's "number". We would like to tell Turing that it should do the same thing multiple times but use different variables each time. The first time it can use BOX1_x1, BOX1_y1, BOX1_x2 and BOX1_y2. The second it can use BOX2_x1, BOX2_y1, BOX2_x2 and BOX2_y2. And so on.

In this way, the example with the prime numbers was similar. The repetitive code was
Turing:
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

Here we wanted to tell Turing to do the same things multiple times, but use prime1 the first time, prime2 the second time and so on.

So what's the solution? Well, an array is a list of variables with a name for the entire list where we can access the the first, second, third, etc variables in the list with numbers.
In the example I gave, the list was a list of integers called primes and I told it to number the variables 1 to 5 (hence why I used array 1..5 of int). Then I could access the first variable in primes (effectively prime1) by writing primes(1), and similarly for the other variables.
From here, I used a for loop to perform the action (printing "Prime number n is _" once for each variable in the list.

In your case you have many boxes that are already numbered and (as far as I can tell) except for the bouncy box, they are treated the same way by your program. So it might make sense to put the boxes into a list and then use for loops to check collisions and draw boxes for all the boxes in your list. This way, you only write the code once even though it gets used many times.

Now you could make an array for each of x1, y1, x2 and y2. This would still allow to eliminate a lot of repetitive code. However, it might feel a bit unorganized to have a list of x1's, a list of x2's etc. So if you are want to organise your code even more, it would be nice to bundle these together for each box. One way would be to place these into a list of variables with an array (and yes an array of arrays is a like a list of lists of variables). You might not like this because when we replaces names like x_2 or y_2 by numbers like 3 and 4 we are losing the name and making the code harder to understand. If you have the time and want to learn even more new things, you might want to look into record which solves this proble. But understand that there is no problem with using one array for each of the coordinates of the boxes, it's just a bit disorganised.

You probably noticed I ignored the bouncy box. It behaves a little differently from your other boxes, so can can't just have it use the same code as the other boxes. For now I suggest you leave i on its own (unless you want to make other bouncy boxes, in which case you might want to make more arrays.

All that being said, using arrays won't change the functionality of your program. But it will help you write code more efficiently and reduce the likelihood of bugs arising from failing to change all instances of code that is repeated.

Author:  ThePyroManiac [ Fri Apr 01, 2016 8:44 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

ok will do

Author:  ThePyroManiac [ Fri Apr 01, 2016 8:49 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

By the way I just wanted to thank you guys for all you're help. Smile Smile Smile

Author:  ThePyroManiac [ Fri Apr 01, 2016 11:08 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'm going to move onto the collision detection however the Tutorial say

Quote:

In order to use rectangular collision detection, you must have these pieces of information about both of your rectangles :
lowest x value of the rectangle
lowest y value of the rectangle
greatest x value of the rectangle
greatest y value of the rectangle



this is a problem because of two things 1st I only have "posx := 20 posy := 400" and 2nd the
lowest x value of the rectangle
lowest y value of the rectangle
greatest x value of the rectangle
greatest y value of the rectangle
all CHANGE god sake

i mean its probable really simple and im just an idiot but please help

Author:  ThePyroManiac [ Fri Apr 01, 2016 11:11 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

BTW im not giving up on the array im just going to take a break

Author:  Insectoid [ Fri Apr 01, 2016 11:49 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

That's what variables are for. Variables change. You don't personally have to know what the values are, just the computer does. Anywhere you need the lowest x values, just use box1_x1. Same for the others. Almost anywhere you need a number, you can use a variable (and 99% of the time you will use a variable).

Author:  ThePyroManiac [ Fri Apr 01, 2016 12:06 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 had 15 posts and 37 Bits but then i donated 5 to Dreadnought and now i only have 3 posts and 7 bits Sad what happened?

Author:  ThePyroManiac [ Fri Apr 01, 2016 12:07 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

and the position of the character only has 1 x and y

Author:  Dreadnought [ Fri Apr 01, 2016 3: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

ThePyroManiac wrote:

and the position of the character only has 1 x and y

Yes, but but given this x and y you can work out what the other values you need are. (Hint: Look at how you draw your character.)

Author:  ThePyroManiac [ Mon Apr 04, 2016 10:49 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

ok i think i got it
code:
var BOX3_x1 : int := 50
var BOX3_y1 : int := 175
var BOX3_x2 : int := 150
var BOX3_y2 : int := 200
const GROUND_HEIGHT := 10
const RUN_SPEED := 10
const JUMP_SPEED := 17
const GRAVITY := 1.5
var chars : array char of boolean
var ground : boolean := true
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
   
    Input.KeyDown (chars)
    if chars ('x') then
        vely := -GRAVITY
    end if
   
    Input.KeyDown (chars)
    if chars ('j') and posy = GROUND_HEIGHT then
        vely := JUMP_SPEED+20
    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 = BOX3_y2 and posx > BOX3_x1 and posx < BOX3_x2 then
        vely := JUMP_SPEED
    end if
   
   


   
    vely -= GRAVITY
    posx += round (velx)
    posy += round (vely)

   
    if posy < GROUND_HEIGHT then
        posy := GROUND_HEIGHT
        vely := 0
    end if   


    cls
   
    if posy = GROUND_HEIGHT then
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
       
   
    else
 
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
    end if
    drawfillbox (BOX3_x1, BOX3_y1, BOX3_x2, BOX3_y2, 138)
    delay (20)

    if posx + 10 > BOX3_x1 and posx - 10 < BOX3_x2 and posy + 20 > BOX3_y1 and posy < BOX3_y2 then
       posy := BOX3_y2
        vely := 0
       
     end if
end loop

this is just a test but it works so im happy

Author:  ThePyroManiac [ Mon Apr 04, 2016 11:29 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 DID IT!!
THANKS FOR ALL THE HELP
code:
%BY ISAAC
%version 2.0
%08/03/2016
%Turing 4.1.1

%Special thanks to Insectoid and Dreadnought
%for all the help on compsci.ca

const GROUND_HEIGHT := 130
const RUN_SPEED := 10
const JUMP_SPEED := 15
const GRAVITY := 1.7

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 := 250
var BOX3_x2 : int := 200
var BOX3_y2 : int := 275
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


View.Set ("graphics:1260;480,nobuttonbar")

var chars : array char of boolean


var posx, posy : int
var velx, vely : real


posx := 20
velx := 0
posy := 400
vely := 0
loop
Draw.Text ("", 220, 380, font1, red)

    Input.KeyDown (chars)
    if chars ('q') then
        exit
    end if
   
    Input.KeyDown (chars)
    if chars ('x') then
        vely := -GRAVITY
    end if
   
    Input.KeyDown (chars)
    if chars ('j') and posy = GROUND_HEIGHT then
        vely := JUMP_SPEED+20
    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+5
    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


   
    vely -= GRAVITY
    posx += round (velx)
    posy += round (vely)

   
    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 + 10 > BOX2_x1 and posx - 10 < BOX2_x2 and posy + 20 > BOX2_y1 and posy < BOX2_y2 then
       posy := BOX2_y2
        vely := 0
    end if
    if posx + 10 > BOX8_1 and posx - 10 < BOX8_3 and posy + 20 > BOX8_2 and posy < BOX8_4 then
       posy := BOX8_4
        vely := 0
    end if
   
   

      if posx + 10 > BOX7_1 and posx - 10 < BOX7_3 and posy + 20 > BOX7_2 and posy < BOX7_4 then
       posy := BOX7_4
        vely := 0
    end if
   
    if posx + 10 > BOX3_x1 and posx - 10 < BOX3_x2 and posy + 20 > BOX3_y1 and posy < BOX3_y2 then
       posy := BOX3_y2
        vely := 0
    end if
    drawfillbox (a1, a2, a3, a4, 79)
    drawfilloval (f1, f2, f3, f4, 0)
    drawfilloval (BOX6_x1, BOX6_y1, BOX6_x2, BOX6_y2, 0)
    drawfilloval (BOX5_x1, BOX5_y1, BOX5_x2, BOX5_y2, 0)
    drawfilloval (BOX4_x1, BOX4_y1, BOX4_x2, BOX4_y2, 0)
    drawfillbox (b1, b2, b3, b4, 10)
    drawfillbox (c1, c2, c3, c4, 67)
    drawfillbox (d1, d2, d3, d4, 65)
    drawfillbox (e1, e2, e3, e4, 65)
   
    if posy = GROUND_HEIGHT then
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
       
   
    else
 
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, 40)
    end if



    drawfillbox (BOX_x1, BOX_y1, BOX_x2, BOX_y2, 121)
    drawfillbox (BOX1_x1, BOX1_y1, BOX1_x2, BOX1_y2, 2)
    drawfillbox (BOX3_x1, BOX3_y1, BOX3_x2, BOX3_y2, 138)
    drawfillbox (BOX2_x1, BOX2_y1, BOX2_x2, BOX2_y2, 138)
    drawfillbox (BOX8_1, BOX8_2, BOX8_3, BOX8_4, 138)
    drawfillbox (BOX7_1, BOX7_2, BOX7_3, BOX7_4, 14)
   
    Draw.Text ("SUPER JUMP BROS", 220, 380, font1, red)

    View.Update
    delay (30)
end loop

Now all I need is a goal for the game.
any suggestions
there are no bad ideas


: