simplify coordinates logic

This commit is contained in:
quenousimporte 2025-03-31 19:45:57 +00:00
parent 9b0d274a26
commit cb0c4f42cb
1 changed files with 21 additions and 16 deletions

37
w/w.c
View File

@ -73,7 +73,7 @@ char charatpos(int x, int y)
{
return ' ';
}
return map[ (mapsize - y - 1) * mapsize + x];
return map[y * mapsize + x];
}
void loadmap()
@ -102,11 +102,10 @@ void loadmap()
void drawmap()
{
for (int i = 0; i < mapsize; i++) {
int y = mapsize - i - 1;
for (int j = 0; j < mapsize; j++) {
char toprint = map[i * mapsize + j];
if (y == state.position.y && j == state.position.x)
for (int y = 0; y < mapsize; y++) {
for (int x = 0; x < mapsize; x++) {
char toprint = charatpos(x,y);
if (y == state.position.y && x == state.position.x)
{
if (state.position.orientation == NORTH) toprint = '^';
if (state.position.orientation == SOUTH) toprint = 'v';
@ -293,19 +292,19 @@ void updatepov()
{
case NORTH:
newX += rtoloffset;
newY += frontoffset;
newY -= frontoffset;
break;
case SOUTH:
newX -= rtoloffset;
newY -= frontoffset;
newY += frontoffset;
break;
case EAST:
newX += frontoffset;
newY -= rtoloffset;
newY += rtoloffset;
break;
case WEST:
newX -= frontoffset;
newY += rtoloffset;
newY -= rtoloffset;
break;
}
pov[2 - frontoffset][1 + rtoloffset] = charatpos(newX, newY);
@ -320,10 +319,10 @@ void forward()
switch (state.position.orientation)
{
case NORTH:
state.position.y += 2;
state.position.y -= 2;
break;
case SOUTH:
state.position.y -= 2;
state.position.y += 2;
break;
case EAST:
state.position.x += 2;
@ -484,14 +483,20 @@ void update(char command[CMD_LEN])
// hero attacks
state.monster.hp--;
// monster attacks
state.hero.hp--;
if (state.monster.hp <= 0)
{
state.hero.gold += state.monster.gold;
state.screen = SC_MAP;
}
else
{
// monster attacks
state.hero.hp--;
if (state.hero.hp <= 0)
{
// game over ?
}
}
}
}
@ -499,7 +504,7 @@ void update(char command[CMD_LEN])
void debugoutput()
{
//drawmap();
}
void draw()