-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapEditor.c
61 lines (47 loc) · 2 KB
/
mapEditor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "headers/mapEditor.h"
void setCurrentSprite(Agent *agent, SDL_Rect *rect) {
agent->currentSprite.x = agent->sprite_w * agent->currentFramex;
agent->currentSprite.y = agent->sprite_h * agent->currentFramey;
agent->currentSprite.w = agent->sprite_w;
agent->currentSprite.h = agent->sprite_h;
}
Agent initAgent(char* textureName, SDL_Rect agent_dest, int facingLeft, int currentFramex, int currentFramey, SDL_Renderer *renderer) {
Agent agent;
agent.sheetTexture = createTexture(textureName, renderer);
agent.x = agent_dest.x;
agent.y = agent_dest.y;
agent.sprite_w = agent_dest.w;
agent.sprite_h = agent_dest.h;
agent.dy = 0;
agent.falling = true;
agent.facingLeft = facingLeft;
agent.currentFramex = currentFramex;
agent.currentFramey = currentFramey;
SDL_Rect currentSprite;
agent.currentSprite = currentSprite;
setCurrentSprite(&agent, &agent.currentSprite);
agent.coll.leftEdge = agent.x;
agent.coll.rightEdge = agent.x + agent.sprite_w;
agent.coll.top = agent.y;
agent.coll.bottom = agent.y + agent.sprite_h;
agent.coll.mass = 1; // 1 means fully dynamic
return agent;
}
Platform initPlatform(char* textureName, SDL_Rect block_dest, int numBlocks, SDL_Renderer *renderer) {
Platform platform;
platform.pTexture = createTexture(textureName, renderer);
platform.block_dest = block_dest;
platform.numBlocks = numBlocks;
platform.coll.leftEdge = platform.block_dest.x;
platform.coll.rightEdge = platform.block_dest.x + platform.block_dest.w;
platform.coll.top = platform.block_dest.y;
platform.coll.bottom = platform.block_dest.y + platform.block_dest.h;
platform.coll.mass = 0; // 0 means fully static
return platform;
}
SDL_Texture *createTexture(char *img_name, SDL_Renderer *renderer) {
SDL_Surface *image = IMG_Load(img_name);
SDL_Texture *image_texture = SDL_CreateTextureFromSurface(renderer, image);
SDL_FreeSurface(image);
return image_texture;
}