Exemple #1
0
// DkPongPort --------------------------------------------------------------------
DkPongPort::DkPongPort(QWidget *parent, Qt::WindowFlags flags) : QGraphicsView(parent) {

	//setAttribute(Qt::WA_TranslucentBackground, true);

	fieldColor = QColor(0,0,0);
	playerColor = QColor(255, 255, 255);

	unit = 10;
	playerSpeed = unit;
	minBallSpeed = 0.5*unit;
	maxBallSpeed = 4*unit;
	ballDir = DkVector(unit*0.15, unit*0.15);
	player1Speed = 0;
	player2Speed = 0;
	player1Pos = INT_MAX;
	player2Pos = INT_MAX;

	ball = QRect(QPoint(), QSize(unit, unit));
	player1 = QRect(QPoint(), QSize(unit, 2*unit));
	player2 = QRect(QPoint(), QSize(unit, 5*unit));

	initGame();
	 
	eventLoop = new QTimer(this);
	eventLoop->setInterval(10);
	eventLoop->start();

	connect(eventLoop, SIGNAL(timeout()), this, SLOT(gameLoop()));

	//show();
}
Exemple #2
0
void Troll::run() {
    while (!_vm->shouldQuit()) {
        intro();
        gameLoop();
        gameOver();
    }
}
Exemple #3
0
int		main(const int ac, const char **av)
{
    if (ac != 1)
        std::cerr << "Error: " <<  av[0] << " too many arguments." << std::endl;

 	initscr(); //init ncurses
    if (has_colors() == FALSE)
        return (0);
    start_color();
    init_color(COLOR_BLUE, 956, 529, 529);
    init_color(COLOR_MAGENTA, 1000, 974, 533);
    init_color(COLOR_CYAN, 416, 965, 686);
    init_pair(1, COLOR_RED, COLOR_BLACK); //Display Player
    init_pair(2, COLOR_CYAN, COLOR_BLACK); //DISPLAY ENEMY UNIT
    init_pair(3, COLOR_GREEN, COLOR_BLACK); //DISPLAY ENEMY UNIT MISSILE
    init_pair(4, COLOR_MAGENTA, COLOR_BLACK); //DISPLAY OBSTACLE
    init_pair(5, COLOR_YELLOW, COLOR_BLACK); //DISPLAY PLAYER MISSILE
	noecho();
    srand(static_cast<unsigned int>(time(0)));
//	raw(); //do not set while debuging or tests
	curs_set(FALSE);
	setlocale(LC_ALL, ""); //handle special symbol as 卐
	timeout(60); //to do set a timeout define
	keypad(stdscr, TRUE);// add special chars as F{1-12}

   
    gameLoop();
	
	endwin(); //end window 
	return (0);
}
Exemple #4
0
//This runs the game
void MainGame::run() {
    initSystems();

 
    //This only returns when the game ends
    gameLoop();
}
void Battleship::play() {
	cout << endl << endl << "~~~~~~ WELCOME TO BATTLESHIPS ~~~~~~" << endl;
	bool gameOver = false;

	while (!gameOver) {
		gameLoop();
		cout << endl << "Do you want to try again? (Y/N)" << endl;
		char tryAgain;
		cin >> tryAgain;

		if (tryAgain == 'Y') {
			resetGame();
			cout << endl << endl;
		}
		else if (tryAgain = 'N'){
			gameOver = true;
		}
		else {
			cout << "Your input was not understood. Ending game..." << endl;
			gameOver = true;
		}
	}

	cout << endl << "~~~~~~~ GAME OVER ~~~~~~~" << endl << endl;
}
Exemple #6
0
/**
 * Class for the Pong game
 */
Game::Game(QWidget *parent) : QGraphicsView(parent){

    this->leftPlayer = new Player(this, Player::LEFT);
    this->rightPlayer = new Player(this, Player::RIGHT);
    this->puck = new Puck(this);
    this->pressedKeys = new QMap<int,bool>();

    QHBoxLayout *layout = new QHBoxLayout;

    layout->addWidget(this->leftPlayer);
    layout->addWidget(this->rightPlayer);
    layout->addWidget(this->puck);

    this->setFocus();

    this->txtStatus =  this->parentWidget()->findChild<QLabel *>("status");
    this->txtLeftPlayer =  this->parentWidget()->findChild<QLabel *>("player1");
    this->txtRightPlayer =  this->parentWidget()->findChild<QLabel *>("player2");




    gameLoopTimer = new QTimer(this);
    connect(gameLoopTimer, SIGNAL(timeout()), this, SLOT(gameLoop()));
    // Connecting the QTimer::timeout() signal to our moveClock() slot
    // then it moves the clock every time the timer times out.

}
Exemple #7
0
Fichier : main.c Projet : ez80/3DCE
void main() {
	gc_InitGraph();
	gc_DrawBuffer();
	gameLoop();
	gc_CloseGraph();
	pgrm_CleanUp();
}
void Instructions()
{
	cls();
	draw_object ("instructions.txt", 0x0A);

	while(true)
	{
		int input1;
		cin >> input1;

		//if the player presses 1...
		//bring to difficulty screen
		if(input1 == yes)
		{
			Beep (1350,150);
			gameLoop();
			break;
		}
		//if the player presses 2...
		if(input1 == no)
		{
			Beep (1350,150);
			cout << "Thank you for playing! ! !" << endl;
			g_quitGame = true;
			break;
		}
	}
}
Exemple #9
0
int main(int argc, char *argv[]) {
    setlocale(LC_ALL,"");
    PDC_set_title("Dungcrwl");

	if (initGame(argc, argv))
		return 1;

    while (quit == FALSE) {
        switch(game_state) {
            case GAME_MENU:
                showMenu();
                break;
            case GAME_INTRO:
                newGame();
                break;
            case GAME_PLAYING:
                gameLoop();
                break;
            case GAME_DONE:
                quit = TRUE;
                break;
        }
    }

    gameShutdown();

	return 0;
}
Exemple #10
0
void Game::start_loss()
{
	if (_gameState != Uninitialized)
		return;

	game_victory = 0;
	_mainWindow.create(sf::VideoMode(1024, 768, 32), "Anne McLaughlin Demo");
	_view.reset(sf::FloatRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
	_view.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));

	PlayerCharacter * player = (PlayerCharacter *)_gameObjectManager.getByTypeSingle("PlayerCharacter");
	player->setPosition(500, 1000);
	player->coins = 0;
	player->lives = 0;
	player->grounded = true;


	reset_mystery_blocks();


	_gameState = Game::ShowingSplashLoss;

	while (!isExiting())
	{
		gameLoop();
	}
	_mainWindow.close();
}
Exemple #11
0
void* serveClient(void* arg) {
	JNIEnv* env;
	(*jvm)->AttachCurrentThread(jvm, &env, NULL);
	int client_idx = (int)arg;

	int n;
	char buffer[BUFFER_SIZE];
	//write(client_fds[client_idx], "You have connected", strlen("You have connected"));

	jclass cls = (*env)->GetObjectClass(env, server_obj);
	jfieldID ifd = (*env)->GetFieldID(env, cls, "boardSize", "I");
	board_size = (*env)->GetIntField(env, server_obj, ifd);

	ifd = (*env)->GetFieldID(env, cls, "komi", "I");
	komi = (*env)->GetIntField(env, server_obj, ifd);

	//send client game info
	int mesg_len = sprintf(buffer, "%d,%d\n", board_size, komi);
	write(client_fds[client_idx], buffer, mesg_len);
	__android_log_print(ANDROID_LOG_VERBOSE, "asdf", "sent: %s", buffer);

	// read client game request
	n = read(client_fds[client_idx], buffer, BUFFER_SIZE - 1);
	buffer[n] = '\0';
	__android_log_print(ANDROID_LOG_VERBOSE, "asdf", "read client game request: %s", buffer);

	if(!strcmp(buffer, REQUEST_GAME_MESG)) {
		// notify UI to allow user to confirm request
		jmethodID instanceMethodId = (*env)->GetMethodID(env, cls, "enableStart", "()V");
		(*env)->CallVoidMethod(env, server_obj, instanceMethodId);

		__android_log_print(ANDROID_LOG_VERBOSE, "asdf", "waiting for UI confirmation");
		//wait for user to confirm request
		pthread_mutex_lock(&m);
		while(game_started == 0) {
			pthread_cond_wait(&cv, &m);
		} pthread_mutex_unlock(&m);

		//notify client of confirmation
		write(client_fds[client_idx], CONFIRM_REQUEST_MESG, strlen(CONFIRM_REQUEST_MESG));

		srand(time(NULL));
		int color = rand() % 2;
		mesg_len = sprintf(buffer, "%d", color ^ 1);
		write(client_fds[client_idx], buffer, mesg_len);

		// notify UI to switch to game view
		instanceMethodId = (*env)->GetMethodID(env, cls, "startGame", "(I)V");
		(*env)->CallVoidMethod(env, server_obj, instanceMethodId, color);

		gameLoop(env, cls, server_obj, client_fds[client_idx], color);
	}

	while((n = read(client_fds[client_idx], buffer, BUFFER_SIZE - 1)) > 0) {
		buffer[n]  = '\0';
		__android_log_print(ANDROID_LOG_VERBOSE, "asdf", "Server: %s", buffer);
	}
	(*jvm)->DetachCurrentThread(jvm);
	return NULL;
}
Exemple #12
0
int main()
{
	/* Procedura startowa:
	- Inicjalizacja biblioteki Allegro 5
	- Inicjalizacja dodatków dla Allegro 5
	- Rejestracja zdarzeñ Allegro 5
	- Uruchomienie g³ównej pêtli
	- Zamkniêcie biblioteki Allegro 5
	- Koniec programu
	*/
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	Init initializer;

	if(!initializer.initAllegro(display, event_queue, resolutionWidth, resolutionHeight))
	{
		return 1; // coœ posz³o nie tak, wychodzimy...
	}
	if(!initializer.initAddons())
	{
		return 1; // coœ posz³o nie tak, wychodzimy...
	}
	initializer.registerEvents(display, event_queue);
	gameLoop();
	initializer.closeAllegro(display, event_queue);

	return 0;
}
Exemple #13
0
int main(int argc, char const *argv[]) {

    system("clear");

    printf("\t      ██╗ ██████╗  ██████╗  ██████╗     ██████╗  ██████╗       █████╗  	\n");
    printf("\t      ██║██╔═══██╗██╔════╝ ██╔═══██╗    ██╔══██╗██╔═══██╗     ██╔══██╗ 	\n");
    printf("\t      ██║██║   ██║██║  ███╗██║   ██║    ██║  ██║██║   ██║     ╚█████╔╝  	\n");
    printf("\t ██   ██║██║   ██║██║   ██║██║   ██║    ██║  ██║██║   ██║     ██╔══██╗ 	\n");
    printf("\t ██   ██║██║   ██║██║   ██║██║   ██║    ██║  ██║██║   ██║     ██╔══██╗ 	\n");
    printf("\t ╚█████╔╝╚██████╔╝╚██████╔╝╚██████╔╝    ██████╔╝╚██████╔╝     ╚█████╔╝ 	\n");
    printf("\t  ╚════╝  ╚═════╝  ╚═════╝  ╚═════╝     ╚═════╝  ╚═════╝       ╚════╝ 	\n");

    // Entrada
    BOARD *board = (BOARD*)malloc(sizeof(BOARD));
    STATE *game = createState();
    createBoard(&board);
    readBoard(&board);
    game->current = board;

    // Fila inicial
    PRIORITY_QUEUE *queue = createQueue();
    insert(queue, game);

    // Loop de jogo
    gameLoop(queue);


    return 0;
}
Exemple #14
0
/*!
 * Run the code inside the gameloop
 */
static void runGameLoop(void)
{
	gameLoopStatus = gameLoop();
	switch (gameLoopStatus)
	{
		case GAMECODE_CONTINUE:
		case GAMECODE_PLAYVIDEO:
			break;
		case GAMECODE_QUITGAME:
			debug(LOG_MAIN, "GAMECODE_QUITGAME");
			stopGameLoop();
			startTitleLoop(); // Restart into titleloop
			break;
		case GAMECODE_LOADGAME:
			debug(LOG_MAIN, "GAMECODE_LOADGAME");
			stopGameLoop();
			initSaveGameLoad(); // Restart and load a savegame
			break;
		case GAMECODE_NEWLEVEL:
			debug(LOG_MAIN, "GAMECODE_NEWLEVEL");
			stopGameLoop();
			startGameLoop(); // Restart gameloop
			break;
		// Never thrown:
		case GAMECODE_FASTEXIT:
		case GAMECODE_RESTARTGAME:
			break;
		default:
			debug(LOG_ERROR, "Unknown code returned by gameLoop");
			break;
	}
}
Exemple #15
0
void Game::start(void)
{
	if (gameState_ != Uninitialized)
		return;

	mainWindow_.create(sf::VideoMode(1024, 768, 32), "Dodge and Load");
	mainWindow_.setFramerateLimit(60);

	init();

	float frameTime = 1.0f / 60.0f;
	float currTime = 0.0f;
	while (!isExiting())
	{
		if (currTime > frameTime)
		{
			gameLoop();
			currTime = 0.0f;
		}
		currTime += clock_.getElapsedTime().asSeconds();
		clock_.restart().asSeconds();
	}

	mainWindow_.close();
}
Exemple #16
0
//function to display gameover screen
void gameover()
{
	cls();
	//show gameover screen
	draw_object ("dead.txt", 0x0C);
	colour(0x0A);
	highscore(score);

	cout << endl << "Enter 1 to replay" << endl;
	cout << "Enter 2 to return to Main Menu" << endl;

	int inputGO = 0;
	cin.clear();
	cin >> inputGO;
	//reset the game
	if (inputGO == 1)
	{
		Beep (2000,200);
		init();
		mainLoop();

	}
	if (inputGO == 2)
	{
		Beep (1350,150);
		init();
		gameLoop();
	}
}
Exemple #17
0
void MainGame::run()
{
	initSystems();


	//_sprite.init(-1.0f, -1.0f, 2.0f, 2.0f, "Texture/PNG/CharacterRight_Standing.png");

	_sprites.push_back(new nEngine::Sprite());
	_sprites.back()->init(0, 0, 500.0f,500.0f, "Texture/PNG/CharacterRight_Standing.png");


	//_sprites.push_back(new nEngine::Sprite());
	//_sprites.back()->init(0.0f, -1.0f, 1.0f, 1.0f, "Texture/PNG/CharacterRight_Standing.png");

	//_sprites.push_back(new nEngine::Sprite());
	//_sprites.back()->init(0.0f, 0.0f, 1.0f, 1.0f, "Texture/PNG/CharacterRight_Standing.png");

	//_sprites.push_back(new nEngine::Sprite());
	//_sprites.back()->init(-1.0f, 0.0f, 1.0f, 1.0f, "Texture/PNG/CharacterRight_Standing.png");

	
	//_playerTexture= ImageLoader::loadPNG("Texture/PNG/CharacterRight_Standing.png");

	gameLoop();
};
Exemple #18
0
int main ( int argc, char** argv )
{
    camera.x = 0;
    camera.y = 0;
    camera.h = screenW;
    camera.w = screenH;
    // initialize SDL video
    if (SDL_Init(SDL_INIT_VIDEO) < 0 )
    {
        //printf( "Unable to init SDL: %s\n", SDL_GetError() );
        std::cout<<"Unable to init SDL: " <<SDL_GetError() <<std::endl;
        return 1;
    }

    /*
    if(!screen)
    {
        std::cout<<"Unable to set screen: " <<SDL_GetError() <<std::endl;
        return 1;
    }
    */

    std::string windowTitle = "soco-*";
    SDL_WM_SetCaption(windowTitle.c_str(), windowTitle.c_str());

    /***** MUSIC *****/

    // initialize BASS

    if(!BASS_Init(-1,44100,0,NULL,NULL))
    {
        BASS_Init(0,44100,0,NULL,NULL);
    }

    /***** GAME *****/
    // specify game loop
    initSpriteManager();
    initTextureManager();
    initSoundManager();

    bool done = false;
    while(!done)
    {
        int menuValue = startScreen();
        switch(menuValue)
        {
            case 0:
            case 1:
                done = gameLoop();
                break;
            case 2:
            case 3:
            default:
                return 0;
                break;
        }
    }
    return 0;
}
Exemple #19
0
int CoreGameApp::run(int argc,char *argv[]){
	if(!coreInitialize()){
		coreShutdown();
		return -1;
	}

	Logger &logger = *Logger::Instance();

	logger.writeToLog("Core systems initialized");

	if(!initialize()){
		logger.writeToLog("User systems failed to initialize, shutting down");
		shutdown();
		coreShutdown();
		return -1;
	}

	logger.writeToLog("User systems initialized");

	ConfigurationManager &config = *ConfigurationManager::Instance();
	int width = config.getVariable<int>("w_width");
	int height = config.getVariable<int>("w_height");
	bool fullscreen = config.getVariable<bool>("w_fullscreen");


	m_wnd = GUI::createWindow(width, height, fullscreen);

	glEnable(GL_DEPTH_TEST); // enable depth-testing
	glDepthMask(GL_TRUE); // turn back on
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0.0f, 1.0f);
	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CCW);
	
	if(m_wnd == NULL){
		logger.writeToLog("Failed to create window, shutting down");
		shutdown();
		coreShutdown();
		return -1;
	}

	std::stringstream ss;
	ss<<"Window created: ("<<width<<" x "<<height<<")";
	logger.writeToLog(ss.str());


	logger.writeToLog("Staring game loop");
	gameLoop();
	
	logger.writeToLog("Shutting down user systems");
	shutdown();

	logger.writeToLog("Shutting down core systems");
	coreShutdown();

	return 0;
}
Exemple #20
0
int main(void) {
  auto display = std::make_shared<Display>();
  display->init();
  auto world = std::make_shared<World>();
  world->init(display);
  gameLoop(world, display);
  return 0;
}
Exemple #21
0
void MainGame::run(){

	initSystems();

	//_playerTexture = LoadGLTexture::LoadTexture("../Textures/jimmyJump_pack/PNG/CharacterRight_Standing.png");

	gameLoop();
}
Exemple #22
0
int main(int, char**) {
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	
	srand(time(NULL));
	
	gameLoop();
	return 0;
}
Exemple #23
0
void MainGame::run() {

    initSystems();

    initLevel();

    gameLoop();
}
Exemple #24
0
void RubikGame::run()
{
	initSystems();
	const std::vector<std::string> texPaths = { texture_path1, texture_path2, texture_path3, texture_path4, texture_path5, texture_path6 };
	const std::string texPathsSame[6] = { texture_pathAyse, texture_pathAyse, texture_pathAyse, texture_pathAyse, texture_pathAyse, texture_pathAyse };
	initVoxels(glm::vec3{ 0.0f, 0.0f, 0.0f }, glm::vec3{ 1.0f, 1.0f, 1.0f }, texPaths);
	gameLoop();
}
//This runs the game
void MainVidGame::run() {
	initSystems();

	_sprite.init(-1.0f, -1.0f, 1.0f, 1.0f);

	gameLoop();

}
Exemple #26
0
void main() {
	init();

	while(1) {
		showTitle();
		gameLoop();
	}
}
Exemple #27
0
void Game::Run() {
	initSystems();

	_sprite.Init(-1.0f, -1.0f, 2.0f, 2.0f);
	_playerTexture = ImageLoader::LoadPNG("textures/jimmyjump_pack/png/characterright_standing.png");

	gameLoop();
}
Exemple #28
0
Game::Game() {
    
    // Initialize SDL subsystems
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
    } else {
        gameLoop();
    }
}
Exemple #29
0
//initialize paramaters that will be passed into the main game loop
void multiPlayer() {
	std::pair < unsigned int,std::string> result;
	std::string playerOne = initPlayer();
	std::string playerTwo = initPlayer();
	unsigned int playerOneScore = 0;
	unsigned int playerTwoScore = 0;
	gameLoop(result,playerOne,playerTwo,playerOneScore,playerTwoScore);
	internalHallOfFame(result);
}
Exemple #30
0
int main () {
	GameInstance demo;
	demo.gameColumns = 20;
	demo.gameRows = 20;
	demo.createBoard();
	demo.clearBoard ();
	gameLoop (demo);
	return EXIT_SUCCESS;
}