Kategoriarkiv: 5SD022

Week 6 – Bomberman level

In this week of Game Programming 1 we started working on our map for our bomberman level. The original bomberman level is built up by three different types of blocks, solid blocks, background blocks and breakable blocks. So we decided to create a class for each one of these blocks. To more easily edit the level, we wanted to load in the level from a txt file. We had alot of problems with getting this to work, but by looking back at previous lectures, we could figure it out. The txt file is constructed of numbers, each specific number is used to decide which block should spawn. The position of each block is set in the constructor of our gamestate by a simple formula.

Week 5 – Arkanoid & Collision

This week we completed Arkanoid. The game is fully functional and the code is the code we are going to use for our own project. In the final version of Arkanoid, we implemented collision for the different objects in the game. The collision checks if an objects half width plus the other objects half width is bigger than one of the objects width. We also implented SpriteText, this is useful when you want to write out text on your screen.

We have also started slightly on our final project, Bomberman. Planned for next week is to work on a level/map and the player.

Week 4 of Game Programming 1 – Project preparation

In this week of Game Programming 1, we have been doing a lot of live coding. The code we have been writing is a blueprint for the upcomming project. The project is to create a game in the Simple DirectMedia Library. The game I and my partner (unoakerlund.wordpress.com) have decided to create is Bomberman, so a lot of time this week has gone to study the mechanics and objects that Bomberman contains.

The coding we have been doing is a blueprint that we can use to create our game. The code contains several classes. Some of the classes is advanced and takes a lot of analyzing to fully understand. The class that brought the most attention from me was the StateManager class. This class handles which state the game is in, for example,  if the game goes from menu state to game state, it is StateManager that handles these actions.

Week 3 of Game Programming 1 – Classes

In this week of game programming, we have worked with classes. A class holds values, the amount and type of values is decided by the programmer. To learn how classes work, we had a bunch of different assignments. The assignment I chose to focus on was to make a deck of cards. I chose to focus on this because it demonstrate really well how classes work together. I made a class called Card, this class held the types Integer and String. The class made cards containing those types which was sent to the class Deck, which put the cards in an Array. From the array, the program could shuffle and pick out cards, every card in the array was unique. What was not programmed was the process to remove cards from the deck.

Shown below is a snapshot from the class Card: In this class all the cards is created, the cards is then put in the deck via a for loop in the Deck class.

Card::Card(int num)
{
if (num < 13)
{
int a = 0;
a++;
int m_num = a;
m_suit = "Hearts";
}
if (12 < num < 27)
{
int a = 0;
a++;
int m_num = a;
m_suit = "Spades";
}
if (26 < num < 40)
{
int a = 0;
a++;
int m_num = a;
m_suit = "Clubs";
}
if (39 < num <= 52)
{
int a = 0;
a++;
int m_num = a;
m_suit = "Diamonds";
}
} 

Second week of Game Programming 1 – Pong

This week we got introduced to our first session of game programming. We got introduced to SDL(Simple DirectMedia Library), the library we will be using in the course to create our own games. The game we got to work on and experiment with was Pong. Pong is a game simulating a game of table tennis. Our task was to implement movement and collision, it was a great task to get a feeling of how a basic game structure looks. However the code structure was a bit messy, but that is something we are going to work on next week when we go through Classes.

This week we also learnt how to use functions, arrays and pointers. Here is an example code that generates a level by using a 2D array for X and Y coordinates. The two for loops generates every position in the array, and the if/else assignes the position to different symbols. In this code, every final row is assigned into ”#” to simulate walls. And random positions in the middle of the walls is assigned to ”&” to simulate trees. If a position is not assigned to either # or &, it is assigned to _ instead to simulate areas where the player can walk.

for (int y = 0; y < yLength; y++)
{
for (int x = 0; x < xLength; x++)
{
if (y == 0 || y == yLength - 1 || x == 0 || x == xLength - 1)
{
lvlArray[x][y] = '#';
}
else
{
int treeGen = rand() % 9;
if (treeGen == 1)
{
lvlArray[x][y] = '&';
}
else
{
lvlArray[x][y] = '_';
}
}
std::cout << lvlArray[x][y];

}
std::cout << std::endl;
}

std::cin.get(); 

First week of Game programming 1

In the beginning of this week, we started the Game programming 1 course. This is a introduction course C and C++. This week we have worked with how variables, loops and branching works in C++. We had over 20 exercises to practise and understand this, but since I have been programming a lot earlier in C and Java, the tasks was pretty simple to understand. But they were great to get in the programming mood.

In this week we also went through Scope and Debugging, but have not got any exercises on them yet.

This is a snapshot from a program I made, the user inputs a number, the computer then tried to guess what the input was.

programming