Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   Works-In-Progress (http://www.alice.org/community/forumdisplay.php?f=14)
-   -   Pool Game (http://www.alice.org/community/showthread.php?t=7702)

davidghemer 11-30-2011 10:53 PM

Pool Game
 
2 Attachment(s)
I decided for some crazy reason to have a go at developing a pool game.

Not too sure how far I will get, but I've attached the first stage. At this stage I can aim the cue and adjust the amount of power on the shot. I've also implemented collision detection on the one ball (other balls hidden for now).

For the next stage I will introduce collision detection for the cushions.

Feel free to use and modify.

#################################################
# EDIT -
# Click on the PoolGame_LATEST.a2w attachment for the latest version
#
# Instructions
# -----------
# Down arrow to pull the cue back (increase power).
# Power is discrete so press the button once to increase power by one
# Up arrow to decrease power
# Left and right arrows to aim the cue ball
# Space to complete a shot
# Restart the game if the yellow ball is pocketed.
#################################################

davidghemer 12-01-2011 02:01 AM

Stage 2: bounce off cushions
 
1 Attachment(s)
I've updated the code so that balls will now bounce off of the cushions using dummy objects as markers.

Also when the cue ball hits the one ball they move in fairly realistic manner - not perfect but you can plan straight shots or cut shots if you clip the ball.

Still thinking about how to bounce the balls off the cushions in a reasonable way. I need to know the angle that the ball hits the cushion at, but not sure on this right now. Any ideas would be welcome.

arty-fishL 12-01-2011 04:41 AM

This is quite ambitious, not just for somebody who is fairly new to the forums, but for anybody. So far it is very good, I'm looking forward to the finished game. At first I couldn't work out the controls, but I worked them out eventually.

What I will suggest is to change the style of the left/right turning of the cue to abruptly. I made a [URL="http://www.alice.org/community/showthread.php?t=7173"]compass[/URL], you could use elements of it to get the angle of the balls.

davidghemer 12-01-2011 04:53 AM

Stage 3: pocketing balls
 
1 Attachment(s)
Ok last update for the day. I've added support for pocketing of balls using circles as dummy markers for the pockets. It seems to work fairly well - slight adjustments of the dummy markers may be needed.

At this stage you will need to restart the game if either of the balls is pocketed.

davidghemer 12-01-2011 05:04 AM

Some brief instructions for those wishing to play with the work in progress version.
- Down arrow to pull the cue back (increase power). Power is discrete so press the button once to increase power by one
- Up arrow to decrease power
- Left and right arrows to aim the cue ball
- Space to complete a shot

Restart the game if either of the balls are pocketed.

davidghemer 12-01-2011 05:13 AM

[QUOTE=arty-fishL;44063]This is quite ambitious, not just for somebody who is fairly new to the forums, but for anybody. So far it is very good, I'm looking forward to the finished game. At first I couldn't work out the controls, but I worked them out eventually.

What I will suggest is to change the style of the left/right turning of the cue to abruptly. I made a [URL="http://www.alice.org/community/showthread.php?t=7173"]compass[/URL], you could use elements of it to get the angle of the balls.[/QUOTE]

Thanks for the feedback. Agree it is ambitious but thought I'd give it a crack. Thought it would be good way to find out some of the finer details and tricks of programming in Alice.

Turning of the cue has been changed to abruptly in the latest version. I'll check out your compass, sounds like it might do the trick.

davidghemer 12-01-2011 07:49 PM

Stage 4: rebound angles
 
1 Attachment(s)
This version uses a bit of trig to calculate the angle of the cue ball when it hits a cushion and then to rebound at an appropriate angle. It is similar to the compass except I compare the current position of the cue ball with a previously marked position. The previous position is stored each time the cue ball changes direction and the end of a shot.

Rebounding for the one ball has not been changed yet, but the same principle could be applied.

Does anybody know if there is some way of adding properties to the balls? At the moment I have to put properties for the cue ball in the table class, which is getting pretty messy.

zero00 12-02-2011 02:17 AM

Thank you so much for making this! :D
I had been trying to figure out how to do this for a long time!
(I didn't know the arcsin function outputs in radians :p)
[SIZE="1"][COLOR="PaleTurquoise"]I don't know what radians are, but I know some basic trig! :P[/COLOR][/SIZE]

davidghemer 12-02-2011 11:53 PM

Stage 6: basic scoring and end game
 
1 Attachment(s)
For this version I've update the rebounding of the one ball so that it follows the same laws as the cue ball. I've also added some basic scoring (counts number of shots) and end game detection.

It generally runs pretty well when the balls are hit at low speed. At high speed it throws a lot of exceptions, so I would recommend only using power 1 or 2 shots.

I doubt that this will scale to a game with 15 balls. There are significant timing issues already with just two balls so with all the balls it just doesn't seem feasible. Another issue relates to decreasing the speed of the balls. Using a variable I can get a gradual decrease. However this doesn't happen when I use an array.

Anyway have a look and have a play and let me know if you see any obvious bugs in the code.

David B 12-04-2011 12:31 PM

Unfortunately, I don't know how to play Pool, but I guess I will have to learn so I can play this game.


All times are GMT -5. The time now is 11:50 PM.

Copyright ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.