Exemple #1
0
Shot::Shot(GameWorld* world, float const life, Vec2D const& position, Vec2D const& velocity) :
  ew::Entity(world), ew::Renderable(world), ew::Updatable(world), ew::Collidable(world),
  gameWorld(world), o(0), life(life), v(velocity), shape(position, RADIUS)
{
  o = glhckSpriteNew(TEXTURE, 8, 8);
  glhckObjectPositionf(o, position.x, position.y, 0);
}
Exemple #2
0
UfoLaser::UfoLaser(GameWorld* world, float const life, Vec2D const& position, Vec2D const& velocity) :
  ew::Entity(world), ew::Renderable(world), ew::Updatable(world), ew::Collidable(world),
  gameWorld(world), o(0), life(life), v(velocity), shape({0, 0}, {0, 0}, RADIUS)
{
  o = glhckSpriteNew(TEXTURE, 4, 16);
  glhckObjectPositionf(o, position.x, position.y, 0);
  glhckObjectRotationf(o, 0, 0, (v.angle() - 0.25) * 360);

  Vec2D r = v.unit().scale(LENGTH/2.0f - RADIUS);
  shape.p1 = position + r;
  shape.p2 = position - r;
}
Exemple #3
0
void Ship::reset(bool full)
{
  dead = false;
  glhckObjectPositionf(o, 0, 0, 0);
  glhckObjectRotationf(o, 0, 0, 0);
  glhckObjectPositionf(shield, 0, 0, 0);
  glhckObjectRotationf(shield, 0, 0, 0);
  v = {0, 0};
  immortalityLeft = 4.0f;
  weapon->stopShooting();

  if(full)
  {
    weapon = &laser;
    laser.setLevel(1);
    spread.setLevel(0);
    beam.setLevel(0);
    plasma.setLevel(0);
    shields = 0;
  }
}
Exemple #4
0
Plasma::Plasma(GameWorld* world, float const life, float const power,
               Vec2D const& position, Vec2D const& velocity) :
  ew::Entity(world), ew::Renderable(world), ew::Updatable(world), ew::Collidable(world),
  gameWorld(world), o(nullptr), oGlow(nullptr), power(power), nextPower(power), life(life), glowPhase(0), v(velocity), shape(position, getRadius())
{
  o = glhckSpriteNew(TEXTURE, 2, 2);

  oGlow = glhckSpriteNew(TEXTURE, 2, 2);
  glhckObjectAddChild(o, oGlow);
  glhckObjectParentAffection(oGlow, GLHCK_AFFECT_TRANSLATION|GLHCK_AFFECT_ROTATION|GLHCK_AFFECT_SCALING);
  glhckMaterialBlendFunc(glhckObjectGetMaterial(oGlow), GLHCK_SRC_ALPHA, GLHCK_ONE);

  glhckObjectScalef(o, getRadius(), getRadius(), 1);
  glhckObjectPositionf(o, position.x, position.y, 0);
  glhckObjectRotationf(o, 0, 0, (v.angle()) * 360);
}
Exemple #5
0
Ship::Ship(GameWorld* world, Vec2D const& position, Vec2D const& velocity) :
  ew::Entity(world), ew::Renderable(world), ew::Updatable(world), ew::Collidable(world), ew::Controllable(world),
  gameWorld(world), o(nullptr), shield(nullptr), v(velocity),
  turningLeft(false), turningRight(false), accelerating(false), shooting(false),
  immortalityLeft(4), shields(0),
  weapon(nullptr), laser(world), spread(world), beam(world), plasma(world),
  weapons({&laser, &spread, &beam, &plasma}),
  dead(false), shape(position, RADIUS)
{
  o = glhckSpriteNew(atlas.getTexture(), 32, 32);
  shield = glhckSpriteNew(atlas.getTexture(), 48, 48);

  glhckMaterialTextureTransform(glhckObjectGetMaterial(o), &atlas.getTransform(DEFAULT).transform, atlas.getTransform(DEFAULT).degree);
  glhckMaterialTextureTransform(glhckObjectGetMaterial(shield), &atlas.getTransform(SHIELD).transform, atlas.getTransform(SHIELD).degree);

  glhckObjectPositionf(o, position.x, position.y, 0);

  weapon = &laser;
  laser.setLevel(1);
}
Exemple #6
0
int main(int argc, char **argv)
{
   GLFWwindow* window;
   glhckTexture *texture;
   glhckMaterial *material;
   glhckObject *cube, *sprite, *cube2, *sprite3, *camObj;
   glhckCamera *camera;
   const kmAABB *aabb;
   kmVec3 cameraPos = { 0, 0, 0 };
   kmVec3 cameraRot = { 0, 0, 0 };
   float spinRadius;
   int queuePrinted = 0;
   float          now          = 0;
   float          last         = 0;
   unsigned int   frameCounter = 0;
   unsigned int   FPS          = 0;
   unsigned int   fpsDelay     = 0;
   float          duration     = 0;
   float          delta        = 0;
   char           WIN_TITLE[256];
   memset(WIN_TITLE, 0, sizeof(WIN_TITLE));

   glfwSetErrorCallback(error_callback);
   if (!glfwInit())
      return EXIT_FAILURE;

   puts("-!- glfwinit");

   glhckCompileFeatures features;
   glhckGetCompileFeatures(&features);
   if (features.render.glesv1 || features.render.glesv2) {
      glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
      glfwWindowHint(GLFW_DEPTH_BITS, 16);
   }
   if (features.render.glesv2) {
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
   }
   if (features.render.opengl) {
      glfwWindowHint(GLFW_DEPTH_BITS, 24);
   }
   if (!(window = glfwCreateWindow(WIDTH, HEIGHT, "display test", NULL, NULL)))
      return EXIT_FAILURE;

   glfwMakeContextCurrent(window);
   puts("-!- window create");

   /* Turn on VSYNC if driver allows */
   glfwSwapInterval(0);

   if (!glhckContextCreate(argc, argv))
      return EXIT_FAILURE;

   puts("-!- glhck init");

   if (!glhckDisplayCreate(WIDTH, HEIGHT, GLHCK_RENDER_AUTO))
      return EXIT_FAILURE;

   puts("-!- glhck display create");

   RUNNING = 1;

   /* test camera */
   if (!(camera = glhckCameraNew()))
      return EXIT_FAILURE;

   glhckCameraRange(camera, 1.0f, 1000.0f);
   camObj = glhckCameraGetObject(camera);

   if (!(texture = glhckTextureNewFromFile("example/media/glhck.png", NULL, NULL)))
      return EXIT_FAILURE;

   if (!(material = glhckMaterialNew(texture)))
      return EXIT_FAILURE;

   glhckTextureFree(texture);

   sprite  = glhckSpriteNew(texture, 0, 0);
   cube2   = glhckCubeNew(1.0f);
   glhckObjectDrawAABB(cube2, 1);
   glhckObjectDrawOBB(cube2, 1);
   glhckObjectScalef(cube2, 1.0f, 1.0f, 2.0f);
   glhckObjectMaterial(cube2, material);

   sprite3 = glhckObjectCopy(sprite);
   glhckObjectScalef(sprite, 0.05f, 0.05f, 0.05f);
   glhckObjectPositionf(sprite3, 64*2, 48*2, 0);

#define SKIP_MMD    0
#define SKIP_OCTM   0
#define SKIP_ASSIMP 0

#if SKIP_MMD
#  define MMD_PATH ""
#else
#  define MMD_PATH "example/media/madoka/md_m.pmd"
#endif

#if SKIP_OCTM
#  define OCTM_PATH ""
#else
#  define OCTM_PATH "example/media/ambulance/ambulance.ctm"
#endif

/* cmake -DGLHCK_IMPORT_ASSIMP=YES */
#if SKIP_ASSIMP
#  define ASSIMP_PATH ""
#else
//#  define ASSIMP_PATH "example/media/chaosgate/chaosgate.obj"
//#  define ASSIMP_PATH "example/media/room/room.obj"
//#  define ASSIMP_PATH "example/media/alletine.x"
#  define ASSIMP_PATH "example/media/player.x"
#endif

   glhckImportModelParameters animatedParams;
   memcpy(&animatedParams, glhckImportDefaultModelParameters(), sizeof(glhckImportModelParameters));
   animatedParams.animated = 1;

   if ((cube = glhckModelNewEx(MMD_PATH, 1.0f, NULL, GLHCK_INDEX_SHORT, GLHCK_VERTEX_V3S))) {
      cameraPos.y =  10.0f;
      cameraPos.z = -40.0f;
   } else if ((cube = glhckModelNewEx(OCTM_PATH, 5.0f, NULL, GLHCK_INDEX_SHORT, GLHCK_VERTEX_V3S))) {
      cameraPos.y =  10.0f;
      cameraPos.z = -40.0f;
      glhckObjectPositionf(cube, 0.0f, 5.0f, 0.0f);
   } else if ((cube = glhckModelNewEx(ASSIMP_PATH, 0.1f, &animatedParams, GLHCK_INDEX_SHORT, GLHCK_VERTEX_V3S))) {
      glhckMaterial *mat;
      glhckTexture *tex;
      if ((tex = glhckTextureNewFromFile("example/media/texture-b.png", NULL, NULL))) {
         if ((mat = glhckMaterialNew(tex))) glhckObjectMaterial(cube, mat);
         glhckTextureFree(tex);
      }
      glhckObjectMovef(cube, 0, 15, 0);
      cameraPos.y =  10.0f;
      cameraPos.z = -40.0f;
   } else if ((cube = glhckCubeNew(1.0f))) {
      glhckObjectMaterial(cube, material);
      cameraPos.z = -20.0f;
   } else return EXIT_FAILURE;

#define SHADOW 0
#if SHADOW
   glhckShader *shader = glhckShaderNew(NULL, "VSM.GLhck.Lighting.ShadowMapping.Unpacking.Fragment", NULL);
   glhckShader *depthShader = glhckShaderNew(NULL, "VSM.GLhck.Depth.Packing.Fragment", NULL);
   glhckShader *depthRenderShader = glhckShaderNew(NULL, "VSM.GLhck.DepthRender.Unpacking.Fragment", NULL);
   glhckShaderSetUniform(shader, "ShadowMap", 1, &((int[]){1}));