Abhishek Joshi

Game Programmer


Resume Github Link

2D Plane Shooter

About

This is a 2d Plane Shooter game where you have survive from enemy planes. You can use bullets and missiles to attack enemy and can use flares for defence.

Project Info

My Role

In this Game Entity works as a GameObject that contains position, scale. It also contains SetPos, SetScale and Destroy function to handle the Entity.

Every object is inherited from Entity class that provides them to renderer on screen, Change position and scale ability.

The game consists three types of enemies SmallEnemy, MediumEnemy and BigEnemies all are inherited from Enemy class. ObjectSpawner.cpp is responsible for spawning enemies, it uses std::vector to store enemies types.


Code snippets

                    

                        Entity::Entity(Vector2f p_pos, SDL_Texture* p_tex, Vector2f p_scale)
                            :pos(p_pos), tex(p_tex), scale(p_scale)
                        {
                            SDL_QueryTexture(tex, NULL, NULL, ¤tFrame.w, ¤tFrame.h);

                            currentFrame.x = 0;
                            currentFrame.y = 0;

                            destroy = false;
                        }

                        void Entity::Update()
                        {
                            dst.x = GetPos().x - currentFrame.w / 2 * GetScale().x;
                            dst.y = GetPos().y - currentFrame.h / 2 * GetScale().y;
                            dst.w = GetScale().x * currentFrame.w;
                            dst.h = GetScale().y * currentFrame.h;
                        }

                        void Entity::SetPos(Vector2f _pos)
                        {
                            pos = _pos;
                        }

                        void Entity::SetScale(Vector2f _scale)
                        {
                            scale = _scale;
                        }

                        void Entity::Destroy()
                        {
                            destroy = true;
                        }



                    
                
                    

                        Game::Game()
                            :window("GAME v1.0", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 720, 720)
                        {
                        }

                        void Game::Init()
                        {
                            if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
                                isRunning = true;
                            else
                                isRunning = false;

                            TTF_Init();

                            SDL_ShowCursor(SDL_DISABLE);

                            Texture::GetInstance().LoadTextures(window);
                            AudioManager::GetInstance().Init();
                            UIManager::GetInstance().SetRenderer(window.GetRenderer());
                        }

                        void Game::Update()
                        {
                            if (!UIManager::GetInstance().m_Exit)
                                isRunning = true;
                            else
                                isRunning = false;

                            SDL_GetMouseState(&mouseX, &mouseY);
                            Texture::GetInstance().m_CursorWhite.SetPos(Vector2f(mouseX, mouseY));
                            Texture::GetInstance().m_CursorRed.SetPos(Vector2f(mouseX, mouseY));

                            Texture::GetInstance().Update();

                            ObjectSpawner::GetInstance().Update();

                            UIManager::GetInstance().Update();

                            CheckCollision();

                            srand(SDL_GetTicks());
                        }

                        void Game::CheckCollision()
                        {
                            std::vector allEnemies;

                            for (int i = 0; i < ObjectSpawner::GetInstance().GetSmallEnemies().size(); i++)
                                allEnemies.push_back(&ObjectSpawner::GetInstance().GetSmallEnemies()[i]);

                            for (int i = 0; i < ObjectSpawner::GetInstance().GetMediumEnemies().size(); i++)
                                allEnemies.push_back(&ObjectSpawner::GetInstance().GetMediumEnemies()[i]);

                            for (int i = 0; i < ObjectSpawner::GetInstance().GetBigEnemies().size(); i++)
                                allEnemies.push_back(&ObjectSpawner::GetInstance().GetBigEnemies()[i]);
                            
                            //Collosion between FirstAid and player 
                            if (Collision::IsCollide(&Texture::GetInstance().m_PlayerShip.GetDst(), &ObjectSpawner::GetInstance().GetFirstAid().GetDst())
                                && !ObjectSpawner::GetInstance().GetFirstAid().IsDestroy()
                                && !Texture::GetInstance().m_PlayerShip.IsDestroy())
                            {
                                AudioManager::GetInstance().PlaySoundEffect(AudioManager::GetInstance().m_FirstAid);
                                Texture::GetInstance().m_PlayerShip.SetHitPoints(50);
                                UIManager::GetInstance().ResetHealthBar();
                                ObjectSpawner::GetInstance().GetFirstAid().Destroy();
                            }

                            //Collosion between Shield and player 
                            if (Collision::IsCollide(&Texture::GetInstance().m_PlayerShip.GetDst(), &ObjectSpawner::GetInstance().GetShield().GetDst())
                                && !ObjectSpawner::GetInstance().GetShield().IsDestroy()
                                && !Texture::GetInstance().m_PlayerShip.IsDestroy())
                            {
                                AudioManager::GetInstance().PlaySoundEffect(AudioManager::GetInstance().m_Shield);
                                Texture::GetInstance().m_PlayerShip.SetShield(20);
                                UIManager::GetInstance().ResetShieldBar();
                                ObjectSpawner::GetInstance().GetShield().Destroy();
                            }

                    
                

What I Learned

While making this game I learned a lot of new things in C++ and SDL2. In C++ I learned more about inheritance, std::vector, static classes.

In SDL2 I learned about Renderer functions, SDL mixer for sound effects and SDL ttf for displying font.

And to solve errors and bugs I used Debugger and Breakpoints in Visual Studio.


Github Link