Alice Community  

Go Back   Alice Community > Alice 2 > Works-In-Progress

Reply
 
Thread Tools Display Modes
Pool Game
Old
davidghemer
Member
 
Status: Offline
Posts: 38
Join Date: Nov 2011
Default Pool Game - 11-30-2011, 09:53 PM

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.
#################################################
Attached Files
File Type: a2w PoolGame_Stage1.a2w (589.4 KB, 82 views)
File Type: a2w PoolGame_LATEST.a2w (883.7 KB, 162 views)


For video tutorials on programming in Alice 2.2 check out my YouTube channel

http://www.youtube.com/user/drdave785

Also check out my Programming in Alice blog at

http://programminginalice.com

Last edited by davidghemer; 12-12-2011 at 03:54 AM. Reason: Add pointer to the latest code
   
Reply With Quote
Stage 2: bounce off cushions
Old
davidghemer
Member
 
Status: Offline
Posts: 38
Join Date: Nov 2011
Default Stage 2: bounce off cushions - 12-01-2011, 01:01 AM

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.
Attached Files
File Type: a2w PoolGame_Stage2.a2w (636.5 KB, 81 views)


For video tutorials on programming in Alice 2.2 check out my YouTube channel

http://www.youtube.com/user/drdave785

Also check out my Programming in Alice blog at

http://programminginalice.com
   
Reply With Quote
Old
arty-fishL
Senior Member
 
arty-fishL's Avatar
 
Status: Offline
Posts: 1,878
Join Date: Mar 2008
Location: In the corner of your eye
Arrow 12-01-2011, 03: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 compass, you could use elements of it to get the angle of the balls.


█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
█░░▓░░░░░░░▓░░░░░░░░░░░▓▓░░▓░░░░░░▓░░░▓░░░░█
█░▓░▓░▓▓▓░▓▓▓░▓░▓░░░░░░▓▒▒░░▒░░▓▓░▓▓▓░▓▒░░░█
█░▓▓▓▒▓▒▒▒░▓▒▒▓▓▓▒▓▓▓░▓▓▓░░▓░░░▓▒▒▓▒▓▒▓▒░░░█
█░▓▒▓▒▓▒░░░▓▓░░▒▓▒░▒▒▒░▓▒▒░▓▓░▓▓▒░▓▒▓▒▓▒░░░█
█░▓▒▓▒░▒░░░░▒▒▓▓▓▒░░░░▓▓▒░░░▒▒░▒▒░░▒░▒▓▓▓░░█
█░░▒░▒░░░░░░░░░▒▒▒░░░░░▒▒░░░░░░░░░░░░░░▒▒▒░█
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█

I have mostly moved on from Alice, but may still respond to messages if important [¬º-°]¬
   
Reply With Quote
Stage 3: pocketing balls
Old
davidghemer
Member
 
Status: Offline
Posts: 38
Join Date: Nov 2011
Default Stage 3: pocketing balls - 12-01-2011, 03:53 AM

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.
Attached Files
File Type: a2w PoolGame_Stage3.a2w (708.3 KB, 49 views)


For video tutorials on programming in Alice 2.2 check out my YouTube channel

http://www.youtube.com/user/drdave785

Also check out my Programming in Alice blog at

http://programminginalice.com
   
Reply With Quote
Old
davidghemer
Member
 
Status: Offline
Posts: 38
Join Date: Nov 2011
Default 12-01-2011, 04: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.


For video tutorials on programming in Alice 2.2 check out my YouTube channel

http://www.youtube.com/user/drdave785

Also check out my Programming in Alice blog at

http://programminginalice.com
   
Reply With Quote
Old
davidghemer
Member
 
Status: Offline
Posts: 38
Join Date: Nov 2011
Default 12-01-2011, 04:13 AM

Quote:
Originally Posted by arty-fishL View Post
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 compass, you could use elements of it to get the angle of the balls.
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.


For video tutorials on programming in Alice 2.2 check out my YouTube channel

http://www.youtube.com/user/drdave785

Also check out my Programming in Alice blog at

http://programminginalice.com
   
Reply With Quote
Stage 4: rebound angles
Old
davidghemer
Member
 
Status: Offline
Posts: 38
Join Date: Nov 2011
Default Stage 4: rebound angles - 12-01-2011, 06:49 PM

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.
Attached Files
File Type: a2w PoolGame_Stage5.a2w (746.9 KB, 68 views)


For video tutorials on programming in Alice 2.2 check out my YouTube channel

http://www.youtube.com/user/drdave785

Also check out my Programming in Alice blog at

http://programminginalice.com

Last edited by davidghemer; 12-02-2011 at 02:44 AM. Reason: Added comments to the code
   
Reply With Quote
Old
zero00
Senior Member
 
zero00's Avatar
 
Status: Offline
Posts: 300
Join Date: Oct 2009
Default 12-02-2011, 01:17 AM

Thank you so much for making this!
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 )
I don't know what radians are, but I know some basic trig! :P


==============Some of my Games and Ideas===========

Sky Warrior: http://www.alice.org/community/showthread.php?t=6291
Health Bars: http://www.alice.org/community/showthread.php?p=36968#post36968
Sky Warrior: Dual Force: http://www.alice.org/community/showthread.php?t=7174

Want to make your own space game? http://www.alice.org/community/showthread.php?t=6389
   
Reply With Quote
Stage 6: basic scoring and end game
Old
davidghemer
Member
 
Status: Offline
Posts: 38
Join Date: Nov 2011
Default Stage 6: basic scoring and end game - 12-02-2011, 10:53 PM

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.
Attached Files
File Type: a2w PoolGame_Stage6.a2w (834.0 KB, 68 views)


For video tutorials on programming in Alice 2.2 check out my YouTube channel

http://www.youtube.com/user/drdave785

Also check out my Programming in Alice blog at

http://programminginalice.com
   
Reply With Quote
Old
David B
Senior Member
 
David B's Avatar
 
Status: Offline
Posts: 1,145
Join Date: Dec 2010
Location: N/A
Default 12-04-2011, 11:31 AM

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

Tags
collision, game, pool, trigonometry

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



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