Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Nabeel Rehman

Pages: [1]
1
Graphics / Setting Background Image Without Slowing Down Game.
« on: May 03, 2017, 08:03:04 pm »
Hi guys, my question is that how can we set a Background Image, something in Tank Game, without slowing down the game, i've tried setting it but my game slows down and below is the link to image i want to set as Background. Please
http://wallpaperswide.com/download/military_camouflage_patterns-wallpaper-1366x768.jpg

2
General / Tank Line of Sight
« on: May 01, 2017, 10:19:23 am »
Hi guys, i'm working on a 2D tank game in which i have to find if user tank is in position with enemy tank in x or y plane. Here's my code.

bool Enemy::lineOfSight_HOR()
{
        int x = e_enemySprite.getPosition().x;
        int y = e_enemySprite.getPosition().y;

       
                for (int i = y; i < VideoMode::getDesktopMode().width; i++)
                {
                        if (i == userTankPos->y)
                        {
                                return true;
                                break;
                        }
                }
       
        return false;
}

Buts it's not working properly, enemy tank moves even if y-point of user tank is greater than enemy tank.  ???

3
General discussions / Artificial Intelligence.
« on: April 29, 2017, 05:57:11 pm »
Hi guys, i'm making a tank game in which i need some type of AI to control my enemy tanks i.e they move on their on and fire on their on, I've never done some thing like this before so i have no idea where to start. If you guys could suggest me something related to Artificial Intelligence to start with i'll be very thankful.

4
Graphics / Re: Rendering objects from different classes to one.
« on: April 28, 2017, 10:52:14 pm »
For loading texture.

void Tank::setSprites()
{
        t_bulletTexture.loadFromFile("bullet.png");
        t_tankTexture.loadFromFile("tank.png");

        t_tankSprite.setTexture(t_tankTexture);

        t_tankSprite.setPosition(t_window.GetWindowSize().x / 2, t_window.GetWindowSize().y / 2);
        t_tankSprite.setOrigin(t_tankTexture.getSize().x / 2, t_tankTexture.getSize().y / 2);
        t_tankSprite.setRotation(360);
}
 

5
Graphics / Rendering objects from different classes to one.
« on: April 28, 2017, 10:00:34 pm »
Hi Guys. i got this problem with with drawing drawables from classes in main class, it does not draw anything accept the window and it's Background Color.

[ Tank.cpp ]

void Tank::Render()
{
        t_window.Draw(t_tankSprite);
        HandleInput();
}

[window.cpp]

void window::Create()
{
        t_window.create({ t_windowSize.x, t_windowSize.y, 32 }, t_windowTitle, Style::Fullscreen);
}

void window::BeginDraw()
{
        t_window.clear(Color(158, 154, 117, 255));
}

void window::EndDraw()
{
        t_window.display();
}

void window::Update()
{
        Event t_event;
        if (t_window.pollEvent(t_event))
        {
                if (t_event.type == Event::Closed || (t_event.type == Event::KeyPressed && t_event.key.code == Keyboard::Escape))
                        t_IsDone = true;
        }

}
 

[ Main.cpp ]

#include <Windows.h>
#include "Tank.h"

#ifndef window_h
#define window_h
#include "window.h"
#endif


using namespace sf;


int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
        window win;
        win.Setup("Tank Game", Vector2u(1024, 786));
        win.Create();

        Tank tank;

        while (!win.IsDone())
        {
                win.BeginDraw();
                win.Update();

                tank.Render();

                win.EndDraw();
        }
        return 0;
}

6
General / Re: Thread stops the GUI/
« on: April 22, 2017, 07:13:53 am »
Thanks its working now....

7
Graphics / Background slows down the game.
« on: April 21, 2017, 11:21:28 am »
Hi guys, I'm having a problem with my background it's 1024x768 resolution, it slow down my game since it had to be redrawn every frame. What should I do now ???

8
General / Re: Thread stops the GUI/
« on: April 20, 2017, 10:00:17 pm »
so what i have to do for parallel processing ????

9
General / Thread stops the GUI/
« on: April 20, 2017, 07:21:59 pm »
Hi guys, i'm having trouble with threads, in this code when i start a thread it stops the game for 10 seconds ( the time for reloading ) and then continues.

I'm using startReloading() as a member function in Tank class.

or maybe you can suggest me a different approach ???

---------------------------------------------------------------
if( reloading == false )
{
          // shoot.
}
else
{
                _reloadTime = _reloadClock.restart();
                reloading = true;

                thread reloadThread(&Tank::startReloading, this);
                reloadThread.join();

}

//...

void Tank::startReloading()
{
        do
        {
                _reloadTime = _reloadClock.getElapsedTime();
                if (_reloadTime.asSeconds() > 10)
                {
                        crntRound = 0;
                        updateAmmoString();
                        reloading = false;
                        break;
                }
        } while (true);
}
 

