diff --git a/src/itoa.h b/src/itoa.h new file mode 100644 index 0000000..6ff4fb5 --- /dev/null +++ b/src/itoa.h @@ -0,0 +1,23 @@ +// From https://www.planet-casio.com/Fr/forums/topic14992-1-programmer-en-c-sur-graph-3575-e.html + +/* itoa: convert n to characters in s */ +void itoa(int n, char s[]) +{ + int i, j, sign; + char c; + + if ((sign = n) < 0) /* record sign */ + n = -n; /* make n positive */ + i = 0; + do { /* generate digits in reverse order */ + s[i++] = n % 10 + '0'; /* get next digit */ + } while ((n /= 10) > 0); /* delete it */ + if (sign < 0) + s[i++] = '-'; + s[i] = '\0'; + for (i = 0, j = strlen(s)-1; i>3)] != 0){ y = i*8-8; break; } } */ - y = 0; + player.y = 0; game = 3; hour = 0; - timing = 0; + player.timing = 0; + player.jumping = 0; + player.jumpheight = 0; + player.falling = 0; + for(i=0;i!=INVENTORY_SIZE;i++){ + player.inventoryitems[i] = 0; + player.inventorynum[i] = 0; + } }else if(game == 3){ clearevents(); - 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; - timing = 0; - }else if(animation == 1 && timing == 5){ - animation = 0; - timing = 0; + if(keydown(KEY_RIGHT) && (collisiononmap(player.x, player.y, terrain, 67, 35) == 0 && collisiononmap(player.x, player.y, terrain, 67, 25) == 0)){ + player.x++; + if(player.animation == 0 && player.timing == 5){ + player.animation = 1; + player.timing = 0; + }else if(player.animation == 1 && player.timing == 5){ + player.animation = 0; + player.timing = 0; } - timing++; - orient = 1; - }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; - timing = 0; - }else if(animation == 1 && timing == 5){ - animation = 0; - timing = 0; + player.timing++; + player.orient = 1; + }else if(keydown(KEY_LEFT) && (collisiononmap(player.x, player.y, terrain, 61, 35) == 0 && collisiononmap(player.x, player.y, terrain, 61, 25) == 0)){ + player.x--; + if(player.animation == 0 && player.timing == 5){ + player.animation = 1; + player.timing = 0; + }else if(player.animation == 1 && player.timing == 5){ + player.animation = 0; + player.timing = 0; } - timing++; - orient = 3; + player.timing++; + player.orient = 3; } - 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; + if(collisiononmap(player.x, player.y, terrain, 62, 40) == 0 && collisiononmap(player.x, player.y, terrain, 66, 40) == 0 && collisiononmap(player.x, player.y, terrain, 60, 40) == 0 && player.jumping == 0){ + player.y++; + player.falling = 1; }else{ - falling = 0; + player.falling = 0; } /* clearevents(); if(keydown(KEY_UP)){ @@ -236,16 +250,102 @@ int main(void) { y++; } */ clearevents(); - if(keydown(KEY_SHIFT)){ - // + if(keydown(KEY_SHIFT) && player.jumping == 0 && player.falling == 0 && player.jumpheight == 0){ + player.jumping = 1; + player.jumpheight = 1; + } + if(player.jumping == 1 && player.jumpheight == 12){ + player.jumping = 0; + player.jumpheight = 0; + }else if(collisiononmap(player.x, player.y, terrain, 62, 23) || collisiononmap(player.x, player.y, terrain, 66, 23) || collisiononmap(player.x, player.y, terrain, 60, 23)){ + player.jumping = 0; + player.jumpheight = 0; + }else if(player.jumping == 1){ + player.jumpheight++; + player.y--; } if(exists(terrain, 5)==0){ addtrees(terrain); } + if(player.y>>3>WORLD_HEIGHT){ + player.y = 0; + } + clearevents(); + if (keydown(KEY_8) && player.sely>-8){ + player.sely--; + }else if (keydown(KEY_5) && player.sely<24){ + player.sely++; + } + clearevents(); + if (keydown(KEY_4) && player.selx>-8){ + player.selx--; + }else if (keydown(KEY_6) && player.selx<16){ + player.selx++; + } + pos = ((player.y+player.sely)>>3)*WORLD_WIDTH+((player.x+player.selx)>>3); + if(pos<=WORLD_WIDTH*WORLD_HEIGHT && pos>=0){ + clearevents(); + if (keydown(KEY_EXE) && terrain[pos] == 0 && player.inventorynum[player.invselect] != 0){ + terrain[pos] = player.inventoryitems[player.invselect]; + player.inventorynum[player.invselect]--; + if(player.inventorynum[player.invselect] == 0) { + player.inventoryitems[player.invselect] = 0; + } + }else if (keydown(KEY_1) && terrain[pos] != 0){ + for(i=0;i!=INVENTORY_SIZE;i++){ + if((terrain[pos] == player.inventoryitems[i] && player.inventorynum[i] < 64 && terrain[pos] != 0) || (player.inventoryitems[i] == 0 && player.inventorynum[i] == 0 && terrain[pos] != 0)) { + player.inventoryitems[i] = terrain[pos]; + terrain[pos] = 0; + player.inventorynum[i]++; + break; + } + } + } + } + clearevents(); + if (keydown(KEY_0)){ + if(player.invselect