This is the project from the course called "How to Code: Simple Data" by UBCx.
The Space Invaders is a interesting arcade video game using Beginning Student Language (BSL) within DrRacket.
Goal: defeat waves after waves of descending aliens with a missle-shooting tank.
During the domain analysis phase, there are mainly four parts to consider:
- Scenario:
- Visualize what the game should look like
- Consider some user cases using illustrations
- Constant:
- This is the point to identify components that should be constant
- constant components include images of tank, aliens, missiles, etc (see the picture of "Domain Analysis.jpg").
- Changing:
- Need to identify all changing components in the game.
- These components change dynamically in different user scenarios
- The crucial part of the game design
- Big-bang options:
- BSL with 2htdp/universe module provides useful functionality for creating interactive, graphical programs.
- I use big-bang functions with 4 clauses to create an interactive game:
- on-tick: An event handler to tell the program to tick in a given rate.
- to-draw: A function to render the image of the game according to its state.
- on-key: An event handler to tell the program to read every keystroke from the user and react accordingly.
- stop-when: Takes a boolean function and a image. Render the image if the boolean function return true
The implementation is simple.
- Start with a single function big-bang (root).
- Split the function into several functions (node) with each function doing their own purpose.
- These functions can be further split into smaller functions, fulfilling smaller tasks.
- The splitting ends when the "leaf" function require no more splitting.
- The whole program can be viewed as a giant tree, with the big-bang function at the root.
- Download the "space-invaders-starter.rkt" file.
- Open the file with DrRacket, feel free to browse through the code to see the internal implementation
- Run the program by clicking the "Run"" button at the top right. You should see "All 89 tests passed!"
- type (main (make-game empty empty T0)) in the interacting window (the bottom panel) to start the game.
- Enjoy it and try not to die!