Computer Science Canada

Collision Problem in Array

Author:  landfarm [ Fri Dec 18, 2009 10:37 pm ]
Post subject:  Collision Problem in Array

What is it you are trying to achieve?
I am trying to create collision detection.


What is the problem you are having?
The problem is that when I put "i" into the collision check, it says it has not been declared yet.


Describe what you have tried to solve this problem
I put a for loop before the collision check, clearly declaring the "i".


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


%General constants
const bottom := 0
const movement := 10
const jump := 35
const grav := 2

%Constants for platforms
const num := 4 %Total number of moving platforms at once
type Platform :
    record
        platx, platy, speed : real
    end record
var platforms : array 1 .. num of Platform

setscreen ("offscreenonly")
var keys : array char of boolean

% player position and velocity
var dx, dy : int
var velx, vely : real
% platform positions
var platx, platy : int

dx := 200
velx := 0
dy := 400
vely := 0
platx := 100
platy := 30
%Randomizes starting locations of moving platforms
for i : 1 .. num
    platforms (i).platx := Rand.Int (0, maxx - 100)
    platforms (i).platy := Rand.Int (20, 350)
    platforms (i).speed := Rand.Int (1, 5)
end for

loop
    Input.KeyDown (keys)
    if keys ('q') then
        exit
    end if

    % to make the player move
    if keys (KEY_LEFT_ARROW) then
        velx := -movement
    elsif keys (KEY_RIGHT_ARROW) then
        velx := movement
    else
        velx := 0
    end if

    if dy <= bottom then
        vely := jump
    end if

    % constantly subtracting gravity from the dy position
    vely -= grav
    dx += round (velx)
    dy += round (vely)

    %Draws platforms
    for i : 1 .. num
        if platforms (i).platx < 0 then
            platforms (i).speed *= -1
        elsif platforms (i).platx + 100 > maxx then
            platforms (i).speed *= -1
        end if
        platforms (i).platx += platforms (i).speed
        drawfillbox (round (platforms (i).platx), round (platforms (i).platy), round (platforms (i).platx + 100), round (platforms (i).platy + 20), blue)
    end for
    % collision check, keeps the player bouncing if they hit the platforms
    if dy < bottom or (dx + 30 < platforms (i).platx + 100 and dx - 30 > platforms (i).platx and dy + 30 < platforms (i).platy + 20 and dy - 10 > platforms (i).platy) then
        dy := bottom
        vely := 0
    end if

    %Draws player
    drawfillbox (dx - 30, dy - 10, dx + 30, dy + 30, green)

    %Draws the bottom, easier to see for testing
    drawline (0, bottom, maxx, bottom, blue)
    View.Update
    delay (30)
    cls
end loop




Please specify what version of Turing you are using
Latest Version.

Author:  Tony [ Fri Dec 18, 2009 10:41 pm ]
Post subject:  RE:Collision Problem in Array

i is local to the score of the for-loop. That is, if it's created inside the for-loop, you can't use it outside. Though in this case, if you want to use the last value of i, you can use "num" instead.

Author:  landfarm [ Sat Dec 19, 2009 12:50 pm ]
Post subject:  Re: Collision Problem in Array

I replaced i with num and now it's working, but the player is not bouncing when it hits the platforms. Is there something wrong with my collision? I'm going to try using WhatDotColour now, but I would still like a clear explanation for my mistake. You guys are the best! Smile

Author:  Tony [ Sat Dec 19, 2009 1:00 pm ]
Post subject:  Re: Collision Problem in Array

I don't really understand why you would check the collision for just one platform, when you have multiple ones.

landfarm @ Sat Dec 19, 2009 12:50 pm wrote:
I would still like a clear explanation for my mistake.

Uhh... perhaps it's...
landfarm @ Sat Dec 19, 2009 12:50 pm wrote:

I'm going to try using WhatDotColour now

Author:  landfarm [ Sat Dec 19, 2009 1:23 pm ]
Post subject:  Re: Collision Problem in Array

