0
\$\begingroup\$

My best goal atm is just make one 1vs1 battle with no animations more than something which makes me realize the attack is done.

I'm learning C and Xlib, and now I know how to put an image in a window in Xlib.

Yes, it's nothing, but it was my first goal, show images in a window, and then start to do things.

So now I'm starting to think how I will make the game.

Since I'm thinking how make a low quality battle 1vs1 with no more than the two sprites and a black background in a window, I'm focusing in the battle "system" to make a little base and see how things will go.

I think the way is this (Maybe you know a better one, but it's just what i was testing one day and it works):

The map has coords like X and Y, so the sprites or enemies or whatever is in the game, are occuping some X and Y.

Then to use an attack I will take the X and Y of the attacker, and move one of them depending on the direction the attacker is looking.

For example, I want attack with a melee skill. I'm looking at right, so I take my X coord and move the X one step (maybe copying it in a variable first). This will be done with something like X=X+1; or X+=1; So my Y coord still unchanged, but my X is one step to right, then it's like I moved to right, but I'm still in my position because are the coords who are moving, not me really.

Then I make a condition like if X and Y are equal to Xenemy and Yenemy then, do attack.

So the base is move my coords or someone coords and do the attack moving X and Y and testing if they are the same of the enemy.

The ranged attacks will be the same, but repeating the process depending on range until it's done or the range is out.

X++; 
if (X and Y are equal to Xtarget Ytarget) then do attack; 
else  X++ and try again until the range is out or attack is done;

But, my questions are:

How I should do to attack more than 1 enemy? I need test all the coords of all sprites while I do this, or there is a better way like a selectable target or something?

I should use the Window coords, and the pixmap coords (the images or sprites) and copy them to attack, or I should make a new map with different X and Y?

What I must have in mind for the future? I mean, how I should make all coordinates and be sure the method I'm using is not lacking something which I should realize?

I'm having a wrong start? I guess I'm wrong when I'm focusing on only one target.

I guess the ranged skills should have X and Y, move on the map, and affect whatever is in the X and Y. But I have no more idea than test all the possible targets every time the skill cords move.

There is a way to create a global target to test only one location and know if there is an attackable target?

BTW: I will appreciate some corrections on my english. I will remember it, so I will learn with your edits. I guess formatting is not needed and will be useless since there is no real code, but maybe you can do or add something to explain better what I'm trying to say.

I must say sorry for my bad english, I'm spanish and the english level here is shit. I've learned more playing wow on pirate servers than at the school and now reading programming docs.

If you know some books, info or questions I can look, please share it if they will be useful for me.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Honestly, it seems to me like you have a lot to learn about programming in general. Its seems like you have mainly come up with solutions for the problems you are having, but they are very simple and naive solutions. Fortunately, it seems like you are on the right path, and working on games is (IMO) probably the best way to improve your programming skill. Additionally, it seems like the project you are starting with is just about the perfect project for you to be taking on, its not too ambitious, but its enough for you to gain valuable experience.

As for your questions:

How I should do to attack more than 1 enemy? I need test all the coords of all sprites while I do this, or there is a better way like a selectable target or something?

Mainly this depends on what you want. Testing all enemy instances should be no problem. There are many ways to solve this problem though, you are basically talking about collision detection, which is a big topic with many solutions. Fortunately, in your case you have very simple requirements, so the simplest solution should be adequate for you. Keep your enemy structures in an array, then use a for loop to iterate through all instances and compare against the player's position + direction. You could store the player's direction as dir_x and dir_y, where facing upward could be dir_x=0; dir_y=-1; and then when you need to attack, you can compare:

if (enemy[i].x == player.x+player.dir_x && enemy[i].y == player.y+player.dir_y)

I should use the Window coords, and the pixmap coords (the images or sprites) and copy them to attack, or I should make a new map with different X and Y?

I think it would be beneficial to you to separate the concept of an enemy position from that of its sprite. This was a mistake I commonly made when I was learning. You are working with a grid, so you can store that position and then to display your sprite, it could be something as simple as:

player.xgrid_x, player.ygrid_y

This can simplify your collision detection and anything else that depends on a position in your grid.

What I must have in mind for the future? I mean, how I should make all coordinates and be sure the method I'm using is not lacking something which I should realize?

This all depends on your requirements. Having clear requirements from the beginning is very important, and don't underestimate the potential issues, don't make the mistake of thinking you don't need to worry about something because it will be easy to solve. For instance, menu navigation seems like something easy to handle, but if you start out building your game around a state machine, where each menu is a state and your gameplay is another state, then a lot of things become a lot easier. Also, think about how you are storing and allocating memory for all your game objects, make sure you don't paint yourself into a corner. Keep in mind what you will need later in the development process, will everything be constrained to a grid? if not then you will need to rethink how you represent your coordinates internally, and this could be difficult to change when you have a lot of code written already.

I'm having a wrong start? I guess I'm wrong when I'm focusing on only one target.

I think you should be considering how it will work with multiple targets, but I don't think you have a wrong start. I think you are on the right track, but the language you are working with has features that will make things a lot easier for you (struct, arrays, for loops).

I guess the ranged skills should have X and Y, move on the map, and affect whatever is in the X and Y. But I have no more idea than test all the possible targets every time the skill cords move.

You should think about how you want to represent "range" internally, and how you want it to work. For instance, can a ranged attack work at short range also? If so then you can have a player.range, and then loop through all positions between the player and the player's position + (player.dir_x, player.dir_y) * player.range

As for testing all targets each time something moves, that should be fine. It seems like you won't have that many targets to actually test, and this kind of test takes no time at all, its about the simplest form of collision detection.

There is a way to create a global target to test only one location and know if there is an attackable target?

Basically, like I said just keep targets in an array and loop through them, in your case, this is a perfectly correct solution. However, if you are really concerned about performance, think more in terms or eliminating possible targets. If you can quickly decide "no, its impossible for this enemy to be attacked by the player, no need to check further", then you can skip checking. However, based on the kind of checking you will be doing, it will likely be faster to just actually do the check. But in the future, if your needs become more complicated, look into quad-trees.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks a lot for your answer. I guess I will try something to check only the X and Y coords and see what is in there, instead of check all possible enemies \$\endgroup\$ Commented Dec 21, 2017 at 18:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .