Re: A question

This is probably buggy as all hell, I'll test it when I get back later on, but it should give you an idea of how you would want to go about it.
//This is how I would write out a map and movement system.
//X keeps track of the player's X coordinat.
//Keeps our tile sounds in a nice array.
sound@[] tile;
//Keeps all of our unique locations in a nice array.
location@[] locations;
int x=0;
//Y keeps track of the player's Y coordinat.
int y=0;
int tiles=2;//Keeps track of how many different types of tiles there are in total.
void main()
{
locations.insert_last(location("Living room", 0, 10, 0, 10));
locations.insert_last(location("Kitchen", 10, 20, 10, 20));
do
{
move();
}
while(key_pressed(KEY_ESCAPE))
}

void move()
{
if(key_pressed(KEY_UP))
{
y=y+1;//Can be shortened to x++;
playSound(tile);
}
if(key_pressed(KE Y_DOWn))
{
y=y-1;//Can be shortened to x--;
playSound(tile);
}
if(key_pressed(KEY_LEFT))
{
X--;
playSound(tile);
}
if(key_pressed(KEY_RIGHT))
{
x++;
playSound(tile);
}
}
void playTileSound(array@ soundArray)
{
for(int z=0; z<soundArray.length; z++)
{
if(x<location[z].x1&&x>locations[z].x1&&y<locations[z].y2&&y>locations[z].y1)
{
if(tile[locations[z].tileNumber].playing)
{
tile[locations[z].tileNumber]].stop();
tile[locations[z].tileNumber]].stop();
}
else
{
tile[locations[z].tileNumber]].stop();
}
}
}
}
void loadSounds()
{
for(x=0; x<tiles; x++)
{
tile.insert_last(sound());
}
for(int z=0; z<tile.length; z++)
{
tile[z].load("tile"+z+".ogg");
wait(5);
}
}
class location
{
string name;< br />int x1;
int x2;
int y1;
int y2;
int tileNumber;
location(string init_name, int init_x1, int init_x2, int init_y1, int init_y2)
{
this.x1=init_x1;
this.x2=init_x2;
this.y1=init_y1;
this.y2=init_y2;
this.name=init_name;
}
}

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : kingzombie via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : MeisamAmini21 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : kingzombie via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : sneak via Audiogames-reflector

Reply via email to