need some help on a program

Posted By: Doof_Guy

need some help on a program - 05/11/10 01:50

Hey, a group of friends and me have been trying to program a simple 2d game for a school. I am making the program that will create the bullet at the players location...Problem is, I have been trying to write this code for a few weeks and i keep getting stuck on how to create input the players x_position for where the bullet should be created on the x-axis...if anyone could lend a hand I would be very happy =D.

As you can see when you run the program, the engine will state the value of 'v' before and after creating the bullet, and they will have that value at the correct number...however the engine will only create the bullet at x_position 0

Quote:
#include <acknex.h>
int v;
var player_score = 0;

PANEL* main_char=
{
bmap = "player.bmp"; //this is where you write the name of the picture you want for the main character
layer = 11;
pos_x = 0; // x position for the char
pos_y = 100; // y position for the char
flags = SHOW | OVERLAY;
}

function update_player(PANEL *paddle,var paddle_mode,var key) //this function updates the player
{
{

paddle.pos_x += 30*time_step*key;
paddle.pos_x = clamp(paddle.pos_x,0,700);
v = paddle.pos_x;
//printf("%d", v);
}

}

#define USER 1

var mode_player = USER;

BMAP *mybullet = "missile.bmp";

void run_bullet()
{

printf("%d", v);
PANEL *mypanel = pan_create( "bmap=mybullet; flags=VISIBLE | OVERLAY; pos_y = 130; pos_x = v;", 11);
printf("%d", v);



while( mypanel->pos_y < screen_size.y )
{
mypanel->pos_y += 15 * time_step;
wait(1);
}

}

function main ()
{
//int v;
int enemy_count;

while (enemy_count != 15)
{
update_player(main_char, mode_player, key_d-key_a); // makes d and a the keys to be pressed in order to move the player
wait (1);
if (key_v)
{
run_bullet();
enemy_count++; //
wait (200);
}
}

}



thanks for any help given!
DG
Posted By: Captain_Kiyaku

Re: need some help on a program - 05/11/10 03:17

I didn't use 3dgs for years but what does your

printf("%d", v);

say?

Don't you have the variable "v" as a string to the panel string instead of writing it as char into the string? I guess it just interpret it as the char "v" which won't work and deliver 0?

I dunno how you can combine strings now in 3dgs but it's probably supposed to be something like this:

PANEL *mypanel = pan_create( "bmap=mybullet; flags=VISIBLE | OVERLAY; pos_y = 130; pos_x = " + v + ";", 11);
Posted By: Superku

Re: need some help on a program - 05/11/10 11:22

PANEL *mypanel = pan_create( "bmap=mybullet; flags=VISIBLE | OVERLAY; pos_y = 130; pos_x = v;", 11);

This won't work. Try this instead:

PANEL *mypanel = pan_create( "bmap=mybullet; flags=VISIBLE | OVERLAY; pos_y = 130;", 11);
mypanel.pos_x = v;
Posted By: Germanunkol

Re: need some help on a program - 05/11/10 16:37

don't you have to typecast?
printf("%d", (double)v);
Posted By: Superku

Re: need some help on a program - 05/11/10 19:45

No, v is of type int.
Posted By: Doof_Guy

Re: need some help on a program - 05/11/10 21:00

Thanks everyone for your fast responses!

Superku's solution worked right away! xD

DG
© 2024 lite-C Forums