Kategoriarkiv: Spelprogrammering I – 5SD022

#5 Big Game Project |

This week has been all over the place. I’ve been working on alot of small things such as new HP bars for all entities. Only displaying the HP bars when necessary i.e settlers hp bar down in the jungle should not be displayed when the camera is above. I also added a simple lever so that the player can order the elevator to go up and down. There is one lever placed down in the jungle and one on top of the island.

I’ve also implemented a magnet to our settlers. The magnets purpose is to ease the process of collecting resources. Example: When a settler hits wood with his axe, the logs comes flying out and land on the ground. Instead of having the player pick each one up individually we have this magnet so that the settler can just run close to the resources on the ground. It works like a vacuum cleaner.

I’ve implemented flying resources to our UI. When a settler picks up resources via the magenet 2D sprites of the resources flies from the settlers position to the settlers inventory. This also happens when a settlers deposits resources to their base storage. The resources fly from the inventory to the storage inventory.

I’ve also added alert notifications when a settler gets damaged so that you are aware if a settler gets damaged if its not on your screen. I’ve also added some small hotkeys such as
SHIFT + Leftclick to select multiple settlers.

Lastly, I’ve implemented a new GUI compared to the last one. The biggest difference is that all the settlers in your colony are visible at all times. Each settler is displayed with a name. If a settler is selected more info will be displayed about the settler such as HP, inventory and equipment.

 


Week 9 | Red Plane1942

I’ve been working on a menu system by creating classes such as the following:

  • GUI_Element: Is the base class for all GUI classes.
  • GUI_Label: Contains a Draw() function and a SpriteText* variable. It can also be parented to another GUI_Element.
  • GUI_Image: Contains a Draw() function and a Sprite* variable. It can also be parented to another GUI_Element.
  • GUI_Button: Contains a Draw() and a CheckCollision() function, a Collider* variable, a GUI_Label* variable and two GUI_Image* variables. One image is for the button sprite. The other image is as an overlay image for when the button is hovered. The button will draw the first image and then draw the label and lastly draw the second image ontop of everything if the button is hovered by the mouse.

This is how my GUI_Image class looks like:

 #include "stdafx.h"
#include "GUI_Image.h"
#include "DrawManager.h"

GUI_Image::GUI_Image(GUI_Element* parent, int x, int y, Sprite* sprite)
{
 //Image
 m_sprite = sprite;
 
 //Element
 if (parent != nullptr)
 {
 m_x = parent->GetX() + x;
 m_y = parent->GetY() + y;
 }
 else
 {
 m_x = x;
 m_y = y;
 }
 
}
GUI_Image::~GUI_Image()
{

}

//Element
int GUI_Image::GetX()
{
 return m_x;
}
int GUI_Image::GetY()
{
 return m_y;
}

//Image
void GUI_Image::Draw(DrawManager* drawManager)
{
 drawManager->Draw(m_sprite, m_x, m_y);
}
Sprite* GUI_Image::GetSprite()
{
 return m_sprite;
} 

I’ve also finished the high score system. It saves the top five users score inside a .txt file. When the game reaches game over the game switches to a HighScoreState. Inside this state i check if the last users score is higher than than any of the other scores on the list. If it is I add the last score to the list and remove the lowest score. The user is also able to enter his/her name.


Week 7-8 | Red Plane1942

Week 7

This week I’ve added coins and power ups dropping from enemies. Both the coin and the power up inherits from the base class Entity. The coin is simple enough, it falls downwards and if hit by the player it adds to the players m_totalcoins. The power up bounces around on the screen edges until the player picks them up. For now i have only added an extra life power up but plan on adding one for adding extra bombs and one for increasing the basic shots.


Week 8

This week I’ve added two more enemies, another type of plane that flies in a zigzag pattern and a boat that has a lot of health and shoots bullets towards the enemy. I’ve also started working on a beginning for a high score system.
I tried to implement a entitypool for the use of entities. By having pre-created entities and reusing them I don’t have to allocate memory dynamically all the time. It did not go well so I decided to wait and maybe continue on it later.


Week 6 | Red Plane1942

I’ve started working on a replica of a game called ”Red Plane 1942”. I’m using the same engine we created in class for the Arkanoid project. What I’ve done this week is to create the basic objects. I made a class called BackgroundObject. It’s basically just a object with a sprite that moves down towards the end of the screen. After it is below the edge it resets above the screen and randomizes a x position. The Player object is always on the samy Y position, when the BackgroundObjects move down they create the illusion of the player flying forward.

So the BackgroundObject class inherits from the base class called Entity. I also started creating a Bullet class wich also inherits from the Entity class. The Bullet class has variables for X and Y direction, speed and damage.

