Пример #1
0
void TestState::initialize() {
	_game->log("Initialize TestState...");

	// ##### TESTS HERE !!! #####

	_loader.addImage("assets/test/tileset.png");
	_loader.addImage("assets/ts_placeholder.png");
	_loader.addImage("assets/test/font_0.png");

	_loader.addSound("assets/test/laser0.wav");
	_loader.addSound("assets/test/laser1.wav");
	_loader.addMusic("assets/test/music.ogg");
	_loader.addFont("assets/test/font.txt");

	_loader.loadAll();

	_left  = _input.addInput("left");
	_right = _input.addInput("right");
	_up    = _input.addInput("jump");
	_down  = _input.addInput("down");
	_use   = _input.addInput("use");

	_input.loadKeyBindingFile("assets/test/keymap.json");

	_input.bindJsonKeys(_left,  "left",  SDL_SCANCODE_LEFT);
	_input.bindJsonKeys(_right, "right", SDL_SCANCODE_RIGHT);
	_input.bindJsonKeys(_up,    "jump",  SDL_SCANCODE_UP);
	_input.bindJsonKeys(_down,  "down",  SDL_SCANCODE_DOWN);
	_input.bindJsonKeys(_use,   "use",   SDL_SCANCODE_SPACE);

	_tilemap = TileMap(_loader.getImage("assets/test/tileset.png"), 32, 32);


	_msound = _loader.getSound("assets/test/laser0.wav");
	_jsound = _loader.getSound("assets/test/laser1.wav");
	_music  = _loader.getMusic("assets/test/music.ogg");
	_mchannel = -1;

	_font = _loader.getFont("assets/test/font.txt");
	_font.setImage(_loader.getImage("assets/test/font_0.png"));

	_scene.level().setTileMap(TileMap(_loader.getImage("assets/ts_placeholder.png"), 32, 32));

	_scene.level().loadFromJsonFile("assets/level_0.json");
	_scene.level().setTileCollision(12, true);
	_scene.level().setTileCollision(13, true);

	_obj = _scene.addObject("Test");
	_scene.addSpriteComponent(_obj, _tilemap, 1);
	_scene.addLogicComponent(_obj, MOVE_COMPONENT_ID, new MoveComponent(_obj));
	_obj->computeBoxFromSprite(Vec2(.5, .5), 1);
	_obj->geom().pos = Vec2(1920/4, 1080/4);
}
Пример #2
0
void SetupScene2()
{
	testDude = sceneMan.CreateSceneObject<TestEntity>();
	testDude->Init();
	//RectSize(50, 50, &test->tf.rectangle);
	testDude->GetComponent<BoxCollider>()->stationary = false;
	testDude->render.renderInfo.depth = 50;
	testDude->tf.SetPos(50.f, 200.f);
	testDude->bc.collisionRect = &testDude->tf.rectangle;
	testDude->bc.stationary = false;

	Entity* textEntity = sceneMan.CreateSceneObject<Entity>();
	Transform* tf = new Transform();
	tf->SetRect(20, 20, 1, 1);
	textEntity->RegisterComponent(tf);
	bmpTextEntity* bmpText = new bmpTextEntity(L"The second screen!", L"fart\\testFont.png", 16, 16);
	bmpText->layer = 31;
	textEntity->RegisterComponent(bmpText);
	bmpText->SetCharacterWidths(L"fart\\BFB Font Metrics.dat");
	bmpText->SetColor(vec4(0.f, 0.6f, 0.2f, 1.f));
	bmpText->SetSize(30);

	TileMap tmap = TileMap(L"fart\\tilemap2.json");
	tmap.Init();
}
Пример #3
0
void Nappaform::fLoad()
{
			frameCount = 0;
			offScreenBitmap = gcnew Bitmap(width, height);
			offScreenCanvas = Graphics::FromImage(offScreenBitmap);
			random = gcnew Random();
			runLeft = gcnew Bitmap("playerRunLeft.bmp");
			runRight = gcnew Bitmap("playerRunRight.bmp");
			mainCanvas = CreateGraphics();

			//Tilemaps
			whiteSquare = gcnew Bitmap("tiles.bmp");
			blackSquare = gcnew Bitmap("tileBlack.bmp");
			tile = gcnew Tile(whiteSquare, true);
			tile2 = gcnew Tile(blackSquare, false);
			tileList = gcnew TileList(2);
			tileList->setTileArrayEntry(tile);
			tileList->setTileArrayEntry(tile2);
			
			//Create the tile map
			tileMap = gcnew TileMap(tileList, offScreenCanvas, TILES_WIDE, TILES_HIGH, TILE_SIDE);

			tileMap->loadFromFile("whiteRoom.csv");

			//TileMaps

			//Viewport

			//Create the view port
			viewPort = gcnew ViewPort(0,0,VP_TILE_WIDE,VP_TILE_HIGH,Width,Height,tileMap, offScreenCanvas, TILE_SIDE);
			
			//ViewPort
			playerList = gcnew SpriteList();

			playerFileNames = gcnew array<String^>{
			"playerRunR.bmp",
			"player5.bmp",
			"playerRun.bmp",
			"player5.bmp"
			};

			int boundX = TILES_WIDE * TILE_SIDE;
			int boundY = TILES_HIGH * TILE_SIDE;

			player = gcnew Player(tileMap, offScreenCanvas, playerFileNames, random, 8, Rectangle(0,0,boundX, boundY),BOUNCE);
			
			playerList->addSprite(player);
			
}
Пример #4
0
void Game::mainLoop() {

    TileMap map = TileMap(graphics);
    world.map = map.getMap();
    int previousTimeMs = SDL_GetTicks();
    while(isRunning) {
        int current = SDL_GetTicks();
        const int elapsedTime = current - previousTimeMs;
        graphics.clearRenderer();
        // Run through Systems
        processInput();
        update(elapsedTime);

        map.render(graphics);

        render();

        int tick = 1000/kFPS;
        if(elapsedTime < tick) {
            SDL_Delay(tick - elapsedTime);
        }
        previousTimeMs = current;
    }
}
int main()
{
	sf::RenderWindow Window;
	Window.create(sf::VideoMode(640, 640), "Fortress Survival 0.0.4, a new approach!");
	Window.setFramerateLimit(300);

	Selection selection(Selection(2, sf::Color::White));
	Player player(Player(sf::Vector2f(32, 32), sf::Vector2f(32, 32)));

	TileMap tile(TileMap(sf::Vector2f(Window.getSize().x / tileW, Window.getSize().y / tileH), sf::Color::Red));
	for(int i = 0; i < tileH; i++)
	{
		for(int j = 0; j < tileW; j++)
		{
			if(level[i][j] == '0')
				map[j][i] = 0;
			else if(level[i][j] == '1')
				map[j][i] = 1;
		}
	}
	int xA, yA, xB, yB;
	std::string route;

	while(Window.isOpen())
	{
		sf::Event Event;
		while(Window.pollEvent(Event))
		{
			switch(Event.type)
			{
			case sf::Event::Closed:
				Window.close();
				break;
			}
		}

		tile.Update(Window);

		selection.Update(Window);

		player.IsSelected(selection, Window);
		//player.Walk(Window);

		if(sf::Mouse::isButtonPressed(sf::Mouse::Right))
		{
		xA = player.rect.getPosition().x / 32; yA = player.rect.getPosition().y / 32; xB = sf::Mouse::getPosition(Window).x / 32; yB = sf::Mouse::getPosition(Window).y /32;

	//std::cout<<"Map Size (X,Y): "<<tileW<<","<<tileH<<std::endl;
    //std::cout<<"Start: "<<xA<<","<<yA<<std::endl;
    //std::cout<<"Finish: "<<xB<<","<<yB<<std::endl;
	// get the route
    //clock_t start = clock();
    route = pathFind(xA, yA, xB, yB);
    if(route=="") std::cout<<"An empty route generated!"<<std::endl;
    //clock_t end = clock();
    //double time_elapsed = double(end - start);
    //std::cout<<"Time to calculate the route (ms): "<<time_elapsed<<std::endl;
    //std::cout<<"Route:"<<std::endl;
    //std::cout<<route<<std::endl<<std::endl;

	 // follow the route on the map and display it 
    if(route.length()>0)
    {
        int j; char c;
        int x=xA;
        int y=yA;
        map[x][y]=2;
        for(int i=0;i<route.length();i++)
        {
            c =route.at(i);
            j=atoi(&c); 
            x=x+dx[j];
            y=y+dy[j];
            map[x][y]=3;
        }
        map[x][y]=4;
    
        // display the map with the route
        /*for(int y=0;y<tileH;y++)
        {
            for(int x=0;x<tileW;x++)
                if(map[x][y]==0)
                    std::cout<<".";
                else if(map[x][y]==1)
                    std::cout<<"O"; //obstacle
                else if(map[x][y]==2)
                    std::cout<<"S"; //start
                else if(map[x][y]==3)
                    std::cout<<"R"; //route
                else if(map[x][y]==4)
                    std::cout<<"F"; //finish
            std::cout<<std::endl;
        }*/

		for(int i = 0; i < tileH; i++)
	{
		for(int j = 0; j < tileW; j++)
		{
			if(level[i][j] == '0')
				map[j][i] = 0;
			else if(level[i+1][j] == '1')
				map[j][i] = 1;
		}
	}


	}
	}
		for(int i = 0; i < route.size(); i++)
		{
			sf::Time wtf;
			if(route[i] == '0')
				player.rect.move(32, 0);
			else if(route[i] == '1')
				player.rect.move(32, 32);
			else if(route[i] == '2')
				player.rect.move(0, 32);
			else if(route[i] == '3')
				player.rect.move(-32, 32);
			else if(route[i] == '4')
				player.rect.move(-32, 0);
			else if(route[i] == '5')
				player.rect.move(-32, -32);
			else if(route[i] == '6')
				player.rect.move(0, -32);
			else if(route[i] == '7')
				player.rect.move(32, -32);
		}
		if(player.rect.getPosition().x > Window.getSize().x || player.rect.getPosition().y > Window.getSize().x)
		{
			player.rect.setPosition(32, 32);
		}
		std::cout<<"Player pos: "<<player.rect.getPosition().x<<", "<<player.rect.getPosition().y<<"\n";

		Window.display();
		Window.clear();
	}
	return 0;
}