Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Hockey Game
Author Message
AiR

Posted: Mon Apr 26, 2004 7:42 pm   Post subject: Hockey Game

I've made a hockey game, the problem I am experiencing is that they won't change paths once they hit a wall. They do repetitive bounces.

var row := 50
var column := 300
var row2 := 300
var column2 := 50
var rowChange, columnChange := 1
var rowChange2, columnChange2 := 1
cls
loop

if row = maxx or row = 1 then
rowChange := -rowChange
end if
if column = maxy or column = 1 then
columnChange := -columnChange
end if
cls
drawfilloval (row, column, 8, 8, black)

delay (5)
row := row + rowChange
column := column + columnChange
if row2 = maxx or row2 = 1 then
rowChange := -rowChange
end if
if column2 = maxy or column2 = 1 then
columnChange2 := -columnChange2
end if
cls
drawfilloval (row2, column2, 8, 8, blue)
cls
delay (5)
row2 := row2 + rowChange
column2 := column2 + columnChange
end loop

Paul

Posted: Mon Apr 26, 2004 7:51 pm   Post subject: (No subject)

Why are there 2 pucks?
Why does one pucks path change if the other one's does?
if your talking about bouncing off on different slopes then you need to randomize the increments of x and y, so it will bounce off at a random slope. I don't like the idea though.
Dan

Posted: Tue Apr 27, 2004 10:57 am   Post subject: (No subject)

some sugestions:

1. insted of using = signs in the if staments use > and <, this way if the puck jumps that one number it will still bouch back

2. you are using the same rowchage for puck2 as one alougth you even made a var for rowcahge2 you forgot to use it. you need to update then 2nd set of if stamens and the line where it chages row2s to value with rowchage2.

2. b. same thing with colchage but just for the updating of col2 line

3. it flickers alot, try using view.update and offscreenmode or drwing over just the chages. also just do cls one time per loop no need to deal 2 times and cls 2 times.

here is what the new code could look like:

 code: View.Set("offscreen") var row := 50 var column := 300 var row2 := 300 var column2 := 50 var rowChange, columnChange := 1 var rowChange2, columnChange2 := 1 cls loop     cls     if row > maxx or row < 1 then         rowChange := -rowChange     end if     if column > maxy or column < 1 then         columnChange := -columnChange     end if           drawfilloval (row, column, 8, 8, black)     row := row + rowChange     column := column + columnChange     if row2 > maxx or row2 < 1 then         rowChange2 := -rowChange2     end if     if column2 > maxy or column2 < 1 then         columnChange2 := -columnChange2     end if     drawfilloval (row2, column2, 8, 8, blue)     row2 := row2 + rowChange2     column2 := column2 + columnChange2     View.Update()         delay(20) end loop
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
AiR

Posted: Tue Apr 27, 2004 4:54 pm   Post subject: (No subject)

Actually it works now, two balls are bouncing. But now it's time to make have them start at a certain destination and also when the balls go into a box (net) I would count it as a point. I was thinking of using randint in the beginning have a ball start at a certain point.

Quote:
setscreen ("graphics:450;500")
var row := 20
var column := 200
var row2 := 200
var column2 := 20
var rowChange, columnChange := 5
var rowChange2, columnChange2 := 5
cls
loop
cls
drawbox (10, 10, 440, 490, black)
drawfillbox (175, 40, 275, 70, blue)
drawfillbox (275, 440, 175, 470, red)
drawline (440, 250, 10, 250, red)
drawline (440, 300, 10, 300, blue)
drawline (440, 200, 10, 200, blue)

if row >= maxx-15 or row = 15 then
rowChange := -rowChange
end if
if column >= maxy-15 or column = 15 then
columnChange := -columnChange
end if
if row2 >= maxx-15 or row2 = 15 then
rowChange2 := -rowChange2
end if
if column2 >= maxy-15 or column2 = 15 then
columnChange2 := -columnChange2
end if

drawfilloval (row, column, 5, 5, black)
drawfilloval (row2, column2, 5, 5, blue)
row := row + rowChange
column := column + columnChange
row2 := row2 + rowChange2
column2 := column2 + columnChange2
delay (20)
end loop
Delta

Posted: Tue Apr 27, 2004 5:03 pm   Post subject: (No subject)

why are you using row/column instead of x/y? Row/column are like text based coordinate holders.... ppl get confused when you put them with graphics instead of x/y.... you should try prettying up your code first... just a suggestion....
Dan

Posted: Tue Apr 27, 2004 5:24 pm   Post subject: (No subject)

he is using x and y just calling it row and col. got to read the code there, lol.

for the closion dection on the nets it is just like the ones of the sies but insted of checking btewen 0 and maxy you check btwen two diffren points on the line x = 0 and x = maxx.

u could do somting like make thess points (maxy div 2) + 50 and (maxy div 2) - 50 to get a net of 100 peixles in the midel of the line.

starting the balls in diffren sposts is easy just chage the starting values (or curent values if u whont to reset) of row, row2 , col and col2 to where u whont it to start and set the chage ones to match the velociy you whont.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Delta

Posted: Tue Apr 27, 2004 5:50 pm   Post subject: (No subject)

no no no I knew that... I just meant why not call your variables x and y... because thats what they are really representing... row and column would bring back completely different values (if the thing was done with row and column)
Dan

Posted: Tue Apr 27, 2004 9:08 pm   Post subject: (No subject)

oh sory, i thought u where implying he was aucaly geting the row and col values.

any how u right about that, made me whonder what was going on for a sec as well.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!

AiR

Posted: Wed Apr 28, 2004 8:49 pm   Post subject: (No subject)

I think this will satisfy you enough Delta =) The only additions I need now are when the puck goes into the net it stops, game restarts, and output the score when a goal goes in.. Best out of 3.

Quote:
setscreen ("graphics:450;500")
var y := 440
var x : int
var y2 := 20
var x2 : int
var xChange, yChange := 5
var xChange2, yChange2 := 5
randint (x, 20, maxx)
randint (x2, 20, maxx)

loop
cls
drawbox (10, 10, 440, 490, black)
drawfillbox (175, 40, 275, 70, blue)
drawfillbox (275, 440, 175, 470, red)
drawline (440, 250, 10, 250, red)
drawline (440, 300, 10, 300, blue)
drawline (440, 200, 10, 200, blue)

if x >= maxx - 15 or x <= 15 then
xChange := -xChange
end if
if y >= maxy - 15 or y <= 15 then
yChange := -yChange
end if
if x2 >= maxx - 15 or x2 <= 15 then
xChange2 := -xChange2
end if
if y2 >= maxy - 15 or y2 <= 15 then
yChange2 := -yChange2
end if

drawfilloval (x, y, 5, 5, red)
drawfilloval (x2, y2, 5, 5, blue)
x := x + xChange
y := y + yChange
x2 := x2 + xChange2
y2 := y2 + yChange2
delay (20)
end loop

For the puck to stop or bounce off the net I was thinking of using something like:

Quote:
if x >= 225 and x >= 225 and x = 20 then
xChange := -xChange
end if
if y >= 300 and y <= 775 and y = 275 then
yChange := -yChange
end if

Of course the numbers are wrong I'd have to play with them but would I be on the right path?
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

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