Computer Science Canada help me? how do i get it to stay on the platform that is visible? |
Author: | babacaba [ Fri May 15, 2009 10:55 am ] |
Post subject: | help me? how do i get it to stay on the platform that is visible? |
% credits to the original jump program % some constants, tweak this to your liking var GROUND_HEIGHT := 180 var GROUND_2 := 120 var GROUND := 1 const invisline:= 150 const RUN_SPEED := 5 const JUMP_SPEED := 20 const GRAVITY := 2 var win := Window.Open ("graphics:640;480,offscreenonly") var chars : array char of boolean % player position and velocity var posx, posy : int var velx, vely : real posx := 20 velx := 0 posy := 120 vely := 0 loop Input.KeyDown (chars) if chars ('q') then exit end if % to make the player move if chars (KEY_LEFT_ARROW) then velx := -RUN_SPEED elsif chars (KEY_RIGHT_ARROW) then velx := RUN_SPEED else velx := 0 end if % remember, in order to jump you MUST be on the ground when pressing UP if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT or posy = GROUND_2 then vely := JUMP_SPEED end if % subtract your "gravity" constant from the velocity EACH frame vely -= GRAVITY posx += round (velx) posy += round (vely) % simple "collision" check. just makes sure the player stays above ground if posy < GROUND_2 then posy := GROUND_2 vely := 0 end if if posy = invisline then posy := GROUND_HEIGHT vely := 0 end if % different colours just to illustrate whether or not you may jump if posy = GROUND_HEIGHT then drawfillbox (posx - 10, posy, posx + 10, posy + 20, red) else drawfillbox (posx - 10, posy, posx + 10, posy + 20, green) end if if posy = GROUND_2 then drawfillbox (posx - 10, posy, posx + 10, posy + 20, red) else drawfillbox (posx - 10, posy, posx + 10, posy + 20, green) end if drawline (100, GROUND_HEIGHT, 200, GROUND_HEIGHT, blue) if posy = GROUND then drawfillbox (posx - 10, posy, posx + 10, posy + 20, red) else drawfillbox (posx - 10, posy, posx + 10, posy + 20, green) end if drawline (0, 0, maxx, 0, red) drawline (0, GROUND_2, 100, GROUND_2, blue) drawline (0,invisline,maxx,invisline, white) View.Update delay (25) cls end loop put "YOU LOSE!!!!!" delay (999999999) Window.Close (win) what am i doing wrong? what havnt i done? |
Author: | ecookman [ Wed May 20, 2009 8:40 pm ] |
Post subject: | RE:help me? how do i get it to stay on the platform that is visible? |
i am not quite sure on how you did this, but the simplest way i can see to do this is color each of the boxes and then create a collision using colors, but if you are determined to keep it this way I'm sure there are some tutorials in the help section. I know how to set up collisions in VB6 but not quite sure about Turing...if someone with some knowledge knows if they are similar please let me know, then i will be happy to help you out with your collision problem. (but i think you need ot set a range of where the floor is not the one pixel) |