Tutoriel : Îles des pirates

Écrivez un jeu de pirates pour les enfants afin de les aider à apprendre les nombres de 1 à 10. Explorez une carte, choisissez une île et sélectionnez la bonne réponse pour obtenir des trésors ! Ce jeu dispose de plusieurs langues (anglais et français) avec voix (text-to-speech).

Code source

'-------------------------------------------------
' Source code for tutorial: Treasure Islands
' English: https://www.d2soft.com/en/Run/Lev/2d86d0279f
' French: https://www.d2soft.com/fr/Run/Lev/2d86d0279f
'-------------------------------------------------

DIM pirate, ribbon, boat AS IMAGE
DIM island1, island2, island3, island4, island5, island6, island7, island8, island9, island10 AS IMAGE
DIM gold1, gold2, gold3, gold4, gold5, gold6, gold7, gold8, gold9, gold10 AS IMAGE
DIM gems AS IMAGE
DIM bgGame AS IMAGE
DIM title, endTitle AS TEXT
DIM current AS STRING
DIM button1, button2, button3, button4, button5, button6, button7, button8, button9, button10 AS BUTTON
DIM retry AS BUTTON
DIM done1, done2, done3, done4, done5, done6, done7, done8, done9, done10 AS BOOLEAN
DIM rec1 AS RECTANGLE
DIM total AS INTEGER : total = 0

BGIMAGE "bg_ocean_water"

ribbon = IMAGE "red_ribbon", (_MIDDLEX, 20), "fade-in", 2000
title = TEXT {"Treasure\n Islands"|[FR]"Iles aux\n trésors"}, (_MIDDLEX, 20), "font1", 40, #FFFFFF, "fade-in", 2000
WAIT
SET VOICE {"emma"|[FR]"sylvie"}
VOICE {"Treasure Islands"|[FR]"Iles aux trésors"}
WAIT
MUSIC "pirate_polska", 30

island1 = IMAGE "pirate_island_anim", (100, 200), "fade-in", 500
gold1 = IMAGE "chest_gold", (120, 190), "hide"
VALUE island1, "1"
SOUND "beep"
WAIT
island2 = IMAGE "pirate_island_anim", (300, 440), "fade-in", 500
gold2 = IMAGE "chest_gold", (320, 430), "hide"
VALUE island2, "2"
SOUND "beep"
WAIT
island3 = IMAGE "pirate_island_anim", (200, 530), "fade-in", 500
gold3 = IMAGE "chest_gold", (220, 520), "hide"
VALUE island3, "3"
SOUND "beep"
WAIT
island4 = IMAGE "pirate_island2_anim", (500, 200), "fade-in", 500
gold4 = IMAGE "chest_gold", (510, 220), "hide"
VALUE island4, "4"
SOUND "beep"
WAIT
island5 = IMAGE "pirate_island2_anim", (50, 340), "fade-in", 500
gold5 = IMAGE "chest_gold", (60, 360), "hide"
VALUE island5, "5"
SOUND "beep"
WAIT
island6 = IMAGE "pirate_island2_anim", (550, 420), "fade-in", 500
gold6 = IMAGE "chest_gold", (560, 440), "hide"
VALUE island6, "6"
SOUND "beep"
WAIT
island7 = IMAGE "pirate_island2_anim", (310, 250), "fade-in", 500
gold7 = IMAGE "chest_gold", (320, 270), "hide"
VALUE island7, "7"
SOUND "beep"
WAIT
island8 = IMAGE "pirate_island3_anim", (60, 490), "fade-in", 500
gold8 = IMAGE "chest_gold", (70, 470), "hide"
VALUE island8, "8"
SOUND "beep"
WAIT
island9 = IMAGE "pirate_island3_anim", (500, 550), "fade-in", 500
gold9 = IMAGE "chest_gold", (510, 530), "hide"
VALUE island9, "9"
SOUND "beep"
WAIT
island10 = IMAGE "pirate_island3_anim", (440, 330), "fade-in", 500
gold10 = IMAGE "chest_gold", (450, 310), "hide"
VALUE island10, "10"
SOUND "beep"
WAIT

rec1 = RECT (100, 100)-(540, 540), #808080, "hide"
endtitle = TEXT {"Game over!"|[FR]"Fin du jeu !"}, (_MIDDLEX, 150), "font1", 40, #FFFFFF, "hide"
pirate = IMAGE "head_pirate1", (_MIDDLEX, _MIDDLEY), "in-down", 2000
WAIT
SET VOICE {"jason"|[FR]"antoine_lent"}
VOICE {"Ahoy! My name is Jack. I am a pirate and I am looking for treasures! Visit each island to help me."|[FR]"Ohé ! Je mappelle Jack. Je suis un pirate et je cherche des trésors ! Visite chaque île pour maider."}
WAIT

HIDE pirate, "fade-out", 1000
boat = IMAGE "pirate_boat_anim", (0, 220), "in-left", 2000
WAIT

' Game screen
bgGame = IMAGE "bg_pirate_island_chest", (0,0), "hide"
button1 = BUTTON "button_square_gray3", "1", (30, 435), "font2", 70, #FFFFFF, "hide"
button2 = BUTTON "button_square_gray3", "2", (150, 435), "font2", 70, #FFFFFF, "hide"
button3 = BUTTON "button_square_gray3", "3", (270, 435), "font2", 70, #FFFFFF, "hide"
button4 = BUTTON "button_square_gray3", "4", (390, 435), "font2", 70, #FFFFFF, "hide"
button5 = BUTTON "button_square_gray3", "5", (510, 435), "font2", 70, #FFFFFF, "hide"
button6 = BUTTON "button_square_gray3", "6", (30, 540), "font2", 70, #FFFFFF, "hide"
button7 = BUTTON "button_square_gray3", "7", (150, 540), "font2", 70, #FFFFFF, "hide"
button8 = BUTTON "button_square_gray3", "8", (270, 540), "font2", 70, #FFFFFF, "hide"
button9 = BUTTON "button_square_gray3", "9", (390, 540), "font2", 70, #FFFFFF, "hide"
button10 = BUTTON "button_square_gray3", "10", (510, 540), "font2", 70, #FFFFFF, "hide"
VALUE button1, "1"
VALUE button2, "2"
VALUE button3, "3"
VALUE button4, "4"
VALUE button5, "5"
VALUE button6, "6"
VALUE button7, "7"
VALUE button8, "8"
VALUE button9, "9"
VALUE button10, "10"

ON PRESS island1, visitIsland
ON PRESS island2, visitIsland
ON PRESS island3, visitIsland
ON PRESS island4, visitIsland
ON PRESS island5, visitIsland
ON PRESS island6, visitIsland
ON PRESS island7, visitIsland
ON PRESS island8, visitIsland
ON PRESS island9, visitIsland
ON PRESS island10, visitIsland

ON CLICK button1, checkAnswer
ON CLICK button2, checkAnswer
ON CLICK button3, checkAnswer
ON CLICK button4, checkAnswer
ON CLICK button5, checkAnswer
ON CLICK button6, checkAnswer
ON CLICK button7, checkAnswer
ON CLICK button8, checkAnswer
ON CLICK button9, checkAnswer
ON CLICK button10, checkAnswer

SUB enableAll
IF NOT done1 THEN
ENABLE island1
END IF
IF NOT done2 THEN
ENABLE island2
END IF
IF NOT done3 THEN
ENABLE island3
END IF
IF NOT done4 THEN
ENABLE island4
END IF
IF NOT done5 THEN
ENABLE island5
END IF
IF NOT done6 THEN
ENABLE island6
END IF
IF NOT done7 THEN
ENABLE island7
END IF
IF NOT done8 THEN
ENABLE island8
END IF
IF NOT done9 THEN
ENABLE island9
END IF
IF NOT done10 THEN
ENABLE island10
END IF
END SUB

SUB disableAll
DISABLE island1
DISABLE island2
DISABLE island3
DISABLE island4
DISABLE island5
DISABLE island6
DISABLE island7
DISABLE island8
DISABLE island9
DISABLE island10
END SUB

SUB visitIsland
DEBUG: CONSOLE VALUE(_OBJECT)
disableAll
VOICE {"Yes Captain!"|[FR]"Oui capitaine!"}
WAIT
MOVE boat, (POSX(_OBJECT), POSY(_OBJECT)), 2000
current = VALUE(_OBJECT)
WAIT
VOICE {"Land ho!"|[FR]"On aborde !"}
WAIT
startGame
END SUB

