Dumb-ways-to-memorize
2D game
Functions
player_controller.c File Reference
#include "globals.h"
#include "player_controller.h"
#include "entity.h"
#include "parsepowerup.h"
#include "player.h"
+ Include dependency graph for player_controller.c:

Go to the source code of this file.

Functions

void DoPlayerThink (void *player, SDL_GameControllerButton button)
 

Function Documentation

void DoPlayerThink ( void *  player,
SDL_GameControllerButton  button 
)

Executes the player think operation for player input.

Parameters
[in,out]playerIf non-null, the player.
buttonThe button.
Author
Anthony Rios
Date
3/29/2016

Definition at line 7 of file player_controller.c.

References ANIMATION_JUMP, ANIMATION_WALK, CountMem(), ENTITY_DIR_LEFT, ENTITY_DIR_RIGHT, gCurrentPowerUp, PLAYER_BASE_JUMP, and PLAYER_BASE_SPEED.

Referenced by ThinkPlayer().

8 {
9  entity_t *ent = (entity_t*) player;
10  switch(button)
11  {
12  case(SDL_CONTROLLER_BUTTON_A):
13  {
14  if(ent->mVelocity.y == 0)
15  {
16  ent->mVelocity.y += PLAYER_BASE_JUMP;
17  ent->mAnimation = ANIMATION_JUMP >= CountMem(ent->mSprites, sizeof(sprite_t*)) ? NULL : ent->mSprites[ANIMATION_JUMP];
18  }
19 
20  break;
21  }
22  case(SDL_CONTROLLER_BUTTON_B):
23  {
24  ent->PowerUp(gCurrentPowerUp);
25  break;
26  }
27  case(SDL_CONTROLLER_BUTTON_DPAD_LEFT):
28  {
29  ent->mVelocity.x -= PLAYER_BASE_SPEED;
30  ent->mAnimation = ANIMATION_WALK >= CountMem(ent->mSprites, sizeof(sprite_t*)) ? NULL : ent->mSprites[ANIMATION_WALK];
31  ent->mDirection = ENTITY_DIR_LEFT;
32  break;
33  }
34  case(SDL_CONTROLLER_BUTTON_DPAD_RIGHT):
35  {
36  ent->mVelocity.x += PLAYER_BASE_SPEED;
37  ent->mAnimation = ANIMATION_WALK >= CountMem(ent->mSprites, sizeof(sprite_t*)) ? NULL : ent->mSprites[ANIMATION_WALK];;
38  ent->mDirection = ENTITY_DIR_RIGHT;
39  break;
40  }
41  default:
42  return;
43  }
44 
45 }
int CountMem(void *src, int size_type)
Definition: mymath.c:51
#define PLAYER_BASE_SPEED
Definition: player.h:8
#define PLAYER_BASE_JUMP
Definition: player.h:7
#define ENTITY_DIR_LEFT
Definition: entity.h:9
#define ENTITY_DIR_RIGHT
Definition: entity.h:10
power_t * gCurrentPowerUp
Definition: parsepowerup.c:16