2019-06-26 00:18:47 (edited by Ahng 2019-06-26 00:27:44)

Hello.
So, I previusley said I know about dialogs and menus etc.
However, currently I know about player things, like positions and health and other integers, as well as speak and nvda menus.
So today, I decided that I would attempt to make a player related game. or test.
Now, i first saw the spelling and other things from the mason's open sourced stuff on his web. I made a half copyd, half my own code, but then i decided to remake it so I'd see if I at least remember something from the copying process. I Didn't actualy copy it from text to text, i just saw it's spelling.
anyway, enough of talking abough. I have a code where A player is in a map. What i want to know about is how to make it actualy jump, add items and walls, guns and doors. as well, as an enemy script with a way to impliment the enemy script into the test project easily, like nathantech's menu.
I'm not expecting people to sit for a few hours writing a code for me. Anyway, I did try to make the gun system, and it workes, I think anyway. . Still, a small weapon system would be very appreciated. I did try to make the jumping system, but it just doesn't go up and down, all it does is play the up sound and the land sound immediately together. I tried making the walls as well, but I couldn't, so i just made it return to main menu. here's the code.
#include "sound_pool.bgt"
#include "menu.bgt"
timer wtimer;
int wspeed=200;
int jump=1000;
int player_x=0;
int player_y=0;
sound_pool spool(20);
timer jumpingtimer;
int health=1000;
void main()
{
int r;
show_game_window("blackredwhitegreentestofdume");
string text="testing0.";
string[] items={"Start","end."};
r=new_menu(text, items, 0);
if(r==1)
{
game();
}
if(r==2)
{
exit();
}
}
void game()
{
spool.play_stationary("sounds/amb.wav", true);
while(true)
{
if(key_pressed(KEY_ESCAPE))
{
exit();
}
if(key_down(KEY_RIGHT) and wtimer.elapsed>=wspeed)
{

spool.play_stationary("sounds/step"+random(1,3)+".ogg", false, false);
player_x+=1;
spool.update_listener_1d(player_x);
wtimer.restart();
}
if(key_down(KEY_LEFT) and wtimer.elapsed>=wspeed)
{
player_x-=1;
spool.play_stationary("sounds/step"+random(1,3)+".ogg", false, false);
spool.update_listener_1d(player_x);
wtimer.restart();
}
if(key_pressed(KEY_UP) and jumpingtimer.elapsed>=jump)
{
spool.play_stationary("sounds/jump.wav", false, false);
player_y+=5;
spool.update_listener_1d(player_y);
jumpingtimer.restart();
player_y-=5;
spool.play_stationary("sounds/land.ogg", false, false);
}
if(key_pressed(KEY_H))
{
speak_wait("your health is, "+health+".");
}
if (key_pressed(KEY_C))
{
speak_wait(""+player_x+", "+player_y+". ");
}
if(key_down(KEY_LEFT) and player_x==0)
{
spool.destroy_all();
main();
}
if(key_down(KEY_RIGHT) and player_x==35)
{
spool.destroy_all();
main();
}
}
}
bye.

see ya later. Hope you don't fall off a roof.

2019-06-26 00:28:29

You don't have a jumptime. So above jumptimer, set a jumptime, so it'd b like int jumpingtime=220;. It's measured  in ms.

-
"There is beauty in simplicity."

2019-06-26 00:44:57

I already have a int jumping thingy, audiogam. it's in the begining, int jump=1000;

see ya later. Hope you don't fall off a roof.

2019-06-26 01:53:01

Ok, that was a different way to do jumping, try this.

int jumptime=100; //the player will rise every 100 m/s.
timer jumptimer; 
int ty1,ty2;
bool jumping=false;
bool ascending=false;
//now for jumping code

if(key_pressed(KEY_UP) and jumping==false)
{
jumping==true;
ascending==true;
spool.play_stationary("jump.ogg",false);
ty=y;
ty2=y+5;
}
if(jumping==true)
{
if(ascending==true and jumptimer.elapsed>=jumptime)
{
jumptimer.restart();
y++;
spool.update_listener_1d("y");
}
if(y>=ty2)
{
ascending=false;
}
if(ascending==false and jumptimer.elapsed>=jumptime)
{
jumptimer.restart();
y-=1;
spool.update_listener_1d("y");
}
if(y<=ty1 and ascending==false)
{
y=ty1;
jumping=false;
spool.update_listener_1d("y");
p.play_stationary("land.ogg",false);
}
}

That'll need some polishing and messing with to fit your game, but ask if you have any more questions.

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-06-26 02:56:31

it doesn't really work. even when i added it, the thing just stayed there and didn't do anything.

see ya later. Hope you don't fall off a roof.

2019-06-26 05:08:22

Well ok, let's try to get you to code it then, because I don't know how you want it to work.

So, first let's examine the jump. What takes place when you jump? 
When you jump, you begin ascending. While ascending, you gradually rise upward. At the peak of your jump, you hang in the air, and then begin descending at the same speed.
Now how would you code this?

Well, after you press up arrow, you, obviously, need to play jump, set jumping to true so that it knows your in the air, and set ascending to true because that's what you do next.

Then, you need to make an if statement, saying if(jumping==true), witch will be true the entire time you are in the air.
Inside this if statement is more if statements. First, you need to make the player gradually rise, so everytime the risetimer or jumptimer is elapsed>=jumptime. rise by 1, update listener position. Once you are above your maximum jump height, you want to descend.
Skip this part if you don't want your player to hang in the air for a moment when at the peak of there jump.
So, if you want them to hang, you would have to say, still in the jumping==true statement, if(Atapex==true and apextimer.elapsed>=apextime) then you would start descending. So obviously, in your if statement to check if your above the jump height, you would set apex=true;.

Descending is just the same as ascending, except with ascending==false instead of true.

Once you are back at 0, or where you jumped from, just play land.ogg, and set jumping to false and you should be good.

I hope this helped a bit.
----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-06-26 14:37:56

I just cannot not not get it to work. here is the code.
it plays the jumping sound but nothing then.
#include "sound_pool.bgt"
#include "menu.bgt"
timer wtimer;
int wspeed=200;
int jumptime=700;
int gold=200;
int player_x=0;
int y=0;
sound_pool spool(20);
timer jumptimer;
int ty1, ty2;
bool jumping=false;
bool ascending=false;
int health=1000;
void main()
{
int r;
show_game_window("blackredwhitegreentestofdume");
string text="testing0.";
string[] items={"Start","end."};
r=new_menu(text, items, 0);
if(r==1)
{
game();
}
if(r==2)
{
exit();
}
}
void game()
{
spool.play_stationary("sounds/amb.ogg", true);
while(true)
{
if(key_pressed(KEY_ESCAPE))
{
exit();
}
if(key_down(KEY_RIGHT) and wtimer.elapsed>=wspeed)
{
spool.play_stationary("sounds/step"+random(1,3)+".ogg", false, false);
player_x+=1;
spool.update_listener_1d(player_x);
wtimer.restart();
}
if(key_down(KEY_LEFT) and wtimer.elapsed>=wspeed)
{
player_x-=1;
spool.play_stationary("sounds/step"+random(1,3)+".ogg", false, false);
spool.update_listener_1d(player_x);
wtimer.restart();
}
if(key_pressed(KEY_UP) and jumping==false)
{
jumping==true;
ascending=true;
spool.play_stationary("sounds/jump.wav", false, false);
ty1=y;
ty2=y+10;
}
if(jumping==true)
{
if(ascending==true and jumptimer.elapsed>=jumptime)
{
jumptimer.restart();
y++;
spool.update_listener_1d(y);
}
if(y>=ty2)
{
ascending=false;
}
if(ascending==false and jumptimer.elapsed>=jumptime)
{
jumptimer.restart();
y-=1;
spool.update_listener_1d(y);
}
}
if(y<=ty1 and ascending==false)
{
y=ty1;
jumping=false;
spool.update_listener_1d(y);
spool.play_stationary("sounds/land.ogg", false, false);
}
if(key_pressed(KEY_H))
{
speak_wait("your health is, "+health+".");
}
if (key_pressed(KEY_C))
{
speak_wait(""+player_x+", "+y+". ");
}
if(key_down(KEY_LEFT) and player_x==0)
{
player_x+=1;
spool.play_stationary("sounds/land.ogg", false, false);
}
if(key_down(KEY_R))
{
wspeed=160;
}
if(key_up(KEY_R))
{
wspeed==200;
}
if(key_pressed(KEY_TAB))
{
speak("Nothing in your invintory.");
}
if(key_down(KEY_RIGHT) and player_x==35)
{
spool.destroy_all();
main();
}
if(key_pressed(KEY_G))
{
speak("You have "+gold+" gold.");
}
}
}

see ya later. Hope you don't fall off a roof.

2019-06-26 18:51:35

The reason you are not rising is because you used the rong arithmetic operator when telling jumping to be true.

When you want something to change it's value, you use one equal sign.

You basically said, is jumping equal to true in the up arrow statement, so the if(jumping--true would never happen.

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)