Exemple #1
0
Input* Input_create() {
	Input* this = malloc(sizeof(Input));
	this->hotkeys = Vector_Create();

	this->joysticks = Vector_Create();

	int joysticksCount = SDL_NumJoysticks();

	if (joysticksCount > 1) {
		printf("Input: found %d Joysticks/Gamepads:\n", joysticksCount);
	} else if (joysticksCount == 1) {
		printf("Input: found 1 Joystick/Gamepad:\n");
	} else {
		printf("Input: found no Joysticks/Gamepads\n");
	}


	for (int i=0; i < joysticksCount; ++i) {
		SDL_Joystick* j = SDL_JoystickOpen(i);
		int axes = SDL_JoystickNumAxes(j);
		int buttons = SDL_JoystickNumButtons(j);
		int hats = SDL_JoystickNumHats(j);
		Vector_AddElement(this->joysticks, j);
		printf("%d: %s | axes:%d buttons:%d hats:%d \n", i, SDL_JoystickName(j), axes, buttons, hats);
	}

//	SDL_JoystickEventState (SDL_IGNORE);


	return this;
}
Exemple #2
0
World World_Initialize(int map_width, int map_height)
{
    World world;

    world.bullets_vector    =   Vector_Create();
    world.bonus_vector      =   Vector_Create();
    world.monsters_vector   =   Vector_Create();
    world.explosions_vector =   Vector_Create();
    world.events_vector     =   Vector_Create();
    world.decals_vector     =   Vector_Create();
    world.props_vector     =   Vector_Create();
    world.non_null_walls = Vector_Create();
    world.map_width         =   map_width;
    world.map_height        =   map_height;
    world.map_size          =   map_width * map_height;
    world.map               =   calloc(world.map_size, sizeof(Entity*));
    world.ground_map        =   calloc(world.map_size, sizeof(Entity*));
    world.player            =   Player_Create(100,
                                              100,
                                              10, 10);

    for(int i = 0 ; i < world.map_size ; i++)
    {
        world.ground_map[i] = Ground_Create(Ground_Grass,
                                            (i % map_width) * TILE_SIZE,
                                            TILE_SIZE*(i/map_width));

    }

    return world;
}
Exemple #3
0
Scene* Scene_create(GameEngine* engine, Scene* lastScene) {
    Scene* this = allocStruct(Scene);

    this->engine = engine;
    SDL_Point screenSize;
    SDL_RenderGetLogicalSize(engine->renderer, &screenSize.x, &screenSize.y);
    this->camera = Camera_create(screenSize.x, screenSize.y);
    this->walkableBounds.x = 0;
    this->walkableBounds.w = 0;
    this->walkableBounds.y = 295 * PHYSICS_SCALE;
    this->walkableBounds.h = 185 * PHYSICS_SCALE;

    this->entities = Vector_Create();
    this->triggers = Vector_Create();
    this->bodies = Vector_Create();
    this->shapes = Vector_Create();

    this->sky = Sky_create(engine->textureCache);

    withSprintf(path, "images/%s/bg.png", anyArgs("red"), {
            SDL_Texture* texture = TextureCache_getForUnconstantPath(engine->textureCache, path);
            this->background = Sprite_create(texture);
        });
Exemple #4
0
Matrix * Matrix_Create(uint dim)
{
Matrix * m;
uint r;
	
	m = new(Matrix);
	assert(m);

	m->dimension = dim;
	m->rows = malloc(sizeofpointer*dim);

	assert(m->rows);
	for(r=0;r<m->dimension;r++)
	{
		m->rows[r] = Vector_Create(dim);
		assert(m->rows[r]);
	}

return m;
}
Exemple #5
0
UiNode* UiNode_create(void* context, UiNode* parent) {
	UiNode* this = malloc(sizeof(UiNode));
	this->parent = parent;
	this->context = context;
	this->children = Vector_Create();
	this->callbackContext = NULL;

	this->destroy = UiNode_emptyDestroy;
	this->draw = UiNode_emptyDraw;
	this->handleEvent = UiNode_emptyHandleEvent;
	this->resize = UiNode_emptyResize;

	SDL_Rect_init(&this->bounds);

	this->selectable = true;
	this->selectedChild = NULL;

	if (parent) {
		Vector_AddElement(parent->children, this); // TODO call add funct
	}

	return this;
}
Exemple #6
0
HRESULT App_CookArgList (
   HCMDLIST * phlst,
   LPCTSTR    aArgs[],
   UINT       ixFirst,  // first arg to execute
   UINT       cArgs)    // count of args to execute
{
   HRESULT    hr = S_FALSE; // there were no args...
   TCHAR      szTempArg[64]; // temp if we need to copy and arg

   HCMDLIST   hlst;

   *phlst = NULL;
   hr = Vector_Create(&hlst, cArgs, -1);
   if (FAILED(hr))
      return hr;

   // look at args, parsing switches and building up the array of filename pointers
   //
   UINT ixLast = (ixFirst + cArgs);
   for (UINT ii = ixFirst; ii < ixLast; ++ii)
      {
      LPCTSTR pszArg = aArgs[ii];
      if ( ! pszArg)
         break;

      // assume a file open command.
      //
      hr = S_OK;
      CMDSWITCH cmd = {APP_CMD_PATH, 0, 1, NULL};

      // if the first character of the arg is an '@', what follows should be a command file.
      //
      if (pszArg[0] == '@')
         {
         // command will be an argfile command
         //
         cmd.idCmd     = APP_CMD_ARGFILE;
         cmd.cParams   = 1;    // on arg needed
         cmd.pszParams = NULL; // no default

         // if next character is not a 0, it must be the filename
         // otherwise, suck up the next token and use it as the filename.
         //
         pszArg = StrCharNext (pszArg); // skip '@'
         if (0 != pszArg[0])
            {
            cmd.pszParams = pszArg;
            }
         else if (ii+1 < ixLast) // next pszArg belongs to us..
            {
            LPCTSTR pszT = aArgs[ii+1];
            if ('-' != pszT[0] && '/' != pszT[0])
               {
               cmd.pszParams = pszT;
               ++ii;  // advance the loop counter.
               }
            }
         }
      else if ('-' == pszArg[0] || '/' == pszArg[0])
         {
         pszArg = StrCharNext (pszArg);
         if (0 == pszArg[0])
            {
            hr = E_INVALIDARG;
            goto bail;
            }

         // look for a ':' in the arg, and
         //
         LPCTSTR psz = StrCharNext(pszArg);
         LPCTSTR pszParam = NULL;
         while (0 != psz[0])
            {
            // if the arg contains a colon, set pszParam to point to it
            // and extract the stuff before the colon as the actual arg.
            //
            if (':' == psz[0])
               {
               pszParam = StrCharNext (psz);
               UINT cch = (UINT)(((LPARAM)psz - (LPARAM)pszArg) / NUMBYTES(TCHAR));
               StrCopyN (szTempArg, NUMCHARS(szTempArg), pszArg, cch + 1);
               DASSERT(0 == szTempArg[min(NUMCHARS(szTempArg)-1, cch)]);
               pszArg = szTempArg;
               break;
               }

            psz = StrCharNext(psz);
            }

         // lookup the argment
         //
         if ( ! App_LookupCmdLineArg (g_aAppCommands, pszArg, &cmd))
            {
            bprintfl("%s is not a valid argument", pszArg);
            hr = E_INVALIDARG;
            goto bail;
            }

         if (pszParam)
            {
            if (cmd.cParams < 1)
               {
               // if we have a param, but the arg doesn't take any, bail.
               //
               bprintfl("the %s argument is does not take parameters", pszArg);
               hr = E_INVALIDARG;
               goto bail;
               }

            cmd.pszParams = pszParam;
            }
         else
            {
            // if the command needs args, but none have been found so
            // far, try sucking up the next token in the command line
            //
            if (cmd.cParams > 0 && NULL == cmd.pszParams)
               {
               if (ii+1 < ixLast) // next pszArg belongs to us..
                  {
                  LPCTSTR pszT = aArgs[ii+1];
                  if ('-' != pszT[0] && '/' != pszT[0])
                     {
                     cmd.pszParams = pszT;
                     ++ii;  // advance the loop counter.
                     }
                  }
               }
            }
         }
      else
         {
         // not a switch, this is an implied file-open command
         //
         cmd.pszParams = pszArg;
         }

      // if the command needs an arg, but we dont have one.
      // the command line is in error.
      //
      if ((cmd.cParams > 0) && (NULL == cmd.pszParams))
         {
         bprintfl("the %s argument requires parameters", pszArg);
         g_app.fUsage = true;
         hr = E_INVALIDARG;
         goto bail;
         }

      // append the command.
      //
      Vector_AppendItem(hlst, cmd);
      }

   // return the command list
   //
   *phlst = hlst;

bail:
   if (FAILED(hr) || Vector_GetCountSafe(hlst) < 1)
      {
      *phlst = NULL;
      if (hlst)
         Vector_Delete (hlst);
      }
   return hr;
}