Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
[Tutorial] Calculating Square Boundaries
Author Message
tjmoore1993

Posted: Sat May 09, 2009 12:39 pm   Post subject: [Tutorial] Calculating Square Boundaries

What is collision?
A collision is an isolated event in which two or more bodies (colliding bodies) exert relatively strong forces on each other for a relatively short time.

Why do we need it?
Games and applications without an occasional hit would be boring. Hit? Well most games now are fighting based and when things are hit they would have to respond right? When a programmer programs a game or application they must (not always the case) have to implement a collision detection to make sure if characters or buttons are touched they do what they are suppose to do.

What kind of games or applications?
In Turing specifically we have fighting and shooting kind of games which will need some sort of collision. Applications will normally have buttons either implemented by a GUI or through "Pic.Draw" function which would need a command to make sure the actual object its self is being toggled properly.

Getting started
The easiest way to get started is to grab a picture that isn't so big but roughly around 100x100. This is so that we have enough space to get an output of the important information.

 Turing: var x1, x2, y1, y2 : int var Picture : int := Pic.FileNew ("C:\\Example.bmp") put "Enter in your starting X-Value." get x1 put "Enter in your starting Y-Value." get y1 x2 := Pic.Width (Picture) + x1 y2 := Pic.Height (Picture) + y1 put "X-Left : ", x1 put "X-Right   : ", x2 put "Y-Bottom : ", y1 put "Y-Top   : ", y2

This will help you figure out your boundaries by taking the x1 and y1 and adding it accordingly

Example:
 code: x1 = Left Wall y1 = Bottom Wall Left Wall + Picture's Width = Right Wall Bottom Wall + Picture's Height = Top Wall

In order to test that our values are correct we must setup a statement. There is a problem though we do not want to waste time setting up a crash of some sort so we will use the simple mouse method.

Example:
 Turing: var x1, x2, y1, y2 : int var Picture : int := Pic.FileNew ("C:\\Example.bmp") var x, y, click : int put "Enter in your starting X-Value." get x1 put "Enter in your starting Y-Value." get y1 cls x2 := Pic.Width (Picture) + x1 y2 := Pic.Height (Picture) + y1 View.Set ("offscreenonly") loop     cls     Mouse.Where (x, y, click)     put "Picture Information : "     put "X-Left   : ", x1     put "X-Right  : ", x2     put "Y-Bottom : ", y1     put "Y-Top    : ", y2     put ""     put "Mouse Location : "     put "x     : ", x     put "y     : ", y     put "click : ", click     Pic.Draw (Picture, x1, y1, 0)     if click = 1 then         if x >= x1 and x <= x2 and y >= y1 and y <= y2 then             put "OBJECT CLICKED"         end if     end if     View.Update end loop

That's it for my tutorial if you have any questions feel free to ask!
Sponsor
Sponsor

 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 1 Posts ]
 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: