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

Username:   Password: 
 RegisterRegister   
 Ball Collision Game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
FeZbOy




PostPosted: Tue Mar 08, 2005 12:41 pm   Post subject: Ball Collision Game

I am a fairly new programmer and i need a little help. My program is almost finished, but i need to add a few things. Here is the code...

code:
var x, y : int := 10
var chars : array char of boolean
var cx, dx : int := 30
var cy, dy : int := 30
var score, count : int := 0
var p1health, p2health : int := 20


loop
    dx += 1
    dy += 1
    delay (2)
    View.Set ("offscreenonly")
    cls
    Draw.FillBox (cx, cy, cx + 20, cy + 20, green)
    Draw.FillOval (x, y, 10, 10, red)
    Draw.FillOval (dx, dy, 10, 10, blue)
    View.Update
    Input.KeyDown (chars)

    if x < 15 then
        x += 1
    elsif x > maxx - 15 then
        x -= 1
    elsif y < 15 then
        y += 1
    elsif y > maxy - 15 then
        y -= 1
    else
        if chars (KEY_UP_ARROW) then
            y := y + 2
        elsif chars (KEY_DOWN_ARROW) then
            y := y - 2
        elsif chars (KEY_LEFT_ARROW) then
            x := x - 2
        elsif chars (KEY_RIGHT_ARROW) then
            x := x + 2
        end if
        if cx < 5 then
            cx += 1
        elsif cx > maxx - 25 then
            cx -= 1
        elsif cy < 0 then
            cy += 1
        elsif cy > maxy - 25 then
            cy -= 1
        else
            if chars ('w') then
                cy := cy + 2
            elsif chars ('s') then
                cy := cy - 2
            elsif chars ('a') then
                cx := cx - 2
            elsif chars ('d') then
                cx := cx + 2
            end if


        end if
        if dx + 10 < 0 or dx > maxx then
            dx *= -1
        elsif dy + 10 < 0 or dy > maxy then
            dy *= -1
        end if
    end if

end loop


In this program, I need 2 things:

- When the balls collide, they lose health
and
- The 3 ball, Ball DX, keeps going out off the edge!

Any help will be appreciated!
Thx
P.S. Feel Free to modify this program!
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Tue Mar 08, 2005 12:48 pm   Post subject: (No subject)

var this
code:

var difx, dify : int := 1

then change this
code:

dx += difx
    dy += dify

and this
code:

if dx - 10 <= 0 or dx + 10 >= maxx then
            difx *= -1
        elsif dy - 10 < 0 or dy + 10 >= maxy then
            dify *= -1
        end if
[/code]
FeZbOy




PostPosted: Tue Mar 08, 2005 12:50 pm   Post subject: (No subject)

Thanks Alot!
Martin




PostPosted: Tue Mar 08, 2005 1:23 pm   Post subject: (No subject)

You should really comment your code.
jamonathin




PostPosted: Tue Mar 08, 2005 2:20 pm   Post subject: (No subject)

yeah i should, people always ask me too, it'd save time...
jamonathin




PostPosted: Wed Mar 09, 2005 8:39 am   Post subject: (No subject)

code:

var difx, dify : int := 1 % larger the number, faster the ball, determines how many pixels it goes by (bothx x and y values)

dx += difx
    dy += dify  %adding the difference to the ball variables to make them move

if dx - 10 <= 0 or dx + 10 >= maxx then
            difx *= -1
        elsif dy - 10 < 0 or dy + 10 >= maxy then
            dify *= -1
        end if % if the ball hits a wall, change direction

I hope this helps you out a lil bit if you didn't understand what it ment b4.
FeZbOy




PostPosted: Wed Mar 09, 2005 9:25 pm   Post subject: (No subject)

jamonathin wrote:
I hope this helps you out a lil bit if you didn't understand what it ment b4.


I got it the first time... thaks again ne ways!
jamonathin




PostPosted: Thu Mar 10, 2005 6:43 am   Post subject: (No subject)

np.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: