Hello again all.
Match Cards has been coming along nicely and im done except for the slowdown problem that i've mentioned in other posts(which I still haven't solved) and this problem. When the player finishes a game, they're given the option to "press 'p' to play again, press 'm' to go to the main menu, or press 'q' to quit...". If the player presses 'm', the main menu background image and the text that is printed onto the screen show correctly for an instant(a small fraction of a second) then they disappear behind an all blue screen. I can't figure out what's making that happen, but if i click on one of the menu items on the main menu("new game" or "quit") then the text will show up through the blue background and the game will start as normal. but for some reason i can't get the main menu to perform correctly after the first time.
Although this would normally be a bad idea to do, i'm posting my entire game code, and attaching the main menu bg image so that someone can see firsthand what i'm talking about. This game will never be commercially released, so i'm willing to risk posting the code in its entirety, in the hopes that no one will screw me over. This is my first game, and I only made it to learn about the language and the game development process. Here's my code:
remstart
`setup screen
if check display mode (1024,768,24) = 1
set display mode 1024,768,24
else
set display mode 1024,768,32
endif
remend
`create data type for array
type CardInfo
Texture as integer
Value$ as string
AlreadyMatched as boolean
FaceDown as boolean
FaceUp as boolean
Suit$ as string
CardXPos#
CardYPos#
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
`load sounds
load sound "cardclick.wav", 1
load sound "nomatch.wav", 2
`load music
remstart
for MusicLoad = 1 to 9
load music "" + str$(MusicLoad) + ".mp3", MusicLoad
next MusicLoad
remend
load music "jazz.mid",1
load music "litegroo.mid", 2
load music "awards.mid", 3
load music "rhythm and blues.wav", 4
`load images
for ImageLoad = 1 to 52
load image "" + str$(ImageLoad) + ".bmp", ImageLoad
next ImageLoad
load image "Playing Card Back.bmp", 53
`setup basic card info
data 0,0, 12.5,0, 25,0, 37.5,0, 50,0, 62.5,0, 75.0,0, 87.5,0, 100,0,
data 0,-15.5, 12.5,-15.5, 25,-15.5, 37.5,-15.5, 50,-15.5, 62.5,-15.5, 75.0,-15.5, 87.5,-15.5, 100,-15.5,
data 0,-31, 12.5,-31, 25,-31, 37.5,-31, 50,-31, 62.5,-31, 75,-31, 87.5,-31, 100,-31,
data 0,-46.5, 12.5,-46.5, 25,-46.5, 37.5,-46.5, 50,-46.5, 62.5,-46.5, 75.0,-46.5, 87.5,-46.5, 100,-46.5,
data 0,-62, 12.5,-62, 25,-62, 37.5,-62, 50,-62, 62.5,-62, 75,-62, 87.5,-62, 100,-62,
data 12.5,-77.5, 25,-77.5, 37.5,-77.5, 50,-77.5, 62.5,-77.5, 75.0,-77.5, 87.5,-77.5
TextureSetter = 1
Increaser = 4
SetChanger = 1
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
`setup the texture data so that it loads correctly into the card array: 1-13clubs, 1-13diamonds, 1-13hearts, 1-13spades
Deck(z).Texture = TextureSetter
inc TextureSetter, Increaser
if TextureSetter >= 53
inc SetChanger
TextureSetter = SetChanger
endif
next z
MainMenu()
`********************************************************MAIN LOOP***********************************************************
while escapekey() <> 1 `hit Escape to exit game
center text (screen width() / 2), (screen height() - ((Screen height()/10) * 9)), str$(screen fps()) `publish game fps
`rotate skybox
angle# = wrapvalue(angle#) + 0.5
rotate object 54, 0, angle#, 0
wait 2000
MatchedCards = 52
MusicPlayer()
Clock()
MouseControl()
GameOver()
endwhile
`*****************************************************END OF MAIN LOOP********************************************************
`------------------------------------------------------END OF PROGRAM--------------------------------------------------------
`---------------------------------------------------------FUNCTIONS----------------------------------------------------------
FUNCTION MainMenu() `main menu
`load Menu background image
if image exist(54) <> 1
load image "MainMenuBackground.bmp", 54
paste image 54,0,0
endif
`start music for menu
play music 1
set music volume 1, 100
loop music 1
`print menu selection text to screen at specified location (bottom-left of screen)
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"
set text size 16
wait 1500
stop music 1
delete image 54
StartUp()
exit
endif
endif
if mousex() >= 60 and mousex() <= 160
if mousey() >=618 and mousey() <= 648
ink rgb(189,239,248),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(189,239,248),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,1000.0
`plain is facing toward monitor, so alter z instead of y for raised camera
position camera 1, 50, -30, -92 `use this camera for direct overhead view
point camera 1, 50, -30, 0
if object exist(54) <> 1
load object "Skybox2.x", 54
SET OBJECT 54, 1, 1, 0, 0, 0
else
show object 54
endif
`setup lighting
set ambient light 100
`start music
NowPlaying = rnd(2) + 2
if music playing(NowPlaying) <> 1
play music NowPlaying
set music volume NowPlaying, 100
loop music NowPlaying
else
stop music NowPlaying
play music NowPlaying
loop music NowPlaying
endif
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 = -12
make object box a, 10, 13, 0
texture object a, 53 `Deck(a).Texture, if i need to see the cards w/out clicking them
set object transparency a, 5
`Assign card a value using MOD
value = a mod 13
if value <= 0 then Deck(a).Value$ = "A"
if value <=9 and value >= 1 then Deck(a).Value$ = str$(value + 1)
if value = 10 then Deck(a).Value$ = "J"
if value = 11 then Deck(a).Value$ = "Q"
if value = 12 then Deck(a).Value$ = "K"
`Assign Suit
SuitHolder = int(a / 13.1) + 1
select SuitHolder
case 1: Deck(a).Suit$ = "Clubs" : endcase
case 2: Deck(a).Suit$ = "Diamonds" : endcase
case 3: Deck(a).Suit$ = "Hearts" : endcase
case 4: Deck(a).Suit$ = "Spades" : endcase
endselect
`make animation for cards falling onto deck
for b = 1 to 5
position object a, 50, 15.5, FallHeight `y pos is 15.5 so that deck will sit beyond card dealing area
FallHeight = FallHeight + 2
wait 1
next b
position object a, 50.0, 15.5, 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).Texture = Deck(card1).Texture
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).Texture = Deck(card2).Texture
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$
Deck(card2).Texture = Shuffler(1).Texture
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$
next n
Deal()
ENDFUNCTION
FUNCTION FlipFirstCardUp(WhichCardOne) `flips the first card over that is clicked
`if the card has already been matched don't continue trying to match it again
if Deck(WhichCardOne).AlreadyMatched = 1
exitfunction
endif
`if card is face down, set its values to face up
if Deck(WhichCardOne).FaceUp = 0 and Deck(WhichCardOne).FaceDown = 1
Deck(WhichCardOne).FaceDown = 0
Deck(WhichCardOne).FaceUp = 1
else
`if its already face up, give error message
set sound volume 2, 90
play sound 2
for ErrorMessage = 1 to 50
set text size 30
center text (screen width() / 2), (screen height() - ((Screen height()/10) * 9.3)), "Please try another card."
set text size 16
wait 1
next ErrorMessage
exitfunction
endif
`play sound for card being clicked
play sound 1
for MoveUp = 1 to 5
move object WhichCardOne, -.6
wait 2
next MoveUp
for TwistLeft = 1 to 10
turn object left WhichCardOne, 18
if TwistLeft = 5 then texture object WhichCardOne, Deck(WhichCardOne).Texture
wait 2
next TwistLeft
wait 1000
for MoveDown = 1 to 5
move object 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 clicked
`if the card has already been matched don't continue trying to match it again
if Deck(WhichCardTwo).AlreadyMatched = 1
exitfunction
endif
`if card is face down, set its values to face up
if Deck(WhichCardTwo).FaceUp = 0 and Deck(WhichCardTwo).FaceDown = 1 `same as function above
Deck(WhichCardTwo).FaceDown = 0
Deck(WhichCardTwo).FaceUp = 1
else
`if its already face up, give error message
set sound volume 2, 85
play sound 2
for ErrorMessage = 1 to 50
set text size 30
center text (screen width() / 2), (screen height() - ((Screen height()/10) * 9.3)), "Please try another card."
set text size 16
wait 1
next ErrorMessage
exitfunction
endif
play sound 1
for MoveUp = 1 to 5
move object WhichCardTwo, -.6
wait 2
next MoveUp
for TwistLeft = 1 to 10
turn object left WhichCardTwo, 18
if TwistLeft = 5 then texture object WhichCardTwo, Deck(WhichCardTwo).Texture
wait 2
next TwistLeft
wait 1000
for MoveDown = 1 to 5
move object WhichCardTwo, -.6
wait 2
next MoveDown
MatchDetector(WhichCardTwo) `sends 2nd card's data to match detection function
ENDFUNCTION
FUNCTION FlipCardDown(WhichCard) `turns card back to face down, and sets its value to face down
for MoveUp = 1 to 5
move object WhichCard, .6
wait 5
next MoveUp
for TwistLeft = 1 to 10
turn object left WhichCard, 18
if TwistLeft = 5 then texture object WhichCard, 53
wait 5
next TwistLeft
for MoveDown = 1 to 5
move object 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 player clicks on empty space, nothing happens
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 the clicked cards match...
if Deck(FirstCard).Value$ = Deck(SecondCard).Value$
`set the cards as matched
Deck(FirstCard).AlreadyMatched = 1
Deck(SecondCard).AlreadyMatched = 1
`fade the cards off the screen
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
`reset clicked card counter
CardsToBeMatched = 0
`increment total number of cards already matched to test for game over
MatchedCards = MatchedCards + 2
exitfunction MatchedCards
else
`if not a match, turn cards face down, and set card values to face down
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() `prints the time up on the screen, in the upper-left corner
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"
if left$(get time$(), 1) = "0" and mid$(get time$(), 2) = "0"
hours$ = "12:"
else
hours$ = mid$(get time$(), 2) + mid$(get time$(), 3)
endif
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 `if game is over...
`fade music out
current = music volume(NowPlaying)
negator = int(current / 2)
for volume = 1 to negator
current = current - 2
set music volume NowPlaying, current
wait 1
next volume
stop music NowPlaying
`delete data
delete camera 1
for done = 1 to 52
delete object done
Deck(done).AlreadyMatched = 0
Deck(done).FaceUp = 0
Deck(done).FaceDown = 1
next done
`hide skybox
hide object 54
`give player options at game over
set text size 25
ink rgb(189,239,248), 0
do
center text 512, 384, "Press 'P' to play again, press 'M' to go to Main Menu, or press 'Q' to quit..."
AfterGame$ = inkey$()
select AfterGame$
case "p": StartUp(): exit: endcase
case "q": wait 500: end: endcase
case "m": MainMenu(): exit: endcase
endselect
loop
endif
ENDFUNCTION
FUNCTION MusicPlayer() `play music and give player control over what song is played
remstart
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
remend
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$() = "*" then stop music NowPlaying
if inkey$() = "-"
set music volume NowPlaying, (music volume(NowPlaying) - 2)
if music volume(NowPlaying) <= 0
set music volume NowPlaying, 0
endif
endif
if inkey$() = "+"
set music volume NowPlaying, (music volume(NowPlaying) + 2)
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)
center text 950, 30, "Hit number keys 1-4"
center text 950, 40, "to change the song."
center text 950, 60, "Hit '+' to increase"
center text 950, 70, "the volume."
center text 950, 90, "Hit '-' to decrease"
center text 950, 100, "the volume."
center text 950, 120, "Hit '*' to stop the"
center text 950, 130, "music."
ENDFUNCTION NowPlaying
background image is attached. Please help, as this is the last really necessary thing that I have to do before the game can be considered complete. It runs at a constant 20fps which is slow, but the game being what it is, doesn't really hinder the gameplay much. I've inquired on these forums before as to help with increasing my frame rate with no success, so im content to release it as is in the Showcase when i have this main menu glitch fixed.
Even still, if anyone would care to take a look at the frame rate problem, please note that the problem doesn't manifest itself unless my skybox is loaded. without the skybox the game runs at 30fps. I've tried scaling the skybox smaller, opening it up in a 3d modeler and scaling it to the size i need to get rid of the scale command, opening up the skybox textures in photoshop and decreasing the image size, doesn't matter. The skybox i'm using is attached, in case anyone wanted to take a look.
Lastly, the Clock(), MusicPlayer() functions, and the fps code that is in the main loop disappears when I click a card and doesn't reappear until the operations on the card are done being performed. I understand that this happens because the card operations, including deck construction, shuffling, and dealing at the beginning of the game all happen outside of the main loop, but I have not been able to find a solution to fix this. I'm ok with it happening, but if anyone knows of a way I could have that text onscreen all the time i'd appreciate it. As I said I made this game to learn and later on I would like to know how to set up my code so that operations that should happen all the time perform correctly. Thank you all for your help, and sorry for the long post; i'm almost done
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.