2011-08-08 04:21:07 (edited by kaigoku 2011-08-08 04:24:28)

Hello all.
Below, I will provide a message that I wrote to the Blast Bay forum to ask for assistance. Reason? I know that the audiogames forum and the blast bay forum are good with responding to questions, and they are a very big help! Another thing, I think I'm going to steer away from actual programming for now, and stick with the BGT Toolkit. As others have said, Philip has made it so easy to add sound to our games. If I were to use another programming language like JAVA, it would probably take me longer! So I'm going to stick to BGT for building audiogames, and actual programming for building other types of applications! Anyway, here is the original message.
Hello all BGT forum members.
Another set of questions from Kaigoku! Thanks for all who have responded willingly and patiently. Now, I shower the willing and the patient with more! Here is what I want to do. If you've read my last post, you know that I've made a menu with five options. Start game, load a saved game, learn game sounds, test speakers, and exit game. I made a function for the main menu, and called it inside the main function. My main function got shorter! It only has the show_game_window and the call to the main_menu function. Anyway, I added a learn_game_sounds function to my main_menu function. So far, I'm good to go. But now, I'm having trouble strategizing what I'm going to do next. Oh yeah! I forgot to mention that I also added code to the exit choice so that it exits and the test speakers option to test speaker orientation. What I'm trying to do is to build a character and some enemies. Would a class be good for this? For example, if I want to build an enemy, I would do something similar to the following:
class enemey
{
void walk()
{
// Code for walking goes here.
}
void weapon()
{
// code for weapons goes here.
}
}
Then, when I want to create a enemy, I would declare a object variable like this:
enemy enemy;
Then, to make the enemy walk, I would do this:
enemy.walk();
So far, I think I'm doing good. The trouble that I'm having is that I don't know how to make my enemy walk! LOL
For example, I'll create a sound that will enable the enemy to walk every second. Then, I'll have it appear randomly. But I want the enemy to travel along the player while fireing his weapon. Player objective is to try to catch the enemy while still walking, and then pressing the space bar to hit him. Then, I want to be able to create a variable that will hold the players statistics about health, score, and whatever else I can think of.
Wow! This is too much for me to think about. But I'm determined to do it with some assistance, I hope.
My big question would be, can someone please help me strategize a way to do all these things without me having to stress a lot of thinking? Oh yeah. Forgot one thing. I also want to be able to walk forward, for example, and walk backward the same amount of steps and end up on the same direction from where I started when I chose to walk forward! Well, I do want to think about what I'm going to do, but can someone give me a good start on it? I would greatly appreciate it!
Thanks too all who help!

2011-08-08 07:54:16 (edited by CAE_Jones 2011-08-08 08:01:15)

It seems that you're going in the right direction.

The problem with giving you a straight answer on the walking is that there are several ways to do it.

I would recommend something like this (I'll use one variable for position, but you can add as many as you like, depending on if you want 2d or 3d or whatever):

 class Enemy {
 int x; // Could use a double or float, if necessary.

 Enemy() {
 x=0; // Or a random value, or a parameter--the important thing is that x needs to be given a value, otherwise it could wind up being some number that's way out of the limits you want.
 }

 // Now, we send the walking method a parameter for distance, that way you can use the same method for walking in different directions, or at different speeds, or whatever you need.
 void walk (int dx) {

 // Code for walking.
 // If it works, you might update the enemy's position like so:
 x+=dx;
 // I can think of situations where you wouldn't want to do it that way, but that's the simplest.
 }

 // And your other methods go here.
}

And then to use this, you'd do something like:

 Enemy enemy();
 enemy.walk(1); // Walk forward.
 enemy.walk(-1); // Walk backward.
 enemy.walk(4); // Fast enemy runs forward...
 enemy.walk(-4) // Or runs backward.

Hope that helps. smile

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2011-08-08 22:25:53

Thanks CAE_Jones.
Can you, by any chance, explain to me what handles are and how they would be useful if I were to use them to position an enemy?

2011-08-08 22:38:43

Hi,
Kaigoku, there's something in the blastbay studios forum that explains that I think.

It is better to remain silent and be thought a fool, than to open your mouth and remove all doubt. -Abraham Lincoln

2011-08-09 05:27:50

You would want to use handles to refer to the enemies.

For example, if you have an array of enemies, you should define it as:

Enemy@[] enemies;

Rather than
Enemy[] enemies;

It's a little confusing, but generally, if you're using objects based on a class, you probably want to use handles to refer to them.

For an example, in my Mario game, I was having a lot of trouble with adding enemies at first; it turns out the problem was that I needed to use handles for pretty much everything related to them. At first, I was using objects directly instead of handles, and I wound up with every enemy that I added being just the last one that I added, but copied into several rooms.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2011-08-09 20:33:53

also, typing
enemy enemy
will make the program mad at you, because you're naming an object with the name of a class, which the program doesn't really like. An easy way to get around this is just to name the class something like
class enem
then BGT will know what you mean when you type
enem enemy;

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!