Wait, I'm trying to check the collision for all of them, but through the use of the array. I just tried using View.WhatDotColour to check if the points turn blue or not but it does not seem to work either. Here's what I changed.
Turing:

%General constants
const bottom := 0
const movement := 10
const jump := 35
const grav := 2

%Constants for platforms
const num := 4 %Total number of moving platforms at once
type Platform :
    record
        platx, platy, speed : real
    end record
var platforms : array 1 .. num of Platform

setscreen ("offscreenonly")
var keys : array char of boolean

% player position and velocity
var dx, dy : int
var velx, vely : real
% platform positions
var platx, platy : int

dx := 200
velx := 0
dy := 400
vely := 0
platx := 100
platy := 30
%Randomizes starting locations of moving platforms
for i : 1 .. num
    platforms (i).platx := Rand.Int (0, maxx - 100)
    platforms (i).platy := Rand.Int (20, 350)
    platforms (i).speed := Rand.Int (1, 5)
end for

loop
    Input.KeyDown (keys)
    if keys ('q') then
        exit
    end if

    % to make the player move
    if keys (KEY_LEFT_ARROW) then
        velx := -movement
    elsif keys (KEY_RIGHT_ARROW) then
        velx := movement
    else
        velx := 0
    end if
    %The collision check
    if dy <= bottom or (View.WhatDotColour (dx - 20, dy - 15) = 1 and View.WhatDotColour (dx, dy - 15) = 1 and View.WhatDotColour (dx + 20, dy - 15) = 1) or (View.WhatDotColour (dx - 20, dy
            - 15) = 1) then
        vely := jump
    end if

    % constantly subtracting gravity from the dy position
    vely -= grav
    dx += round (velx)
    dy += round (vely)

    %Draws platforms
    for i : 1 .. num
        if platforms (i).platx < 0 then
            platforms (i).speed *= -1
        elsif platforms (i).platx + 100 > maxx then
            platforms (i).speed *= -1
        end if
        platforms (i).platx += platforms (i).speed
        drawfillbox (round (platforms (i).platx), round (platforms (i).platy), round (platforms (i).platx + 100), round (platforms (i).platy + 20), 1)
    end for
    % collision check, keeps the player above the ground
    if dy < bottom then
        vely := 0
    end if

    %Draws player
    drawfillbox (dx - 30, dy - 10, dx + 30, dy + 30, green)
    Draw.ThickLine (dx - 20, dy - 8, dx - 20, dy - 15, 5, black)
    Draw.ThickLine (dx, dy - 8, dx, dy - 15, 5, black)
    Draw.ThickLine (dx + 20, dy - 8, dx + 20, dy - 15, 5, black)

    %Draws the bottom, easier to see for testing
    drawline (0, bottom, maxx, bottom, 1)
    View.Update
    delay (30)
    cls
end loop

Author:  landfarm [ Sat Dec 19, 2009 2:12 pm ]
Post subject:  RE:Collision Problem in Array

Ok, I put the collision check for the platforms inside the for loop like this. The problem is that the player will sometimes drop through the platforms. What can I do to fix this? And I'm sorry from jumping from problem to problem.
Turing:

    %Draws platforms
    for i : 1 .. num
        if platforms (i).platx < 0 then
            platforms (i).speed *= -1
        elsif platforms (i).platx + 100 > maxx then
            platforms (i).speed *= -1
        end if
        platforms (i).platx += platforms (i).speed
        drawfillbox (round (platforms (i).platx), round (platforms (i).platy), round (platforms (i).platx + 100), round (platforms (i).platy + 20), 1)
        %Checks if the player hits any platforms
        if View.WhatDotColour (dx - 20, dy - 15) = 1 or View.WhatDotColour (dx, dy - 15) = 1 or View.WhatDotColour (dx + 20, dy - 15) = 1 or (View.WhatDotColour (dx - 20, dy - 15) = 1 and
            View.WhatDotColour (dx, dy - 15) = 1 and View.WhatDotColour (dx + 20, dy - 15) = 1) then
            vely := jump
        end if
    end for

Author:  Tony [ Sat Dec 19, 2009 2:28 pm ]
Post subject:  RE:Collision Problem in Array

