Need help on another program xD

Posted By: Doof_Guy

Need help on another program xD - 05/20/10 01:42

Im stuck on making a program that will tell if 2 objects (in this case .bmp panels) collide and if/when they do both are deleted. The game im working on is a castle defence game where the player drops objects from above and tries to hit the enemies below. Im trying to make it so that when the object dropped hits the enemy, the enemy and dropped object both are deleted (and maybe adds an explosion sprite?). If any one could help me on this, that would be great!

DG
Posted By: Redeemer

Re: Need help on another program xD - 05/20/10 15:31

Here's a simple method for checking whether or not two panels overlap:

Code:
PANEL* pan_one =
{
  ...
}

PANEL* pan_two =
{
  ...
}

...

if( ( pan_one.pos_x + pan_one.size_x >= pan_two.pos_x ) || ( pan_one.pos_x <= pan_two.pos_x + pan_two.size_x ) ) // overlapping in x dimension
  if( ( pan_one.pos_y + pan_one.size_y >= pan_two.pos_y ) || ( pan_one.pos_y <= pan_two.pos_y + pan_two.size_y ) ) // overlapping in y dimension
  {
    // now we know both panels are overlapping in both the x and y dimension!
    // now destroy panels, etc.
  }



If you have any questions, fire away laugh
Posted By: Doof_Guy

Re: Need help on another program xD - 05/22/10 02:49

thanks for the help! (sorry i wasn't able to answer right away...been very busy with school =S)

I tried that, but when i run it, an error comes up saying that 'pos_x is not part of BMAP'

i'll post the program i have written so far, and if it wouldnt trouble you too much to take a look at i would really appreciate if you could help me out with it =D
Quote:
include <acknex.h>
var player_score = 0;
FONT* digital_font = "digital.pcx";

PANEL* main_char=
{
bmap = "enemy_ship1.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 = "missile2.bmp";

void run_bullet()
{



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






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

}

BMAP *myenemy = "ship3.bmp";

void run_enemy()
{

PANEL *mypannel = pan_create( "bmap=myenemy; flags=VISIBLE | OVERLAY; pos_y = 350; pos_x = 790;", 11);



while( mypannel->pos_x < screen_size.x )
{
mypannel->pos_x -= 4 * time_step;
wait(1);
}

}


function main ()
{
//int v;
int enemy_count=0,create_counter=0;

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);

create_counter++;


// if (PANEL mybullet.pos_x = PANEL myenemy.pos_x && PANEL mybullet.pos_y = PANEL myenemy.pos_y)
if ((mybullet.pos_x +*/ mybullet.size_x >= myenemy.size_x) || (mybullet.size_x <= /*myenemy.pos_x +*/ myenemy.size_x))
if((mybullet.pos_y +*/ mybullet.size_y >= myenemy.size_y) || (mybullet.size_y <= /*myenemy.pos_y +*/ myenemy.size_y))
{
printf("hit");
}
if (create_counter%600 == 0)
{
run_enemy();
enemy_count++; //

}
if (key_v)
{
if (create_counter%100 == 0)
{

run_bullet();
// run_enemy();
// enemy_count++; //
}
}
else if (key_esc) { sys_exit(NULL); }


}
}



btw thanks for the help so far!
Posted By: TrackingKeks

Re: Need help on another program xD - 05/22/10 09:06


BMAP *mybullet = "missile2.bmp";

has to be a PANEL*:
PANEL* mybullet =
{
layer=3;
flags=OVERLAY,SHOW;
bmap="missile2.bmp";
}
Posted By: Doof_Guy

Re: Need help on another program xD - 05/23/10 00:20

(edit - ok i think i see where i went wrong, i am going to try to work on that, but i am open to suggestions...=D)

