First, sorry if I opened this thread in wrong place.
My name is Josip and I recently found about this site from my friend. I became interested in game developing since I was kid, and 6 years ago I found out a way to start developing my own games. Problem is that there weren't anyone who I can ask how to do something; only literature I could get were Intellisense (yeah), some tutorials on the Net and MSDN Library,
For now, I'm using XNA Framework for start to get a grip on basics. I started writing several small, useless projects to test stuff and handle basic algorithms and XNA's classes and methods. Some of them were shooting ducks with mouse, simple catching game and simple movement with top-down view (like Battle City on NES).
Now, my biggest project (which is currently on hold and I could resume or rewrite it) is a playable Arkanoid clone. For now, I only finished a bat, basic ball movement using simple textures, collision detection and bouncing. Bricks are next
So, since it's my current project I'll use it for my examples and to concretize questions.
Now, several questions; also, when possible, I'd like only an idea so that I can try it first for myself:
1) Hitboxes: how to define them? For rectangular-shaped objects is fine since I can use simple Rectangle as a texture holder; however, it seems that having an array of Rectangles is not memory effective. Another problem appears when using irregular shapes (which WILL be used in each 2D game); having Rectangle as a placeholder to check for collision will detect collision on a place where the sprite is transparent.
I was checking for some ideas and found out about "underlay sprites"; using a sprite of the same shape and checking for it's position (via color?) and just drawing regular sprite over it. I forgot the exact site where it is, and don't have an idea how to perform it. Is it possible to draw textures on different levels (I saw that one overload of Spritebatch.Draw has something like "level" parameter) and to check pixel by color on that level?
2) I'm having little problems with Bat-Ball collision detection. I implemented ball moving with trigonometry which works well. Only problem is, depending on ball speed and bat texture height, ball sometimes enter the bat or completely pass through it. Here is the code:
//Definitions
private Texture2D Ball;
private Vector2 BallCenter;
private Vector2 BallOffset;
private bool BallLaunch;
private double BallAngle;
private int BallSpeed;
private int BallRadius;
//Collision with bat
if (BallLaunch)
{
for (x = 0; x < 2 * Math.PI; x += Math.PI / (Math.Pow(2.0d, (double)BallRadius)))
{
Helper.X = (int)(BallCenter.X + (double)BallRadius * Math.Cos(x));
Helper.Y = (int)(BallCenter.Y + (double)BallRadius * Math.Sin(x));
if (BatBorder.Contains(Helper))
if ((Helper.Y > BatBorder.Y + 2) && (Helper.Y < BatBorder.Y + BatBorder.Height - 2))
BallAngle = 3 * Math.PI - BallAngle;
else
BallAngle = 2 * Math.PI - BallAngle;
}
}
//Ball movement
if (BallLaunch)
{
BallCenter.X += BallSpeed / (float)Math.Cos(BallAngle);
BallCenter.Y += BallSpeed / (float)Math.Sin(BallAngle);
}
Collision with bat and Ball Movement are inside the Update(gametime GameTime) method. Should I do that differently?
3) Is it good for me to continue working with XNA Framework or should I transition to another engine? I know C# and VB well and have some problems with C++ (mainly due to lack of Intellisense in VS 2010 for C++) since I don't know all functions and procedures; yet, I can transition to it without problems. If I should work with another engine, which one would You recommend?
I'll ask more questions when they pop to my mind or I need help with something
Thanks for reading and even more for answering.