Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Whatdotcolor collision help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sierius




PostPosted: Sun Nov 16, 2008 2:18 pm   Post subject: Whatdotcolor collision help

code:

View.Set ("graphics:max;max;offscreenonly;nocursor")
const base := 60
const movement := 10
const jump_dis := 25
const gravity := 2
var keyslah : array char of boolean
var tcoins : nat := 0
var jumponly := true
% player position and velocity
var posx := 20
var velx := 0.0
var posy := base
var vely := 0.0


loop
    cls
    Input.KeyDown (keyslah)
    % left and right keyt
    if keyslah (KEY_LEFT_ARROW) and posx - 10 > 0 then
        velx := -movement
    elsif keyslah (KEY_RIGHT_ARROW) and posx + 10 < maxx - 10 then
        velx := movement
    else
        velx := 0
    end if
    %% up key
    if keyslah (KEY_UP_ARROW) and jumponly = true then
        vely := jump_dis
        jumponly := false
    end if
    % subtract your gravity constant from the velocity
    if View.WhatDotColor (posx, posy - 1) not= black then
        vely -= gravity
        posx += round (velx)
        posy += round (vely)
    end if
    % on the ground ?
    if posy < base then
        posy := base
        vely := 0
        jumponly := true
    end if
    if View.WhatDotColor (posx, posy-1) = black then
        vely := 0
        vely += gravity
        jumponly := true
        delay (40)
    end if
    % change if colors if you can't jump
    if jumponly = true then
        drawfillbox (posx , posy, posx + 20, posy + 20, green)
    else
        drawfillbox (posx , posy, posx + 20, posy + 20, 79)
    end if
    % drawing stuff in the background
    Draw.ThickLine (25, 180, 100, 180, 2, black)
    Draw.ThickLine(200, 220, 315, 220, 2, black)
    Draw.ThickLine(450, 240, 575, 240, 2, black)
    Draw.ThickLine(660, 260, 785, 260, 2, black)
    drawline (0, base, maxx, base, 64)
    %% just so I know where posx and posy are
    drawfilloval (posx, posy, 1, 1, 12)
    drawbg
    level_tut_1
    delay (25)
    View.Update
end loop



This is the code of a platformer game I was trying to create.
I first approached by trying to input if any point on the base posx ... poxs + 20 and and posy -1 was the leveled black line then don't move. but I have 4 platforms so that would be a hassle.

I looked a little into whatdotcolor collision and found it should be able to help me.
But what I no understand is how to make it function. I have set a boolean variable called jumponly so you can only jump once again if you are on a platform or the 'base'

However, the square never halted when its above the platform, instead it falls down.

If anyone could tell me what I am doing wrong it would be appreciated ^^
Sponsor
Sponsor
Sponsor
sponsor
DanielG




PostPosted: Sun Nov 16, 2008 2:30 pm   Post subject: RE:Whatdotcolor collision help

doesn't run, missing drawbg and level_tut_i procs
isaiahk9




PostPosted: Sun Nov 16, 2008 2:43 pm   Post subject: RE:Whatdotcolor collision help

@ DanielG : Just comment it out. Although, you don't actually need to see the program running to help sierius.

@ sierius : Before you draw your square in your loop, you have to go something ike this :

If View.WhatDotColor (posx, posy ) = black then
posy += 5
End If

Off the top of my head, that's it.

PS : I'm pretty sure most of that code can be found in that gravity tutorial in the tutorial section. . .
TheGuardian001




PostPosted: Sun Nov 16, 2008 2:48 pm   Post subject: Re: Whatdotcolor collision help

major edit here:

ok, having looked over your code again, I know why it doesn't work. at the start of the loop you clear the screen with cls. then check for collisions. then draw the boxes.

since you cleared the screen, it is now completely white. you then check if you've hit a black pixel, which you haven't, because the screen is white, then you draw.

simply switching the order of these things should make it work properly.
isaiahk9




PostPosted: Sun Nov 16, 2008 3:39 pm   Post subject: RE:Whatdotcolor collision help

TheGaurdian001 makes an excellent point : your amount of pixels you increase in height should equal your gravity decreasing your pixels. But that wasn't his excellent point. it is that : View.WhatDotColor really is not good. I spent hours on my project last year trying to fix failing View.WhatDotColor, and in the end the best choice was to "hard-code" the platforms (make it so that if the user's position is where the platform is, their y variable/x variable increases/decreases). Saving yourself the trouble, in my mind would be avoiding View.WhatDotColor.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: