Hi,

I've just created my first working BGT script! The code is pasted below. It's not much of a game, but still lets you play around. You'll need to supply your own .wav files, the ones I used are quite silly. But first, a description of the, um, game.


You, the player of this fine game that's sure to make me a multi-millionaire, are at the left edge of a game board fifty-spaces long. You move your, er, character across the board using the left and right arrow keys. Each time you successfully move, a walking sound is played. If you bump the left edge, a bump left sound is played, and if you bump the right edge, a bump right sound is played. The goal of the game is to make 100 successful movements before bumping an edge six times. If you bump six times, a losing sound is played and the game exits. If you move 100 times successfully, a winning sound is played and the game exits. And of course, we have a logo sound to get things started for my wonderful audiogames company! Also, a background sound to get you in the mood to play!So here's the code, hopefully it will be useful to someone!
Jayson

// Define sound objects.
sound logo; // Starting sound.
sound amb; // Background sound.
sound walk; // Movement sound.
sound bumpl; // Bump left edge.
sound bumpr; // Bump right edge.
sound youlose;
sound youwin;

// Define variables we'll need.
int position; // The player's position on the board.
int bumps; // How many times we've bumped an edge.
int moves; // How many times we've moved successfully.

void main() {
// Load sounds.
amb.load("amb.wav");
bumpl.load("bumpl.wav");
bumpr.load("bumpr.wav");
logo.load("logo.wav");
walk.load("walk.wav");
youlose.load("youlose.wav");
youwin.load("youwin.wav");
// Play the logo.
logo.play_wait();
wait(1000);

// Initialize the environment.
position = 0;
bumps = 0;
moves = 0;
show_game_window("Jayson's Test Game");
amb.volume = -10.0;
amb.play_looped();

// The main game loop!
while (true) {
if (bumps > 5) {
// You lose!
amb.stop();
wait(50);
youlose.play_wait();
wait(100);
exit();
}
if (moves >= 100) {
// You win!
amb.stop();
wait(50);
youwin.play_wait();
wait(100);
exit();
}
if (key_down(KEY_RIGHT)) move_right();
if (key_down(KEY_LEFT)) move_left();
}
}

// Move right.
void move_right() {
if (position == 49) {
// Oops. Too far. Bump.
bumpr.play_wait();
wait(100);
bumps ++;
return;
}
moves ++;
position ++;
walk.play_wait();
wait(50);
}

// Move left.
void move_left() {
if (position == 0) {
// Oops. Too far. Bump.
bumpl.play_wait();
wait(100);
bumps ++;
return;
}
moves ++;
position --;
walk.play_wait();
wait(50);
}


---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gam...@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.

Reply via email to