summary refs log tree commit diff stats
path: root/src/mapview.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-02-19 20:10:11 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-02-19 20:10:11 -0500
commitcd48894563052baeddff64f6bbc13ccc7fa6e081 (patch)
treec7ab2a9b4cbb7ac0d921cf486aef00c5b5623144 /src/mapview.cpp
parentc1b1558256997df22678f6405ea320ae454ad5b4 (diff)
downloadtherapy-cd48894563052baeddff64f6bbc13ccc7fa6e081.tar.gz
therapy-cd48894563052baeddff64f6bbc13ccc7fa6e081.tar.bz2
therapy-cd48894563052baeddff64f6bbc13ccc7fa6e081.zip
Added CRT mesh!
Also a character sprite, changed up the map file format, fixed some shader bugs
Diffstat (limited to 'src/mapview.cpp')
-rw-r--r--src/mapview.cpp112
1 files changed, 85 insertions, 27 deletions
diff --git a/src/mapview.cpp b/src/mapview.cpp index f524d46..78dd770 100644 --- a/src/mapview.cpp +++ b/src/mapview.cpp
@@ -17,7 +17,13 @@ MapView::MapView(Map* first, int x, int y)
17 player->x_accel = 0; 17 player->x_accel = 0;
18 player->y_accel = jump_gravity; 18 player->y_accel = jump_gravity;
19 player->w = 10; 19 player->w = 10;
20 player->h = 14; 20 player->h = 12;
21 player->onGround = false;
22 player->animFrame = 0;
23
24 bg = createTexture(GAME_WIDTH, GAME_HEIGHT);
25 chara = loadTextureFromBMP("../res/Starla.bmp");
26 tiles = loadTextureFromBMP("../res/tiles2.bmp");
21 27
22 loadMap(first); 28 loadMap(first);
23} 29}
@@ -25,6 +31,8 @@ MapView::MapView(Map* first, int x, int y)
25MapView::~MapView() 31MapView::~MapView()
26{ 32{
27 destroyTexture(bg); 33 destroyTexture(bg);
34 destroyTexture(chara);
35 destroyTexture(tiles);
28 36
29 delete player; 37 delete player;
30} 38}
@@ -41,55 +49,47 @@ void MapView::loadMap(Map* m)
41 add_collision(-6, 0, GAME_WIDTH, left, (m->getLeftMap() == NULL) ? 1 : 2); 49 add_collision(-6, 0, GAME_WIDTH, left, (m->getLeftMap() == NULL) ? 1 : 2);
42 add_collision(GAME_WIDTH+6, 0, GAME_WIDTH, right, (m->getRightMap() == NULL) ? 1 : 2); 50 add_collision(GAME_WIDTH+6, 0, GAME_WIDTH, right, (m->getRightMap() == NULL) ? 1 : 2);
43 51
44 if (bg == NULL)
45 {
46 bg = createTexture(GAME_WIDTH, GAME_HEIGHT);
47 }
48
49 fillTexture(bg, NULL, 0, 0, 0); 52 fillTexture(bg, NULL, 0, 0, 0);
50 53
51 const char* mapbuf = m->mapdata(); 54 const int* mapbuf = m->mapdata();
52 55
53 for (int i=0; i<MAP_WIDTH*(MAP_HEIGHT-1); i++) 56 for (int i=0; i<MAP_WIDTH*(MAP_HEIGHT-1); i++)
54 { 57 {
55 int x = i % MAP_WIDTH; 58 int x = i % MAP_WIDTH;
56 int y = i / MAP_WIDTH; 59 int y = i / MAP_WIDTH;
57 Rectangle dst(x*TILE_WIDTH, y*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); 60 Rectangle dst(x*TILE_WIDTH, y*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT);
58 //Rectangle src; 61 Rectangle src(mapbuf[i]%8*TILE_WIDTH, mapbuf[i]/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT);
59 62
60 switch (mapbuf[i]) 63 if (mapbuf[i] > 0)
61 { 64 {
62 case ' ': break; 65 blitTexture(tiles, bg, &src, &dst);
63 case 'X': fillTexture(bg, &dst, 255, 85, 85); break; 66 }
64 case 'P': fillTexture(bg, &dst, 85, 255, 255); break;
65 }
66
67 //blitTexture(tiles, bg, &src, &dst); 67 //blitTexture(tiles, bg, &src, &dst);
68 68
69 if (mapbuf[i] == 'X') 69 if ((mapbuf[i] > 0) && (!((mapbuf[i] >= 5) && (mapbuf[i] <= 7))))
70 { 70 {
71 if ((x != 0) && (mapbuf[i-1] != 'X')) 71 //if ((x != 0) && (mapbuf[i-1] != 'X'))
72 { 72 {
73 add_collision(x*TILE_WIDTH, y*TILE_HEIGHT, (y+1)*TILE_HEIGHT, right, 0); 73 add_collision(x*TILE_WIDTH, y*TILE_HEIGHT, (y+1)*TILE_HEIGHT, right, 0);
74 } 74 }
75 75
76 if ((x != 39) && (mapbuf[i+1] != 'X')) 76 //if ((x != 39) && (mapbuf[i+1] != 'X'))
77 { 77 {
78 add_collision((x+1)*TILE_WIDTH, y*TILE_HEIGHT, (y+1)*TILE_HEIGHT, left, 0); 78 add_collision((x+1)*TILE_WIDTH, y*TILE_HEIGHT, (y+1)*TILE_HEIGHT, left, 0);
79 } 79 }
80 80
81 if ((y != 0) && (mapbuf[i-MAP_WIDTH] != 'X')) 81 //if ((y != 0) && (mapbuf[i-MAP_WIDTH] != 'X'))
82 { 82 {
83 add_collision(y*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, down, 0); 83 add_collision(y*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, down, 0);
84 } 84 }
85 85
86 if ((y != 23) && (mapbuf[i+MAP_WIDTH] != 'X')) 86 //if ((y != 23) && (mapbuf[i+MAP_WIDTH] != 'X'))
87 { 87 {
88 add_collision((y+1)*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, up, 0); 88 add_collision((y+1)*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, up, 0);
89 } 89 }
90 } else if (mapbuf[i] == 'P') 90 } else if ((mapbuf[i] >= 5) && (mapbuf[i] <= 7))
91 { 91 {
92 add_collision(y*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, down, 0); 92 add_collision(y*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, down, 3);
93 } 93 }
94 } 94 }
95 95
@@ -112,16 +112,38 @@ void MapView::input(int key, int action)
112 { 112 {
113 switch (key) 113 switch (key)
114 { 114 {
115 case GLFW_KEY_LEFT: holding_left = true; break; 115 case GLFW_KEY_LEFT:
116 case GLFW_KEY_RIGHT: holding_right = true; break; 116 holding_left = true;
117 case GLFW_KEY_UP: player->y_vel = jump_velocity; break; 117 break;
118 case GLFW_KEY_RIGHT:
119 holding_right = true;
120 break;
121 case GLFW_KEY_UP:
122 if (player->onGround)
123 {
124 player->y_vel = jump_velocity;
125 player->onGround = false;
126 }
127 break;
128 case GLFW_KEY_DOWN:
129 holding_down = true;
130 break;
118 } 131 }
119 } else if (action == GLFW_RELEASE) 132 } else if (action == GLFW_RELEASE)
120 { 133 {
121 switch (key) 134 switch (key)
122 { 135 {
123 case GLFW_KEY_LEFT: holding_left = false; break; 136 case GLFW_KEY_LEFT:
124 case GLFW_KEY_RIGHT: holding_right = false; break; 137 holding_left = false;
138 if (!holding_right) player->animFrame = 1;
139 break;
140 case GLFW_KEY_RIGHT:
141 holding_right = false;
142 if (!holding_left) player->animFrame = 0;
143 break;
144 case GLFW_KEY_DOWN:
145 holding_down = false;
146 break;
125 } 147 }
126 } 148 }
127} 149}
@@ -153,12 +175,37 @@ void MapView::tick()
153 175
154void MapView::render(Texture* tex) 176void MapView::render(Texture* tex)
155{ 177{
178 if (animFrame == 0)
179 {
180 if (holding_left)
181 {
182 if (player->animFrame == 3)
183 {
184 player->animFrame = 5;
185 } else {
186 player->animFrame = 3;
187 }
188 } else if (holding_right)
189 {
190 if (player->animFrame == 2)
191 {
192 player->animFrame = 4;
193 } else {
194 player->animFrame = 2;
195 }
196 }
197 }
198
199 animFrame++;
200 animFrame %= 10;
201
156 // Draw the background 202 // Draw the background
157 blitTexture(bg, tex, NULL, NULL); 203 blitTexture(bg, tex, NULL, NULL);
158 204
159 // Draw the player 205 // Draw the player
206 Rectangle src_rect(player->animFrame * 10, 0, 10, 12);
160 Rectangle dst_rect(player->x, player->y, player->w, player->h); 207 Rectangle dst_rect(player->x, player->y, player->w, player->h);
161 fillTexture(tex, &dst_rect, 255, 255, 255); 208 blitTexture(chara, tex, &src_rect, &dst_rect);
162} 209}
163 210
164void MapView::add_collision(int axis, int lower, int upper, direction_t dir, int type) 211void MapView::add_collision(int axis, int lower, int upper, direction_t dir, int type)
@@ -305,9 +352,20 @@ void MapView::check_collisions(mob_t* mob, int x_next, int y_next)
305 { 352 {
306 y_next = it->axis - mob->h; 353 y_next = it->axis - mob->h;
307 mob->y_vel = 0; 354 mob->y_vel = 0;
355 mob->onGround = true;
308 } else if (it->type == 1) 356 } else if (it->type == 1)
309 { 357 {
310 y_next = 1 - mob->h/2; 358 y_next = 1 - mob->h/2;
359 } else if (it->type == 3)
360 {
361 if (holding_down)
362 {
363 holding_down = false;
364 } else {
365 y_next = it->axis - mob->h;
366 mob->y_vel = 0;
367 mob->onGround = true;
368 }
311 } 369 }
312 370
313 break; 371 break;