Need help with 2d game panels.

Posted By: Crazykins

Need help with 2d game panels. - 10/19/09 10:46

I am writing a 2d game. I have a panel that is my player. I also have a panel that acts as the players weapon. My player moves so how would I get the weapon to move with the player. I was thinking perhaps I could add a window element to the player panel and just add the bmap to the window. I can't seem to get it to work.

So far I have the pick up of the weapon in the level working. But am at a stand still as far as how to add one panel to another moving panel. I want the weapon and the player to move as one.

The reason why I want 2 panels instead of just creating one panel with the weapon is I want the weapon to be animated separatly from the player.

Thanks for your help! laugh
Posted By: seecah

Re: Need help with 2d game panels. - 10/19/09 14:09

Can you post your codes how you let your player moves? Is it through mouse_force or keyboard? I might be able to add from it for you to add another panel on your player's panel..
Posted By: Crazykins

Re: Need help with 2d game panels. - 10/19/09 23:21

here is my player panel code. The bmap changes based on direction of the keyboard.

Code:
function player_startup()
{
	VECTOR player_speed;
	var horizontal_speed = 0;
	var vertical_speed = 0;
	player_pan = pan_create("bmap = player.png", 150);
	player_pan.pos_x = 75;
	player_pan.pos_y = 158;
	player_pan.flags |= VISIBLE;
	player_pan.center_x = player_pan.size_x * 1; // set the rotation point for the panel
	player_pan.center_y = player_pan.size_y; // at its center on the x and at its bottom at its y axis
	while (1)
	{
		vec_set(player_speed.x, accelerate (horizontal_speed, 3 * (key_cur - key_cul), 0.3)); // 2 gives the acceleration, 0.3 the friction
		player_pan.pos_x += player_speed.x;
		vec_set(player_speed.y, accelerate (vertical_speed, 3 * (key_cud - key_cuu), 0.3)); // 2 gives the acceleration, 0.3 the friction
		player_pan.pos_y += player_speed.y;
		
		if (key_cul + key_cur + key_cuu + key_cud)
		{
			player_pan.angle += 0.8 * sin(60 * total_ticks);
		
			if (key_cul)
			{
				player_pan.bmap = player_left;
			}
			
			if (key_cur)
			{
				player_pan.bmap = player_right;
			}
			
			if (key_cuu)
			{
				player_pan.bmap = player_up;
			}
			
			if (key_cud)
			{
				player_pan.bmap = player_down;
			}
		}
			
			else
			{
				player_pan.bmap = player_center;
				player_pan.angle = 0;
			}
		
		wait (1);
	}
}



And here is my weapon panel code so far. It just disapears once the player gets close to the object then in another panel it shows that the weapon is equipped. But is not yet attached to the player.

Code:
function weapon_startup()
{
	VECTOR weapon_pos;
	 	weapon_pan = pan_create("bmap = skilletright1.png", 150);
		weapon_pan.pos_x = 125;
		weapon_pan.pos_y = 320;
		weapon_pan.flags |= VISIBLE;
	   while ((abs(player_pan.pos_x - weapon_pan.pos_x) > 40) || (abs(player_pan.pos_y - weapon_pan.pos_y) > 40))
	   {
	           wait (1);
	   }
	   
	   weapon_equip_pan.bmap = skillet_Right1;
	   ptr_remove(weapon_pan); // remove the weapon once picked up.
	   wait (1);
}



Thanks for the help grin
Posted By: Crazykins

Re: Need help with 2d game panels. - 10/20/09 00:01

I got it! Just needed some sleep lol.

Code:
pan_setwindow(player_pan,0,40,10,178,160,skillet_Right1,0,NULL);



Works exactly the way I want it. Now I just need to fix the settings of the window so I looks right.

Thanks though for your help! grin
Posted By: seecah

Re: Need help with 2d game panels. - 10/20/09 03:19

wink That's really the result of no sleep.. grin
© 2024 lite-C Forums