SUB startGame
SHOW bgGame, "fade-in", 1000
WAIT
IF current = "1" THEN
gems = IMAGE "pirate_gems1", (190, 250), "fade-in", 1000
ANIM gems, "yoyo", (190, 250)-(190, 260)
END IF
IF current = "2" THEN
gems = IMAGE "pirate_gems2", (190, 240), "fade-in", 1000
ANIM gems, "yoyo", (190, 250)-(190, 260)
END IF
IF current = "3" THEN
gems = IMAGE "pirate_gems3", (190, 240), "fade-in", 1000
ANIM gems, "yoyo", (190, 250)-(190, 260)
END IF
IF current = "4" THEN
gems = IMAGE "pirate_gems4", (190, 240), "fade-in", 1000
ANIM gems, "yoyo", (190, 250)-(190, 260)
END IF
IF current = "5" THEN
gems = IMAGE "pirate_gems5", (190, 240), "fade-in", 1000
ANIM gems, "yoyo", (190, 250)-(190, 260)
END IF
IF current = "6" THEN
gems = IMAGE "pirate_gems6", (190, 240), "fade-in", 1000
ANIM gems, "yoyo", (190, 250)-(190, 260)
END IF
IF current = "7" THEN
gems = IMAGE "pirate_gems7", (190, 240), "fade-in", 1000
ANIM gems, "yoyo", (190, 250)-(190, 260)
END IF
IF current = "8" THEN
gems = IMAGE "pirate_gems8", (190, 240), "fade-in", 1000
ANIM gems, "yoyo", (190, 250)-(190, 260)
END IF
IF current = "9" THEN
gems = IMAGE "pirate_gems9", (190, 240), "fade-in", 1000
ANIM gems, "yoyo", (190, 250)-(190, 260)
END IF
IF current = "10" THEN
gems = IMAGE "pirate_gems10", (190, 240), "fade-in", 1000
ANIM gems, "yoyo", (190, 250)-(190, 260)
END IF
WAIT
SHOW button1, "fade-in", 300
SHOW button2, "fade-in", 300
SHOW button3, "fade-in", 300
SHOW button4, "fade-in", 300
SHOW button5, "fade-in", 300
SHOW button6, "fade-in", 300
SHOW button7, "fade-in", 300
SHOW button8, "fade-in", 300
SHOW button9, "fade-in", 300
SHOW button10, "fade-in", 300
END SUB

SUB checkAnswer
IF VALUE(_OBJECT) = current THEN
winner
ELSE
SOUND "error"
HIDE _OBJECT
END IF
END IF

SUB winner
hideButtons
SOUND "win"
total = total + 1
WAIT
HIDE boat
HIDE gems, "fade-out", 1000
HIDE bgGame, "fade-out", 1000
WAIT
IF current = "1" THEN
done1 = TRUE
SHOW gold1
PARTICLES "gold_pieces", (POSX(gold1), POSY(gold1))
END IF
IF current = "2" THEN
done2 = TRUE
SHOW gold2
PARTICLES "gold_pieces", (POSX(gold2), POSY(gold2))
END IF
IF current = "3" THEN
done3 = TRUE
SHOW gold3
PARTICLES "gold_pieces", (POSX(gold3), POSY(gold3))
END IF
IF current = "4" THEN
done4 = TRUE
SHOW gold4
PARTICLES "gold_pieces", (POSX(gold4), POSY(gold4))
END IF
IF current = "5" THEN
done5 = TRUE
SHOW gold5
PARTICLES "gold_pieces", (POSX(gold5), POSY(gold5))
END IF
IF current = "6" THEN
done6 = TRUE
SHOW gold6
PARTICLES "gold_pieces", (POSX(gold6), POSY(gold6))
END IF
IF current = "7" THEN
done7 = TRUE
SHOW gold7
PARTICLES "gold_pieces", (POSX(gold7), POSY(gold7))
END IF
IF current = "8" THEN
done8 = TRUE
SHOW gold8
PARTICLES "gold_pieces", (POSX(gold8), POSY(gold8))
END IF
IF current = "9" THEN
done9 = TRUE
SHOW gold9
PARTICLES "gold_pieces", (POSX(gold9), POSY(gold9))
END IF
IF current = "10" THEN
done10 = TRUE
SHOW gold10
PARTICLES "gold_pieces", (POSX(gold10), POSY(gold10))
END IF
SOUND "chest_gold_coins"
SLEEP 2000
WAIT
IF total < 10 THEN
SHOW boat
enableAll
ELSE
gameOver
END IF
END SUB

SUB hideButtons
HIDE button1 : HIDE button2 : HIDE button3 : HIDE button4 : HIDE button5 : HIDE button6 : HIDE button7 : HIDE button8 : HIDE button9 : HIDE button10
END SUB

SUB gameOver
SHOW rec1
ALPHA rec1, 75
SHOW endtitle, "fade-in", 1000
SET VOICE {"emma"|[FR]"sylvie"}
VOICE {"Game Over"|[FR]"Fin du jeu"}
WAIT
SHOW pirate, "fade-in", 2000
WAIT
SET VOICE {"jason"|[FR]"antoine_lent"}
VOICE {"Ahoy! Thank you for your help, I found all the treasures!"|[FR]"Ohé ! Merci pour ton aide, jai trouvé tous les trésors !"}
WAIT
retry = BUTTON "button_anim_orange", {"Again!"|[FR]"Encore !"}, (_MIDDLEX, 450), "font2", 35, #FFFFFF
ON CLICK retry, playAgain, 1
END SUB

SUB playAgain
SOUND "click"
WAIT
RELOAD
END SUB


Retour à la liste des tutoriels.