10
Graphics / how to set background.
« on: April 19, 2017, 08:34:19 am »
Hi guys, i'm having trouble in setting up the background for my tank game, the image 'background.png' just don't show up!!!  ???
------------------------------------------------------------
// Image size is 1280x1024

        RenderWindow window(VideoMode(1024, 786, 32), "Test 32");

        Texture texture;
        texture.loadFromFile("background.png");
        Sprite sprite;
        Vector2u size = texture.getSize();
        sprite.setTexture(texture);
        sprite.setOrigin(size.x / 2, size.y / 2);

        while (window.isOpen())
        {
                Event e;
                while (window.pollEvent(e))
                {
                        if (e.type == Event::Closed)
                                window.close();
                }
                window.draw(sprite);
                window.display();
        }

11
General / Re: Application hanging up.
« on: April 17, 2017, 07:10:35 pm »
Thank's a lot guys, finally it's working  ;D

12
General / Re: Application hanging up.
« on: April 16, 2017, 08:43:31 pm »
Well i've found a way to fire bullets but the problem is if space bar is pressed it just show long continuous image of my ' bullet '.
-----------------------------------------
#define X_COL 0
#define Y_COL 1
#define EMPTY_CELL -1.0f
RenderWindow window(VideoMode(600, 600, 32), "Test 32");
float ammo[100][2];

int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
        Texture texture;
        Sprite sprite;
        texture.loadFromFile("bullet.png");
        sprite.setTexture(texture);
        sprite.setPosition(window.getSize().x / 2, window.getSize().y / 2);
        sprite.setOrigin(texture.getSize().x / 2, texture.getSize().y / 2);
        sprite.setRotation(360);

        #pragma region Initialize 'ammo'

        for (int i = 0; i < 100; i++)
        {
                for (int j = 0; j < 2; j++)
                {
                        ammo[i][j] = EMPTY_CELL;
                }
        }

        #pragma endregion

        thread thr;
        int crntRound = 0;
        float angle;
        window.setKeyRepeatEnabled(false);
        while (window.isOpen())
        {
                Event _event;
                while (window.pollEvent(_event))
                {
                        if (_event.type == Event::Closed)
                                window.close();
                }
                window.clear(Color::Black);
                if (Keyboard::isKeyPressed(Keyboard::Space))
                {
                       
                                if (crntRound != 100)
                                {
                                        ammo[crntRound][X_COL] = 300;
                                        ammo[crntRound][Y_COL] = 300;
                                        crntRound++;
                                }
                                else
                                {
                                        crntRound = 0;
                                }
                }
               
                for (int i = 0; i < 100; i++)
                {
                        if (ammo[i][X_COL] != EMPTY_CELL && ammo[i][Y_COL] != -EMPTY_CELL)
                        {
                                if (!(ammo[i][X_COL] > 600 || ammo[i][Y_COL] > 600))
                                        sprite.setPosition(++ammo[i][X_COL], ammo[i][Y_COL]);
                                else
                                {
                                        ammo[i][X_COL] = EMPTY_CELL;
                                        ammo[i][Y_COL] = EMPTY_CELL;
                                }
                        }
                        window.draw(sprite);
                }
                window.display();
        }
        return 0;
}

13
General / Application hanging up.
« on: April 16, 2017, 07:29:28 pm »
hi guys,
i'm coding a tank game and i'm stuck at the point where tank shoot bullets, below is the unit of code i used to shoot bullets i've marked up where i think my applications hanging up. Please Help :-\
----------------------------------------------
#include <Windows.h>
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <vector>
#include <thread>

using namespace sf;
using namespace std;
#define X_COL 0
#define Y_COL 1

RenderWindow window(VideoMode(600, 600, 32), "Test 32");
Texture texture;
vector<Sprite> sprite(10, Sprite(texture));
float ammo[10][2];

int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
   
   texture.loadFromFile("bullet.png");
   sprite[0].setPosition(window.getSize().x / 2, window.getSize().y / 2);
   sprite[0].setOrigin(texture.getSize().x / 2, texture.getSize().y / 2);
   sprite[0].setRotation(360);

   for (int i = 0; i < 10; i++)
   {
      for (int j = 0; j < 2; j++)
      {
         ammo[j] = -1.0f;
      }
   }

   thread thr;
   int curntRound = 0;
   float angle;

   while (window.isOpen())
   {
      Event _event;
      while (window.pollEvent(_event))
      {
         if (_event.type == Event::Closed)
            window.close();
      }

      if (Keyboard::isKeyPressed(Keyboard::Space))
      {
         ammo[curntRound][X_COL] = sprite[0].getPosition().x;          // Application hang up here.
         ammo[curntRound][Y_COL] = sprite[0].getPosition().y;          // it only insert x y points at
                                                                                                                           // first iteration in 'ammo' array
         curntRound++;
      }
      window.clear(Color::Black);
      window.display();
   }
   return 0;
}
void fire()
{
   for (int i = 0; i < 10; i++)
   {
      if (ammo[X_COL] != 1.0f && ammo[Y_COL] != -1.0f)
         sprite[0].setPosition(++ammo[X_COL], ammo[Y_COL]);
      window.draw(sprite[0]);
   }
}

Pages: [1]
anything