Noob learns to code in 3 months
Re: Noob learns to code in 3 months
hmm managed to build now, nothing gets drawn and sreen size is different :S
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Noob learns to code in 3 months
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
Re: Noob learns to code in 3 months
yep,
tried doing the opposite too and copy all code from my game into the 3d repo but that too just gave it aids
tried doing the opposite too and copy all code from my game into the 3d repo but that too just gave it aids
Re: Noob learns to code in 3 months
Trying to figure out how the level thingy would be...
Is this in the ball park?
Is this in the ball park?
Code: Select all
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;
}
}
}
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Noob learns to code in 3 months
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.
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
Re: Noob learns to code in 3 months
Alright I'll try this, will have to rewrite all entities a bit first thoughalbinopapa 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.
Re: Noob learns to code in 3 months
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
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
........
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
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
........
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
Re: Noob learns to code in 3 months
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.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Re: Noob learns to code in 3 months
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
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
Re: Noob learns to code in 3 months
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
the spawnfunctions look like this
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
So I call the level.Read() in the constructor of world.
The read function is like this
Code: Select all
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;
}
}
}
}
Code: Select all
void SmallEnemyManager::SpawnSmallShip(float X, float Y)
{
nSmallShip++;
smallShip.emplace_back<SmallEnemyShip>(SmallEnemyShip{ X, Y, smallExhaust, smallExplode, exploSound, leftM, rightM});
}
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