Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualSeiryuEnder

Posted 15 February 2012 - 07:57 PM

I'm not sure what your language, OS, or scripting interface is; so I'm going to answer as if you're in Windows C++.
It's been several years since I've made a tile-based game, so bear with me. These are the highlights that I remember.

Tile maps:
The key thing to realize is that tile maps can have multiple "layers".
Primary layer: where your character runs around.
Foreground layers: objects 'in front' of your character, usually scrolls faster than primary layer
Background layers: objects 'behind' your character (IE scenery), usually scrolls slower than primary layer
Collision layer: non-visible areas where the character will 'collide' with the world. May define several types of collision, such as slopes or different terrain (ice)
Trigger layer: Areas that cause an event when something enters them (player, enemy, etc)

Refer to TehOwn's post for more information about tile collision.



Mouse Input & bullet firing:
You really want your input to be hardware accelerated, but to get things going quickly you can use the windows function GetCursorPos(LPPOINT).
This returns a point in screen space, you need to convert it to client space.

PSEUDOCODE

void Player::UpdateGun()
{
	 // This buffers the input, so we aren't shooting a bullet
	 // every frame the left mouse button is held
	 static bool bMouseWasClicked = false;

	 // Check if the left mouse button is pressed
	 if( GetAsyncKeyState( VK_LBUTTON ) && !bMouseWasClicked )
	 {
		  POINT mousePos;
		  float bulletDirX, bulletDirY;
		  bMouseWasClicked = true;

		  // Get current position of mouse
		  GetCursorPos( &mousePos );
		  ScreenToClient( hWindow, &mousePos );

		  // Get a vector from the gun to the mouse
		  bulletDir.x = mousePos.x - m_Gun.x;
		  bulletDir.y = mousePos.y - m_Gun.y;

		  // Normalize the direction vector
		  float mag= sqrt( bulletDirX * bulletDirX + bulletDirY * bulletDirY );
		  if( mag == 0.0f ) mag = 1.0f;
		  bulletDirX /= mag;
		  bulletDirY /= mag;

		  // Tell the gun which way to fire
		  m_Gun.Fire( bulletDirX, bulletDirY );
	 }
	 else
	 {
		  bMouseWasClicked = false;
	 }
}


This is completely untested code, but that's the general idea.

#7SeiryuEnder

Posted 15 February 2012 - 06:30 AM

I'm not sure what your language, OS, or scripting interface is; so I'm going to answer as if you're in Windows C++.
It's been several years since I've made a tile-based game, so bear with me. These are the highlights that I remember.

Tile maps:
The key thing to realize is that tile maps can have multiple "layers".
Primary layer: where your character runs around.
Foreground layers: objects 'in front' of your character, usually scrolls faster than primary layer
Background layers: objects 'behind' your character (IE scenery), usually scrolls slower than primary layer
Collision layer: non-visible areas where the character will 'collide' with the world. May define several types of collision, such as slopes or different terrain (ice)
Trigger layer: Areas that cause an event when something enters them (player, enemy, etc)

Refer to TehOwn's post for more information about tile collision.



Mouse Input & bullet firing:
You really want your input to be hardware accelerated, but to get things going quickly you can use the windows function GetCursorPos(LPPOINT).
This returns a point in screen space, you need to convert it to client space.

PSEUDOCODE

void Player::UpdateGun()
{
	 // This buffers the input, so we aren't shooting a bullet
	 // every frame the left mouse button is held
	 static bool bMouseWasClicked = false;

	 // Check if the left mouse button is pressed
	 if( GetAsyncKeyState( VK_LBUTTON ) && !bMouseWasClicked )
	 {
		  POINT mousePos;
		  float bulletDirX, bulletDirY;
		  bMouseWasClicked = true;

		  // Get current position of mouse
		  GetCursorPos( &mousePos );
		  ScreenToClient( hWindow, &mousePos );

		  // Get a vector from the gun to the mouse
		  bulletDir.x = mousePos.x - m_Gun.x;
		  bulletDir.y = mousePos.y - m_Gun.y;

		  // Normalize the direction vector
		  float mag= sqrt( bulletDirX * bulletDirY + bulletDirX * bulletDirY );
		  if( mag == 0.0f ) mag = 1.0f;
		  bulletDirX /= mag;
		  bulletDirY /= mag;

		  // Tell the gun which way to fire
		  m_Gun.Fire( bulletDirX, bulletDirY );
	 }
	 else
	 {
		  bMouseWasClicked = false;
	 }
}


