Thank you as always BatVink
. any idea what i can do to rid myself of some of the slow down? im currently converting all my .pngs for the card images to .bmps since i still haven't figured out how to get png's to turn transparent. I thought using bitmaps would slow the game down more because of their larger file size. here's the code with all the media handling included:
`setup screen
if check display mode (1024,768,24) = 1
set display mode 1024,768,24
else
set display mode 1024,768,32
endif
`create data type for array
type CardInfo
Color as integer
Value$ as string
AlreadyMatched as boolean
FaceDown as boolean
FaceUp as boolean
Suit$ as string
CardXPos as integer
CardYPos as integer
endtype
`create arrays and variables
dim Deck(52) as CardInfo `deck
dim FirstCard(1) as CardInfo `first clicked card info holder variable for match detecion
dim SecondCard(1) as CardInfo `second clicked card info holder variable for match detecion
dim Card(1) as CardInfo `function parameter being passed to match detection function
dim Shuffler(1) as CardInfo `variable to hold data during shuffle function
global NumberOfCardsFlipped = 0 `keeps track of how many cards have been flipped over
global FirstCardClicked `1st card clicked, info to be passed to card flipping and match detecting function
global SecondCardClicked `2nd card clicked, info to be passed to card flipping and match detecting function
global CardsToBeMatched `keeps track of how many cards have been passed to match detecting function
global FirstCard `holds info for 1st card sent to match detecting function
global SecondCard `holds info for 2nd card sent to match detecting function
global MatchedCards `holds number of cards that have been matched together for GameOver() function
global NowPlaying `holds number of song being played in MusicPlayer() function
`setup basic card info
data 0,0, 125,0, 250,0, 375,0, 500,0, 625,0, 750,0, 875,0, 1000,0,
data 0,-175, 125,-175, 250,-175, 375,-175, 500,-175, 625,-175, 750,-175, 875,-175, 1000,-175,
data 0,-350, 125,-350, 250,-350, 375,-350, 500,-350, 625,-350, 750,-350, 875,-350, 1000,-350,
data 0,-525, 125,-525, 250,-525, 375,-525, 500,-525, 625,-525, 750,-525, 875,-525, 1000,-525,
data 0,-700, 125,-700, 250,-700, 375,-700, 500,-700, 625,-700, 750,-700, 875,-700, 1000,-700,
data 0,-875, 125,-875, 250,-875, 375,-875, 500,-875, 625,-875, 750,-875, 875,-875, 1000,-875,
data 0,-1050, 125,-1050, 250,-1050, 375,-1050, 500,-1050, 625,-1050, 750,-1050
for z = 1 to 52
read Deck(z).CardXPos
read Deck(z).CardYPos
Deck(z).FaceDown = 1
Deck(z).FaceUp = 0
Deck(z).AlreadyMatched = 0
next z
`load sounds
load sound "cardclick.wav", 1
`load music
for MusicLoad = 1 to 9
load music "" + str$(MusicLoad) + ".mp3", MusicLoad
next MusicLoad
load image "2 of Clubs.bmp", 1 `not load all images cuz still in testing phase
load image "Playing Card Back.bmp", 2
MainMenu()
`********************************************************MAIN LOOP***********************************************************
while escapekey() <> 1 `hit Escape to exit game
text 400, 10, str$(screen fps()) `publish game fps
angle = wrapvalue(angle) + 1
rotate object 54, 0, angle, 0 `rotate skybox
MusicPlayer()
Clock()
MouseControl()
GameOver()
endwhile
`*****************************************************END OF MAIN LOOP********************************************************
`------------------------------------------------------END OF PROGRAM--------------------------------------------------------
`---------------------------------------------------------FUNCTIONS----------------------------------------------------------
FUNCTION MainMenu() `main menu
if image exist(54) <> 1
load image "MainMenuBackground.bmp", 54
paste image 54,0,0
endif
set text font "Century Gothic"
set text size 30
ink rgb(79,114,218),0
text 60, 568, "New Game"
text 60, 618, "Options"
text 60, 668, "Quit"
do
if mouseclick() = 1
if mousex() >= 60 and mousex() <= 205
if mousey() >=568 and mousey() <= 598
play sound 1
ink rgb(189,239,248),0
text 60, 568, "New Game"
wait 1500
StartUp()
exit
endif
endif
if mousex() >= 60 and mousex() <= 160
if mousey() >=618 and mousey() <= 648
ink rgb(255,255,255),0
text 60, 618, "Options"
play sound 1
wait 1500
`Options()
exit
endif
endif
if mousex() >= 60 and mousex() <= 100
if mousey() >=668 and mousey() <= 698
ink rgb(255,255,255),0
text 60, 668, "Quit"
play sound 1
wait 1500
end
endif
endif
endif
loop
ENDFUNCTION
FUNCTION StartUp()
MatchedCards = 0
`setup camera
make camera 1
Set Camera Range 1, 30.0,170000.0
position camera 1, 500, -900, -800 `plain is facing toward monitor, so alter z instead of y for raised camera
point camera 1, 500, 0, 900
`load background
if object exist(54) <> 1
load object "skybox.x", 54
SET OBJECT 54, 1, 1, 0, 0, 0
scale object 54, 170000, 170000, 170000
endif
`setup lighting
set ambient light 100
`start music
NowPlaying = rnd(8) + 1
play music NowPlaying
loop music NowPlaying
set music volume NowPlaying, 70
StartGame()
ENDFUNCTION
FUNCTION StartGame() `draws the deck onscreen and assigns objects card values and textures
`create deck entities
LastCardPos = 0 `keeps track of z value of card in deck
for a = 52 to 1 step -1
FallHeight = -120
make object box a, 100, 130, 0
texture object a, 2
set object transparency a, 5
`Assign card a value using MOD, and a specific color depending on what card it is, to group the cards by color
value = a mod 13
`if value <= 0 then Deck(a).Value$ = "A": color object a, rgb(0, 255, 0): Deck(a).Color = rgb(0, 255, 0)
`if value <=9 and value >= 1 then Deck(a).Value$ = str$(value + 1): color object a, rgb((value^value)+ 100, (value*25)+30, value*12):Deck(a).Color = rgb((value^value)+ 100, (value*25)+30, value*12)
`if value = 10 then Deck(a).Value$ = "J": color object a, rgb(255,255,255): Deck(a).Color = rgb(255,255,255)
`if value = 11 then Deck(a).Value$ = "Q": color object a, rgb(0,0,255):Deck(a).Color = rgb(0,0,255)
`if value = 12 then Deck(a).Value$ = "K": color object a, rgb(255,0,0): Deck(a).Color = rgb(255,0,0)
`Assign Suit
SuitHolder = int(a / 13.1) + 1
select SuitHolder
case 1: Deck(a).Suit$ = "Clubs" : endcase
case 2: Deck(a).Suit$ = "Hearts" : endcase
case 3: Deck(a).Suit$ = "Spades" : endcase
case 4: Deck(a).Suit$ = "Diamonds" : endcase
endselect
`make animation for cards falling onto deck
for b = 1 to 5
position object a, 0, 200, FallHeight `y pos is 200 so that deck will sit beyond card dealing area
FallHeight = FallHeight + 20
wait 1
next b
position object a, 0, 200, LastCardPos `these 2 lines place cards slightly above each other
LastCardPos = LastCardPos - 1 `creating the appearance of a stack of cards
next a
Shuffle()
ENDFUNCTION
FUNCTION Deal() `deals the cards out onscreen
for a = 1 to 52
position object a, Deck(a).CardXPos, Deck(a).CardYPos, 1
wait 30
next a
ENDFUNCTION
FUNCTION Shuffle() `randomizes the card data
randomize timer()
for n = 1 to 5000
card1 = rnd(51) + 1
card2 = rnd(51) + 1
if card1 = card2 `make sure each of the 52 cards are represented by making sure that the 2 variables that
while card1 = card2 `store the random object numbers are not the same
card1 = rnd(51) + 1
card2 = rnd(51) + 1
endwhile
endif
Shuffler(1).Color = Deck(card1).Color
Shuffler(1).Value$ = Deck(card1).Value$
Shuffler(1).AlreadyMatched = Deck(card1).AlreadyMatched
Shuffler(1).FaceDown = Deck(card1).FaceDown
Shuffler(1).FaceUp = Deck(card1).FaceUp
Shuffler(1).Suit$ = Deck(card1).Suit$
Deck(card1).Color = Deck(card2).Color
Deck(card1).Value$ = Deck(card2).Value$
Deck(card1).AlreadyMatched = Deck(card2).AlreadyMatched
Deck(card1).FaceDown = Deck(card2).FaceDown
Deck(card1).FaceUp = Deck(card2).FaceUp
Deck(card1).Suit$ = Deck(card2).Suit$
`color object card1, Deck(card1).Color
Deck(card2).Color = Shuffler(1).Color
Deck(card2).Value$ = Shuffler(1).Value$
Deck(card2).AlreadyMatched = Shuffler(1).AlreadyMatched
Deck(card2).FaceDown = Shuffler(1).FaceDown
Deck(card2).FaceUp = Shuffler(1).FaceUp
Deck(card2).Suit$ = Shuffler(1).Suit$
`color object card2, Deck(card2).Color
next n
Deal()
ENDFUNCTION
FUNCTION FlipFirstCardUp(WhichCardOne) `flips the first card over that is clicked
if Deck(WhichCardOne).AlreadyMatched = 1 `if the card has already been matched don't continue trying to match it again
exitfunction
endif
if Deck(WhichCardOne).FaceUp = 0 and Deck(WhichCardOne).FaceDown = 1 `if card is face down, set its values to face up
Deck(WhichCardOne).FaceDown = 0
Deck(WhichCardOne).FaceUp = 1
else
for ErrorMessage = 1 to 70 `if its already face up, give error message
text (screen width() - ((Screen width()/10) * 9)), (screen height() - ((Screen height()/10) * 9)), "Please try another card."
wait 1
next ErrorMessage
exitfunction
endif
play sound 1
for MoveUp = 1 to 5 `if card is being set to face up, animate the card flipping over and being tilted
move object up WhichCardOne, 6 `toward the player
wait 2
next MoveUp
for TwistLeft = 1 to 10
turn object left WhichCardOne, 18
if TwistLeft = 5 then texture object WhichCardOne, 1
wait 2
next TwistLeft
wait 1000 `short delay for card to face toward player
for MoveDown = 1 to 5
move object down WhichCardOne, 6
wait 2
next MoveDown
MatchDetector(WhichCardOne) `send the first card's data to match detection functino
ENDFUNCTION
FUNCTION FlipSecondCardUp(WhichCardTwo) `flips 2nd card over that is flipped
if Deck(WhichCardTwo).AlreadyMatched = 1 `same as function above
exitfunction
endif
if Deck(WhichCardTwo).FaceUp = 0 and Deck(WhichCardTwo).FaceDown = 1 `same as function above
Deck(WhichCardTwo).FaceDown = 0
Deck(WhichCardTwo).FaceUp = 1
else
for ErrorMessage = 1 to 70 `same as function above
text (screen width() - ((Screen width()/10) * 9)), (screen height() - ((Screen height()/10) * 9)), "Please try another card."
wait 1
next ErrorMessage
exitfunction
endif
play sound 1
for MoveUp = 1 to 5 `same as function above
move object up WhichCardTwo, 6
wait 2
next MoveUp
for TwistLeft = 1 to 10
turn object left WhichCardTwo, 18
if TwistLeft = 5 then texture object WhichCardTwo, 1
wait 2
next TwistLeft
wait 1000
for MoveDown = 1 to 5
move object down WhichCardTwo, 6
wait 2
next MoveDown
MatchDetector(WhichCardTwo) `sends 2nd card's data to match detection function
ENDFUNCTION
FUNCTION FlipCardDown(WhichCard) `turns card back over
for MoveUp = 1 to 5
move object up WhichCard, 6
wait 5
next MoveUp
for TwistLeft = 1 to 10
turn object left WhichCard, 18
if TwistLeft = 5 then texture object WhichCard, 1
wait 5
next TwistLeft
for MoveDown = 1 to 5
move object down WhichCard, 6
wait 5
next MoveDown
Deck(WhichCard).FaceDown = 1 `sets card data back to face down
Deck(WhichCard).FaceUp = 0
ENDFUNCTION
FUNCTION MouseControl() `let player use mouse to interact with cards
if MouseClick() = 1 `if mouse is clicked
blanktester = pick object (mousex(), mousey(), 1, 52)
if blanktester = 0
exitfunction
endif
NumberOfCardsFlipped = NumberOfCardsFlipped + 1 `increment how many cards have been clicked so far
if NumberOfCardsFlipped = 1
FirstCardClicked = pick object (mousex(), mousey(),1,52) `if 1, send that card data to card flipper
FlipFirstCardUp(FirstCardClicked)
exitfunction
else
if NumberOfCardsFlipped = 2
SecondCardClicked = pick object (mousex(), mousey(),1,52) `if 2 send 2nd card data to card flipper
FlipSecondCardUp(SecondCardClicked)
NumberOfCardsFlipped = 0 `set # of cards clicked back to 0 for next match test
endif
endif
endif
ENDFUNCTION
FUNCTION MatchDetector(Card)
CardsToBeMatched = CardsToBeMatched + 1
if CardsToBeMatched = 1
FirstCard = Card
exitfunction
endif
if CardsToBeMatched = 2
SecondCard = Card
if Deck(FirstCard).Value$ = Deck(SecondCard).Value$
Deck(FirstCard).AlreadyMatched = 1
Deck(SecondCard).AlreadyMatched = 1
ghost object on FirstCard
ghost object on SecondCard
for fader = 10 to 1 step -1
fade object FirstCard, fader * 10
fade object SecondCard, fader * 10
wait 7
next fader
delete object FirstCard
delete object SecondCard
CardsToBeMatched = 0
MatchedCards = MatchedCards + 2
exitfunction MatchedCards
else
FlipCardDown(FirstCard)
Deck(FirstCard).FaceUp = 0
Deck(FirstCard).FaceDown = 1
FlipCardDown(SecondCard)
Deck(SecondCard).FaceUp = 0
Deck(SecondCard).FaceDown = 1
CardsToBeMatched = 0
endif
endif
ENDFUNCTION MatchedCards
FUNCTION Clock()
ink rgb(255,153,0), 0
line 5,28,155,28
line 155,5,155,28
seconds$ = right$(get time$(), 3)
minutes$ = mid$(get time$(), 4) + mid$(get time$(), 5)
set text font "Arial"
set text size 16
if left$(get time$(), 1) = "0"
hours$ = mid$(get time$(), 2) + mid$(get time$(), 3)
text 10,10, "The time is: " + hours$ + minutes$ + seconds$ + "am"
else
if left$(get time$(), 2) <> "10" and left$(get time$(), 2) <> "11" and left$(get time$(), 2) <> "12"
hours = (val(left$(get time$(), 2)) - 12)
hours$ = str$(hours) + mid$(get time$(), 3)
text 10,10, "The time is: " + hours$ + minutes$ + seconds$ + "pm"
else
hours$ = left$(get time$(), 3)
text 10,10, "The time is: " + hours$ + minutes$ + seconds$ + "am"
endif
endif
ENDFUNCTION
FUNCTION GameOver()
if MatchedCards >=52
`cls
current = music volume(NowPlaying)
negator = int(current / 2)
for volume = 1 to negator
current = current - 2
set music volume NowPlaying, current
next volume
stop music NowPlaying
delete camera 1
`delete image 54
for done = 1 to 52
delete object done
next done
`create bitmap 54, 1024, 768
`set current bitmap 54
set text size 25
ink rgb(189,239,248), 0
do
center text 512, 384, "Press '1' to play again, press 'M' to go to the Main Menu, or press 'Q' to quit..."
AfterGame$ = inkey$()
select AfterGame$
case "1": StartUp(): exit: endcase
case "q": wait 500: end: endcase
case "m": MainMenu(): exit: endcase
endselect
loop
endif
ENDFUNCTION
FUNCTION MusicPlayer()
if inkey$() = "1" then stop music NowPlaying: play music 1: loop music 1: NowPlaying = 1: exitfunction NowPlaying
if inkey$() = "2" then stop music NowPlaying: play music 2: loop music 2: NowPlaying = 2: exitfunction NowPlaying
if inkey$() = "3" then stop music NowPlaying: play music 3: loop music 3: NowPlaying = 3: exitfunction NowPlaying
if inkey$() = "4" then stop music NowPlaying: play music 4: loop music 4: NowPlaying = 4: exitfunction NowPlaying
if inkey$() = "5" then stop music NowPlaying: play music 5: loop music 5: NowPlaying = 5: exitfunction NowPlaying
if inkey$() = "6" then stop music NowPlaying: play music 6: loop music 6: NowPlaying = 6: exitfunction NowPlaying
if inkey$() = "7" then stop music NowPlaying: play music 7: loop music 7: NowPlaying = 7: exitfunction NowPlaying
if inkey$() = "8" then stop music NowPlaying: play music 8: loop music 8: NowPlaying = 8: exitfunction NowPlaying
if inkey$() = "9" then stop music NowPlaying: play music 9: loop music 9: NowPlaying = 9: exitfunction NowPlaying
if inkey$() = "*" then stop music NowPlaying
if inkey$() = "-"
set music volume NowPlaying, (music volume(NowPlaying) - 5)
if music volume(NowPlaying) <= 0
set music volume NowPlaying, 0
endif
endif
if inkey$() = "+"
set music volume NowPlaying, (music volume(NowPlaying) + 5)
if music volume(NowPlaying) >= 100
set music volume NowPlaying, 100
endif
endif
ink rgb(255,153,0), 0
line 864,28,1019,28
line 864,5,864,28
center text 941,10, "Now Playing: Track No. " + str$(NowPlaying)
ENDFUNCTION NowPlaying
Also of note: 32-bit depth was still slower for me than 16-bit ever was, i would stick with 16-bit depth if it didn't mess up the color blending on my images. what do u think?
Lastly an unrelated problem: my main menu background image shows up fine when i first execute the code, but if i complete a game and choose to go back to the main menu, the background image shows up for a brief instant, then either disappears or is covered by a blue screen the same color as the screen that pops up to give the player choices after a game has been completed (look in the gameover() function to see the choices im referring to). i think its the default blue for dbpro when you clear the screen or whatever its called. Anyway i haven't been able to fig out how to get main menu image to stay visible like its supposed to, could use u guys help.
DBPro User
PC: WinXP, AthlonXP 2100+ 1.7ghz, 80gb HD, Nvidia GeForce FX 5200 (128mb onboard RAM), 512mb DDR400 system RAM. Thank you for your help.