I don't think I'm trying to do polymorphism. Aren't dynamic arrays suppose to be similar to vectors? Well I had a problem a while ago with a dynamic array only applying the results of a conditional statement from the last element to the whole array. With a vector wouldn't I be able to apply my condition to each element individually?
Anyways I needed time to figure out how to print my code to site. I wanted to make sure it was eligible and pasting to notepad and then to the site seems to have did the trick.
Main function
Code:
#include "global.h"
#include "Function.h"
#include <iostream>
#include <vector>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
#include "SDL_image.h"
#include "Tile.h"
#include "Move.h"
#include "Timer.h"
#include "constant.h"
int main( int argc, char* args[] )
{
//Quit flag
bool quit = false;
//The dot
Move character;
//The tiles that will be used
Tile *tiles[ TOTAL_TILES ];
//The beginning of creating the vector
std::vector <SideTile> walls;
//The frame rate regulator
Timer delta;
//Initialize SDL
if( init() == false )
{
return 1;
}
//Load the files
if( load_files() == false )
{
return 1;
}
//Clip the tile sheet
clip_tiles();
clips_ys();
//Set the tiles. Where the vector should be created
if( set_tiles( tiles, walls) == false )
{
return 1;
}
//While the user hasn't quit
while( quit == false )
{
//While there's events to handle
while( SDL_PollEvent( &event ) )
{
//Handle events for the dot
character.attack_input();
character.handle_input();
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
//Move the dot
character.move( tiles,walls, delta.get_ticks() );
character.attack(delta.get_ticks());
//Restart delta timer
delta.start();
//Set the camera
character.set_camera();
//Show the tiles
for( int t = 0; t < TOTAL_TILES; t++ )
{
tiles[ t ]->show();
}
character.layer_maintance(tiles,walls);
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
}
//Clean up
clean_up( tiles, walls );
return 0;
}
Set tiles function where I'm trying to make the vector
Code:
bool set_tiles( Tile *tiles[], vector <SideTile>& walls)
{
//The tile offsets
int x = 0, y = 0;
int a = 0, b = 0;
int p = 0, q = 0;
int c = 0, d = 0;
int z = 0;
//Open the map
std::ifstream map( "lazy.map" );
std::ifstream map2( "Zrender.map" );
std::ifstream lv_1acoords ("lv1_aCoords.map");
std::ifstream lv_1zcoords ("lv1_zCoords.map");
std::ifstream lv_1xcoords ("lv1_xCoords.map");
//If the map couldn't be loaded
if( map == NULL )
{
return false;
}
if( map2 == NULL )
{
return false;
}
//Initialize the tiles
for( int t = 0; t < TOTAL_TILES; t++ )
{
//Determines what kind of tile will be made
int tileType = -1;
//Read tile from map file
map >> tileType;
//If the was a problem in reading the map
if( map.fail() == true )
{
//Stop loading map
map.close();
return false;
}
//If the number is a valid tile number
if( ( tileType >= 0 ) && ( tileType < TILE_SPRITES ) )
{
tiles[ t ] = new Tile(NULL, NULL, NULL , NULL, x, y, tileType );
//Move to next tile spot
x += TILE_WIDTH;
}
//If we don't recognize the tile type
else
{
//Stop loading map
map.close();
return false;
}
//If we've gone too far
if( x >= LEVEL_WIDTH )
{
//Move back
x = 0;
//Move to the next row
y += TILE_HEIGHT;
}
}
//Ending of for loop
for( int s = 0; s < TOTAL_TILES_WALL; s++ )
{
//Determines what kind of tile will be made
int tileTypeWall = -1;
int aPosition = -1, zPosition = -1, xPosition = -1;
//Read tile from map file
map2 >> tileTypeWall;
lv_1acoords >> aPosition;
lv_1zcoords >> zPosition;
lv_1xcoords >> xPosition;
//If the was a problem in reading the map
if( map2.fail() == true )
{
//Stop loading map
map2.close();
return false;
}
a = aPosition;
z = zPosition;
x = xPosition;
//If the number is a valid tile number
if (( tileTypeWall <= TILE_REDCUBE_MEDIUM ) && ( tileTypeWall >= TILE_REDCUBE_LARGE ))
{
SideTile newSideTile( a, b, NULL , NULL, x, z, tileTypeWall );
walls.push_back(newSideTile);
}
}
//Close the file
map.close();
//If the map was loaded fine
return true;
}