Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
[Tutorial] Collision Detection
Author Message
Bacchus

Posted: 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.

Jujeff

Posted: 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

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

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

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 3 of 3  [ 34 Posts ]
Goto page Previous  1, 2, 3
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: