Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Mobile card game design problem  (Read 1452 times)
0 Members and 1 Guest are viewing this topic.
Offline javamobilegame

Senior Newbie




Java games rock!


« Posted 2004-11-05 04:26:53 »

If I want to design a card game, and I want to use Sprite to represent each card (p.s: one PNG contains 52 cards), also I want to draw 13 cards from 52 cards and place on the desk accordingly, Do anybody can tell me what should I do?
I try make a For Loop statement, but it cannot place 13
cards on the desk, it only place "1" card on the desk.

the statements are:

LayerManager lm = new LayerManager();
private Sprite[] c2 = new Sprite[51];

for (int i=0; i<13; i++) {
c2 = createCard("/LONGMinicardfull2.png");
lm.append(c2);
Random rand = new Random();
n = Math.abs(rand.nextInt()%52);
coordX = coordX+5;
Graphics g = getGraphics();
render(g);
}




Thanks for you help!
Offline moonknightskye

Senior Newbie




^_~! love is in the air


« Reply #1 - Posted 2004-11-05 22:51:09 »

;Duh... the randoming of your cards is at poor design coz its possible to draw identical cards more than twice... instead make a condition that the

card will random
compare the cards from previous random numbers
if it is identical random new number then compare again...actually place it to do..while statement that while there are identical cards random again... ihope im makin sense here.

about the sprite problem... i presume this is your class
c2 = createCard("/LONGMinicardfull2.png");
the canvas displays your 13 cards but the thing is in your code they are overlapping that's why you cannot see the other cards

i suggest you to use
c2.setRefPixelPosition(Xaxis+ increment, Yaxis);
if you want to place yor cards horizontally and place them on your designated position.
then layer.append(c2); to place it on layermnger...

and another this is... your image in the sprite contains 51 concatenated images right?

i think you should use this code...
modify your initialisation to this

for(i=0;i<51;i++){
c2 = createCard("/LONGMinicardfull2.png",i);
}

you will pass the "i" value to your createCard class. to your createCard class... modify your constructor like this...

but add this b4 your constructor

private int[] FRAME_SEQUENCE; //this must be array because framesequence class accepts only arrays

private createCard(Image img, int SEQUENCE){
         super(img, 15, 20); //if the res of the single card  is 15x20
         FRAME_SEQUENCE = SEQUENCE;
          setFrameSequence(FRAME_SEQUENCE);
}

because if your PNG image consists of 51 images the class will automatically cut it to 51 pieces based on the parameters of super(img, frameWidth, frameHeight). frameWidth and frameHeight is the basis on how many pieces the PNG will be cut into . be sure to put the exact pixel width and height or your card(not the whole PNG but the small card in it)

to wrap this up. this must be the pseudocode of your program


1. initialise/make the 51 cards ( see the for loop with i<51)
2.create 13 random numbers which makes sure that every number is unique (see the first part of this message)
3.place/append the cards on the layer and make sure to set each card to its referencePixelPosition
4. PAINT! ::)

At the dark MOON, a KNIGHT will appear to clear the SKYE.

MABUHAY ANG PILIPINAS!
Offline serdarso

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-11-05 23:28:29 »

besides you can try clipping so then you dont need to implement any sprite array at all in addition; that will save from heap plus; you wont require MIDP2.0 for clipping.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline moonknightskye

Senior Newbie




^_~! love is in the air


« Reply #3 - Posted 2004-11-06 02:54:56 »

;DYeah! why did i forgot about clipping! heheh! Cheesy

At the dark MOON, a KNIGHT will appear to clear the SKYE.

MABUHAY ANG PILIPINAS!
Offline javamobilegame

Senior Newbie




Java games rock!


« Reply #4 - Posted 2004-11-06 06:18:05 »

:DThanks for all suggestions.
Can you tell me where can I find the tutorial about clipping? Cheesy
Thanks a lot~ Cheesy
Offline davidaprice

Junior Member





« Reply #5 - Posted 2004-11-06 07:43:31 »

Clipping is really easy. If your cards image has all the cards in a horizontal row, to draw card i do:

 g.setClip(x, y, cardWidth, cardHeight);
 g.drawImage(cardsImage, x - i * cardWidth, y, Graphics.TOP | Graphics.LEFT);

What you're doing is saying: set the clipping so that whatever graphics drawing methods I use, only the stuff inside this 'clip rectangle' actually gets drawn. Then you draw the cards image offset left so that the card you want overlaps the clipping rectangle, and only it gets drawn.

If you want to unset the clipping afterwards, use e.g.:
 g.setClip(0, 0, getWidth(), getHeight());
If you forget to do this and try to draw other stuff afterwards, it won't actually get drawn. You will make this mistake, but if you're prepared you'll spot it and fix it quickly Smiley.
Offline javamobilegame

Senior Newbie




Java games rock!


« Reply #6 - Posted 2004-11-06 12:08:05 »

Cheesy I see, thanks a lot~
And Does it an AWT's elements?
Also can I set different properties for each clips?
Thanks for your reply~
Offline moonknightskye

Senior Newbie




^_~! love is in the air


« Reply #7 - Posted 2004-11-06 12:39:19 »

NOPE! j2me is just taken from J2SE and they chopped some librararies to make it run on mini devices such as cellphones and AWT's have been eliminated.

about setting diffetent props on clips... i dun think so because clips is just a method of GRAPHICS and it is not a Class... but still not sure abt this staement coz i just started 3 weeks ago from programming J2ME. you should ask DAVE... Grin

At the dark MOON, a KNIGHT will appear to clear the SKYE.

MABUHAY ANG PILIPINAS!
Offline javamobilegame

Senior Newbie




Java games rock!


« Reply #8 - Posted 2004-11-06 13:54:27 »

I see  Cheesy
:DThanks for your suggestions~~ Cheesy
Offline davidaprice

Junior Member





« Reply #9 - Posted 2004-11-08 07:32:47 »

Moonknightskye is right: clipping in MIDP is much simpler than in AWT: there are just the two methods in the Graphics class:
  • setClip, which sets the clipping rectangle (to unset it, just set it to 0, 0, getWidth(), getHeight())
  • clipRect, which intersects the current clipping rectangle with another rectangle (if the rectangles don't overlap at all, nothing will get drawn anywhere afterwards)

Oh, and there are the getClipX/Y/Width/Height methods, of course.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline javamobilegame

Senior Newbie




Java games rock!


« Reply #10 - Posted 2004-11-09 16:29:48 »

Smiley I see, Thanks a lot~~ Cheesy
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (7 views)
2014-07-29 18:09:19

Riven (5 views)
2014-07-29 18:08:52

Dwinin (8 views)
2014-07-29 10:59:34

E.R. Fleming (25 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!