CSCS1320 C/C++ Programming
PROJECT: FUN WITH GAMES (fwg4)
OBJECTIVE
Using your Vircon32 build and installation from fwg0, and the game
foundations from fwg1, fwg2, and fwg3, implement a simple 2D game using
C++ classes. This project introduces the v32c++ C++ transpiler,
which allows you to write object-oriented code that is translated into
C code the Vircon32 compile tool can understand.
Your game can be an OOP reimagining of one of your earlier efforts
(pong, breakout, or your fwg3 game) or something entirely new. Where
fwg3 grouped related data into structs, here you will go a step further:
bundle the data and the operations on that data into classes, and
use access control (public / private) to protect the internal state
of your objects.
THE V32C++ TRANSPILER
The Vircon32 compile tool only understands C. The v32c++ transpiler
bridges the gap: it takes your C++ source (.cpp), and translates it
into plain C (.c), which then enters the normal build pipeline.
NOTE: you should already have installed v32c++ per the instructions
given in class. If you have not, do so now, outside of your
repository (just as with Vircon32 and DevTools). Do NOT add the
v32c++ source or binaries to your repository!
Verify the installation works by running it from the command line:
yoursystem:~$ which v32c++
yoursystem:~$ v32c++ --help
Should either command fail, check that the install location is in your
PATH (the same way you did for the DevTools), and consult the class
notes / Discord for troubleshooting.
Since the transpiler is not a full C++ compiler, expect some limitations on which C++ features are available. Stick to the basics we've covered: classes, constructors, member functions, and public/private sections. When in doubt, keep it simple, and test early and often (compile after every small change, rather than writing everything at once).
NOTE: the first gamepad by default is mapped to the keyboard
PROGRAM
You are to write a Vircon32 C++ game that:
- has a player-controlled object, moved via the gamepad
- has at least one other kind of game object (enemy, obstacle, ball, projectile, pickup, etc.) that acts on its own
- detects collisions between objects, with a meaningful result
- keeps a score (or lives, or timer) displayed or otherwise tracked
- has a win and/or lose condition (even if it simply resets)
- is built around classes:
- define at least TWO distinct classes in your game, for example a player class and an enemy/ball/projectile class
- each class has private member data (position, velocity, size, and an active/alive flag at a minimum, as relevant to your game); code outside the class must NOT touch these directly
- each class has public member functions to operate on that
data, including:
- a constructor to initialize the object into a valid state
- accessor ("getter") functions to read private data
- mutator ("setter") or behavior functions to change private
data (such as
move(),update(),bounce(),reset()) - a function to draw the object to the screen
- create objects (instances) of your classes in your game
-
main()should primarily coordinate the objects: let the objects do the work via their member functions
NOTE: you are free to use arrays of objects if your game calls for it, but the emphasis of this project is on the design and use of the classes themselves, and the separation of public interface from private data.
CLASS REMINDERS
A quick example of the sort of thing we are after (yours will differ):
class Sprite
{
private:
int x; // where it is on screen
int y;
int dx; // how it moves each frame
int dy;
int active; // is it currently in play?
public:
Sprite(int startx, int starty)
{
x = startx;
y = starty;
dx = 0;
dy = 0;
active = 1;
}
int getX() { return x; }
int getY() { return y; }
void setVelocity(int newdx, int newdy)
{
dx = newdx;
dy = newdy;
}
void move()
{
x += dx;
y += dy;
}
};
Remember: use the dot operator (.) with an object variable, and the
arrow operator (->) with a pointer to an object. Members declared
private are only accessible from within the class's own member
functions; everything else must go through the public interface.
CARTRIDGE BUILD PROCESS
All of these steps can be automated with the use of the provided
Makefile simply by typing make at the prompt.
NOTE that with certain modifications, you'll first need to modify the XML file as appropriate.
TRANSPILE
First step is to transpile your C++ code into C, with the v32c++ tool
(consult v32c++ --help for the exact options of your installed
version):
yoursystem:~/src/SEMESTER/cprog/fwg4$ v32c++ fwg4.cpp -o fwg4.c
This translates your C++ code into a C file, which will then be compiled
like any other Vircon32 C program. Do NOT track the generated .c
file in your repository; it is a build product (the .cpp is your
source code).
COMPILE
Next, compile the generated C code with the Vircon32 developer tools C
compiler (compile):
yoursystem:~/src/SEMESTER/cprog/fwg4$ compile fwg4.c -o fwg4.asm
This compiles, or translates, the C code into Vircon32 assembly language code, which will then need to be assembled to machine code:
ASSEMBLE
Once you've compiled your code successfully, you can use the Vircon32
assemble DevTool to assemble the assembly:
yoursystem:~/src/SEMESTER/cprog/fwg4$ assemble fwg4.asm -o fwg4.vbin
IMAGE CONVERSION
Any PNG images you'd like to use need to be converted to Vircon32 texture
format via the png2vircon tool:
yoursystem:~/src/SEMESTER/cprog/fwg4$ png2vircon background.png -o background.vtex
yoursystem:~/src/SEMESTER/cprog/fwg4$ png2vircon sprites.png -o sprites.vtex
Note that you'll also want to ensure the XML file has been updated to reference these textures:
<binary path="fwg4.vbin" />
<textures>
<texture path="background.vtex" />
<texture path="sprites.vtex" />
</textures>
AUDIO CONVERSION
Should you have any WAV files you'd like to use need to be converted to
the Vircon32 sound format via the wav2vircon tool:
yoursystem:~/src/SEMESTER/cprog/fwg4$ wav2vircon backgroundmusic.wav -o backgroundmusic.vsnd
yoursystem:~/src/SEMESTER/cprog/fwg4$ wav2vircon soundfx.wav -o soundfx.vsnd
Note that you'll also want to ensure the XML file has been updated to reference these sounds:
<sounds>
<sound path="backgroundmusic.vsnd" />
<sound path="soundfx.vsnd" />
</sounds>
PACKING THE ROM
Once all the components have been built, you can pack them together into
a Vircon32 cartridge for use in the emulator via the packrom tool:
yoursystem:~/src/SEMESTER/cprog/fwg4$ packrom fwg4.xml
SUBMISSION
To be successful in this project, the following criteria (or their equivalent) must be met:
- Project must be submit on time, by the deadline.
- Late submissions will lose 33% credit per day, with the submission window closing on the 3rd day following the deadline.
- Executed programs must display in a manner similar to provided output
- output formatted, where applicable, must match that of project requirements
- Processing must be correct based on input given and output requested
- Output, if applicable, must be correct based on values input
- Code must be nicely and consistently indented
- Code must be consistently written, to strive for readability from having a consistent style throughout
- Code must be commented
- Any "to be implemented" comments MUST be removed
- these "to be implemented" comments, if still present at evaluation time, will result in points being deducted.
- Sufficient comments explaining the point of provided logic MUST be present
- Any "to be implemented" comments MUST be removed
- No global variables (without instructor approval), no goto statements, no calling of main()!
- Track/version the source code in your private semester repository
- Submit a copy of your source code to me using the submit tool by the deadline.
SUBMIT TOOL USAGE
Let's say you have completed work on the project, and are ready to submit, you would do the following:
lab46:~/src/SEMESTER/cprog/fwg4$ make submit
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
RUBRIC
I'll be evaluating the project based on the following criteria:
260:fwg4:final tally of results (260/260)
*:fwg4:code modified to meet project specifications [26/26]
*:fwg4:screenshot or video posted to class DISCORD of game running [26/26]
*:fwg4:at least two distinct classes defined and used [26/26]
*:fwg4:classes use private member data and public member functions [26/26]
*:fwg4:constructors, accessors, and behavior functions implemented [26/26]
*:fwg4:working collision detection between game objects [26/26]
*:fwg4:game has scoring (or lives/timer) and a win/lose condition [26/26]
*:fwg4:v32c++ transpile step integrated into build process [26/26]
*:fwg4:game uses at least one texture and one sound [13/13]
*:fwg4:source file, XML file, build script, and cartridge submit [13/13]
*:fwg4:code compiles, cartridge builds with no warning or error [13/13]
*:fwg4:committed project related changes to private semester repo [13/13]
Additionally:
- Solutions not abiding by spirit of project will be subject to a 50% overall deduction
- Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction
- Solutions not utilizing indentation to promote scope and clarity or otherwise maintaining consistency in code style and presentation will be subject to a 25% overall deduction
- Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction