Haha, take that! By using 3 variables, I could make the card system 100% accurate to the one seem in LI2. This code goes to the persistent object's creation code:
Using gml Syntax Highlighting
//LI2 Cards System code - BY LU9
//global.card_numb = Number of the card being displayed on the screen
//global.card_duplicate = Number of duplicates of a card
//global.card_collected = If the player has collected that particular card already
//Set default card to view at the first time you go on the screen
global.card_numb = 1
//Resets all duplicates
global.card_duplicate[1] = 0
global.card_duplicate[2] = 0
global.card_duplicate[3] = 0
global.card_duplicate[4] = 0
global.card_duplicate[5] = 0
global.card_duplicate[6] = 0
global.card_duplicate[7] = 0
global.card_duplicate[8] = 0
global.card_duplicate[9] = 0
global.card_duplicate[10] = 0
//Set this so all cards are empty until you collect them.
global.card_collected[1] = false
global.card_collected[2] = false
global.card_collected[3] = false
global.card_collected[4] = false
global.card_collected[5] = false
global.card_collected[6] = false
global.card_collected[7] = false
global.card_collected[8] = false
global.card_duplicate[9] = false
global.card_duplicate[10] = false
Code for when the player gets the card:
Using gml Syntax Highlighting
//Chooses a random card (this code is for normal cards, cards 1, 4, 6, and 8 are star cards)
global.card_numb = choose(2,3,5,7,9,10)
//Adds another to the number of duplicates of this card.
global.card_duplicate[global.card_numb] +=1
//If you already collected the card, it will show a different icon...
if global.card_collected[global.card_numb] = true
{
ID = instance_create(0,0,obj_cardget)
with (ID) image_index = 1
}
else
{
ID = instance_create(0,0,obj_cardget)
with (ID) image_index = 0
}
//Now you collected this card (if you haven't before)
if global.card_collected[global.card_numb] = false
{
global.card_collected[global.card_numb] = true
}
//Adds this object to the map of objects so it doesn't appear again once collected.
ds_map_add(global.cards,id,1)
//After all that, destroy.
instance_destroy()
And finally, the code for the card viewer, it is in the step command:
Using gml Syntax Highlighting
//The player can view cards only from 1 to 10.
if global.card_numb = 0
global.card_numb = 10
else if global.card_numb = 11
global.card_numb = 1
//Displays the cards correctly
if global.card_numb = 1
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[1] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 2
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[2] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 3
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[3] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 4
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[4] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 5
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[5] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 6
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[6] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 7
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[7] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 8
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[8] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 9
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[9] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 10
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[10] = true
image_index = 1
else
image_index = 0
}
That's it, if anyone wants to have a similiar trading cards system in your game you can use this code, as long as you give me credit :3
Haha, take that!
By using 3 variables, I could make the card system 100% accurate to the one seem in LI2.
This code goes to the persistent object's creation code:
[syntax=gml]//LI2 Cards System code - BY LU9
//global.card_numb = Number of the card being displayed on the screen
//global.card_duplicate = Number of duplicates of a card
//global.card_collected = If the player has collected that particular card already
//Set default card to view at the first time you go on the screen
global.card_numb = 1
//Resets all duplicates
global.card_duplicate[1] = 0
global.card_duplicate[2] = 0
global.card_duplicate[3] = 0
global.card_duplicate[4] = 0
global.card_duplicate[5] = 0
global.card_duplicate[6] = 0
global.card_duplicate[7] = 0
global.card_duplicate[8] = 0
global.card_duplicate[9] = 0
global.card_duplicate[10] = 0
//Set this so all cards are empty until you collect them.
global.card_collected[1] = false
global.card_collected[2] = false
global.card_collected[3] = false
global.card_collected[4] = false
global.card_collected[5] = false
global.card_collected[6] = false
global.card_collected[7] = false
global.card_collected[8] = false
global.card_duplicate[9] = false
global.card_duplicate[10] = false[/syntax]
Code for when the player gets the card:
[syntax=gml]
//Chooses a random card (this code is for normal cards, cards 1, 4, 6, and 8 are star cards)
global.card_numb = choose(2,3,5,7,9,10)
//Adds another to the number of duplicates of this card.
global.card_duplicate[global.card_numb] +=1
//If you already collected the card, it will show a different icon...
if global.card_collected[global.card_numb] = true
{
ID = instance_create(0,0,obj_cardget)
with (ID) image_index = 1
}
else
{
ID = instance_create(0,0,obj_cardget)
with (ID) image_index = 0
}
//Now you collected this card (if you haven't before)
if global.card_collected[global.card_numb] = false
{
global.card_collected[global.card_numb] = true
}
//Adds this object to the map of objects so it doesn't appear again once collected.
ds_map_add(global.cards,id,1)
//After all that, destroy.
instance_destroy()[/syntax]
And finally, the code for the card viewer, it is in the step command:
[syntax=gml]//The player can view cards only from 1 to 10.
if global.card_numb = 0
global.card_numb = 10
else if global.card_numb = 11
global.card_numb = 1
//Displays the cards correctly
if global.card_numb = 1
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[1] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 2
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[2] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 3
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[3] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 4
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[4] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 5
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[5] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 6
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[6] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 7
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[7] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 8
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[8] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 9
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[9] = true
image_index = 1
else
image_index = 0
}
else if global.card_numb = 10
{
sprite_index = [removed because it's a surprise :3]
if global.card_collected[10] = true
image_index = 1
else
image_index = 0
}[/syntax]
That's it, if anyone wants to have a similiar trading cards system in your game you can use this code, as long as you give me credit :3
_________________
|