Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Advice on developing first game with AGK - Card game

Author
Message
Shiftenrych
7
Years of Service
User Offline
Joined: 11th Jan 2017
Location:
Posted: 11th Jan 2017 18:01
Hi guys,

I am new to AppGameKit and app development in general, so I am searching for some advice on how to best tackle my first game which will be specifically for iOS and Android. The concept is pretty simple:

- It will be a card game, with a deck of 50-100 cards randomly shuffled each game and facing down
- The view of the game will be a top down view of the deck of cards
- To flip a card the player whose turn it is will double tap the card
- The player must then complete the task. i.e like charades
- Once completed, that player swipes the card off the screen and hands the phone to the next player

The part I am seeking advice on is the action of flipping the card. Executing the double tap is no problem, but I would like the flip itself to be animated. It should look as though the card has been lifted off the deck and turned over horizontally. Maybe a 2-3 second animation. I think it would be a nice touch. What would be the best way to create this? Also, how best to render an entire deck of cards and shuffle them randomly?

Thanks!

Shiftenrych

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Jan 2017 20:23 Edited at: 11th Jan 2017 20:23
Welcome

Quote: "The part I am seeking advice on is the action of flipping the card"


If you are working in 2D you need to give the illusion of a turning card. I would use 2 actions:

1. Increase the size of the card then decrease it again. this gives the illusion of the card rising as you turn it. Try a 10% increase and see how it looks
2. Shrink the card along one axis to zero, change the image to the face of the card, and expand it back out again. This will imitate the flip.

How do you implement this? Take a look at tweens (CreateTweenSprite), these can be used to animate parameters over time. You can chain tweens together (expand for 1.5 seconds, shrink for 1.5 seconds)
2 tween chains running concurrently will give you your rise and flip. If you delay the flip by 0.25 seconds you have a "rise before flipping"

Quote: " how best to render an entire deck of cards and shuffle them randomly?"

To shuffle the cards programmatically create an array of cards, plus an additional variable. Then:
1. Pick two Random() positions in the array
2. Save Random element 1 to the temporary variable
3. Move Random element 2 to Random element 1
4. Move temporary variable to Random element 2
5. Repeat 10,000 times.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Shiftenrych
7
Years of Service
User Offline
Joined: 11th Jan 2017
Location:
Posted: 12th Jan 2017 18:25
Perfect. This information will get me started nicely. Thank you very much!
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 12th Jan 2017 23:54 Edited at: 12th Jan 2017 23:55
Quote: "Also, how best to render an entire deck of cards and shuffle them randomly?"


Quote: "To shuffle the cards programmatically create an array of cards, plus an additional variable. Then:
1. Pick two Random() positions in the array
2. Save Random element 1 to the temporary variable
3. Move Random element 2 to Random element 1
4. Move temporary variable to Random element 2
5. Repeat 10,000 times."


Works, but there is a better ( cleaner ) way.

Create an array of cards ( let's assume your deck has 52 cards ). Mark each card as unpicked.

1. Generate a random number between 1 and the total number of unpicked cards ( let's say random comes up with 23 )
2. Pick the 23th unpicked card, mark it as picked
3. Repeat

This also works with a vast amount of cards in your deck or with any other gigantic array, without the need of swapping items a million times.
You only go once through the entire array. Fastest and most random way to shuffle stuff in existence

Here's some code to show how it's done:




Cheers,
PSY
PSY LABS Games
Coders don't die, they just gosub without return
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 13th Jan 2017 02:45
Clever PSY, does look efficient
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Jan 2017 16:31
Is that method not susceptible to less shuffling? When your random number is already chosen you just work up through the pack until you find an unchosen card.

Worst case scenario, your first random number is 1. The second is 1 or 2, the third 1-3 and so on. In this scenario no shuffling happens. There can be varying degrees of this issue which reduce the shuffling. The problem gets greater as you get nearer the end of the pack.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 13th Jan 2017 17:35
Picking back to back positions repeatedly can happen in any method, it's a valid random occurrence, it's also relatively unlikely in any method across a full size deck.

I think if you shuffled a deck with each of these methods a million times, you would find an acceptable amount of shuffle on all of them, but one would complete much faster.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 14th Jan 2017 00:07 Edited at: 14th Jan 2017 00:30
Quote: "Is that method not susceptible to less shuffling? When your random number is already chosen you just work up through the pack until you find an unchosen card."

Nope.
It doesn't matter at all whether the number is already chosen or not, because it's all about the xth number of the REMAINING cards, where x is the random number.


Quote: "Worst case scenario, your first random number is 1. The second is 1 or 2, the third 1-3 and so on. In this scenario no shuffling happens."

No.
There is only no shuffling if every random number was 1. The odds of this scenario to happen with a deck of 52 cards are 1 : 52!, which equals 1 : 52*51*50*.....*2 which equals 1 : 8.06581751709E+67. Which is quite a bit.
With 14 cards odds are already 1 : 87178291200

Quote: " There can be varying degrees of this issue which reduce the shuffling. The problem gets greater as you get nearer the end of the pack."

No. Getting to the end of the pack has no influence at all on the shuffling.

The system works as follows:
Let's assume we have a deck with cards labeled A, B, C, D and E.
First random number is 1 (1-5), so A is drawn.
Second random number is 2(1-4), so C is drawn.
Third random number is 3(1-3), so E is drawn.
Forth random number is 1(1-2), so B is drawn.
Fifth random number is 1(1-1), so D is drawn.

As mentioned, there is only no shuffling if every random number is 1.
When you swap cards, chances are pretty "high" that a swapped card eventually lands on its original spot, no matter how often you shuffle.

As I said, the system picks the xth number of the REMAINING cards. You can't pick more randomly. The only limit would be the random generator.

Quote: "Picking back to back positions repeatedly can happen in any method, it's a valid random occurrence, it's also relatively unlikely in any method across a full size deck. "

That is correct
PSY LABS Games
Coders don't die, they just gosub without return
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Jan 2017 08:26
Thanks for the explanation, I missed the part where the shuffling occurs with only the remaining cards.
Essentially the difference is using 2 arrays instead of 1 to eliminate the 3-step process to swap 2 cards over.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 14th Jan 2017 10:56
@BatVink
No problem at all, you're welcome

Yes, in case of a card game, a second array is needed to store the drawn cards, or rather the new order of cards.





PSY LABS Games
Coders don't die, they just gosub without return
Shiftenrych
7
Years of Service
User Offline
Joined: 11th Jan 2017
Location:
Posted: 24th Jan 2017 19:11
Thanks for the advice so far guys. I have spent some time playing around with sprites and tweens and I have a function working for the card flip animation. I haven't gotten to the part of shuffling the deck, as I am stuck on building and handling the cards. This is the BuildDeck function I have right now (I set positions to random so I can see the different cards for now):



This function seems to work as intended. I have another function called KillCard which i am using to test controlling the cards. I.e I should be able to delete the card from the top of the pile without effecting the others cards. Problem is I have not been able to get this to work. It will delete the first card but the next card it will throw up an error "sprite 00002 does not exist". I was using GetSpriteHitTest to detect the sprite hit, but after some reading maybe GetSpriteHit is what I should be using? I tinkered with the function a bit more I used 'print' to try to identify my sprites, and they all come back with the same sprite ID, sprite00001... so maybe it's something to do with the BuildDeck function after all. Anyway, heres the KillCard function at the moment:


Things are starting to get pretty ugly, so would appreciate some input . I realise I may be tackling this whole thing the wrong way, so let me know if there is a better way.

Thanks!
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 24th Jan 2017 23:05 Edited at: 24th Jan 2017 23:06
Hey,

first thing that strikes me is your index when deleting the sprite.
You are using TotalCards as index, but you must use i ( the current card ).

Also, when killing a sprite, the handle ( spriteindex ) is still there. Therefore, you should flag the card by setting the handle to 0 or -1 or whatever, or use a dynamic list where you can remove and add items.

Maybe something like this: ( no guarantee, it's late and I didn't test the code, but you'll get the point )

PSY LABS Games
Coders don't die, they just gosub without return
Shiftenrych
7
Years of Service
User Offline
Joined: 11th Jan 2017
Location:
Posted: 25th Jan 2017 16:57
Hey PSY,

I was originally using [i] as the index, but switched the TotalCards during my tinkering. It looks like what I was missing was Card[i].sprite = 0. I thought DeleteSprite was enough, but I guess not . Seems to be working as intended now.

Thank you muchly!
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 23rd Feb 2017 03:47
I recently did a simple drag and drop routine for for sprites (and i did thinking about cards). Let me know if you think this is useful for your game and i share here.

Login to post a reply

Server time is: 2024-11-22 09:49:41
Your offset time is: 2024-11-22 09:49:41