I hereby claim:
- I am mikepicker on github.
- I am mikepicker (https://keybase.io/mikepicker) on keybase.
- I have a public key ASBV-rCdor5LkYkzuyARoo81AnHDMm-8wLz0ocYzRGSiNQo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
// Game objects | |
struct Background { | |
SDL_Texture* texture; | |
}; | |
struct Platform { | |
int x, y, w, h; | |
SDL_Texture* texture; | |
}; |
bool loadMedia() { | |
// Loading success flag | |
bool success = true; | |
// Init background | |
background.texture = loadTexture("assets/background.png"); | |
SDL_QueryTexture(background.texture, NULL, NULL, &background.w, &background.h); | |
background.x = 0; | |
background.y = SCREEN_HEIGHT-background.h; |
void render() { | |
// Render background | |
SDL_Rect dstBackground = { .x = background.x, .y = background.y, .w = background.w, .h = background.h }; | |
SDL_RenderCopy(gRenderer, background.texture, NULL, &dstBackground); | |
// Render platform | |
SDL_Rect dstPlatf = { .x = platform.x, .y = platform.y, .w = platform.w, .h = platform.h }; | |
SDL_RenderCopy(gRenderer, platform.texture, NULL, &dstPlatf); | |
} |
struct Survivor { | |
int x, y, w, h; | |
int scaleX, scaleY; | |
int frameX, frameY; | |
int animSpeed = 6; | |
int speed = 3; | |
bool animCompleted = false; | |
bool shot = false; | |
std::string state; | |
SDL_Texture* texture; |
bool loadMedia() { | |
// Init survivor | |
survivor.texture = loadTexture("assets/survivor.png"); | |
survivor.x = 200; | |
survivor.y = 100; | |
survivor.w = 64; | |
survivor.h = 64; | |
survivor.scaleX = 1; | |
survivor.scaleY = 1; |
void update() { | |
// Physics | |
survivor.y += world.gravity; | |
// Platform collision | |
if (survivor.y + survivor.h > platform.y && | |
survivor.x + 48 >= platform.x && | |
survivor.x + survivor.w - 48 <= platform.x + platform.w && | |
survivor.y + (survivor.h/2) < platform.y) { |
void render() { | |
// Clear screen | |
SDL_RenderClear(gRenderer); | |
// Render survivor | |
SDL_Rect srcSurv = { .x = (survivor.frameX / survivor.animSpeed) * survivor.w, .y = survivor.frameY * survivor.h, .w = survivor.w, .h = survivor.h }; | |
SDL_Rect dstSurv = { .x = survivor.x, .y = survivor.y, .w = survivor.w, .h = survivor.h }; | |
SDL_RendererFlip flip = survivor.scaleX == 1 ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; | |
SDL_RenderCopyEx(gRenderer, survivor.texture, &srcSurv, &dstSurv, 0, NULL, flip); |
const int BULLET_COUNT = 10; | |
SDL_Texture* bulletTexture; | |
int bulletWidth, bulletHeight; | |
int bulletSpeed = 20; | |
struct Bullet { | |
int x, y; | |
int dir = 1; | |
bool alive = false; | |
}; |
bool loadMedia() { | |
// Init bullet | |
bulletTexture = loadTexture("assets/bullet.png"); | |
SDL_QueryTexture(bulletTexture, NULL, NULL, &bulletWidth, &bulletHeight); | |
} |