示例#1
0
void Game::draw() {
	if (!states.empty()) {
		GameState *current = states.top();
		current->draw();
	}
	SDL_Flip(window);
}
示例#2
0
void main()
{
	sfw::initContext(800, 600, "NSFW Draw");
	sfw::setBackgroundColor(BLACK);	


	// Now I'm using the loadTexture from AssetLibrary! Notice how I Get to name it now.
	// The name lets me easily refer to it later!
	loadTexture("Explosion", "../res/explosion.png", 5, 3); // so this is an explosion sprite sheet. TLDR WE WILL MAKE DINOSAURS EXPLODE!
	addAnimation("Explosion", "BOOM", {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14});
	addAnimation("Explosion", "NOTVERYBOOM", { 0,1 });

	//MenuState menu;

	// All of the logic for our game goes here now!
	GameState game;

	while (sfw::stepContext())
	{
		//switch ()
		//{
		//case MENU:
		//	menu.update();
		//	menu.draw();
		//case GAME:
			game.update(); // Do the thing!
			game.draw();   // Draw it!	    
		//}
	}

	sfw::termContext();
}
示例#3
0
int main()
{
	//Remove Console Window
	FreeConsole();

	//Render Game Window
	sfw::initContext(800, 800, "Basic");

	//Load Textures from File
	loadTexture("Background", "./Textures/Dungeon.png", 1, 1);
	loadTexture("Title",      "./Textures/title.png",   1, 1);
	loadTexture("dKnight",    "./Textures/dKnight.png", 4, 4);
	loadTexture("spear",      "./Textures/spear.PNG",   8, 8);
	loadTexture("slime",      "./Textures/Slime.png",   6, 4);
	loadTexture("press",      "./Textures/pressF.png",  1, 1);
	loadTexture("pressA",     "./Textures/pressA.png",  1, 1);
	loadTexture("win",        "./Textures/win.png",     1, 1);
	loadTexture("lose",       "./Textures/lose.png",    1, 1);
	loadTexture("move",       "./Textures/moveText.png",1, 1);
	loadTexture("fire",       "./Textures/fireText.png",1, 1);
	loadTexture("font",       "./Textures/fontmap.png", 16, 16);

	//Set Animations
	addAnimation("dKnight",   "walkLeft",  { 4, 5, 6, 7 });
	addAnimation("dKnight",   "walkRight", { 8, 9, 10, 11 });
	addAnimation("dKnight",   "walkUp",    { 12, 13, 14, 15 });
	addAnimation("dKnight",   "walkDown",  { 0, 1, 2, 3 });
	addAnimation("slime",     "slideUp",   { 0, 1, 2, 3 });

	//Instantiate necessary Classes
	GameState game;
	STATE state = Splash;
	
	//Set Main Game States and continue looping until exited
	while (sfw::stepContext())
	{
		switch (state)
		{
		case Splash:
			state = game.splashScreen(); break;
		case Main:
			return Game;
		case Game:
			game.update();
			state = game.draw(); break;
		case Win:
			state = game.win(); break;
		case Lose:
			state = game.lose(); break;
		}
	}
	sfw::termContext();
	return 0;
}
示例#4
0
int main()
{
	sfw::initContext(SCREEN_WIDTH, SCREEN_HEIGHT, "NSFW Draw");
		

	loadTexture("Background","./Textures/background.png", 1, 1);

	loadTexture("Start",   "./Textures/GameButton.png", 1, 1);
	loadTexture("Credits", "./Textures/CreditsButton.png", 1, 1);
	loadTexture("Quit",    "./Textures/QuitButton.png", 1, 1);
	loadTexture("Mouse",   "./Textures/mouse.jpg", 1, 1);

	loadTexture("Fireball", "./Textures/Player/newFireball.png", 5, 1);

	loadTexture("playerIDLE", "./Textures/Player/playerIDLE.png", 6, 1);
	loadTexture("playerHIT", "./Textures/Player/playerHIT.png", 6, 1);
	loadTexture("playerRUN", "./Textures/Player/playerRUN.png", 8, 1);
	loadTexture("playerSHOOT", "./Textures/Player/playerShoot.png", 6, 1);

	loadTexture("enemyIDLE", "./Textures/Enemy/enemyIDLE.png", 6, 1);
	loadTexture("enemyHIT", "./Textures/Enemy/enemyHIT.png", 8, 1);
	loadTexture("enemyWALK", "./Textures/Enemy/enemyWALK.png", 8, 1);
	loadTexture("enemySPAWN", "./Textures/Enemy/enemySPAWN.png", 10, 1);
	loadTexture("enemyDIE", "./Textures/Enemy/enemyDIE.png", 8, 1);

	addAnimation("Fireball", "bAni", { 0,1,2,3,4 }, 12);

	addAnimation("playerIDLE", "pIDLE", { 0,1,2,3,4,5}, 12);
	addAnimation("playerHIT", "pHIT", { 0,1,2,3,4,5 }, 12);
	addAnimation("playerRUN", "pRUN", { 0,1,2,3,4,5,6,7 }, 12);
	addAnimation("playerSHOOT", "pSHOOT", { 0,1,2,3,4,5 }, 12);

	addAnimation("enemyIDLE", "eIDLE", { 0,1,2,3,4,5 }, 12);
	addAnimation("enemyHIT", "eHIT", { 0,1,2,3,4,5,6,7 }, 12);
	addAnimation("enemyWALK", "eWALK", { 0,1,2,3,4,5,6,7 }, 12);
	addAnimation("enemySPAWN", "eSPAWN", { 0,1,2,3,4,5,6,7,8,9 }, 12);
	addAnimation("enemyDIE", "eDIE", { 0,1,2,3,4,5,6,7 }, 12);

	GameState game;
	MenuState menu;

	STATE current = MENU;

	while (sfw::stepContext())
	{
		
		switch (current)
		{
		case MENU:
			current = menu.update();
			menu.draw();
			break;
		case GAME:
			current = game.update();
			game.draw(); 
			break;
		case CREDITS:
			break;
		case QUIT:
			return 0;
		}
		
		
		//dinosaur.CollisionBox(CLEAR);
 
	}

	sfw::termContext();
}
示例#5
0
int main(int argc, char** argv) {

    initLog("luola.log");

    tk::net::initialize();

    Global global;
    global.settings = {
        Vec2i{ 1024, 576 }
    };

    tk_assert(SDL_Init(SDL_INIT_EVERYTHING) == 0, "SDL_Init failed");

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8);

    SDL_Window* window = SDL_CreateWindow("Luola",
                                          SDL_WINDOWPOS_UNDEFINED,
                                          SDL_WINDOWPOS_UNDEFINED,
                                          global.width, global.height,
                                          SDL_WINDOW_OPENGL);
    tk_assert(window, "SDL_CreateWindow failed");

    SDL_GLContext context = SDL_GL_CreateContext(window);
    tk_assert(context, "SDL_GL_CreateContext failed");

    tk_assert(tk::graphics::initialize(), "Error initializing the graphics");

    loadResources(global.cache);

    if (argc == 1) {
        // No address provided, host the game
        global.server.reset(new GameServer(global));
    } else {
        // Address provided, join that address
        global.remote = argv[1];
    }

    GameState* state = new Playground(global);

    UpdateTimer updateTimer(60);

    while (global.running) {
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_QUIT:
                global.running = false;
                break;
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                global.input.handleKeyboard(event.key.keysym.sym, event.type == SDL_KEYDOWN);
                break;
            case SDL_MOUSEBUTTONDOWN:
            case SDL_MOUSEBUTTONUP:
                global.input.handleMouse(event.button.button, event.type == SDL_MOUSEBUTTONDOWN);
                break;
            case SDL_MOUSEMOTION:
                global.input.handleMotion(event.motion.x, event.motion.y);
                break;
            }
        }

        glClear(GL_COLOR_BUFFER_BIT);

        while (updateTimer.update()) {
            GameState* newState = state->update(updateTimer.period());
            if (newState) {
                state->shutdown();
                delete state;
                state = newState;
            }
        }

        state->draw();

        SDL_GL_SwapWindow(window);
    }

    if (state) {
        state->shutdown();
        delete state;
    }

    return 0;
}
示例#6
0
void main()
{
	sfw::initContext(800, 600, "Saving Bob");
	sfw::setBackgroundColor(BLACK);

	loadTexture("Space", "../res/space800x600.jpg", 1, 1);
	loadTexture("Asteroid Belt", "../res/asteroidbelt.png", 1, 1);
	loadTexture("Nebula", "../res/nebula.png", 1, 1);
	loadTexture("Nebula2", "../res/nebula2.png", 1, 1);
	loadTexture("Player", "../res/playership.png", 8, 1);
	loadTexture("Bullet", "../res/bullet.png", 1, 1);
	loadTexture("eBullet", "../res/enemyBullet.png", 1, 1);
	loadTexture("Enemy", "../res/enemyship.png", 9, 1);
	loadTexture("Explosion", "../res/explosion.png", 4, 4);
	loadTexture("Play", "../res/PlayBlue.png", 1, 1);
	loadTexture("Exit", "../res/ExitBlue.png", 1, 1);
	loadTexture("Credits", "../res/CreditsBlue.png", 1, 1);
	loadTexture("GameOver", "../res/GameOver.jpg", 1, 1);
	loadTexture("Options", "../res/OptionsBlue.png", 1, 1);
	loadTexture("Crosshair", "../res/crosshair.png", 1, 1);
	loadTexture("SavingTitle", "../res/savingTitle.png", 1, 1);
	loadTexture("BobTitle", "../res/bobTitle.png", 1, 1);
	loadTexture("PlanetBob", "../res/planetBob.png", 5, 4);
	loadTexture("Back", "../res/backButton.png", 1, 1);
	loadTexture("CreditsPage", "../res/Credits.jpg", 1, 1);
	addAnimation("Player", "Thrusters", { 0,1,2,3,4,5,6,7 });
	addAnimation("Enemy", "eThrusters", { 0,1,2,3,4,5,6,7,8 });
	addAnimation("Explosion", "Boom", { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 });
	addAnimation("PlanetBob", "Rotation", { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 });

	GameState game;
	MenuState menu;
	CreditsPage creditsPage;
	GameOverBG gameOverPage;
	menu.menuLayout();
	game.start();
	creditsPage.creditsPG();
	//gameOverPage.gameOverPG();
	


	while (sfw::stepContext())
	{
		
		
		switch (menuSelection)
		{
		case 1:
			menu.update();
			menu.draw();
			break;
		case 2:
			game.update();
			game.draw();
			break;
		case 3:
			creditsPage.update();
			creditsPage.draw();
			break;
		case 4:
			sfw::termContext();
			break;
		case 5:
			gameOverPage.update();
			gameOverPage.draw();
		}

		
	}
	sfw::termContext();
}