(edit 2 - i updated my program, but it still isnt working...im not sure how to globally declare the panel's position...any help on this area will be appreciated)


I tried that, but now if messes up my whole program - I will post what i have tho:

Quote:
#include <acknex.h>
int v, h, k, p, w;
var player_score = 0;
FONT* digital_font = "digital.pcx";

PANEL* main_char=
{
bmap = "enemy_ship1.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);
}

}

//function delete_enemy
//{

//}
#define USER 1

var mode_player = USER;

//PANEL* mybullet =
//{
//layer=3;
//flags=OVERLAY,SHOW;
//bmap="missile2.bmp";
//}

void run_bullet()
{



PANEL *mybullet = pan_create( "bmap=missile2.bmp; flags=VISIBLE | OVERLAY; pos_y = 130;", 11);
mybullet.pos_x = v+15;

//h = v + 15;

//k = mypanel.pos_y;




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

}

//PANEL* myenemy =
//{
//layer=3;
//flags=OVERLAY,SHOW;
//bmap="ship3.bmp";
//}


void run_enemy()
{

PANEL *myenemy = pan_create( "bmap=ship3.bmp; flags=VISIBLE | OVERLAY; pos_y = 350; pos_x = 790;", 11);

//p = mypanel.pos_x;
//w = mypanel.pos_y;

while( myenemy->pos_x < screen_size.x )
{
myenemy->pos_x -= 4 * time_step;
wait(1);
}

}


function main ()
{
//int v;
int enemy_count=0,create_counter=0;

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);

create_counter++;



if ((mybullet.pos_x + mybullet.size_x >= myenemy.size_x) || (mybullet.size_x <= myenemy.pos_x + myenemy.size_x))
if((mybullet.pos_y + mybullet.size_y >= myenemy.size_y) || (mybullet.size_y <= myenemy.pos_y + myenemy.size_y))
{
// printf("hit");
}
if (create_counter%600 == 0)
{
run_enemy();
enemy_count++; //

}
if (key_v)
{
if (create_counter%100 == 0)
{

run_bullet();

}
}
else if (key_esc) { sys_exit(NULL); }


}
}





thanks for taking the time to help!
Posted By: Doof_Guy

Re: Need help on another program xD - 05/23/10 22:14

bump...im pretty stuck on this...any tips?
Posted By: Doof_Guy

Re: Need help on another program xD - 05/24/10 19:31

ok, I was able to figure out how to do it. Ill post the program on here incase anyone has trouble doing it too.

Quote:

#include <acknex.h>
int v, h, k, p, w, enemy_pos_x, bullet_pos_y;
var player_score = 0;
FONT* digital_font = "digital.pcx";


PANEL* main_char=
{
bmap = "enemy_ship1.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;
}

void run_bullet()
{



PANEL *mybullet = pan_create( "bmap=missile2.bmp; flags=VISIBLE | OVERLAY; pos_y = 130;", 11);
mybullet.pos_x = v+15;
{
while( mybullet->pos_y < screen_size.y )
{
mybullet->pos_y += 15 * time_step;
if((mybullet.pos_y > 300)&&(mybullet.pos_y < 400)&&(mybullet.pos_x > (w-100))&&(mybullet.pos_x < (w+100)))
{
printf("Hit");
}

wait(1);
}
}
}

void run_enemy()
{

PANEL *myenemy = pan_create( "bmap=ship3.bmp; flags=VISIBLE | OVERLAY; pos_y = 350; pos_x = 790;", 11);
{
while( myenemy->pos_x < screen_size.x )
{
myenemy->pos_x -= 4 * time_step;
wait(1);
w= myenemy.pos_x;
}
}
}

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;

}

}


#define USER 1

var mode_player = USER;


function main ()
{

int enemy_count=0,create_counter=0;

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);

create_counter++;
if (create_counter%600 == 0)
{
run_enemy();
enemy_count++; //

}
if (key_v)
{
if (create_counter%100 == 0)
{

run_bullet();

}

}

else if (key_esc) { sys_exit(NULL); }


}



}



Thanks again for taking the time to help me =].

DG
© 2024 lite-C Forums