Noob learns to code in 3 months

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 8th, 2017, 1:46 pm

hmm managed to build now, nothing gets drawn and sreen size is different :S

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Noob learns to code in 3 months

Post by albinopapa » March 8th, 2017, 2:06 pm

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

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 8th, 2017, 4:07 pm

yep,

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

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 8th, 2017, 7:40 pm

Trying to figure out how the level thingy would be...
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;
             }
        }
    }


albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Noob learns to code in 3 months

Post by albinopapa » March 8th, 2017, 8:44 pm

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

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 8th, 2017, 9:23 pm

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

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 8th, 2017, 10:34 pm

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

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Noob learns to code in 3 months

Post by LuisR14 » March 9th, 2017, 3:58 am

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 :mrgreen: --

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 9th, 2017, 12:37 pm

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

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 9th, 2017, 1:15 pm

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: 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;
			}
		}
	}
}
the spawnfunctions look like this

Code: Select all

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

Post Reply