Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / "Vampire Ball"...need help with collisions?

Author
Message
Confused1612
14
Years of Service
User Offline
Joined: 9th Feb 2012
Location:
Posted: 19th Feb 2012 21:39
For a class we were given some code and asked to make some changes. The changes were:

*Reduce the number of balls
*Make the 1 ball change directions when hit

Changing the number of balls was easy, but I don't know how to do the next one. If I have time, I might also like to tweak some of the other stuff depending on how hard it would be...maybe make the sprite grow instead of steal color and/or change to more original sprites, like maybe an actual vampire looking guy in the place of the original ball and a human in the place of the others. Anyway, here is the code I have (all I have done is change the number of balls from 10 to 5:

The Weeping Corpse
14
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 19th Feb 2012 22:53
I can't test this because the required .BMP files are not on my system, but looking at the code it seems that

ball(n).speedx

and

ball(n).speedy

control the velocity in each direction of ball(n) and so combined together they determine the angle of ball(n) movement.

so, change sprite collision code from

if sprite collision(1, n)
`suck the life out of this poor ball!
ball(n).x = ball(n).x + ball(n).speedx * 2
ball(n).y = ball(n).y + ball(n).speedy * 2

to

if sprite collision(1, n)
` change direction of ball 1 at random
ball(1).speedx = rnd(4) + 2
ball(1).speedy = rnd(4) + 2
`suck the life out of this poor ball!
ball(n).x = ball(n).x + ball(n).speedx * 2
ball(n).y = ball(n).y + ball(n).speedy * 2
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 19th Feb 2012 23:33 Edited at: 19th Feb 2012 23:34
Howdy. The first thing I would have changed, was how the code was laid out.



Don't know if that's how you received it, or if that's how it was copied and pasted, but it is always easier to look and see what the code is doing when it is spaced a little cleaner.

Since you already have code to check whether a ball has gone off the screen in any given direction and change accordingly, you already have the code needed to perform the operation of changing the Vampire's direction when it is hit.

You also have the code needed to check the collision on whether the Vampire is hitting another ball. I added some comments to show where this is all taking place.

This should get you on the right track. Good luck and comment back if you don't get it!

Edit: I don't have the media used ("woodgrain.bmp" and "ball.bmp") So I didn't run the program. But using the logic above, you should be able to get it.

Login to post a reply

Server time is: 2026-07-09 17:42:44
Your offset time is: 2026-07-09 17:42:44