Re: some bgt issues

Hi,

So ...what's going on is this. My code is below, it is a modified version of the windows_attack script. I am trying to make it into a pong game, but I'm having a few problems, namely:
- The ball comes towards the player, but the volume doesn't really increase. Ithink there's something wrong with my volume calculations or I am suing soundPool wrong.
- I am trying to , instead of having balls spawn space-invader style, have a hit ball be either hit back or let  through based on a random number. Not sure if I should trick it into just still spawning balls but make it a random event and use a 'hit back'  sound, or actually make the same ball object go up and down. What would be the best strategy here?

Here's my code:

#include "sound_positioning.bgt"
#include "dynamic_menu.bgt"


// Constants
const int board_size = 21;
const int initial_position = 10;
const int initial_lives = 11;
const int initial_spawn_interval = 3500;
const int initial_enemy_speed = 20;

// Game state
enemy@[] board(board_size);
int player_position;
int player_lives;
int score;
int enemy_speed;
int spawn_interval;

// Pre-loaded sounds
sound start;
sound hit;
sound miss;
sound end;
sound music;
void init() {
// Set up variables with their initial values
player_lives = initial_lives;
player_position = initial_position;
score = 0;
enemy_speed = initial_enemy_speed;
spawn_interval = initial_spawn_interval;

// Preload some sounds
start.stream("start.wav");
end.stream("end.wav");
hit.load("hit.wav");
miss.load("miss.wav");
}

void main() {
init();
start.play();
show_game_window("Windows Attack");

while(start.playing) {
// Make it interruptable like the pros do
if(key_pressed(KEY_RETURN)) {
start.stop(); // This line will go down in history
}
wait(5);
}
start.close();
music.load("marble.ogg");
music.volume=-10;

dynamic_menu menu;
menu.add_item("menu_start_game.wav", "start");
menu.add_item("menu_exit.wav", "exit");
menu.allow_escape = true;
menu.wrap = true;
music.play_looped();
int choice;
do {
choice = menu.run("menustart.wav", false);
if(choice == 1) {
PlayRound();
}
} while(choice!=0 and choice!=2);

}

void PlayRound() {

timer spawner; // This controls the spawning of pingpong balls

// Main loop begins here
while(true) {
// Player death
if(player_lives <= 0 or key_pressed(KEY_ESCAPE)) {
for(int i=0; i<board_size; i++) {
@board[i] = null;
}
end.play_wait();
alert("No pingPong ball anymore my friend", "Your score was: " + score);
exit();
}

// Allow player to move
if(key_pressed(KEY_LEFT) and player_position>0) {
player_position--;
}

if(key_pressed(KEY_RIGHT) and player_position < (board_size-1)) {
player_position++;
}

// Allow player to use bat
if(key_pressed(KEY_SPACE)) {
if(@board[player_position] !is null) {
hit.stop();
hit.play();
score += board[player_position].landed ? 5 : 10;
enemy_speed += 1; // will take this out later, and change the speed in the form of difficulty levels
@board[player_position] = null;
}
else {
miss.stop();
miss.play();
}
}

// Spawn pingpong balls  at the specified interval
if(spawner.elapsed >= spawn_interval) {
spawner.restart();
// Determine its horizontal position
int enemy_position;
enemy_position = random(0, board_size-1);
if(@board[enemy_position] is null) {
enemy e(enemy_position);
@board[enemy_position] = @e;
}
}

// Allow all pingpong balls to move
for(int i=0; i<board_size; i++) {
if(@board[i] !is null) {
board[i].act();
}
}

wait(5);
}
}
class enemy {
int horizontal_position;
int height; // in this case means the ball's vertical axis from the opposite player to the human player
bool landed;
int speed;
sound noise;
timer mover;
enemy(int pos) {
// alert("Message", "Enemy created at" + pos + ".");
horizontal_position = pos;
height = 100;
speed = enemy_speed;
landed = false;
noise.load("ping.wav");
noise.volume = -100;
position_sound_2d(@noise, player_position, 0, horizontal_position, height, 1, 10, 1); // this is supposed to increase in volume when it comes closer, but that doesn't seem to work
noise.play_looped();
}

void act() {
if(landed) { // scored
if(!noise.playing) {
@board[horizontal_position] = null;
}
else {
position_sound_1d(@noise, player_position, horizontal_position, 1, 1);
}
return;
}
height = 100 - mover.elapsed*speed/500;
if(height<=0) {
landed = true;
noise.stop();
noise.load("land.wav");
noise.volume = 0;
position_sound_1d(@noise, player_position, horizontal_position, 1, 1);
noise.play();
player_lives--;
return;
}
position_sound_1d(@noise, player_position, horizontal_position, 1, 1);
noise.volume = 0 + height;
}
}
_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Zersiax via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Omar Alvarado via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zersiax via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Omar Alvarado via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zersiax via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zersiax via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : lukas via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zersiax via Audiogames-reflector

Reply via email to