This is completely untested code, but that's the general idea.

#6SeiryuEnder

Posted 15 February 2012 - 06:27 AM

I'm not sure what your language, OS, or scripting interface is; so I'm going to answer as if you're in Windows C++.
It's been several years since I've made a tile-based game, so bear with me. These are the highlights that I remember.

Tile maps:
The key thing to realize is that tile maps can have multiple "layers".
Primary layer: where your character runs around.
Foreground layers: objects 'in front' of your character, usually scrolls faster than primary layer
Background layers: objects 'behind' your character (IE scenery), usually scrolls slower than primary layer
Collision layer: non-visible areas where the character will 'collide' with the world. May define several types of collision, such as slopes or different terrain (ice)
Trigger layer: Areas that cause an event when something enters them (player, enemy, etc)

Mouse Input:
You really want your input to be hardware accelerated, but to get things going quickly you can use the windows function GetCursorPos(LPPOINT).
This returns a point in screen space, you need to convert it to client space.

PSEUDOCODE

void Player::UpdateGun()
{
	 // This buffers the input, so we aren't shooting a bullet
	 // every frame the left mouse button is held
	 static bool bMouseWasClicked = false;

	 // Check if the left mouse button is pressed
	 if( GetAsyncKeyState( VK_LBUTTON ) && !bMouseWasClicked )
	 {
		  POINT mousePos;
		  float bulletDirX, bulletDirY;
		  bMouseWasClicked = true;

		  // Get current position of mouse
		  GetCursorPos( &mousePos );
		  ScreenToClient( hWindow, &mousePos );

		  // Get a vector from the gun to the mouse
		  bulletDir.x = mousePos.x - m_Gun.x;
		  bulletDir.y = mousePos.y - m_Gun.y;

		  // Normalize the direction vector
		  float mag= sqrt( bulletDirX * bulletDirY + bulletDirX * bulletDirY );
		  if( mag == 0.0f ) mag = 1.0f;
		  bulletDirX /= mag;
		  bulletDirY /= mag;

		  // Tell the gun which way to fire
		  m_Gun.Fire( bulletDirX, bulletDirY );
	 }
	 else
	 {
		  bMouseWasClicked = false;
	 }
}


This is completely untested code, but that's the general idea.

#5SeiryuEnder

Posted 15 February 2012 - 06:26 AM

I'm not sure what your language, OS, or scripting interface is; so I'm going to answer as if you're in Windows C++.
It's been several years since I've made a tile-based game, so bear with me. These are the highlights that I remember.

Tile maps:
The key thing to realize is that tile maps can have multiple "layers".
Primary layer: where your character runs around.
Foreground layers: objects 'in front' of your character, usually scrolls faster than primary layer
Background layers: objects 'behind' your character (IE scenery), usually scrolls slower than primary layer
Collision layer: non-visible areas where the character will 'collide' with the world. May define several types of collision, such as slopes or different terrain (ice)
Trigger layer: Areas that cause an event when something enters them (player, enemy, etc)

Mouse Input:
You really want your input to be hardware accelerated, but to get things going quickly you can use the windows function GetCursorPos(LPPOINT).
This returns a point in screen space, you need to convert it to client space.

PSEUDOCODE

void Player::UpdateGun()
{
	 // This buffers the input, so we aren't shooting a bullet
	 // every frame the left mouse button is held
	 static bool bMouseWasClicked = false;

	 // Check if the left mouse button is pressed
	 if( GetAsyncKeyState( VK_LBUTTON ) && !bMouseWasClicked )
	 {
          POINT mousePos;
		  float bulletDirX, bulletDirY;
		  bMouseWasClicked = true;

		  // Get current position of mouse
		  GetCursorPos( &mousePos );
		  ScreenToClient( hWindow, &mousePos );

		  // Get a vector from the gun to the mouse
		  bulletDir.x = mousePos.x - m_Gun.x;
		  bulletDir.y = mousePos.y - m_Gun.y;

		  // Normalize the direction vector
		  float mag= sqrt( bulletDirX * bulletDirY + bulletDirX * bulletDirY );
		  if( mag == 0.0f ) mag = 1.0f;
		  bulletDirX /= mag;
		  bulletDirY /= mag;

		  // Tell the gun which way to fire
		  m_Gun.Fire( bulletDirX, bulletDirY );
	 }
	 else
	 {
		  bMouseWasClicked = false;
	 }
}


