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

Username:   Password: 
 RegisterRegister   
 [Tutorial] Collision Detection
Index -> Programming, Turing -> Turing Tutorials
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Bacchus




PostPosted: Sun Jun 05, 2005 6:27 pm   Post subject: (No subject)

Well, then start to program smaller and easier to understand program until your able to program larger more complex ones instead of relying on others to give you the code, because if you just 'mooch' off of other you won't learn anything.
Sponsor
Sponsor
Sponsor
sponsor
Jujeff




PostPosted: Mon May 12, 2008 12:01 pm   Post subject: Re: [Tutorial] Collision Detection

Hello! I'm new to here, and Turing (sort of) so I'm sorry if I appear a noob. I wanted to make a platformer for a school project, so I realized I needed to make my character jump. I found the highly-helpful Mazer Jump Tutorial, copied and pasted (there are some numbers I couldn't figure out the use of), and tweaked it to my needs.

After putting in a platform, I discovered that this messed everything up (the character cannot jump once on a platform), I tried to fix it as best as I could, and added in a boolean variable by recommendation of a friend, however as it is not clear to me the use of this, I will paste the code that I had before the boolean variable.

(The problem of the jumping of the platform, as far as I can see, is that the Yvelocity must be 0 to be able to jump, but the character can only be on the platform if Yvelocity is above the value of "gravity".)

Code:

setscreen ("graphics:1011;699;nobuttonbar;offscreenonly")

% VARIABLES!

var keystroke : array char of boolean

var height : int := 1
var LeftWall : int := 1
var RightWall : int := 1011
var movespeed : int := 10
var jumpspeed : int := 30
var gravity : int := 2

var Xposition, Yposition : int
var Xvelocity, Yvelocity : real

Xposition := 20
Yposition := 400
Xvelocity := 0
Yvelocity := 0

% game loop

loop

Input.KeyDown (keystroke)

% horizontal movement

if keystroke ('a') then
Xvelocity := -movespeed
elsif keystroke ('d') then
Xvelocity := movespeed
else
Xvelocity := 0
end if

% jump movement

if keystroke ('w') and Yposition = height then
Yvelocity := jumpspeed
end if
% world (lines and where you can walk and such)

drawline (0, height, maxx, height, blue)

drawline (245, 146, 384, 146, blue)

% line (if you're on the middle line, stay on it)

if Xposition >= 245 and Xposition <= 384 and Yposition >= 140 then

Yposition := 140
Yvelocity := 10
end if

% reinstate gravity every loop

Yvelocity -= gravity
Xposition += round (Xvelocity)
Yposition += round (Yvelocity)

% don't fall through the ground or go past the edges

if Yposition <= height then
Yposition := height
Yvelocity := 0
end if

if Xposition < LeftWall then
Xposition := 1
end if

if Xposition > RightWall then
Xposition := 1010
end if

% character (square for now)

drawfillbox (Xposition - 10, Yposition, Xposition + 10, Yposition + 20, green)

drawfillbox (Xposition - 10, Yposition, Xposition + 10, Yposition + 20, red)

% animation

View.Update
delay (25)
cls

end loop
Jujeff




PostPosted: Mon May 12, 2008 7:48 pm   Post subject: Re: [Tutorial] Collision Detection

EDIT:::: don't worry, it's been figured out
DaveAngus




PostPosted: Tue May 20, 2008 12:39 pm   Post subject: Re: [Tutorial] Collision Detection

This is great Dan!
Another easy way to detect colour could be

whatdotcolor


you could do something like

code:


 if whatdotcolor (posx + 25, posy) = black then

        % What ever you want inside here

    end if




I think this would work.
Let me know if it wouldnt.

Take care
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 3  [ 34 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: