I give a code lecture in my intro-to-game development course (which has very little to do with programming) that gets students pretty excited. I basically code a very simple 2D game engine, just to show students who have never seen C++ before what it looks like to program a game, at least in concept.
Some of them really run with it, and start adding new features to the game, like collision detection, collide-able objects, victory and defeat conditions, AI players moving around, items to pick up, mazes read from a file, drawing without scrolling, drawing without flickering, story and RPG elements, etc..
Here's the code from the lecture:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
using namespace std;
#include <conio.h>
void main()
{
int x = 5, y = 4;
int height = 15, width = 20;
char input;
do
{
for(int r = 0; r < height; ++r)
{
for(int c = 0; c < width; ++c)
{
if(r == y && c == x)
{
cout << (char)1;
}
else
{
cout << '.';
}
}
cout << endl;
}
cout << endl;
input = getch();
switch(input)
{
case 'w': y--; break;
case 'a': x--; break;
case 's': y++; break;
case 'd': x++; break;
}
}
while(input != 'q');
}
|
I always encourage students to try building a roguelike using this as a base.