Information about object: obj_level
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code: ///set up cards //set random seed randomize(); deck=ds_list_create();//create a list //add 2 of each card to deck: ds_list_add(deck,spr_1,spr_1); ds_list_add(deck,spr_2,spr_2); ds_list_add(deck,spr_3,spr_3); ds_list_add(deck,spr_4,spr_4); ds_list_add(deck,spr_5,spr_5); ds_list_add(deck,spr_6,spr_6); ds_list_add(deck,spr_7,spr_7); ds_list_add(deck,spr_8,spr_8); ds_list_add(deck,spr_9,spr_9); ds_list_add(deck,spr_10,spr_10); ds_list_add(deck,spr_11,spr_11); ds_list_add(deck,spr_12,spr_12); ds_list_add(deck,spr_13,spr_13); ds_list_add(deck,spr_14,spr_14); ds_list_add(deck,spr_15,spr_15); ds_list_add(deck,spr_16,spr_16); ds_list_add(deck,spr_17,spr_17); ds_list_add(deck,spr_18,spr_18); //shuffle the deck: ds_list_shuffle(deck); //create a grid of cards with this list var i; for (i = 0; i <= 35; i += 1) { card=instance_create(70+(i mod 6)*70,70+(i div 6)*70,obj_card); card.sprite_index=deck[| i]; card.xx=i mod 6; card.yy=i div 6; card.flipped=false; } //create a list to hold player's selections global.selected=ds_list_create();Information about object: obj_card
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Mouse Event for Left Pressed:
execute code: ///allow flipping if only none or one card selected if !flipped && global.plays<2 { flipped=true;//set flag so face can be shown ds_list_add(global.selected,id);//add the id to a list global.plays++;//mark as a selection made }
Draw Event:
execute code: ///draw front or back of card if flipped { draw_sprite(spr_front_med,0,x,y);//show back draw_self();//show front } else draw_sprite(spr_back_med,0,x,y);//show back Information about object: obj_controlSprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask: No Physics ObjectCreate Event:execute code: ///set up goes=25;//how many attempts the player gets global.plays=0; matches=0;Alarm Event for alarm 0:execute code: ///flip cards back to showing back if not matched card1.flipped=false; card2.flipped=false; global.plays=0;//allow playing againStep Event:execute code: ///check cards if ds_list_size(global.selected)==2//check if two cards selected { if global.selected[|0].sprite_index == global.selected[|1].sprite_index //check if cards face image matches { //if matched: ds_list_clear(global.selected); goes--; global.plays=0; matches++; } else { //if not matched card1=global.selected[|0];//these two cards are to store id for alarm event card2=global.selected[|1]; ds_list_clear(global.selected); goes--; alarm[0]=room_speed; } } //check for game end if goes==0 { show_message("You Lose"); game_restart(); } if matches==18 { show_message("You Win"); game_restart(); }Draw Event:execute code: draw_text(10,10,"Tries remainging "+string(goes));
No comments:
Post a Comment