Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Text collision help
Author Message
Freakish

Posted: Wed Nov 09, 2005 9:41 pm   Post subject: Text collision help

I made alittle program with a bouncing star line
 code: var x, y, nx, ny : int x := 1 y := 1 nx := 1 ny := 1 loop     delay (100)     locate (10,10)     put "0000000000000000000000000000"..     x := x + nx     y := y + ny     if y = 79 then         ny := -1     end if     if y = 1 then         ny := 1     end if     if x = 24 then         nx := -1     end if     if x = 1 then         nx := 1     end if     Text.Locate (x, y)     put "*" ..     end loop

I'm trying to figure out how to get the star to bounce off of another character like 0. so far i haven't been able to find anything on it.

i'm just don't want to do this.
 code: var x, y, nx, ny : int x := 1 y := 1 nx := 1 ny := 1 loop     locate (10, 50)     put "0000000000" ..     delay (100)     x := x + nx     y := y + ny     if y = 79 then         ny := -1     end if     if y = 1 then         ny := 1     end if     if x = 24 then         nx := -1     end if     if x = 1 then         nx := 1     end if     locate (x, y)     put "*" ..     % Top of Walls     if x = 9 and y = 51 then         nx := -1     elsif x = 9 and y = 52 then         nx := -1     elsif x = 9 and y = 53 then         nx := -1     elsif x = 9 and y = 54 then         nx := -1     elsif x = 9 and y = 55 then         nx := -1     elsif x = 9 and y = 56 then         nx := -1     elsif x = 9 and y = 57 then         nx := -1     elsif x = 9 and y = 58 then         nx := -1     elsif x = 9 and y = 59 then         nx := -1     elsif x = 9 and y = 60 then         nx := -1     end if     % Bottem of Walls         if x = 11 and y = 51 then         nx := 1     elsif x = 11 and y = 52 then         nx := 1     elsif x = 11 and y = 53 then         nx := 1     elsif x = 11 and y = 54 then         nx := 1     elsif x = 11 and y = 55 then         nx := 1     elsif x = 11 and y = 56 then         nx := 1     elsif x = 11 and y = 57 then         nx := 1     elsif x = 11 and y = 58 then         nx := 1     elsif x = 11 and y = 59 then         nx := 1     elsif x = 11 and y = 60 then         nx := 1     end if end loop

pavol

Posted: Thu Nov 10, 2005 10:48 am   Post subject: (No subject)

what you can do is use a loop instead of so many if statements
 code: var x, y, nx, ny : int x := 1 y := 1 nx := 1 ny := 1 loop     locate (10, 50)     put "0000000000" ..     delay (100)     x := x + nx     y := y + ny     if y = 79 then         ny := -1     end if     if y = 1 then         ny := 1     end if     if x = 24 then         nx := -1     end if     if x = 1 then         nx := 1     end if     locate (x, y)     put "*" ..     % Top of Walls     for i : 50 .. 60         if x = 9 and y = i then             nx := -1         end if     end for     % Bottom of Walls     for i : 50 .. 60         if x = 11 and y = i then             nx := 1         end if     end for end loop
do_pete

Posted: Thu Nov 10, 2005 11:48 am   Post subject: (No subject)

you can store all the text in an array and use that to chech for collision
Tony

Posted: Thu Nov 10, 2005 11:49 am   Post subject: (No subject)

or use ranges in your if statements
 Turing: % Bottom of Walls         if x = 11 and y >= 50 and y <= 60 then             nx := 1         end if
Freakish

Posted: Thu Nov 10, 2005 11:59 am   Post subject: (No subject)

Thx I think i'll try tony's idea
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

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