I like how you posted just the relevant part of the code Smile

But... why is that inside a for-loop? And, for bonus points (read as: "required question"), why was the array-based collision outside of for-loop originally?

Author:  TheGuardian001 [ Sat Dec 19, 2009 2:30 pm ]
Post subject:  Re: Collision Problem in Array

My assumption would be that your character is simply moving too fast. When you change the characters position, it doesn't hit every point in between where it was and where it will be. This means if it moves fast enough, your character will pass right by the platform without ever appearing to hit it.

you will either have to limit the characters downward speed, or find a way to check farther below the player if they get above a certain speed.

Author:  landfarm [ Sat Dec 19, 2009 2:55 pm ]
Post subject:  RE:Collision Problem in Array

@ Tony, I just thought if it right now, and it's in the for loop because it doesn't seem to work when it's outside of it. Very strange.
Thanks Guardian, I just made the platforms longer so it shouldn't have that problem.

Author:  Tony [ Sat Dec 19, 2009 4:35 pm ]
Post subject:  RE:Collision Problem in Array

But the if-statement doesn't even rely on the value of i.

Author:  landfarm [ Sun Dec 20, 2009 2:47 pm ]
Post subject:  RE:Collision Problem in Array

I'm not sure, but it doesn't work if it's outside the for loop. Doesn't the i represent each platform though?

Author:  TheGuardian001 [ Sun Dec 20, 2009 3:30 pm ]
Post subject:  Re: Collision Problem in Array

landfarm wrote:

I'm not sure, but it doesn't work if it's outside the for loop. Doesn't the i represent each platform though?

Yes, i does represent that. But you aren't ever using i in your collision detection, since you're using whatdotcolour. The computer doesn't care which block dy-15 belongs to, it just cares if it's blue.

Lets walk through your main loop before you put the collisions inside:

code:

loop start
    check for input
        respond to input
   
    check for colours

    for loop
        draw colours
   
    clear screen
loop end


Can you see anything wrong with where you're checking the colours in relation to where you're drawing the colours?

Author:  landfarm [ Mon Dec 21, 2009 2:59 pm ]
Post subject:  RE:Collision Problem in Array

Oh, I see. The check is before the for loop actually draws them. There shouldn't be a problem though if the boxes are thick enough though? And also, out of a question of laziness, is it okay if I just the colour check inside the for loop?

Author:  TheGuardian001 [ Mon Dec 21, 2009 3:47 pm ]
Post subject:  Re: Collision Problem in Array

landfarm wrote:

Oh, I see. The check is before the for loop actually draws them.

Exactly.
landfarm wrote:

There shouldn't be a problem though if the boxes are thick enough though?

The thickness of the box is irrelevant. if you check before you draw them, there won't be anything to check, regardless of how thick they will be when you actually draw them.
landfarm wrote:

And also, out of a question of laziness, is it okay if I just the colour check inside the for loop?

For the sake of you not getting into bad practices, No, it's not okay. All you need to do is move it outside of the loop, it's really not that much trouble.
Something like this might not present much of a problem in this specific program, but what if you had 10 platforms to draw? what if you had 100? whatdotcolour itself is a relatively costly procedure to call, and if you're calling it repeatedly in a for loop, there's a good chance you'll see some performance issues.

Author:  landfarm [ Tue Dec 22, 2009 9:32 pm ]
Post subject:  Re: Collision Problem in Array

TheGuardian001 @ Sat Dec 19, 2009 2:30 pm wrote:
My assumption would be that your character is simply moving too fast. When you change the characters position, it doesn't hit every point in between where it was and where it will be. This means if it moves fast enough, your character will pass right by the platform without ever appearing to hit it.

you will either have to limit the characters downward speed, or find a way to check farther below the player if they get above a certain speed.

That's why I increased the thickness of the platforms. Thanks for your help though. I'm gonna fix it right now. Smile

Author:  landfarm [ Thu Dec 24, 2009 12:31 pm ]
Post subject:  Re: Collision Problem in Array

Um, I just fixed it up now, and I decided to add a power bar for a superjump. I used the formula, percentage * pixel distance of the starting part of the bar to the end. I read that somewhere here, but I can't find it now. Anyway, first of all, the bar is way too high at the beginning, and then goes below the bottom when it depletes. I'm very confused right now. Can anyone shed some light on this? I wasn't sure if I was supposed to make this another topic because it is a different problem, so I just put it in here. Here is the new code. I'm going to copy and paste the whole thing since it's fairly different from the first one.
Turing:

%General constants
const bottom := -50
const top := maxy - 75
const movement := 17
const jump := 15
const grav := 1
%%%%%%%%%%%%%%%%%%%%%%

%Fonts and options variables
var font2, font4 : int
var answer : string
font2 := Font.New ("serif:12")
assert font2 > 0
font4 := Font.New ("Algerian:20")
assert font4 > 0
%%%%%%%%%%%%%%%%%%%%%%

%Constants for platforms
const bnum := 4 %Total number of moving platforms at once
const gnum := 3 %Total number of still boxes
type Platform :
    record
        bplatx, bplaty, speed : real %Blue platforms (moveable)
        gplatx, gplaty : int %Green platforms (still)
    end record
var platforms : array 1 .. bnum of Platform
var gplatforms : array 1 .. gnum of Platform

%%%%%%%%%%%%%%%%%%%%%%
setscreen ("offscreenonly")
var keys : array char of boolean
%%%%%%%%%%%%%%%%%%%%%%

% player position and velocity
var dx, dy : int
var velx, vely, powery : real
% bottom platform position
var px, py, inc, bplatx, bplaty, gplatx, gplaty : int
% points system and jump power if it fully recharged or not
var points, power : int

dx := 200
velx := 0
dy := 400
vely := 0
bplatx := 100
bplaty := 30
px := 100
py := 10
inc := 2
gplatx := 100
gplaty := 30
power := 250
powery := 250 * power / 250 %The power bar
%%%%%%%%%%%%%%%%%%%%%%

%Randomizes starting locations of moving platforms
for i : 1 .. bnum
    platforms (i).bplatx := Rand.Int (100, maxx - 200)
    platforms (i).bplaty := Rand.Int (20, 350)
    platforms (i).speed := Rand.Int (1, 5)
end for
%%%%%%%%%%%%%%%%%%%%%%

%Randomizes starting locations for still platforms
for ii : 1 .. gnum
    gplatforms (ii).gplatx := Rand.Int (100, maxx - 100)
    gplatforms (ii).gplaty := Rand.Int (20, 300)
end for
%%%%%%%%%%%%%%%%%%%%%%

%Sets up the replay, and return to GUI options.  r : Replay, q : MainMenu
answer := "r"
%%%%%%%%%%%%%%%%%%%%%%

%Instructions for the game
procedure doodlejumpinstructions
    setscreen ("no echo, no cursor")
    locate (1, 20)
    colour (green)
    put "Doodlejump - Turing"
    put skip
    put "Did you ever play Doodlejump on the iPhone or iPod Touch?"
    put "This is a crossover version of it. Although it does not look"
    put "like it, it is basically the same concept. You control the"
    put "green box with 3 legs. All you have to do is keep jumping"
    put "upwards from platform to platform. Everytime the platforms"
    put "go below the screen, you will score 50 points. Unfortunately,"
    put "there are gaps too large for you to jump, which is where the"
    put "superjump comes into play. You have a skill called 'SuperJump'"
    put "which would allow you to jump a lot higher than normal. However,"
    put "it takes time to charge, allowing you only to use it at certain"
    put "times. Have fun and good luck!"
    put "Press any key to continue~"
    View.Update
    Input.Pause
    cls
