Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 372 posts ]  Go to page Previous  1 ... 31, 32, 33, 34, 35, 36, 37, 38  Next
Author Message
 Post Posted: March 8th, 2017, 1:46 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 281
Location: Idiot from northern Europe
hmm managed to build now, nothing gets drawn and sreen size is different :S


Top 
 Profile  
Reply with quote  
 Post Posted: March 8th, 2017, 2:06 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2378
Location: Oklahoma, United States
That's no fun

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: March 8th, 2017, 4:07 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 281
Location: Idiot from northern Europe
yep,

tried doing the opposite too and copy all code from my game into the 3d repo but that too just gave it aids


Top 
 Profile  
Reply with quote  
 Post Posted: March 8th, 2017, 7:40 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 281
Location: Idiot from northern Europe
Trying to figure out how the level thingy would be...
Is this in the ball park?

Code:
const int width = 20;
const int height = 100;
const int cellDimension = 40;
int level[height][width];
ifstream read("level.txt");

//put the data from the text file into the 2d array
for (int i = 0; i <height; i++)
{
    for (int j = 0; j < width; j++)
    {
          read>>cells[i][j];
    }
}


// loop through the 2d array and choose action depending on number
for (int i = 0; i <height; i++)
    {
        for (int j = 0; j < width; j++)
        {
             switch(cells[i][j])
            {
             case 1:
                  MineManager.SpawnMine(j * cellDimension, i * cellDimension);
                  break;
             }
        }
    }



Top 
 Profile  
Reply with quote  
 Post Posted: March 8th, 2017, 8:44 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2378
Location: Oklahoma, United States
Yeah, that's practically it, just don't forget to call read.close() :).

Since you cache the file contents in the 2D array, you can close it once it's cached.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: March 8th, 2017, 9:23 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 281
Location: Idiot from northern Europe
albinopapa wrote:
Yeah, that's practically it, just don't forget to call read.close() :).

Since you cache the file contents in the 2D array, you can close it once it's cached.


Alright :) I'll try this, will have to rewrite all entities a bit first though


Top 
 Profile  
Reply with quote  
 Post Posted: March 8th, 2017, 10:34 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 281
Location: Idiot from northern Europe
OMG!!!! So I was coding up a storm and through the whole thing felt 100% sure that lol no way this will work. But seems to kinda work :D

Feels good after spending 10+ hours failing today


edit: now one problem is that the first line in the text file will spawn objects at the top of the screen, the lines below will spawn objects below the top while I'd need them to be spawned above it.

like if I give the a mine the y position of i * cellDimension (say 40 * 40) this is 1600 and would mean it gets spawned below the ship.

Also it now stopped working out of nowhere :S no black holes show up anymore

Edit 2: figured out why no black holes were showing up but now the engine crashes instead lol

edit 3: found the bug

edit 4: still not sure how to make the map go "upwards"

last edit promise :D

........
I'm a poerplayer and a known liar/scumbag so here's edit 5:
figured it out: float(-i * cellDimension));
I tried this before but for whatever reason it didn't work. Well that's because I had a condition not to update the black hole if the position was less than 0


Top 
 Profile  
Reply with quote  
 Post Posted: March 9th, 2017, 3:58 am 
User avatar

Joined: May 23rd, 2013, 3:52 pm
Posts: 1223
Location: USA
tho the file just might autoclose if it goes out of scope o.o

_________________
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
irc://irc.freenode.net/#pchili alt -- join up if ever want real-time help or to just chat :mrgreen: --


Top 
 Profile  
Reply with quote  
 Post Posted: March 9th, 2017, 12:37 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 281
Location: Idiot from northern Europe
Alright all the shits are now in this level thingy. Had to make a bunch of changes to all the entites and will have some cleaning up to do...

Not sure if this code is very good/efficient since all entities are created at the start and none of them are destroyed during the game. Will post code later if anyone want to look at it. Gonna figure out a way to reset the positions between lives now


Top 
 Profile  
Reply with quote  
 Post Posted: March 9th, 2017, 1:15 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 281
Location: Idiot from northern Europe
Alright I'm just resetting the position between lives now, so that works.

So I call the level.Read() in the constructor of world.

The read function is like this

Code:
void Level::ReadLevel()
{
   read.open("level.txt");
   for (int i = 0; i < height; i++)
   {
      for (int j = 0; j < width; j++)
      {
         read >> level[i][j];
      }
   }
   read.close();

   for (int i = 0; i < height; i++)
   {
      for (int j = 0; j < width; j++)
      {
         switch (level[i][j])
         {
         case 1:
            bHoleM.SpawnBlackHole(float(j * cellWidth), float(i * cellHeight));
            break;

         case 2:
            droneM.SpawnDrone(float(j * cellWidth), float(i * cellHeight));
            break;

         case 3:
            eBoostM.SpawnEnergyBoost(float(j * cellWidth), float(i * cellHeight));
            break;

         case 4:
            mineM.SpawnMine(float(j * cellWidth), float(i * cellHeight));
            break;

         case 5:
            obstacleM.SpawnObstacle(float(j * cellWidth), float(i * cellHeight));
            break;

         case 6:
            shieldM.SpawnShield(float(j * cellWidth), float(i * cellHeight));
            break;

         case 7:
            smallEnemyM.SpawnSmallShip(float(j * cellWidth), float(i * cellHeight));
            break;

         case 8:
            bigEnemyM.Spawn(float(j * cellWidth), float(i * cellHeight));
            break;
         }
      }
   }
}


the spawnfunctions look like this

Code:
void SmallEnemyManager::SpawnSmallShip(float X, float Y)
{
   nSmallShip++;
   smallShip.emplace_back<SmallEnemyShip>(SmallEnemyShip{ X, Y, smallExhaust, smallExplode, exploSound, leftM, rightM});
}


Then when I reset when the player dies, it's just pos = resetPos

So basically all entites gets created at the start of the game and exist through the whole game. Is this very inefficient and I should somehow deconstruct the entities when they go off screen etc or something similar?

If this seems alright I'm gonna make a function to read blackholelevel too and then start designing the level


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 372 posts ]  Go to page Previous  1 ... 31, 32, 33, 34, 35, 36, 37, 38  Next

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: