Пример #1
0
			EM_BOOL fullscreenchange_callback(int eventType, const EmscriptenFullscreenChangeEvent *e, void *userData)
			{
				//printf("%s, isFullscreen: %d, fullscreenEnabled: %d, fs element nodeName: \"%s\", fs element id: \"%s\". New size: %dx%d pixels. Screen size: %dx%d pixels.",
      //Cast::toString<int>(eventType).c_str(), e->isFullscreen, e->fullscreenEnabled, e->nodeName, e->id, e->elementWidth, e->elementHeight, e->screenWidth, e->screenHeight);

				EmscriptenFullscreenChangeEvent state;
				emscripten_get_fullscreen_status(&state);

				GameContainer* container = ARK2D::getContainer();
				int newWidth = 100;
				int newHeight = 100;
				if (state.isFullscreen) {  
					newWidth = state.screenWidth;
					newHeight = state.screenHeight;
				} else {
					newWidth = container->getWidth();
					newHeight = container->getHeight();
				}
 
				container->setSize(newWidth, newHeight);
				container->getPlatformSpecific()->setFullscreenInternal(e->isFullscreen);
				//container->resizeBehaviour(newWidth, newHeight); 
				//container->resizeWindowToFitViewport(); 

				return 0;
			}	
Пример #2
0
int main() {

    GameContainer GC;

    GC.start();

    return EXIT_SUCCESS;
}
Пример #3
0
		void flascc_event_mouseMoved(int x, int y) {
			GameContainer* container = ARK2D::getContainer();

			float thisx = (float) x;
			float thisy = (float) y;
			
			thisx -= container->getTranslateX();
			thisy -= container->getTranslateY();

			thisx /= container->getScale();
			thisy /= container->getScale();

			Input* i = ARK2D::getInput();
			ARK2D::getLog()->mouseMoved((int) thisx, (int) thisy, i->mouse_x, i->mouse_y);
			ARK2D::getGame()->mouseMoved((int) thisx, (int) thisy, i->mouse_x, i->mouse_y);
			i->mouse_x = (int) thisx;
			i->mouse_y = (int) thisy;
		}
Пример #4
0
		void flascc_event_mouseUp(int button, int x, int y) {
			GameContainer* container = ARK2D::getContainer();

			float thisx = (float) x;
			float thisy = (float) y;
			thisx -= container->getTranslateX();
			thisy -= container->getTranslateY();

			thisx /= container->getScale();
			thisy /= container->getScale();

			unsigned int key = Input::MOUSE_BUTTON_LEFT;
			if (button == 0) {
				key = Input::MOUSE_BUTTON_LEFT;
			} else if (button == 1) {
				key = Input::MOUSE_BUTTON_RIGHT;
			}

			Input* i = ARK2D::getInput();
			i->mouse_x = (int) thisx;
			i->mouse_y = (int) thisy;
			i->releaseKey(key);
		}