end doodlejumpinstructions
%Starts the game
procedure doodlejump
    points := 0
    if answer = "r" then
        loop
            Input.KeyDown (keys)
            % to make the player move
            if keys (KEY_LEFT_ARROW) and dx - 30 > 100 then
                velx := -movement
            elsif keys (KEY_RIGHT_ARROW) and dx + 30 < maxx - 100 then
                velx := movement
            elsif keys (KEY_UP_ARROW) and power = 250 then
                vely += 30 %Because jump is a constant, then the extra power must be added to the velocity
                power := 0
            else
                velx := 0
            end if
            %Two side borders
            drawfillbox (0, 0, 100, maxy, black)
            drawfillbox (maxx - 100, 0, maxx, maxy, black)
            %The collision check
            if dy <= bottom then
                vely := jump
            end if
            % constantly subtracting gravity from the dy position
            vely -= grav
            dx += round (velx)
            dy += round (vely)
            %Draws platforms
            for i : 1 .. bnum
                if platforms (i).bplatx < 100 then
                    platforms (i).speed *= -1
                elsif platforms (i).bplatx + 100 > maxx - 100 then
                    platforms (i).speed *= -1
                end if
                platforms (i).bplatx += platforms (i).speed
                drawfillbox (round (platforms (i).bplatx), round (platforms (i).bplaty), round (platforms (i).bplatx + 50), round (platforms (i).bplaty + 50), 1)
                %Checks if the player hits any platforms
                if View.WhatDotColour (dx - 10, dy - 15) = 1 or View.WhatDotColour (dx, dy - 15) = 1 or View.WhatDotColour (dx + 10, dy - 15) = 1 or (View.WhatDotColour (dx - 10, dy - 15) = 1 and
                        View.WhatDotColour (dx, dy - 15) = 1 and View.WhatDotColour (dx + 10, dy - 15) = 1) or View.WhatDotColour (dx - 10, dy - 8) = 1 or View.WhatDotColour (dx, dy - 8) = 1 or
                        View.WhatDotColour (dx + 10, dy
                        - 8) = 1 or (View.WhatDotColour (dx - 10, dy - 8) = 1 and View.WhatDotColour (dx, dy - 8) = 1 and View.WhatDotColour (dx + 10, dy
                        - 8) = 1) then
                    vely := jump
                end if
                %Checks if the player is moving up on the screen
                if dy + 30 >= 300 then
                    platforms (i).bplaty -= grav * 4
                end if
                %Checks if the platforms go below screen, then randomizes them again if they do. Player scores 50 points for every platform that resets
                if platforms (i).bplaty + 50 < 0 then
                    platforms (i).bplatx := Rand.Int (100, maxx - 200)
                    platforms (i).bplaty := Rand.Int (350, maxy + 50)
                    platforms (i).speed := Rand.Int (1, 5)
                    points += 50
                end if
                %Draws bottom blue platform that never leaves the screen
                if px > maxx - 200 then
                    inc *= -1
                elsif px < 100 then
                    inc *= -1
                end if
                px += inc
                drawfillbox (px, py - 30, px + 100, py + 20, 1)
                for ii : 1 .. gnum
                    %Checks if the platforms go below screen, then randomizes them again if they do. Player scores 50 points for every platform that resets
                    if gplatforms (ii).gplaty + 50 < 0 then
                        gplatforms (ii).gplatx := Rand.Int (100, maxx - 200)
                        gplatforms (ii).gplaty := Rand.Int (300, maxy)
                        points += 50
                    end if
                    %Checks if the player is moving up on the screen, moves everything else down
                    if dy + 30 >= 300 then
                        gplatforms (ii).gplaty -= grav * 2
                    end if
                    drawfillbox (gplatforms (ii).gplatx, gplatforms (ii).gplaty, gplatforms (ii).gplatx + 60, gplatforms (ii).gplaty + 50, green)
                end for
            end for
            %Checks if the player hits the green platforms
            if View.WhatDotColour (dx - 10, dy - 15) = green or View.WhatDotColour (dx, dy - 15) = green or View.WhatDotColour (dx + 10, dy - 15) = green or (View.WhatDotColour (dx - 10, dy -
                    15)
                    =
                    green
                    and
                    View.WhatDotColour (dx, dy - 15) = green and View.WhatDotColour (dx + 10, dy - 15) = green) or View.WhatDotColour (dx - 10, dy - 8) = green or View.WhatDotColour (dx, dy -
                    8) =
                    green
                    or
                    View.WhatDotColour (dx + 10, dy
                    - 8) = green or (View.WhatDotColour (dx - 10, dy - 8) = green and View.WhatDotColour (dx, dy - 8) = green and View.WhatDotColour (dx + 10, dy
                    - 8) = green) then
                vely := jump
            end if
            % collision check to see if the player died
            if dy < bottom then
                loop
                    Font.Draw ("Game Over!", 200, 300, font2, red)
                    Font.Draw ("Press any 'q' to return to MainMenu or 'r' to play again.", 130, 270, font2, red)
                    %Randomizes starting locations of moving platforms
                    for i : 1 .. bnum
                        platforms (i).bplatx := Rand.Int (100, maxx - 200)
                        platforms (i).bplaty := Rand.Int (20, 350)
                        platforms (i).speed := Rand.Int (1, 5)
                    end for
                    dx := 200
                    dy := 400
                    %%%%%%%%%%%%%%%%%%%%%%
                    %Randomizes starting locations for still platforms
                    for ii : 1 .. gnum
                        gplatforms (ii).gplatx := Rand.Int (100, maxx - 100)
                        gplatforms (ii).gplaty := Rand.Int (20, 300)
                    end for
                    %%%%%%%%%%%%%%%%%%%%%%
                    put "POINTS: ", points
                    points := 0
                    power := 250
                    View.Update
                    get answer
                    exit when answer = "q" or answer = "r"
                end loop
            end if
            if dy + 20 > top then
                vely := 0
            end if
            %Shows how many points the player has
            put "POINTS: ", points
            put power %ERASE THIS AFTER TESTING
            powery := power * 250 / 100 %The power bar
            Font.Draw ("S", 5, 340, font4, brightred)
            Font.Draw ("U", 5, 310, font4, brightred)
            Font.Draw ("P", 5, 280, font4, brightred)
            Font.Draw ("E", 5, 250, font4, brightred)
            Font.Draw ("R", 5, 220, font4, brightred) %Says SUPERJUMP off to the side
            Font.Draw ("J", 5, 190, font4, brightred)
            Font.Draw ("U", 5, 160, font4, brightred)
            Font.Draw ("M", 5, 130, font4, brightred)
            Font.Draw ("P", 5, 100, font4, brightred)
            drawfillbox (40, 100, 75, 350, red)
            drawfillbox (40, 100, 75, round (powery), yellow)
            %%%%%%%%%%

            %This is the power recharging part
            if power < 250 then
                power += 1
            end if
            %Draws player
            drawfillbox (dx - 20, dy - 10, dx + 20, dy + 10, green)
            Draw.ThickLine (dx - 10, dy - 8, dx - 10, dy - 15, 5, black)
            Draw.ThickLine (dx, dy - 8, dx, dy - 15, 5, black)
            Draw.ThickLine (dx + 10, dy - 8, dx + 10, dy - 15, 5, black)
            exit when answer = "q"
            View.Update
            delay (30)
            cls
        end loop
    end if
