Full source of game for developers to check why it crashes
Posted: Tue Apr 23, 2013 8:32 am
Code: Select all
; HANGMAN V1.0
; @ 2013 Marco A.G.Pinto (code)
; and
; Robert Bergström (graphics)
;
; Init stuff
InitSprite()
InitSound()
InitKeyboard()
InitMovie()
; Declare Procedures
Declare place_words_score_left(words, score)
Declare death_frame_player(death_frame)
Declare place_word_hidden(word_during_game_hidden$)
Declare place_letters_failed(letters_failed$)
Declare place_word_failed(word_during_game$)
Declare congratulations()
; Load the font
LoadFont(0, "Courier", 10) ;Load Courrier Font, Size 10
LoadFont(1, "Courier", 16) ;Load Courrier Font, Size 16
; Reserve the words
Global word_during_game$=""
Global word_during_game_hidden$=""
Global letters_failed$=""
Global Dim current_word$(100)
Global Dim word_selected(100) ;0=not played, 1=played
Global number_of_words=0 ; total number of words in the data section
; Read the words
Restore words
Repeat
Read.s a$
If a$<>"*"
number_of_words=number_of_words+1
current_word$(number_of_words)=a$
EndIf
Until a$="*"
; Create the main menu
OpenScreen(1024,768,32,"Hangman V1.0 - build 4")
; Load frames of guy dieing
For f=0 To 11
UsePNGImageDecoder()
LoadImage(f+2,GetCurrentDirectory()+"media\graphics\hangman_frame_"+Right("0"+Str(f),2)+".png")
Next f
main_menu_lp:
StartDrawing(ScreenOutput())
UsePNGImageDecoder()
LoadImage(1,GetCurrentDirectory()+"media\graphics\mainmenu.png")
DrawingMode(#PB_2DDrawing_Default)
DrawImage(ImageID(1),0,0)
DrawingFont(FontID(0)) ;Use the 'Courier' font
BackColor(RGB(0,0,0))
FrontColor(RGB(255,255,255))
DrawingMode(1) ;Transparent TextBackground
DrawText(1024-50-50-50-20-20,768-50,"V1.0 alpha - Build 4")
StopDrawing()
FlipBuffers()
LoadMovie(1,GetCurrentDirectory()+"media\music\title.mp3")
PlayMovie(1,ScreenID())
Repeat
ExamineKeyboard()
i$=KeyboardInkey()
Until i$<>""
If i$=Chr(27)
End
EndIf
StopMovie(1)
Delay(400) ;a small pause
words=0
score=0
; Load audio to play during game
LoadMovie(2,GetCurrentDirectory()+"media\music\beep.mp3")
LoadMovie(3,GetCurrentDirectory()+"media\music\dead.mp3")
; Clear the words already used during last play
For f=1 To number_of_words
word_selected(f)=0
Next f
game_lp:
ClearScreen(RGB(0,0,0))
StartDrawing(ScreenOutput())
UsePNGImageDecoder()
LoadImage(1,GetCurrentDirectory()+"media\graphics\gamebackground.png")
DrawingMode(#PB_2DDrawing_Default)
StopDrawing()
letters_failed$=""
death_frame=0
word_during_game_hidden$=""
; SELECT THE RANDOM WORD
t=0
For f=1 To number_of_words
If word_selected(f)=1
t=t+1
EndIf
Next f
If t=number_of_words
congratulations()
ClearScreen(RGB(0,0,0))
Goto main_menu_lp
EndIf
RandomSeed(ElapsedMilliseconds())
Repeat
t=Random(number_of_words,1)
Until word_selected(t)=0
word_selected(t)=1
word_during_game$=current_word$(t)
For f=1 To Len(word_during_game$)
word_during_game_hidden$=word_during_game_hidden$+"-"
Next f
; END SELECT THE RANDOM WORD
game_lp1:
; The main functions to avoid flicker
StartDrawing(ScreenOutput())
; DrawText(20,20,word_during_game$+"xxx",RGB(255,255,255),RGB(0,0,0))
DrawImage(ImageID(1),0,0)
StopDrawing()
place_words_score_left(words, score)
place_letters_failed(letters_failed$)
death_frame_player(death_frame)
If Len(letters_failed$)=11
place_word_failed(word_during_game$)
words=words+1
Goto game_lp
EndIf
place_word_hidden(word_during_game_hidden$)
FlipBuffers()
Delay(400)
Repeat
ExamineKeyboard()
i$=UCase(KeyboardInkey())
; Validate the letters pressed which can only be between A and Z and <ESC>
If (Asc(i$)<Asc("A") Or Asc(i$)>Asc("Z")) And i$<>Chr(27)
i$=""
EndIf
If i$<>Chr(27) And i$<>""
PlayMovie(2,ScreenID())
t=0 ; if t=1 it means the letter is already failed and in the list of failed letters
If Len(letters_failed$)>0
For f=1 To Len(letters_failed$)
If Mid(letters_failed$,f,1)=i$
t=1
EndIf
Next f
EndIf
If t=0
tt=0
For f=1 To Len(word_during_game$)
If Mid(word_during_game$,f,1)=i$
tt=1
EndIf
Next f
If tt=0
letters_failed$=letters_failed$+i$
death_frame=death_frame+1
Goto game_lp1
EndIf
tt$=""
For f=1 To Len(word_during_game$)
t$=Mid(word_during_game$,f,1)
If t$=i$
tt$=tt$+i$
Else
tt$=tt$+Mid(word_during_game_hidden$,f,1)
EndIf
Next f
word_during_game_hidden$=tt$
Goto game_lp1
EndIf
EndIf
; Win the current word
If word_during_game$=word_during_game_hidden$
words=words+1
score=score+1
Goto game_lp
EndIf
Until i$=Chr(27)
ClearScreen(RGB(0,0,0))
FlipBuffers()
Delay(400) ;a small pause
Goto main_menu_lp
; Places words and score on the screen
; V1.0 - 21/APR/2013
; V1.1 - 23/APR/2013
; a) Now shows on screen the number of words left
Procedure place_words_score_left(words, score)
StartDrawing(ScreenOutput())
DrawingFont(FontID(1)) ;Use the 'Courier' font
DrawText(100,10, "WORDS:"+Str(words), RGB(255,0,0))
DrawText(500-50,10, "SCORE:"+Str(score), RGB(255,0,0))
DrawText(500-50+400-50,10, "LEFT:"+Str(number_of_words-words), RGB(255,0,0))
StopDrawing()
EndProcedure
; Places the frames of the hanging man
; V1.0 - 21/APR/2013
Procedure death_frame_player(death_frame)
StartDrawing(ScreenOutput())
DrawImage(ImageID(death_frame+2),100+200+100,100+100)
StopDrawing()
If death_frame=11
FlipBuffers()
Delay(400)
StartDrawing(ScreenOutput())
DrawImage(ImageID(10+2),100+200+100,100+100)
StopDrawing()
PlayMovie(3,ScreenID())
Delay(6000)
EndIf
EndProcedure
; Places the hidden word on the screen with "-"s and letters
; 1.0 - 21/APR/2013
Procedure place_word_hidden(word_during_game_hidden$)
StartDrawing(ScreenOutput())
DrawingFont(FontID(1)) ;Use the 'Courier' font
DrawText((1024/2)-(Len(word_during_game_hidden$)*8/2),100+100+200+100,word_during_game_hidden$,RGB(255,255,255),RGB(0,0,0))
StopDrawing()
EndProcedure
; Places the 11 letters failed
; 1.0 - 21/APR/2013
Procedure place_letters_failed(letters_failed$)
StartDrawing(ScreenOutput())
DrawingFont(FontID(1)) ;Use the 'Courier' font
DrawText(50,700,letters_failed$,RGB(255,255,255),RGB(0,255,0))
StopDrawing()
EndProcedure
; Places the failed word centered on the screen and pauses
; 1.0 - 21/APR/2013
Procedure place_word_failed(word_during_game$)
StartDrawing(ScreenOutput())
DrawingFont(FontID(1)) ;Use the 'Courier' font
DrawText((1024/2)-(Len("The word was: "+word_during_game$)*8/2),100+100+200+100,"The word was: "+word_during_game$,RGB(255,255,255),RGB(255,0,0))
StopDrawing()
FlipBuffers()
Delay(400)
Repeat
ExamineKeyboard()
i$=UCase(KeyboardInkey())
Until i$<>""
EndProcedure
; Places the congratulation image for solving all words
; 1.0 - 21/APR/2013
Procedure congratulations()
StartDrawing(ScreenOutput())
UsePNGImageDecoder()
LoadImage(14,GetCurrentDirectory()+"media\graphics\congratulations.png")
DrawingMode(#PB_2DDrawing_Default)
DrawImage(ImageID(14),0,0)
StopDrawing()
FlipBuffers()
Delay(4000)
EndProcedure
DataSection
words:
Data.s "SCHOOL", "TOMORROW","ADDRESS","LENGTH","EXPERT"
Data.s "*"
EndDataSection