Platforms
Author |
Message |
TopBypass
|
Posted: Sat Jan 19, 2008 11:51 am Post subject: Platforms |
|
|
Alright i have managed to get my character to jump but now i need him to jump of a platform. How do i go about creating a solid object in my code? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
TokenHerbz
![](http://compsci.ca/v3/uploads/user_avatars/717170395558e628d9452b.jpg)
|
Posted: Sat Jan 19, 2008 11:55 am Post subject: RE:Platforms |
|
|
detection. there are serveral ways, the easier methods would be to use whatdotcolor.
otherwise you can specifically make the detection coding youself, but maybe try whatdotcolor first. |
|
|
|
|
![](images/spacer.gif) |
TopBypass
|
Posted: Sat Jan 19, 2008 12:20 pm Post subject: RE:Platforms |
|
|
thanks soo much ill try it now and see if it works! |
|
|
|
|
![](images/spacer.gif) |
TopBypass
|
Posted: Sat Jan 19, 2008 12:22 pm Post subject: RE:Platforms |
|
|
hmm i dont really see how this would help me... Im using the code from the tutorial " How to jump" |
|
|
|
|
![](images/spacer.gif) |
TokenHerbz
![](http://compsci.ca/v3/uploads/user_avatars/717170395558e628d9452b.jpg)
|
Posted: Sat Jan 19, 2008 12:39 pm Post subject: RE:Platforms |
|
|
Oh, well after looking threw his code, It's not a good code to start using for a platform jumping type of program. As you can test yourself changing his constant variable ground_height changes the line which the box is on.
The idea is great but since you are aiming for different ground heights on your game, this wont work unless you overhauled his code, and its always better to start your code from scratch. |
|
|
|
|
![](images/spacer.gif) |
TopBypass
|
Posted: Sat Jan 19, 2008 12:47 pm Post subject: RE:Platforms |
|
|
Alright thanks for the advice ill take a diff aproach to the game. Thanks again! ( +Karma ) |
|
|
|
|
![](images/spacer.gif) |
BigBear
|
Posted: Mon Mar 10, 2008 9:40 am Post subject: Re: Platforms |
|
|
I do not believe that code needs to be overhauled. Just needs a few more constants and if statements.
First you need to draw a platform so a rectangle using drawfillbox (x1, y1, x2, y2, colour). Then just follow his examples and create if statements. Please follow my comments and compare my version of this program to the original which I would like to thank Mazer.
There is another thread trying to do the same thing and also didn't credit Mazer.
Turing: |
% some constants, tweak this to your liking
const GROUND_HEIGHT := 120
const RUN_SPEED := 10
const JUMP_SPEED := 30
const GRAVITY := 2
%four new constants controlling where your platform is
const BOX_x1 := 170
const BOX_y1 := 170
const BOX_x2 := 300
const BOX_y2 := 200
%end of my revisions
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 := 400
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 then
vely := JUMP_SPEED
end if
%again follow the ubove if statement if the movable box is on the ground then so make it the platform to allow jumping from platform
if chars (KEY_UP_ARROW) and posy = BOX_y2 and posx > BOX_x1 and posx < BOX_x2 then
vely := JUMP_SPEED
end if
%end of my revisions
% 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_HEIGHT then
posy := GROUND_HEIGHT
vely := 0
end if
%so if movable box isn't on the ground and he is in between box then set his y position to the height of the platform
if posy not= GROUND_HEIGHT and posy < BOX_y2 and posx + 10 > BOX_x1 and posx < BOX_x2 then
posy := BOX_y2
vely := 0
end if
%end of my revisions
% different colours just to illustrate whether or not you may jump
if posy = GROUND_HEIGHT then
drawfillbox (posx - 10, posy, posx + 10, posy + 20, green)
%or he is on the platform change colours
elsif posy = BOX_y2 then
drawfillbox (posx - 10, posy, posx + 10, posy + 20, green)
%end of my revisions
else
drawfillbox (posx - 10, posy, posx + 10, posy + 20, red)
end if
%draw the platform
drawfillbox (BOX_x1, BOX_y1, BOX_x2, BOX_y2, 5)
%end of my revisions
drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
View.Update
delay (25)
cls
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
Sean
![](http://compsci.ca/v3/uploads/user_avatars/47413941748406f441f83e.png)
|
Posted: Mon Mar 10, 2008 9:43 am Post subject: Re: Platforms |
|
|
BigBear, once again you are not to give them the code, but are to instruct them.
And you over-comment
What you want to do, is make your boxes, they could be variables, or constants like mentioned above. After doing so, you want to compare these variables with your character position, and have the character stay between the length of the platform, and along the top of the platform. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|