Hello, I am creating a card game and need some advice/pointers or code snipets if possible on sprite movement in the sence I need to create an action of a card been drawn from the deck. Basicly I need to make the sprite(card) move from the deck posion(x,y) to the players hand position(x,y) or from hand/deck to the waste pile, the game will consist of 4 players so the cards will be going in all directions and I can not fiqure out a formula that will make the cards move quick and smothly to their correct possitions and I cant seem to find anything online to help with this as I am new to working with sprits and I am just an amature programmer. Is there a way to use cos, sin and/or pi to achive this? if so how? any infomation on this would be greatly apreciated.

Thanks.

Well, I don't know if it's too complicated for this project, but as for the graphics part, you could use OpenGL. It's portable and efficient. (Here's a link to a good book about OpenGL:

You could make it so that it moves in small steps; use a for-loop, for example. For instance, divide the distance on the X and Y axes by the amount of steps, and then, for each iteration of the loop body, add that to the current position.

## All 5 Replies

Well, I don't know if it's too complicated for this project, but as for the graphics part, you could use OpenGL. It's portable and efficient. (Here's a link to a good book about OpenGL: http://www.amazon.com/OpenGL-Programming-Guide-Official-Learning/dp/0321552628/ref=sr_1_2?ie=UTF8&qid=1309967373&sr=8-2).

As for the movement part.. that depends on your rendering library, but with OpenGL, you could probably just move the cards to the hands of the players.

Kind regards,

Imkj.

Well, I don't know if it's too complicated for this project, but as for the graphics part, you could use OpenGL. It's portable and efficient. (Here's a link to a good book about OpenGL: http://www.amazon.com/OpenGL-Programming-Guide-Official-Learning/dp/0321552628/ref=sr_1_2?ie=UTF8&qid=1309967373&sr=8-2).

As for the movement part.. that depends on your rendering library, but with OpenGL, you could probably just move the cards to the hands of the players.

Kind regards,

Imkj.

Hi imkj thanks for the quick reply but the game is running on OpenGL its been designed for the wii using devkitpro and mllib, I can get the cards to draw and I can place the cards in the right hands/deck/waste pile with no problem, my question is/was how would I draw the cards in a movement so it will take the card from one pile ie. The deck to another pile ie. Players hand? So you see the card flying from one pile to another? Insted of it just appearing in the destination pile.
Thank you.

You could make it so that it moves in small steps; use a for-loop, for example. For instance, divide the distance on the X and Y axes by the amount of steps, and then, for each iteration of the loop body, add that to the current position.

Hi, after many days of searching I managed to find this code that works to a degree the only problem is that it works slow, is there a way to implament a speed variable as im not sure how the code works I just know it works lol? Here is the code im using...

``````float dx = (float)(x2 - x1);
float dy = (float)(y2 - y1);
float x = (float)x1;
float y = (float)y1;
if (abs(dy/dx)<1){
int stepx = (dx > 0) ? 1 : -1;
float slope = (dx > 0)?dy / dx : -dy / dx;
while (x != x2){
x += stepx; y += slope;
window.SetPixel((int)x, (int)y, c);
}
} else {
int stepy = (dy > 0) ? 1 : -1;
float slope = (dy > 0)? dx / dy: -dx / dy;
while (y != y2){
y += stepy; x += slope;
window.SetPixel((int)x, (int)y, c);
}
}``````

well I managed to figure it out since no one here could or was too lazy to lend someone a hand... herew is the updated code if anyone is intrested.

``````int speed = 5;
float dx = (float)(x2 - x1);
float dy = (float)(y2 - y1);
float x = (float)x1;
float y = (float)y1;
if (abs(dy/dx) < speed){
int stepx = (dx > 0) ? 1 : -1;
float slope = (dx > 0)?dy / dx : -dy / dx;
while (x != x2){
x += (stepx * speed);
y += (slope * speed);
window.SetPixel((int)x, (int)y, c);
}
} else {
int stepy = (dy > 0) ? 1 : -1;
float slope = (dy > 0)? dx / dy: -dx / dy;
while (y != y2){
y += (stepy * speed);
x += (slope * speed);
window.SetPixel((int)x, (int)y, c);
}
}``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.