I like embedded programming. I like the restrictions you have to work around when trying to get your code to run on a small device. This is what wakes up my inner tinkerer because, unlike today, back when computers had fewer transistors and were much slower, you really had to hack your hardware to get it to do what you want. A great example is the game Doom (created by the company id Software), when one of the core developers, John Carmack, was trying find a solution to keep the game engine running at a decent framerate because of the increasingly complex level designs of his colleagues. He ended up using BSP (Binary Space Partitioning, which he read about in a paper) to draw only the portions of the 3d world currently visible in the player's viewport. This allowed the game to run much more smoothly on the same hardware. Nowadays we get a bit spoiled because on most modern devices there's an abundance of processing power and storage that makes it more difficult to find out where your code might be causing performance issues.
This was a small experimental project I did with an Arduino Uno, OLED display and a 5-way joystick. The goal was to create a small side-scrolling space-themed videogame. I wrote this in C and built the engine from scratch with basic functionalities like collision detection, projectiles, and horizontal and vertical movement.
Here's a code snippet of the Gun class:
#ifndef Gun_h
#define Gun_h
#include <Arduino.h>
#include "Bullet.h"
class Gun
{
private:
int m_ammo, m_clipSize;
int m_index;
int m_rate;
Bullet* bullets[10];
public:
Gun();
int getAmmo();
int getClipSize();
void fire(int x, int y);
void reload();
void render();
};
Gun::Gun()
{
m_index = 0;
m_clipSize = 10;
m_ammo = 10;
reload();
}
int Gun::getAmmo()
{
return m_ammo;
}
int Gun::getClipSize()
{
return m_clipSize;
}
void Gun::fire(int x, int y)
{
bullets[m_index] = setXY(x, y);
m_ammo--;
m_index++;
}
void Gun::reload()
{
for(int i=0; i<m_clipSize; i++)
{
bullets[i] = new Bullet;
}
m_index = 0;
m_ammo = m_clipSize;
}
void Gun::render()
{
if (m_ammo <= 0) reload();
for (int i=0; i<m_clipSize; i++)
{
bullets[i]->render();
if (bullets[m_index]->getPos() > 127) delete(bullets[m_index]);
}
}
#endif
back