2015-02-18 13:45:13

Here is the code of my game:
#include "dynamic_menu.bgt"
#include "sound_pool.bgt"

const int board = 50;
int player_position = 0;
int player_hp = 100;
sound_pool pool;
sound_pool wep;
sound start;
sound music1;
sound music;
sound shag;
sound win;
timer steper;
timer enemyy;

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;
win.load("sounds/win.wav");
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!=2);
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)<=10 and this.ammo>0) {
if(enemyy.elapsed>1000)
{
wep.play_1d("sounds/vin.wav", player_position, position, false);
this.ammo--;
player_hp-=50;
enemyy.restart();
}
}
}
}

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_down(KEY_LEFT) and player_position>0) {
if(steper.elapsed>300)
{
player_position--;
shag.play();
steper.restart();
}
}
if(key_down(KEY_RIGHT) and player_position<board) {
if(steper.elapsed>300)
{
player_position++;
shag.play();
steper.restart();
}
}
if(player_position<0)
{
player_position++;
}
if(player_position>board)
{
player_position--;
}
if(player_hp<=0)
{
exit();
}
if(key_pressed(KEY_SPACE))
{
atak();
}
enem.move();
enem.atak();
if(enem.hp <= 0)
{
main();
}
}
}
How to check whether the enemy of my position 10? ;that is, the function of attack, so that we can attack at the same positions.

2015-02-20 13:54:31

uu please

2015-02-22 16:34:34

pleeeeeeeeeeeeeeeeeeeeeeease

2015-02-23 19:49:46

jonikster you just can't come, show a enormous piece of code and ask for answers! sad you main problem is the structure of your game I think. You have to think about it before coming to classes definition sad