2014-12-23 13:43:52

Hello everyone!
;Interested in this:
;1. how to bind to an object such as sound_pool class enemy?
;2. as when traveling in the menu to play sound?
;3. So I did the code:
;class enemy
;{
;int hp;
;int speed;
;int position;
;enem ()
;{
;hp = 100;
;speed.init ();
;position = 20;
;}
;}

;void move ()
;{
;// Cod
;}
;please tell me how to properly organize his movement?
;further:
;void wep ()
;{
;// Cod
;}
;how to organize it and my shooting?

Thumbs up

2014-12-23 16:23:27

Perhaps add a timer as a property?
timer time;

then the movement function looks like this, assuming you have a variable called player_position:

void move() {
if(time.elapsed>=speed) {
if(position>player_position) position--;
else position++;
pool.play_1d("sounds/step.wav", player_position, position, false);
time.restart();
time.resume();
}
}


For that to work, you will need, somewhere outside the enemy class:
int player_position=0;
sound_pool pool;


And for the sound_pool to work, you must include it, with something like this at hte top of the script:
#include "sound_pool.bgt"

You mentioned menus with sound. The dynamic_menu can do this, and it, too, must be included, like so:
#include "dynamic_menu.bgt"

I can try to explain or comment on the above, if you like. (I'd do it now, but am in a hurry.)

ごめんなさいのときですね?

Thumbs up

2014-12-23 22:40:57 (edited by jonikster 2014-12-23 22:43:49)

hello!
;you have a very clear explanation, and I almost entirely got it left only the following:
;1. how to create the function of weapons?
2. how to make my attack, and that the enemy attacked, too?
;if you can help, I will be happy.
;thank you!

Thumbs up

2014-12-23 23:07:17

And by the way, I do not quite understand the function of movement in the class to write the enemy or not, and how it is caused

Thumbs up

2014-12-24 09:45:24

Here is what is wrong in this code:
#include "dynamic_menu.bgt"
#include "sound_pool.bgt"

int player_position=1;
const int board = 30;
sound step;
sound_pool pool;
sound music;
sound start;
sound game;

void main()
{
// Load the music.
music.load("sounds/menu.wav");
music.volume = -10;
step.load("sounds/step.wav");
start.load("sounds/start.wav");
game.load("sounds/start1.wav");
// Set up voice.
tts_voice voice;

// Set up menu.
dynamic_menu menu;
menu.allow_escape = true;
menu.wrap = true;
menu.add_item_tts("Start game");
menu.add_item_tts("Exit game");

// Show game window and speak welcome message.
show_game_window("Battl cry");
voice.speak_wait("Welcome to Battl cry!");

// Loop the music in the background before running the menu.
music.play_looped();

int choice; // This stores the user's menu selections.

do
{
choice = menu.run("Please choose a menu item with the arrow keys, then hit enter to activate it.", true);
if(choice==1)
{
music.stop();
play_round(); // We will define this function later.
}
}
while(choice!=0 and choice!=2);

// The user pressed escape or chose to exit.
voice.speak_wait("Thanks for playing.");
}

class enemy
{
int hp;
int position;
int speed;
timer time;
enemy()
{
hp = 100;
speed = 100;
position = 10;
}
void move() {
if(time.elapsed>=speed) {
if(position>player_position) position--;
else position++;
pool.play_1d("sounds/step.wav", player_position, position, false);
time.restart();
time.resume();
}
}
}

void play_round()
{
start.play_wait();
game.play_wait();
while(true)
{
enemy enem;
if(key_pressed(KEY_RIGHT))
{
player_position++;
step.play();
}
if(key_pressed(KEY_LEFT))
{
player_position--;
step.play();
}
if(player_position < board)
{
player_position++;
}
if(player_position > board)
{
player_position--;
}
enem.move();
}
}

Thumbs up

2014-12-24 19:35:12

That code is mostly good.
There are only two major problems:
1. The enemy is declared inside the loop, so it is created and destroyed every iteration. Just move the line
enemy enem;
Above the line that says while(true)
2. There's no way to leave the game after it starts. Maybe add something so that if the user presses key_escape, play_round returns?

A smaller issue: inside the loop of play_round, you probably want a call to wait(). It isn't necessary, but without it, the game will quickly use up the CPU resources. Just put something like wait(5); somewhere inside the loop.


About attacking: It depends on things like the range, fire speed, and damage that you want. A gun works differently from a knife, and you might even want a more complicated damage system. Can you say more about what you need for the attack?

ごめんなさいのときですね?

Thumbs up

2014-12-24 20:44:15 (edited by jonikster 2014-12-27 06:39:49)

Lord, thank you good people there !!!
;Well, let it be automatic, 40 ammo in the cage, and the enemy is exactly the same weapon. ;one injury 10 hp, attack distance of at least 10 positions.

Thumbs up

2014-12-26 07:06:36

well, please help

Thumbs up

2014-12-26 09:34:18

so it will help someone?

Thumbs up

2014-12-26 19:36:41

The easiest way to do this looks something like:

if(absolute(player_position-this.position)<=10 and this.ammo>0) {
// play the attack sound.
this.ammo--;
player_hp-=10;
}

But this probably won't be enough to make for a playable game; if this is your enemy::attack method, the player will die 10 frames after the enemy is in range, which is too short a time for most players to escape.
This isn't too difficult to correct, but it will require adjustment to the move method.

ごめんなさいのときですね?

Thumbs up

2014-12-27 06:38:43

принцип я понял, скажите, что менять в передвижении? она не исправна.

Thumbs up

2014-12-27 07:19:51

instead, the code okay, just tell me please how now do my attack, the death of the enemy, and how you can make a move, so that when you hold the right arrow, he moved. ;Here's the code:
#include "dynamic_menu.bgt"
#include "sound_pool.bgt"

const int board = 50;
int player_position = 0;
int hp = 20;
sound_pool pool;
sound start;
sound music1;
sound music;
sound vin;
sound shag;

void main()
{
vin.load("sounds/vin.wav");
music.load("sounds/music.wav");
music.volume = -30;
music1.load("sounds/music1.wav");
music1.volume = -10;
shag.load("sounds/shag.wav");
shag.volume = 50;
start.load("sounds/start.wav");
start.volume = 30;
tts_voice voice;
dynamic_menu menu;
menu.allow_escape = true;
menu.wrap = true;
menu.add_item_tts("Start game");
menu.add_item_tts("Exit game");
show_game_window("Enemy");
voice.speak_wait("Welcome to Enemy");
music.play_looped();
int choice;
do
{
choice = menu.run("Please choose a menu item with the arrow keys, then hit enter to activate it.", true);
if(choice==1)
{
music.stop();
game_play();
}
}
while(choice!=0 and choice!=3);
music.stop();
voice.speak_wait("Thanks for playing.");
}

class enemy
{
int hp;
int position;
timer time;
int speed;
enemy()
{
hp = 10;
position = 50;
speed = 300;
}
void move() {
if(time.elapsed>=speed) {
if(position>player_position) position--;
else position++;
pool.play_1d("sounds/step.wav", player_position, position, false);
time.restart();
time.resume();
}
}
}

void game_play()
{
start.play();
while(start.playing)
{
if(key_pressed(KEY_RETURN))
{
start.stop();
break;
}
}
enemy enem;
while(true)
{
music1.play_looped();
if(key_pressed(KEY_F4))
{
exit();
}
if(key_pressed(KEY_LEFT) and player_position>0) {
player_position--;
shag.play();
}
if(key_pressed(KEY_RIGHT) and player_position<board) {
player_position++;
shag.play();
}
if(player_position<0)
{
player_position++;
}
if(player_position>board)
{
player_position--;
}
enem.move();
}
}

Thumbs up

2014-12-27 08:06:13 (edited by jonikster 2014-12-27 08:07:02)

and still guys like to do during the shooting normally play a sound, and that sound is one of 10 shots
#include "dynamic_menu.bgt"
#include "sound_pool.bgt"

const int board = 50;
int player_position = 0;
int player_hp = 500;
sound_pool pool;
sound_pool wep;
sound start;
sound music1;
sound music;
sound shag;

void main()
{
music.load("sounds/music.wav");
music.volume = -30;
music1.load("sounds/music1.wav");
music1.volume = -10;
shag.load("sounds/shag.wav");
shag.volume = 50;
start.load("sounds/start.wav");
start.volume = 30;
tts_voice voice;
dynamic_menu menu;
menu.allow_escape = true;
menu.wrap = true;
menu.add_item_tts("Start game");
menu.add_item_tts("Exit game");
show_game_window("Enemy");
voice.speak_wait("Welcome to Enemy");
music.play_looped();
int choice;
do
{
choice = menu.run("Please choose a menu item with the arrow keys, then hit enter to activate it.", true);
if(choice==1)
{
music.stop();
game_play();
}
}
while(choice!=0 and choice!=3);
music.stop();
voice.speak_wait("Thanks for playing.");
}

class enemy
{
int hp;
int position;
timer time;
int speed;
int ammo = 1000;
enemy()
{
hp = 10;
position = 50;
speed = 300;
}
void move() {
if(time.elapsed>=speed) {
if(position>player_position) position--;
else position++;
pool.play_1d("sounds/step.wav", player_position, position, false);
time.restart();
time.resume();
}
if(absolute(player_position-this.position)<=4 and this.ammo>0) {
wep.play_1d("sounds/vin.wav", player_position, position, false);
this.ammo--;
player_hp-=10;
}
}
}

void game_play()
{
start.play();
while(start.playing)
{
if(key_pressed(KEY_RETURN))
{
start.stop();
break;
}
}
enemy enem;
while(true)
{
music1.play_looped();
if(key_pressed(KEY_F4))
{
exit();
}
if(key_pressed(KEY_LEFT) and player_position>0) {
player_position--;
shag.play();
}
if(key_pressed(KEY_RIGHT) and player_position<board) {
player_position++;
shag.play();
}
if(player_position<0)
{
player_position++;
}
if(player_position>board)
{
player_position--;
}
if(player_hp<=0)
{
exit();
}
enem.move();
}
}

Thumbs up

2014-12-29 20:10:57

well, please help to put the timer on the shot.

Thumbs up