end doodlejump
%%%%%%%%%%%%%%%%%%%%%%

%Calls the procedures
doodlejumpinstructions
doodlejump

Author:  TheGuardian001 [ Thu Dec 24, 2009 12:51 pm ]
Post subject:  Re: Collision Problem in Array

Lets start with it being too high up. Now, your power bar maxes out at 250. Normally, you'd have to calculate a percentage and draw based on that. But the height of the graphical power bar is also 250. So you actually don't need to do any calculations at all, since they are both the same size.

Now, as for it going too low, when you draw the yellow bar, you draw it with this:
code:

drawfillbox (40, 100, 75,round (powery), yellow)


you tell the box to draw from a starting height of 100, and to finish at powery with absolutely no relation to the starting height. If you want it to draw a certain amount above the starting height, you'll need to relate the two.

Author:  landfarm [ Thu Dec 24, 2009 1:08 pm ]
Post subject:  RE:Collision Problem in Array

Smile You're the best man! I fixed it now, and the 250 think was a coincidence. I just had to add 100 to the powery. Actually, I could just remove that variable because powery = power.

Author:  landfarm [ Thu Dec 24, 2009 1:21 pm ]
Post subject:  RE:Collision Problem in Array

Wait, I just realized that my collision checks were still inside one of the for loops, so I moved them out. Unfortunately, now it's no longer working. What happened?
Turing:

            for i : 1 .. bnum
                if platforms (i).bplatx < 100 then
                    platforms (i).speed *= -1
                elsif platforms (i).bplatx + 100 > maxx - 100 then
                    platforms (i).speed *= -1
                end if
                platforms (i).bplatx += platforms (i).speed
                drawfillbox (round (platforms (i).bplatx), round (platforms (i).bplaty), round (platforms (i).bplatx + 50), round (platforms (i).bplaty + 50), 1)
                %Checks if the player is moving up on the screen
                if dy + 30 >= 300 then
                    platforms (i).bplaty -= jump div 2
                end if
                %Checks if the platforms go below screen, then randomizes them again if they do. Player scores 50 points for every platform that resets
                if platforms (i).bplaty + 50 < 0 then
                    platforms (i).bplatx := Rand.Int (100, maxx - 200)
                    platforms (i).bplaty := Rand.Int (350, maxy + 50)
                    platforms (i).speed := Rand.Int (1, 5)
                    points += 50
                end if
            end for
            %Draws bottom blue platform that never leaves the screen
            if px > maxx - 200 then
                inc *= -1
            elsif px < 100 then
                inc *= -1
            end if
            px += inc
            drawfillbox (px, py - 30, px + 100, py + 20, 1)
            if points < 4000 then
                for ii : 1 .. gnum
                    %Checks if the platforms go below screen, then randomizes them again if they do. Player scores 50 points for every platform that resets
                    if gplatforms (ii).gplaty + 50 < 0 then
                        gplatforms (ii).gplatx := Rand.Int (100, maxx - 200)
                        gplatforms (ii).gplaty := Rand.Int (300, maxy)
                        points += 50
                    end if
                    %Checks if the player is moving up on the screen, moves everything else down
                    if dy + 30 >= 300 then
                        gplatforms (ii).gplaty -= jump div 2
                    end if
                    drawfillbox (gplatforms (ii).gplatx, gplatforms (ii).gplaty, gplatforms (ii).gplatx + 60, gplatforms (ii).gplaty + 50, green)
                end for
            end if
            % collision check to see if the player died
            if dy < bottom then
                loop
                    Font.Draw ("Game Over!", 200, 300, font2, red)
                    Font.Draw ("Press any 'q' to return to MainMenu or 'r' to play again.", 130, 270, font2, red)
                    %Randomizes starting locations of moving platforms
                    for i : 1 .. bnum
                        platforms (i).bplatx := Rand.Int (100, maxx - 200)
                        platforms (i).bplaty := Rand.Int (20, 350)
                        platforms (i).speed := Rand.Int (1, 5)
                    end for
                    dx := 200
                    dy := 400
                    %%%%%%%%%%%%%%%%%%%%%%
                    %Randomizes starting locations for still platforms
                    for ii : 1 .. gnum
                        gplatforms (ii).gplatx := Rand.Int (100, maxx - 100)
                        gplatforms (ii).gplaty := Rand.Int (20, 300)
                    end for
                    %%%%%%%%%%%%%%%%%%%%%%
                    put "POINTS: ", points
                    points := 0
                    power := 250
                    View.Update
                    get answer
                    exit when answer = "q" or answer = "r"
                end loop
            end if
            if dy + 20 > top then
                vely := 0
            end if
            %Shows how many points the player has
            put "POINTS: ", points
            put power %ERASE THIS AFTER TESTING
            Font.Draw ("S", 5, 340, font4, brightred)
            Font.Draw ("U", 5, 310, font4, brightred)
            Font.Draw ("P", 5, 280, font4, brightred)
            Font.Draw ("E", 5, 250, font4, brightred)
            Font.Draw ("R", 5, 220, font4, brightred) %Says SUPERJUMP off to the side
            Font.Draw ("J", 5, 190, font4, brightred)
            Font.Draw ("U", 5, 160, font4, brightred)
            Font.Draw ("M", 5, 130, font4, brightred)
            Font.Draw ("P", 5, 100, font4, brightred)
            drawfillbox (40, 100, 75, 350, red)
            drawfillbox (40, 100, 75, round (power + 100), yellow)
            %%%%%%%%%%
            %This is the power recharging part
            if power < 250 then
                power += 1
            end if
            %Draws player
            drawfillbox (dx - 20, dy - 10, dx + 20, dy + 10, green)
            Draw.ThickLine (dx - 10, dy - 8, dx - 10, dy - 15, 5, black)
            Draw.ThickLine (dx, dy - 8, dx, dy - 15, 5, black)
            Draw.ThickLine (dx + 10, dy - 8, dx + 10, dy - 15, 5, black)
            %Checks if the player hits the green platforms
            if View.WhatDotColour (dx - 10, dy - 15) = green or View.WhatDotColour (dx, dy - 15) = green or View.WhatDotColour (dx + 10, dy - 15) = green or (View.WhatDotColour (dx - 10, dy -
                    15)
                    =
                    green
                    and
                    View.WhatDotColour (dx, dy - 15) = green and View.WhatDotColour (dx + 10, dy - 15) = green) or View.WhatDotColour (dx - 10, dy - 8) = green or View.WhatDotColour (dx, dy -
                    8) =
                    green
                    or
                    View.WhatDotColour (dx + 10, dy
                    - 8) = green or (View.WhatDotColour (dx - 10, dy - 8) = green and View.WhatDotColour (dx, dy - 8) = green and View.WhatDotColour (dx + 10, dy
                    - 8) = green) then
                vely := jump
            end if
            %Checks if the player hits any blue platforms
            if View.WhatDotColour (dx - 10, dy - 15) = 1 or View.WhatDotColour (dx, dy - 15) = 1 or View.WhatDotColour (dx + 10, dy - 15) = 1 or (View.WhatDotColour (dx - 10, dy - 15) = 1 and
                    View.WhatDotColour (dx, dy - 15) = 1 and View.WhatDotColour (dx + 10, dy - 15) = 1) or View.WhatDotColour (dx - 10, dy - 8) = 1 or View.WhatDotColour (dx, dy - 8) = 1 or
                    View.WhatDotColour (dx + 10, dy
                    - 8) = 1 or (View.WhatDotColour (dx - 10, dy - 8) = 1 and View.WhatDotColour (dx, dy - 8) = 1 and View.WhatDotColour (dx + 10, dy
                    - 8) = 1) then
                vely := jump
            end if
            exit when answer = "q"
            View.Update
            delay (30)
            cls
        end loop

Author:  TheGuardian001 [ Thu Dec 24, 2009 1:32 pm ]
Post subject:  Re: Collision Problem in Array

I could be wrong, but I believe your collision check is hitting the character. Try drawing the character after the hit checks and see if that fixes anything.

Author:  landfarm [ Thu Dec 24, 2009 1:46 pm ]
Post subject:  RE:Collision Problem in Array

Um, I put it at the very bottom, after everything is drawn, including the player. In fact, the drawing of the player is right above the collision checks. This is strange. I'm going to keep them in the for loops for now, since it works. EDIT: Ohh, nvm, I see what you mean. It works now, but there doesn't seem to be any logic in that.

Author:  TheGuardian001 [ Thu Dec 24, 2009 2:10 pm ]
Post subject:  Re: Collision Problem in Array

landfarm wrote:

Um, I put it at the very bottom, after everything is drawn, including the player.

Which is exactly the problem. If your character is drawn, and the detection is looking at the area occupied by one of his legs, it's going to be seeing black, not blue or green, since your character is drawn last and will be on top of everything else.

Author:  landfarm [ Thu Dec 24, 2009 2:14 pm ]
Post subject:  RE:Collision Problem in Array

Oh, I see now. That logic stuff is getting to me. Thanks again.


: