card images?

i am sure that people have made card games so my question is this: where do you get the card images? any good websites? any place i could find them on my computer(they are used by solitare, arnt they). Please help me.
[224 byte] By [apasechnik1a] at [2007-9-28 11:19:12]
# 1
btw, google is not much of a help
apasechnik1a at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 2
I spent a few hours a couple of weeks ago getting the cards out of my solitaire game, though I'm sure there's an easier way. Anyway here's the cards: http://www32.brinkster.com/woogley/cards.gif
Woogleya at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 3
well, i think that i will do the same as you, because the link does not work. Something about access issues.
apasechnik1a at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 4
bleh, hate free hosts. I need to go back to my old one. Anyways, try this: http://www32.brinkster.com/woogley/cards.html
Woogleya at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 5
open a new browser window and copy&paste the url into it (the server just doesnt like your "referer") ;)
oNyxa at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 6
doesn't matter either way, I just have to wait for my other host's bill to run through :P
Woogleya at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 7
just curious, is there a special snippet of code that will separate the cards into the ones i want, when i want, or do i have to separate the image by hand and use 52 separate images?
apasechnik1a at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 8

I coded this a few weeks ago:

public Image[] getCards(Image img) {

Image[] temp = new Image[52];

int j = 0;

ImageFilter filter;

ImageProducer prod = img.getSource();

for (int y = 0;y < 384;y+=96) {

for (int x = 0;x < 923;x+=71) {

filter = new CropImageFilter(x,y,71,96);

temp[j] = createImage(new FilteredImageSource(prod,filter));

//tracker.addImage(temp[j],j);

j++;

}

}

return temp;

}

Just use it like:

Image[] cards = getCards(getCodeBase(),"cards.gif");

and then you use cards[number] to access the image. the tracker.addImage that's commented out is used for a mediatracker, becuase on some systems it takes a little bit to crop all of it.

Woogleya at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 9
im a newbie so please explain to me why it is not "static"thanx
apasechnik1a at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 10

what do you want to be static...? Here's a full-working example:

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

import java.awt.image.*;

// <applet code="CardSolitaire.class" width=400 height=400></applet>

// cards.gif must be in same directory!

public class CardSolitaire extends Applet implements Runnable,KeyListener,MouseListener,MouseMotionListener {

Image b,cards[],img;

Graphics gfx;

MediaTracker tracker;

int card,w,h,x,y;

Dimension d;

boolean loaded,over;

Rectangle r;

public void init() {

loaded = false;

cards = new Image[52];

card = 0;

tracker = new MediaTracker(this);

d = getSize();

w = d.width;

h = d.height;

b = createImage(w,h);

r = new Rectangle(10,100,71,96);

x = 10;

y = 100;

addKeyListener(this);

addMouseListener(this);

addMouseMotionListener(this);

new Thread(this).start();

}

public Image[] getCards() {

Image[] temp = new Image[52];

int j = 0;

ImageFilter filter;

ImageProducer prod = img.getSource();

for (int y = 0;y < 384;y+=96) {

for (int x = 0;x < 923;x+=71) {

filter = new CropImageFilter(x,y,71,96);

temp[j] = createImage(new FilteredImageSource(prod,filter));

tracker.addImage(temp[j],j);

j++;

}

}

return temp;

}

public void run() {

while (true) {

if (!loaded) {

img = getImage(getCodeBase(),"cards.gif");

tracker.addImage(img,0);

try {

tracker.waitForAll();

}

catch (InterruptedException e) {

break;

}

cards = getCards();

try {

tracker.waitForAll();

}

catch (InterruptedException e) {

break;

}

loaded = true;

}

repaint();

try {

Thread.sleep(10);

}

catch (InterruptedException e) {

break;

}

}

}

public void paint(Graphics g) {

gfx = b.getGraphics();

gfx.setColor(new Color(0,150,0));

gfx.fillRect(0,0,w,h);

gfx.setColor(Color.white);

if (!loaded) {

FontMetrics f = gfx.getFontMetrics();

String s = "Loading...";

gfx.drawString(s,w/2-(f.stringWidth(s)/2),h/2);

}

else {

gfx.drawString(""+card,10,10);

gfx.drawImage(cards[card],r.x,r.y,null);

}

g.drawImage(b,0,0,null);

}

public void update(Graphics g) {

paint(g);

}

public void keyPressed(KeyEvent e) {

if (loaded) switch (e.getKeyCode()) {

case KeyEvent.VK_UP:

card++;

if (card == cards.length) card = 0;

break;

case KeyEvent.VK_DOWN:

card--;

if (card < 0) card = cards.length-1;

break;

default:

break;

}

}

public void mousePressed(MouseEvent e) {

if (loaded && r.contains(e.getX(),e.getY())) {

over = true;

x = e.getX();

y = e.getY();

}

}

public void mouseDragged(MouseEvent e) {

if (loaded && over) {

r.x += (x < e.getX()?e.getX()-x:-(x-e.getX()));

r.y += (y < e.getY()?e.getY()-y:-(y-e.getY()));

x = e.getX();

y = e.getY();

}

}

public void mouseReleased(MouseEvent e) {

over = false;

}

public void keyReleased(KeyEvent e) {}

public void keyTyped(KeyEvent e) {}

public void mouseClicked(MouseEvent e) {}

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

public void mouseMoved(MouseEvent e) {}

}

Woogleya at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 11

> just curious, is there a special snippet of code that

> will separate the cards into the ones i want, when i

> want, or do i have to separate the image by hand and

> use 52 separate images?

no need to seperate em by hand... well kinda... but the image stays the way it is :)

g.drawImage can do the trick.

g.drawImage(cardsImage,

on_screen_up_x, on_screen_up_y, //upper left

on_screen_dn_x, on_screen_dn_y, //lower right

card_up_x, card_up_y, //upper left on the image

card_dn_x, card_dn_y, //lower right on the image

null);

after u figured out the dimension of the cards, u can get the desired one with muliplicating.

eg:

card_up_x=col*CARD_WIDTH;

card_up,y=row*CARD_HEIGHT;

card_dn_x=col*CARD_WIDTH+CARD_WIDTH;

card_dn_y=col*CARD_HEIGHT+CARD_HEIGHT;

row is from 0 to 3

col is from 0 to 12 (shifting this one up might be a good idea)

btw i dont know if made any mistakes :x

but it should work ;)

oNyxa at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 12
hehe well the solution by Woogley is somewhat better (at least if u dont like to jump through images) =)
oNyxa at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 13

Well, now that i know how to get the images, could you tell me how to use them with a GUI application, as in, where do i get the Graphics? I mean, i have to create a fame, and add buttons to it(this whole idea is a video poker game) and add listeners to the buttons, but how do i add the images? Can i use something like add(image) or... what do i do?

i am a bit confused

thanx!

apasechnik1a at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 14
im talking about an application not an applet
apasechnik1a at 2007-7-12 1:48:48 > top of Java-index,Other Topics,Java Game Development...
# 15
im talking about an application not an applet
apasechnik1a at 2007-7-18 20:26:25 > top of Java-index,Other Topics,Java Game Development...
# 16
read this: http://java.sun.com/docs/books/tutorial/uiswing/painting/index.htmlThat applies to any component, Applets are components you know. :)
Woogleya at 2007-7-18 20:26:25 > top of Java-index,Other Topics,Java Game Development...
# 17
ah, well see, theres the problem! i use AWT and you are taliking about Swing. See, i am a simple student leaning java, and my teacher and the book teach AWT and not Swing. I hope somebody knows how to use AWT and could help me with this problem.
apasechnik1a at 2007-7-18 20:26:25 > top of Java-index,Other Topics,Java Game Development...
# 18

AWT... well... fine... ok. it's quite simple :)

your class with the drawing action should simply extend Canvas (Canvas is usually taken for that cuz it's an emty component)

public class MySexyCanvas extens Canvas

{

//[...]

public MySexyCanvas()

{

//setup

//[...]

}

public void paint(Graphics g) //overwrite the paint method

{

//all your painting stuff goes here

}

public void update(Graphics g) //overwrite the update method

{

paint(g); //leave it this way... no more needed here

}

}

well it isnt doublebuffered this way. that can be changed quite easily once u got it working (but i dont wanna confuse at this point) :)

oNyxa at 2007-7-18 20:26:25 > top of Java-index,Other Topics,Java Game Development...
# 19
How do i use my sexy canvas and where do i get the Graphics g to pass to it...I am confusedbtw, i will need to change the image throughout the program(it is a card game after all)
apasechnik1a at 2007-7-18 20:26:25 > top of Java-index,Other Topics,Java Game Development...
# 20
I read the api documentation about Canvas and am still very confusedDoes anybody know any code samples that show the use of Canvas?
apasechnik1a at 2007-7-18 20:26:25 > top of Java-index,Other Topics,Java Game Development...
# 21
Just figured out Canvas and now i am confused with how to create an image. I tried to do Image i = new Image("name") but that did not work. what should i do? the API is not much of a help.
apasechnik1a at 2007-7-18 20:26:25 > top of Java-index,Other Topics,Java Game Development...
# 22
Ok, I know that it was a stupid question but can somebody answere it? How do I create an Image object? I am very confused.
apasechnik1a at 2007-7-18 20:26:25 > top of Java-index,Other Topics,Java Game Development...