20220707 - On ne peut plus traverser les blocs et le joueur peut tomber. Nouveaux sprites.

This commit is contained in:
mibi88 2022-07-07 13:02:27 +02:00
parent cf1397f6a9
commit 57cc1aad3f
1 changed files with 35 additions and 31 deletions

View File

@ -21,7 +21,7 @@ extern bopti_image_t skin1_player_left2;
extern bopti_image_t skin1_player_right1;
extern bopti_image_t skin1_player_right2;
int x, y, pos, hour, animation, orient, timing;
int x, y, pos, hour, animation, orient, timing, falling;
void drawselectedgame(int selected) {
dclear(C_WHITE);
@ -54,6 +54,8 @@ void addtrees(unsigned short int * terrain){
}
}
void mappartdisplaying(int x, int y, unsigned short int * terrain, int player) {
x = x-60;
y = y-24;
int firsttile_x = x>>3, firsttile_y = y>>3;
int base_x = firsttile_x*8, base_y = firsttile_y*8;
int sx = base_x - x, sy = base_y - y, tx = (SCREEN_WIDTH>>3) + 1, ty = (SCREEN_HEIGHT>>3) + 1;
@ -82,14 +84,14 @@ void mappartdisplaying(int x, int y, unsigned short int * terrain, int player) {
px = sx;
}
switch(player){
case 1:
dimage(60, 24, &skin1_player_right1); break;
case 2:
dimage(60, 24, &skin1_player_right2); break;
case 3:
dimage(60, 24, &skin1_player_left1); break;
case 4:
dimage(60, 24, &skin1_player_left2); break;
default:
dimage(60, 24, &skin1_player_right1); break;
}
}
int exists(unsigned short int * terrain, short type) {
@ -101,40 +103,35 @@ int exists(unsigned short int * terrain, short type) {
}
return 0;
}
int pointoverrectangle(int x1, int y1, int x2, int y2, int x, int y){
if ((x >= x1 && x<=x2) && (y >= y1 && y<=y2)){
int pointoverrectangle(int rx1, int ry1, int rx2, int ry2, int x, int y){
if ((x>=rx1 && y>=ry1) && (x<=rx2 && y<=ry2)){
return 1;
}
return 0;
}
void collisiononmap(int x, int y, unsigned short int * terrain) {
int collisiononmap(int x, int y, unsigned short int * terrain, int testx, int testy) {
x = x-60;
y = y-24;
int firsttile_x = x>>3, firsttile_y = y>>3;
int base_x = firsttile_x*8, base_y = firsttile_y*8;
int sx = base_x - x, sy = base_y - y, tx = (SCREEN_WIDTH>>3) + 1, ty = (SCREEN_HEIGHT>>3) + 1;
int cx, cy, px = sx, py = sy;
unsigned short type, type_over;
unsigned short type;
dclear(C_WHITE);
for(cy = 0;cy != ty;cy++){
for(cx = 0;cx != tx;cx++){
type = terrain[(firsttile_y+cy)*WORLD_WIDTH+(firsttile_x+cx)];
type_over = terrain[(firsttile_y+cy-1)*WORLD_WIDTH+(firsttile_x+cx)];
switch(type){
case 1:
if(type_over == 0){dimage(px, py, &grass_tile);}else{dimage(px, py, &soil_tile);} break;
case 2:
dimage(px, py, &stone_tile); break;
case 3:
dimage(px, py, &coal_tile); break;
case 4:
dimage(px, py, &steel_tile); break;
case 5:
dimage(px, py, &wood_tile); break;
if(type != 0){
if(pointoverrectangle(px, py, px+8, py+8, testx, testy)){
return 1;
}
}
px += 8;
}
py += 8;
px = sx;
}
return 0;
}
int main(void) {
dclear(C_WHITE);
@ -181,7 +178,7 @@ int main(void) {
terrain[i] = 0;
}
srand(clock());
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 40) - (WORLD_HEIGHT - 60) + 1)) + WORLD_HEIGHT - 60), WORLD_HEIGHT - 60, WORLD_HEIGHT - 40, 0, 1);
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 40) - (WORLD_HEIGHT - 50) + 1)) + WORLD_HEIGHT - 50), WORLD_HEIGHT - 50, WORLD_HEIGHT - 40, 0, 1);
srand(clock());
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 30) - (WORLD_HEIGHT - 40) + 1)) + WORLD_HEIGHT - 40), WORLD_HEIGHT - 40, WORLD_HEIGHT - 30, 3, 2);
srand(clock());
@ -190,19 +187,20 @@ int main(void) {
///// Add trees /////
addtrees(terrain);
/////////////////////
x = 200;
for(i=0;i!=WORLD_HEIGHT;i++){
if(terrain[i*WORLD_WIDTH+(x>>3)] != 0){
y = i * 8;
break;
}
}
x = 0;
/*for(i=0;i!=WORLD_HEIGHT;i++){
if(terrain[i*WORLD_WIDTH+(x>>3)] != 0){
y = i*8-8;
break;
}
} */
y = 0;
game = 3;
hour = 0;
timing = 0;
}else if(game == 3){
clearevents();
if(keydown(KEY_RIGHT)){
if(keydown(KEY_RIGHT) && (collisiononmap(x, y, terrain, 67, 35) == 0 && collisiononmap(x, y, terrain, 67, 25) == 0)){
x++;
if(animation == 0 && timing == 5){
animation = 1;
@ -213,7 +211,7 @@ int main(void) {
}
timing++;
orient = 1;
}else if(keydown(KEY_LEFT)){
}else if(keydown(KEY_LEFT) && (collisiononmap(x, y, terrain, 61, 35) == 0 && collisiononmap(x, y, terrain, 61, 25) == 0)){
x--;
if(animation == 0 && timing == 5){
animation = 1;
@ -225,12 +223,18 @@ int main(void) {
timing++;
orient = 3;
}
clearevents();
if(collisiononmap(x, y, terrain, 61, 40) == 0 && collisiononmap(x, y, terrain, 67, 40) == 0 && collisiononmap(x, y, terrain, 60, 40) == 0){
y++;
falling = 1;
}else{
falling = 0;
}
/* clearevents();
if(keydown(KEY_UP)){
y--;
}else if(keydown(KEY_DOWN)){
y++;
}
} */
clearevents();
if(keydown(KEY_SHIFT)){
//