class Bullet : public Entity
{
public:
 Bullet(float x, float y, Sprite* sprite, int damage, int speed, int xDirection, int yDirection, EType type);
 ~Bullet();

 //Entity
 void Update(float deltatime);
 EType GetType();
 Sprite* GetSprite();
 Collider* GetCollider();
 float GetX();
 float GetY();
 void SetVisibility(bool state);
 bool IsVisible();

 //Bullet
 int GetDamage();

private:
 //Entity
 EType m_type;
 Sprite* m_sprite;
 Collider* m_collider;
 float m_x;
 float m_y;
 bool m_visible;

 //Bullet
 int m_damage;
 int m_speed;
 int m_xDirection;
 int m_yDirection;
};

EType is a enum which describes what type of Entity the object is. In this case the bullet has a variable for it because the bullet can be either a playerbullet E_PBULLET or a enemybullet E_EBULLET.


Programming – Week 5

This week we finished the Arkanoid project. The last parts were to add images that could handle alpha. We extended our project with an extension called SDL_IMAGE. The extension lets us load files with different file endings such as PNG etc. By doing this we could achieve transparency around the ball object in Arkanoid.

We also extended the project by adding a CollisionManager and a Collider class. Theese two work together to achieve
box vs box collision, I dont want to go into more detail but the Collision works by using the Separting Axis Theorem (SAT).


Programming – Week 4

This week we have worked together in class on creating a blueprint for a ”simple” game engine. We are going to use this engine to create a copy of Arkanoid. The engine includes a DrawManager, InputManager and a StateManager so far.

DrawManager creates a window and a renderer. It has a functions that clears the screen with a single color and a functions that presents what we have drawn onto the screen.

InputManager contains a Mouse and Keyboard pointer. The values of inside the pointers is set from SDL_Event ‘s. The events are controlled and checked inside a function in Engine called HandleEvents.

StateManager handles different states. A state can be for an example GameState which handles logic and drawing for when the game is running. We could also have a MenuState which has its own logic and drawing. By using polymorphism we can create different logic and drawing in each state.
All states will inherit from the base class State. The State class contains pure virtual functions which means that we have to override them when inheriting from the State class.


Programming – Week 3

This week I’ve learned how to create classes using header and cpp files.

This is an example of a header named Student

 class Student
{
public:
 Student(std::string name, int age);

 int GetAge();
 void SetAge(int newAge);

 std::string GetName();
 void SetName(std::string newName);

private:
 int age;
 std::string name;
}; 

The keyword ”public” describes what functions and variables are accesable from outside the class. All ”private” variables and functions are only accesable inside the class.

Student(std::string name, int age)    is the constructor of the class. The constructor works like a function but is automaticly called when a object is initialized with the class name as datatype. In this case the constructor is overloaded, the default constructor does not have any parameters.

By having name and age private we can use functions such as SetAge and GetAge in order to controll the variables value.

Example:

void SetAge(int newAge)
{
    if (newAge >= 0)
    {
        age = newAge;
    }
}

Here i can say that we accept no age below 0.


Programming – Week 2

This week we worked with pointers in C++. You create a pointer by adding a
” * ” at the end of the data type. Pointers works just like the name describes, it points towards a memory address instead of a value. To access a variables memory address you add ” & ” in front of the variable name. To access the value of a pointer you can use ” * ” in front of the pointer variable.

This is an example of how pointer can be used:


#include 

void main()
{
  int variable = 5;
  int* pointer = &variable;

  std::cout << "Address: " << pointer << "\nValue: " << *pointer;
  std::cin.get();
}


We also started a new project to create the classic Pong game. In order to create a window and draw graphics we use a library called SDL (Simple DirectMedia Layer). By using functions and data types from SDL library we could create our own window and graphics-renderer.
The game works by having a game loop, in this case a while loop. We handle all logic in a function called ”Update” and after all logic is done we call a function called ”Draw” which renders everything to the screen. By creating Pong we learned about creating structs, using functions and more.


Programming – Week 1

This weeks assignments was a bit to easy because I’ve been programming in C# before. I decided to give myself an assignment, Tic Tac Toe.

By creating this game i learned new syntax such as std::string and system(”cls”). I also learned how to create a two dimensional array. In C# you could create one using the datatype and then [ ] for normal array and [ , ] for a two dimensional.
I learned that in C++ you create arrays by typing the datatype and then [ ] for normal array and [ ][ ] for a two dimensional.

My version of Tic Tac Toe works by waiting for player input. The player enters a row and a column and the symbol either X or O depending on player 1 or player 2 is placed on that spot. I’m using a while loop in order to clear the console screen and redrawn the playfield each time a player places a symbol.