Пример #5
0
Boss::Boss(): GameObject()  {
	m_game = DefaultGame::getGame();

	m_spitTimer = 0;

	m_image = m_game->sheet->getSubImage(m_game->sheet_desc->getItemByName("boss1.png")); //new Image("data/game/boss1.png");
	m_imageRight = m_image->getFlippedCopy(true, false);

	m_animation = new Animation();
	m_animation->setFrameTime(500);
	m_animation->addImage(m_game->sheet->getSubImage(m_game->sheet_desc->getItemByName("boss2.png"))); //new Image("data/game/boss2.png"));
	m_animation->addImage(m_game->sheet->getSubImage(m_game->sheet_desc->getItemByName("boss3.png"))); //new Image("data/game/boss3.png"));

	m_animationRight = new Animation();
	m_animationRight->setFrameTime(500);
	m_animationRight->addImage(m_animation->getFrame(0)->getFlippedCopy(true, false));
	m_animationRight->addImage(m_animation->getFrame(1)->getFlippedCopy(true, false));

	//m_animation->addImage(m_game->sheet->getSubImage(m_game->desc->getItemByName("couldron1.png"))->getScaledCopy(4, 4));
	//m_animation->addImage(m_game->sheet->getSubImage(m_game->desc->getItemByName("couldron2.png"))->getScaledCopy(4, 4));

	m_timer = 0;

	m_bounds->setWidth(100);
	m_bounds->setHeight(100);
	//m_bounds->setWidth(m_animation->getCurrentFrame()->getWidth());
	//m_bounds->setHeight(m_animation->getCurrentFrame()->getHeight());

	GameContainer* container = ARK2D::getContainer();
	m_bounds->setLocationByCenter(float(container->getWidth()/2), float(container->getHeight()/2));

	m_velocity->set(0, 0);
	m_velocityMaximum->set(2000, 25);

	m_acceleration->set(400, 5);
}
Пример #6
0
int main(int argc, char** argv) {

	DefaultGame game("HOT CROSS BUNIONS");
	GameContainer* container;
	if (DefaultGame::ARCADE_VERSION) {
		container = new GameContainer(game, 1024, 768, 32, false);
		//container->setScaleToWindow(true);
		//container->setResizable(true);
	} else {
		container = new GameContainer(game, 640, 480, 32, false);
	}

	container->setClearColor(Color::darker_grey);
	container->setCursorVisible(true);
	container->setIcon(container->getResourcePath() + "data/icon.ico");
	container->start();

	return 0;
}
Пример #7
0
int main (int argc, const char * argv[])
{  
  string gameName = "Lazy Crab";
  float currentFPS = 0;
  
  // Create the main window
  sf::VideoMode DesktopMode = sf::VideoMode::getDesktopMode();
  sf::RenderWindow* window = new sf::RenderWindow(sf::VideoMode(DesktopMode.width/2, DesktopMode.height/2,DesktopMode.bitsPerPixel), gameName);
  window->setVerticalSyncEnabled(true);
  
  
  // Load a sprite to display
  sf::Texture texture;
  if (!texture.loadFromFile(resourcePath() + "images/cute_image.jpg"))
  	return EXIT_FAILURE;
  sf::Sprite sprite(texture);

  // Create a graphical text to display
  sf::Font font;
  if (!font.loadFromFile(resourcePath() + "fonts/sansation.ttf"))
  	return EXIT_FAILURE;
  sf::Text text("Hello SFML", font, 50);
  text.setColor(sf::Color::Black);

  // Load a music to play
  sf::Music music;
  if (!music.openFromFile(resourcePath() + "music/fairy_road.ogg"))
  	return EXIT_FAILURE;

  
  sf::Clock frameTimer;
  sf::Time deltaTime;
    
  // Generates the World
  b2Vec2 gravity(0, -9.8);
  b2World* world = new b2World(gravity);
  
  GameContainer* gc = new GameContainer(window, world);
    
  
  EntityManager* em = new EntityManager();
  
  Entity* player = em->addEntity(new Entity(gc, "player"));
  player->setPosition(8, 0);
  player->addComponent(new BodyComponent(gc, 0.6f, 1.8f, true));
  player->addComponent(new WireboxRenderComponent("wirebox"));
  
  float windowRatio = (float)gc->getWindow()->getSize().y / (float)gc->getWindow()->getSize().x;
  Entity* camera = em->addEntity(new Entity(gc, "camera"));
  camera->setPosition(100, 10);
  camera->addComponent(new CameraComponent(gc, player, 30, 30*windowRatio));
  
  Entity* terrain = em->addEntity(new Entity(gc, "terrain"));
  terrain->setPosition(0, -10);
  terrain->addComponent(new WirechainRenderComponent(6));
  terrain->addComponent(new TerrainComponent(gc, "gameTerrain", 6));
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(0, 5, 0);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(1, 20, 5);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(2, 30, -2);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(3, 50, 10);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(4, 80, 5);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(5, 100, 15);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->generate();
  
  Entity* options = em->addEntity(new Entity(gc, "options"));
  options->addComponent(new OptionComponent("controls", "moveLeft", "A"));
  options->addComponent(new OptionComponent("controls", "moveLeft_alt", "arrow_left"));
  options->addComponent(new OptionComponent("controls", "moveRight", "D"));
  options->addComponent(new OptionComponent("controls", "moveRight_alt", "arrow_right"));
  
  
  
  
  //ControlManager::player(player);
  
  
  // Play the music
  music.play();
      

  // Start the game loop
  while (window->isOpen())
  {
  	// Process events
  	sf::Event event;
  	while (window->pollEvent(event))
  	{
  		// Close window : exit
  		if (event.type == sf::Event::Closed)
  			window->close();
          
  		// Escape pressed : exit
  		if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
  			window->close();
  	}
    
    currentFPS =  1000 / (gc->getDelta().asMicroseconds() / 1000.0f);

  	// Clear screen
  	gc->getWindow()->clear();
  	    
    em->updateRender();
    
    em->getNearbyEntities(em->getEntity("player"), 2);
    
    
    
    gc->getWorld()->Step(1/currentFPS,  8, 3);
    gc->getWindow()->setView(gc->view);
    
    // Update the window
  	gc->getWindow()->display();
    
    gc->setDelta(frameTimer.restart());
  }

	return EXIT_SUCCESS;
}
Пример #8
0
int main (int argc, const char * argv[])
{

  string gameName = "Wombat Combat";

  bool fullscreen;

  // Generates the window and reads the window mode for resolution and colordepth
  sf::VideoMode DesktopMode = sf::VideoMode::getDesktopMode();
  sf::RenderWindow* window = new sf::RenderWindow(sf::VideoMode(DesktopMode.width/2, DesktopMode.height/2,DesktopMode.bitsPerPixel), gameName);
  window->setVerticalSyncEnabled(true);
  
  sf::Clock frameTimer;
  sf::Time deltaTime;
  
  
  
  // Generates the World
  b2Vec2 gravity(0, -9.8);
  b2World* world = new b2World(gravity);

  ContactListener contactListener;
  world->SetContactListener(&contactListener);

  GameContainer* gc = new GameContainer(window, world);

  // Create the main window
  //gc->getWindow()->setFramerateLimit(500);

  BaseGame* baseGame = new BaseGame(gc);

  while (gc->getWindow()->isOpen())
  {
  	// Process events
  	sf::Event event;
  	while (gc->getWindow()->pollEvent(event))
  	{
  		// Close window : exit
  		if (event.type == sf::Event::Closed)
  			gc->getWindow()->close();

  		// Escape pressed : exit
  		if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
        gc->getWindow()->close();

      //Fullscreen toggle
      if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::F)) {
        fullscreen = !fullscreen;
        if (fullscreen)
          gc->getWindow()->create(sf::VideoMode(DesktopMode.width, DesktopMode.height,DesktopMode.bitsPerPixel), gameName, (fullscreen ? sf::Style::Fullscreen : sf::Style::Resize|sf::Style::Close));
        else
          gc->getWindow()->create(sf::VideoMode(DesktopMode.width/2, DesktopMode.height/2,DesktopMode.bitsPerPixel), gameName);

      }
      //
  	}
    
    float currentFPS =  1000 / (gc->getDelta().asMicroseconds() / 1000.0f);    
    
    // Update everything
    baseGame->update();    
    gc->getWorld()->Step(1/currentFPS, 8, 3);
    
  	// Clear screen
  	gc->getWindow()->clear();

    // Render everything
    baseGame->render();
    gc->getWindow()->setView(gc->view);

    // Update the window
  	gc->getWindow()->display();
    
    gc->setDelta(frameTimer.restart());
    
  }

	return EXIT_SUCCESS;
}
Пример #9
0
int main (int argc, const char * argv[])
{  
  string gameName = "Lazy Crab";
  float currentFPS = 0;
  
  // Create the main window
  sf::VideoMode DesktopMode = sf::VideoMode::getDesktopMode();
  sf::RenderWindow* window = new sf::RenderWindow(sf::VideoMode(DesktopMode.width/2, DesktopMode.height/2,DesktopMode.bitsPerPixel), gameName);

  sf::Clock frameTimer;
    
  // Generates the World
  b2Vec2 gravity(0, -9.8);
  b2World* world = new b2World(gravity);
  
  GameContainer* gc = new GameContainer(window, world);
    
  
  EntityManager* em = new EntityManager();
  
  Entity* player = em->addEntity(new Entity(gc, "player"));
  player->setPosition(8, 30);
  player->addComponent(new BodyComponent(gc, 0.6f, 1.8f, true));
  player->addComponent(new WireboxRenderComponent("wirebox"));
  
  float windowRatio = (float)gc->getWindow()->getSize().y / (float)gc->getWindow()->getSize().x;
  Entity* camera = em->addEntity(new Entity(gc, "camera"));
  camera->setPosition(100, 10);
  camera->addComponent(new CameraComponent(gc, player, 30, 30*windowRatio));
  
  Entity* terrain = em->addEntity(new Entity(gc, "terrain"));
  
  terrain->setPosition(0, 0);
  terrain->addComponent(new WirechainRenderComponent(5));
  terrain->addComponent(new TerrainComponent(gc, "gameTerrain", 5));
  /*for(int i = 0; i != coords.size(); i++)
  {
    ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(i, coords[i].x, coords[i].y);
  }*/
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(0, 0, 5);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(1, 30, -2);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(2, 50, 10);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(3, 80, 5);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(4, 100, 15);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->generate();

  
  Entity* options = em->addEntity(new Entity(gc, "options"));
  options->addComponent(new OptionComponent("controls", "moveLeft", "A"));
  options->addComponent(new OptionComponent("controls", "moveLeft_alt", "arrow_left"));
  options->addComponent(new OptionComponent("controls", "moveRight", "D"));
  options->addComponent(new OptionComponent("controls", "moveRight_alt", "arrow_right"));
  
  
  
  
  
  
  //ControlManager::player(player);
  
  // Start the game loop
  while (window->isOpen())
  {
  	// Process events
  	sf::Event event;
  	while (window->pollEvent(event))
  	{
  		// Close window : exit
  		if (event.type == sf::Event::Closed)
  			window->close();
          
  		// Escape pressed : exit
  		if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
  			window->close();
  	}
    
    currentFPS =  1000 / (gc->getDelta().asMicroseconds() / 1000.0f);

  	// Clear screen
  	gc->getWindow()->clear();
  	    
    em->updateRender();
    
    em->getNearbyEntities(em->getEntity("player"), 2);
    
    
    
    gc->getWorld()->Step(1/currentFPS,  8, 3);
    gc->getWindow()->setView(gc->view);
    
    // Update the window
  	gc->getWindow()->display();
    
    gc->setDelta(frameTimer.restart());
  }

	return EXIT_SUCCESS;
}
Пример #10
0
		void Camera::update() {
			SceneNode::update();

			if (viewportAutosize) {
				setViewport(0, 0, ARK2D::getContainer()->getDynamicWidth(), ARK2D::getContainer()->getDynamicHeight() );
			}

            direction = (lookAt - transform.position);
            direction.normalise();

			// need to set the matrix state. this is only important because lighting doesn't work if this isn't done

		    if (type == TYPE_ORTHO) {
		    	//our projection matrix will be an orthogonal one in this case
				//if the values are not floating point, this command does not work properly
				//need to multiply by aspect!!! (otherise will not scale properly)

				//projection = glm::ortho((scaleMaybe*-1) * float(viewportAspectRatio), scaleMaybe * float(viewportAspectRatio), scaleMaybe*-1, scaleMaybe, nearClip, farClip);
                projection.identity();
                projection.ortho2d((viewportOrtho3dScale*-1) * float(viewportAspectRatio), viewportOrtho3dScale * float(viewportAspectRatio), viewportOrtho3dScale*-1, viewportOrtho3dScale, nearClip, farClip);


					// http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/
				float verticalAngle = camera_pitch;
				float horizontalAngle = camera_heading;
				direction.set(
					cos(verticalAngle) * sin(horizontalAngle),
					sin(verticalAngle),
					cos(verticalAngle) * cos(horizontalAngle)
				);

                lookAt = transform.position + direction;

		    } else if (type == TYPE_ORTHO_2D) {

				//projection = glm::ortho(float(viewportX), float(viewportWidth), float(viewportHeight), float(viewportY), float(nearClip), float(farClip));
                projection.identity();
                projection.ortho2d(float(viewportX), float(viewportWidth), float(viewportHeight), float(viewportY), float(nearClip), float(farClip));

                lookAt = transform.position + direction;

			} else if (type == TYPE_PERSPECTIVE) {
				//projection = glm::perspective(fieldOfView, viewportAspectRatio, nearClip, farClip);
                projection.identity();
                projection.perspective(fieldOfView, viewportAspectRatio, nearClip, farClip);
				//detmine axis for pitch rotation
                Vector3<float> axis = direction.cross(up);
				//compute quaternion for pitch based on the camera pitch angle
                Quaternion<float> pitch_quat = Quaternion<float>::angleAxis(MathUtil::toDegrees(camera_pitch), axis);
				//determine heading quaternion from the camera up vector and the heading angle
                Quaternion<float> heading_quat = Quaternion<float>::angleAxis(MathUtil::toDegrees(camera_heading), up);
				//add the two quaternions
				Quaternion<float> temp = pitch_quat.cross(heading_quat);
                temp.normalise();

                // http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/
				float verticalAngle = camera_pitch;
				float horizontalAngle = camera_heading;
				direction.set(
					cos(verticalAngle) * sin(horizontalAngle),
					sin(verticalAngle),
					cos(verticalAngle) * cos(horizontalAngle)
				);

            	//set the look at to be infront of the camera
                lookAt = transform.position + direction;



			}






			// compute the MVP

			if (type == TYPE_ORTHO_2D) {

                //view.lookAt(transform.position.x, transform.position.y, transform.position.z, lookAt.x, lookAt.y, lookAt.z, up.x, up.y, up.z);

				//view = glm::translate(view, glm::vec3(container->getTranslateX(), container->getTranslateY(), 0.0f) );
				//view = glm::scale(view, glm::vec3(container->getScaleX(), container->getScaleY(), 0.0f) );
				GameContainer* container = ARK2D::getContainer();
				view.identity();
				view.lookAt(transform.position.x, transform.position.y, transform.position.z, lookAt.x, lookAt.y, lookAt.z, up.x, up.y, up.z);
                view.translate(container->getTranslateX(), container->getTranslateY(), 0.0f);
                // todo: rotate
                view.scale(container->getScaleX(), container->getScaleY(), 1.0f);

                model.identity(); // = glm::mat4(1.0f);

			} else if (type == TYPE_PERSPECTIVE || type == TYPE_ORTHO) {

				/*float scaleX = 1.0f / float(viewportWidth);
				float scaleY = 1.0f / float(viewportHeight);
				if (scaleX > scaleY) {
					scaleY = scaleX;
				} else {
					scaleX = scaleY;
				}
				view = glm::lookAt(position, lookAt, up);
				view = glm::scale(view, glm::vec3(scaleX, scaleY, 0.0) );
				view = glm::translate(view, glm::vec3(1280.0*-0.5, 720.0*-0.5, 0.0) );*/

//				view = glm::lookAt(position, lookAt, up);
                view.identity();
                view.lookAt(transform.position.x, transform.position.y, transform.position.z, lookAt.x, lookAt.y, lookAt.z, up.x, up.y, up.z);
//				model = glm::mat4(1.0f);
                model.identity();
			}

			//MVP = projection * view * model;

		}