The initial phase of this project is to get the ball bouncing on the screen (in Haskell), in one direction (x), then both directions (x,y). This has been accomplished in several ways:
- using function pattern matching - very messy
- using guards - better
- using where clause
For the where clause, we initially broke out the boundary condition checking code into a separate function using function pattern matching. Then we simplified the code by changing the function definition to use tuples to pass the ball position and increment for x and y coordinates. Further simplifications provided for static declarations of boundary limits.
The next phase is to separate out the pure code from the IO. The loop code can be modified to use a state generater that creates a static list of projected positions of the ball. Then this list is used as forcing function data to simluate ball trajectory data instead of using the loop to update the ball trajectory. This allows the ball position state to become pure and pump the next known state to the IO to print.
To do: (not in any particular order)
- Add paddles (requires check for keyboard events)
- Add acceleration and variable ball velocity
- Add checks for above
- Add more balls
- Separate out impure from pure code
- Break out functions into separate threads
- Check for keyboard activity in its own thread
- Add obstructions
- Add more windows
- Allow balls to pass between windows
- Randomize starting ball position
- Add degree of difficulty
- Add option to change default speed (of ball)
- Add acceleration, momentum, weight?, size to ball
- Add responsivity to paddles
- Add score board
- Add gaming structure - start, end, save, game tally, player 1/2
- Add timer
- Add moving targets
- Add moving obstructions
- Add option to change size of paddles
Due to system library dependencies on ncurses and some implementation issues with the haskell-ncurses library, building on Ubuntu is more reliable than other Linux distributions.
- VirtualBox - https://www.virtualbox.org/
- Vagrant - https://www.vagrantup.com/
- In the project directory, run the following to configure and provision a VM with ncurses and Haskell Stack
vagrant up
- ssh to the VM
vagrant ssh
- Switch to the /vagrant directory which is shared folder between your host machine and the VM
cd /vagrant
- Build using Haskell Stack
stack build
- Docker
- Build
pong-dev
Docker image which is based on Ubuntu and includes ncurses and Haskell Stack
cd docker
docker build -t pong-dev:latest .
cd ..
- Run container with a volume mount containing project source code
docker run -it -v `pwd`:/src --name pong-dev pong-dev:latest bash
- Build using Haskell Stack
cd /src
stack build
If you exit the container, it will be in the "Exited" state, but you can simply start it again.
docker start pong-dev
docker exec -it pong-dev bash