This is completely untested code, but that's the general idea.

#4SeiryuEnder

Posted 15 February 2012 - 06:25 AM

I'm not sure what your language, OS, or scripting interface is; so I'm going to answer as if you're in Windows C++.
It's been several years since I've made a tile-based game, so bear with me. These are the highlights that I remember.

Tile maps:
The key thing to realize is that tile maps can have multiple "layers".
Primary layer: where your character runs around.
Foreground layers: objects 'in front' of your character, usually scrolls faster than primary layer
Background layers: objects 'behind' your character (IE scenery), usually scrolls slower than primary layer
Collision layer: non-visible areas where the character will 'collide' with the world. May define several types of collision, such as slopes or different terrain (ice)
Trigger layer: Areas that cause an event when something enters them (player, enemy, etc)

Mouse Input:
You really want your input to be hardware accelerated, but to get things going quickly you can use the windows function GetCursorPos(LPPOINT).
This returns a point in screen space, you need to convert it to client space.

PSEUDOCODE

void Player::UpdateGun()
{
	 // This buffers the input, so we aren't shooting a bullet
	 // every frame the left mouse button is held
	 static bool bMouseWasClicked = false;

	 // Check if the left mouse button is pressed
	 if( GetAsyncKeyState( VK_LBUTTON ) && !bMouseWasClicked )
	 {
		  bMouseWasClicked = true;


		  POINT mousePos;
		  float bulletDirX, bulletDirY;

		  // Get current position of mouse
		  GetCursorPos( &mousePos );
		  ScreenToClient( hWindow, &mousePos );

		  // Get a vector from the gun to the mouse
		  bulletDir.x = mousePos.x - m_Gun.x;
		  bulletDir.y = mousePos.y - m_Gun.y;

		  // Normalize the direction vector
		  float mag= sqrt( bulletDirX * bulletDirY + bulletDirX * bulletDirY );
		  if( mag == 0.0f ) mag = 1.0f;
		  bulletDirX /= mag;
		  bulletDirY /= mag;

		  // Tell the gun which way to fire
		  m_Gun.Fire( bulletDirX, bulletDirY );
	 }
	 else
	 {
		  bMouseWasClicked = false;
	 }
}


This is completely untested code, but that's the general idea.

#3SeiryuEnder

Posted 15 February 2012 - 06:25 AM

I'm not sure what your language, OS, or scripting interface is; so I'm going to answer as if you're in Windows C++.
It's been several years since I've made a tile-based game, so bear with me. These are the highlights that I remember.

Tile maps:
The key thing to realize is that tile maps can have multiple "layers".
Primary layer: where your character runs around.
Foreground layers: objects 'in front' of your character, usually scrolls faster than primary layer
Background layers: objects 'behind' your character (IE scenery), usually scrolls slower than primary layer
Collision layer: non-visible areas where the character will 'collide' with the world. May define several types of collision, such as slopes or different terrain (ice)
Trigger layer: Areas that cause an event when something enters them (player, enemy, etc)

Mouse Input:
You really want your input to be hardware accelerated, but to get things going quickly you can use the windows function GetCursorPos(LPPOINT).
This returns a point in screen space, you need to convert it to client space.

PSEUDOCODE

void Player::UpdateGun()
{
     // This buffers the input, so we aren't shooting a bullet
     // every frame the left mouse button is held
	 static bool bMouseWasClicked = false;

     // Check if the left mouse button is pressed
	 if( GetAsyncKeyState( VK_LBUTTON ) && !bMouseWasClicked )
	 {
		  bMouseWasClicked = true;


		  POINT mousePos;
          float bulletDirX, bulletDirY;

		  // Get current position of mouse
		  GetCursorPos( &mousePos );
		  ScreenToClient( hWindow, &mousePos );

          // Get a vector from the gun to the mouse
		  bulletDir.x = mousePos.x - m_Gun.x;
		  bulletDir.y = mousePos.y - m_Gun.y;

          // Normalize the direction vector
          float mag= sqrt( bulletDirX * bulletDirY + bulletDirX * bulletDirY );
          if( mag == 0.0f ) mag = 1.0f;
		  bulletDirX /= mag; 
          bulletDirY /= mag;

          // Tell the gun which way to fire
		  m_Gun.Fire( bulletDirX, bulletDirY );
	 }
	 else
	 {
		  bMouseWasClicked = false;
	 }
}


This is completely untested code, but that's the general idea.

PARTNERS