Game programming: Week two & three

Week two started off with an introduction to ArraysMemory and Functions.

At the end of the second week our lecturer guided the class in building a basic version of the game Pong during Thursday and Friday using SDL  (Simple Direct-Media Layer). There were a lot of flaws in the game that could be improved for example the movement of the ball and the collision with the paddles, although all the basic elements of the game were there.

Featured image

On our third week of programming we have started to go through Classes. Classes consists of member functions/methods and variables.

Classes also consists of a Constructor, a Copy Constructor and a Destructor. The constructor initializes variables and the destructor cleans up after the class, which includes freeing any memory allocated.

When creating a class, instead of writing completely new members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is called the derived class.

class Base
{
public:
Base() { std::cout << "Base class ctor" << std::endl; }
~Base() { std::cout << "Base class dtor" << std::endl; }

void BaseMethod()
{
}

int m_public;

protected:
int m_health;
};

class Derived : public Base
{
public:
Derived() { std::cout << "Derived class ctor" << std::endl; }
~Derived() { std::cout << "Derived class dtor" << std::endl; }

void DerivedMethod()
{
}
};

//main.cpp
int main(int argc, char* argv[])
{
Derived d;
return 0;
}

About Lucas Gullback

2014  Programming