Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


maximo1491

Member Since 29 Nov 2010
Offline Last Active Jul 25 2013 08:22 AM

Topics I've Started

2D grid based strategy engine

02 July 2013 - 02:25 AM

Hey guys, I'm sure this question has been asked a hundred times before but after a quick look through the posts I cant really find anything, I recently participated in the Brains Eden game jam and afterwards I really just want to expand the game we made for it!

 

What I am wondering is if their is a 2D engine you can recommend for me to use or is it better to make my own one, which I am fine with just obviously there is no point doing it if there is a perfectly good tool already out there! The style of the game has an age of empires feel but will be a more modern day equivalent, the plan is to have quite a big map so obviously when all the AI and pathfinding come into play some performance problems could be an issue! Any suggestions you guys have would be much appreciated!

 

EDIT: Obviously didnt look very hard just found this in the beginner section, would rather build this game in C++ as well which I forgot to mention but have got experience in C# and js!


Help with simple collision

29 November 2010 - 07:14 AM

Basically im trying to do a rectangle collision so if rectangle intersects with blah blah then do this, but im trying to do this between two separate classes so when I run the code it is saying that it does not exist in current context because im guessing that the rectangle im trying to intersect it with is in the other class therefore not knowing where it is, is there a way I can get it to detect the rectangle in the other class?

Ok I know im doing something wrong.... and its probably something simple

29 November 2010 - 04:27 AM

Ok so im trying to get two objects to collide with each other and for now just to move them to a different position so that I know that the collision is working I can sort the rest out after the collisions are confirmed. Im getting 2 CS0103 error - "The name 'enemyWarriorRectangle' does not exist in current context" and "The name 'warriorRectangle' does not exist in current context". Basically I just want to know how I can fix this problem and any help is much appreciated. This is not the entire code but im assuming the issue is coming from the classes themselves rather than the actual game although if I am mistaken I can post the rest of the code.

public class Warrior
{

public Vector2 warriorPosition = new Vector2(250, 500);
public Vector2 warriorSpeed = new Vector2(1f, 0f);
public static Texture2D warriorTexture;

public bool warriorExists = true;
public bool warriorHit;


public Warrior()
{

}

public void Update(GameTime gameTime)
{
warriorPosition.X += warriorSpeed.X;

Rectangle warriorRectangle = new Rectangle((int)warriorPosition.X, (int)warriorPosition.Y, warriorTexture.Width, warriorTexture.Height);

warriorHit = false;

if (warriorRectangle.Intersects(enemyWarriorRectangle))
{
warriorHit = true;
}

if (warriorHit)
{
warriorPosition = new Vector2 (0,0);
}
}

public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin();
spriteBatch.Draw(warriorTexture, warriorPosition, null, Color.Blue, 0,new Vector2(0, 0), 0.3f, SpriteEffects.None,0);
spriteBatch.End();

}
}

public class enemyWarrior
{

public Vector2 enemyWarriorPosition = new Vector2(1250, 500);
public Vector2 enemyWarriorSpeed = new Vector2(-1f, 0f);
public static Texture2D enemyWarriorTexture;

public bool enemyWarriorExists = true;
public bool enemyWarriorHit;

public enemyWarrior()
{
}

public void Update(GameTime gameTime)
{
enemyWarriorPosition.X += enemyWarriorSpeed.X;

Rectangle enemyWarriorRectangle = new Rectangle((int)enemyWarriorPosition.X, (int)enemyWarriorPosition.Y, enemyWarriorTexture.Width, enemyWarriorTexture.Height);

enemyWarriorHit = false;

if (enemyWarriorRectangle.Intersects(warriorRectangle))
{
enemyWarriorHit = true;
}

if (enemyWarriorHit)
{
enemyWarriorPosition = new Vector2(0, 200);
}
}

public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin();
spriteBatch.Draw(enemyWarriorTexture, enemyWarriorPosition, null, Color.Red, 0, new Vector2(0, 0), 0.3f, SpriteEffects.FlipHorizontally, 0);
spriteBatch.End();
}
}

PARTNERS