I liked your binary clock so much, it made me go back to when I programmed in Fortran using punchcards; so little by little I added graphics and a simple game.
Since I am a newbie in PB, every advice is really important to me.
At present I tested this game on different machines and I got no problem, but a friend of mine sees just a white window: he uses Seven 64bit; i could not understand why.
Code: Select all
; by Venom
; arrangé par Dobro ;
; game added by Luciano
Global Dim tableau.S (6)
Enumeration
#sprite_spento
#sprite_acceso
#window
#sprite_fondo
#pallina
#pallina_N
#pallina_NE
#pallina_E
#pallina_SE
#pallina_S
#pallina_SW
#pallina_W
#pallina_NW
#pad
#punchcard
;-----suoni
#hit
#miss
#hop
#slip
EndEnumeration
UsePNGImageDecoder()
;InitKeyboard()
;InitSprite ()
pall_x=0
pall_y=200
speed_x=4
speed_y=Random(3)+2
pad_x=200
automatic=1
punchcard=0
Punchcard_Position_y=250
Punchcard_Position_x=8
UseSound=0
;If UseSound
If InitSound()=0
MessageRequester("Error","Failed to Initialize Sound Environment"+#CRLF$+"(Use WITHOUT Audio)",#MB_ICONERROR)
End
EndIf
;EndIf
If InitSprite()=0 Or InitKeyboard()=0
MessageRequester("Error","Failed to Initialize DirectX "+#CRLF$+"(program unusable)",#MB_ICONERROR)
End
EndIf
CatchSound(#hit,?hit)
CatchSound(#miss,?miss)
CatchSound(#hop,?hop)
CatchSound(#slip,?slip)
If OpenWindow ( #window,0,0,400,450,"Binary Clock Game ",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered )
If OpenWindowedScreen ( WindowID ( #window ),0,0,400,450,1,0,0)=0: MessageRequester("Error" ,"Windowed screen error!") : EndIf
SetFrameRate (75)
fontid = LoadFont (#PB_Any, "Arial" , 44 , #PB_Font_Bold )
If Not fontid : MessageRequester("Font not loaded...",Str(fontid)) : EndIf
F2 = LoadFont (#PB_Any, "Arial" , 8, #PB_Font_Bold )
CatchSprite(#sprite_acceso, ?acceso)
CatchSprite(#sprite_spento, ?spento)
CatchSprite(#sprite_fondo, ?fondo)
CatchSprite(#pallina, ?pallina_N)
CatchSprite(#pallina_N, ?pallina_N)
CatchSprite(#pallina_NE, ?pallina_NE)
CatchSprite(#pallina_E, ?pallina_E)
CatchSprite(#pallina_SE, ?pallina_SE)
CatchSprite(#pallina_S, ?pallina_S)
CatchSprite(#pallina_SW, ?pallina_SW)
CatchSprite(#pallina_W, ?pallina_W)
CatchSprite(#pallina_NW, ?pallina_NW)
CatchSprite(#pad, ?pad)
CatchSprite(#punchcard, ?punchcard)
Repeat
Event = WaitWindowEvent(10)
If GetWindowState(#Window)=#PB_Window_Minimize: event=WaitWindowEvent(100):EndIf
If #True
If StartDrawing ( ScreenOutput())
DrawingFont (FontID(F2))
DrawText (0, 0, "A:Automatic, S/N:Sound/No sound, P:Play; Move with left/right keys" , RGB (0, 80, 0), RGB (0, 22, 0))
y=320 : x=377
DrawText (x, y, "1" , RGB (0, 180, 0), RGB (0, 0, 0)) :y-50
DrawText (x, y, "2" , RGB (0, 180, 0), RGB (0, 0, 0)) :y-50
DrawText (x, y, "4" , RGB (0, 180, 0), RGB (0, 0, 0)) :y-50
DrawText (x, y, "8" , RGB (0, 180, 0), RGB (0, 0, 0)):y-50
DrawText (x, y, "16" , RGB (0, 180, 0), RGB (0, 0, 0)):y-50
DrawText (x, y, "32" , RGB (0, 180, 0), RGB (0, 0, 0))
DrawingFont ( FontID(fontid) )
date$ = FormatDate( "%hh:%ii:%ss" , Date())
DrawText (0,360," ora: "+ date$+" ", RGB (0, 130, 0), RGB (0, 0, 0))
;
heure$ =Bin(Hour(Date()),#PB_Byte )
minute$=Bin(Minute(Date()))
seconde$=Bin(Second(Date()))
;{ ******** dessine le decors **********************
Restore sprite_off
; ++++++++++ dizaine heure (off) +++++++++
For o=1 To 3
Read n
Read p
y=300
For i=1 To n
DisplayTransparentSprite(#sprite_spento,p,y+15)
y-50
Next
Next
; ++++++++++++++++++++++++++++++++++++++
;}
;{ affichage de l'heure
; ++++++++++ dizaine heure (on) +++++++++
tableau.S (1)=heure$
tableau.S (2)=minute$
tableau.S (3)=seconde$
Restore sprite_on
For o=1 To 3
Read.i y
Read n
Read.i p
var$=tableau.S(o)
For i=1 To n
If Len (var$)<n
var$= "0" +var$
EndIf
If Mid (var$,i,1)= "1"
DisplayTransparentSprite(#sprite_acceso ,p,y+15)
If SpritePixelCollision(#pallina, pall_x, pall_y, #sprite_acceso, p, y+15)
If UseSound: PlaySound(#hit,0,Random(60)+40):EndIf
speed_x=-speed_x+Random(2)-1 ;speed_x= speed_x +Random(4):
If pall_x<=p: pall_x-7:EndIf
If pall_x>=p: pall_x+7:EndIf
speed_y=-speed_y+Random(2)-1
If pall_y<=y+15: pall_y-7:EndIf
If pall_y>y+15: pall_y+7:EndIf
EndIf
EndIf
y=y+50
Next i
Next o
; ++++++++++++++++++++++++++++++++++++++
;} ++++++++++++++++++++++++++++++++++++++
;----------- Punchcard
If Random(32)>30:punchcard=1:EndIf
If Random(32)>31:punchcard=0:Punchcard_Position_y=Random(250)+70:Punchcard_Position_x=Random(50):EndIf
If punchcard
DisplayTransparentSprite(#punchcard ,Punchcard_Position_x,Punchcard_Position_y)
EndIf
;---------- pallina
pall_x+speed_x;+speed_x
pall_y+speed_y;+speed_y
If pall_x<=0: speed_x=Abs(speed_x):pall_x=0:speed_y+Random(2)-1:EndIf
If pall_x>384: speed_x=-Abs(speed_x):pall_x=384:speed_y+Random(2)-1:EndIf
If pall_y<=0: speed_y=Abs(speed_y):pall_y=0:speed_x+Random(2)-1:EndIf
If pall_y>500
If pall_y<650:EndTime=ElapsedMilliseconds()
If UseSound: StopSound(-1):PlaySound(#miss,0):EndIf
EndIf
pall_y=700
speed_x=4
speed_y=Random(3)+2
;Debug pall_y
DrawingFont (FontID(F2))
DrawText (0, 16, "MISSED! Press A or P to start again" , RGB (0, 120, 0), RGB (0, 22, 0))
DrawText (0, 32, "POINTS: "+Str((EndTime-StartTime)/100)+".dec = "+RSet(Bin((EndTime-StartTime)/100), 16, "0")+".bin = "+RSet(Hex((EndTime-StartTime)/100), 4, "0")+".hex" ,RGB (100, 120, 0), RGB (0, 22, 0))
EndIf
ExamineKeyboard()
If speed_x>6:speed_x-Random(1):EndIf
If speed_y>6:speed_y-Random(1):EndIf
If speed_x<-6:speed_x+Random(1):EndIf
If speed_y<-6:speed_y+Random(1):EndIf
If speed_x=0:speed_x=Random(4)-2:EndIf
If speed_y=0:speed_y=Random(4)-2:EndIf
;Debug speed_x
;Debug speed_y
CopySprite(#pallina_N, #pallina)
If speed_y>0:CopySprite(#pallina_S,#pallina):EndIf
If speed_x>0
CopySprite(#pallina_E, #pallina)
If speed_y>0
CopySprite(#pallina_SE, #pallina)
If speed_x/speed_y>3:CopySprite(#pallina_E, #pallina):EndIf
If (speed_x+speed_x)/speed_y=0:CopySprite(#pallina_S, #pallina):EndIf
EndIf
If speed_y<0
CopySprite(#pallina_NE, #pallina)
If speed_x/speed_y<-3:CopySprite(#pallina_E, #pallina):EndIf
If (speed_x+speed_x)/speed_y=0:CopySprite(#pallina_N, #pallina):EndIf
EndIf
EndIf
If speed_x<0
CopySprite(#pallina_W, #pallina)
If speed_y>0
CopySprite(#pallina_SW, #pallina)
If speed_x/speed_y<-3:CopySprite(#pallina_W, #pallina):EndIf
If (speed_x+speed_x)/speed_y=0:CopySprite(#pallina_S, #pallina):EndIf
EndIf
If speed_y<0
CopySprite(#pallina_NW, #pallina)
If speed_x/speed_y>3:CopySprite(#pallina_W, #pallina):EndIf
If (speed_x+speed_x)/speed_y=0:CopySprite(#pallina_N, #pallina):EndIf
EndIf
EndIf
;------------- Pad
If automatic
pad_x=pall_x
Else
If KeyboardPushed(#PB_Key_Left)
If pad_x>20:pad_x-10:EndIf
EndIf
If KeyboardPushed(#PB_Key_Right)
If pad_x<361:pad_x+10:EndIf
EndIf
EndIf
If KeyboardPushed(#PB_Key_A)
pall_x=0
pall_y=200
speed_x=4
speed_y=Random(3)+2
pad_x=200
automatic=1
EndIf
If KeyboardPushed(#PB_Key_P)
StartTime = ElapsedMilliseconds()
pall_x=0
pall_y=200
speed_x=4
speed_y=Random(3)+2
pad_x=200
automatic=0
EndIf
If KeyboardPushed(#PB_Key_S)
UseSound=1
EndIf
If KeyboardPushed(#PB_Key_N)
UseSound=0
EndIf
DisplaySprite(#pad ,pad_x-30,440)
If SpriteCollision(#pallina, pall_x, pall_y, #pad, pad_x-30, 440)
speed_y=-Abs(speed_y):pall_y-4-Random(2):speed_x+Random(2)-1
If UseSound:StopSound(-1):PlaySound(#hop,0,Abs(speed_y*10)):EndIf
EndIf
If punchcard=1 And SpriteCollision(#pallina, pall_x, pall_y, #punchcard, Punchcard_Position_x, Punchcard_Position_y)>0
If UseSound:PlaySound(#slip,0,Abs(speed_y*10)):EndIf
If speed_y>3: speed_y=3:EndIf
EndIf
DisplayTransparentSprite(#pallina ,pall_x,pall_y)
exit:
StopDrawing()
FlipBuffers ()
DisplaySprite(#sprite_fondo ,0,0)
EndIf
EndIf
; ; ++++++++++++++++++++++++++++++++++++++
;EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
DataSection
sprite_off:
Data.i 5,150,6,240,6,330
sprite_on:
Data.i 100,5,150,50,6,240,50,6,330
EndDataSection
End
acceso: IncludeBinary "acceso.png"
spento: IncludeBinary "spento.png"
fondo: IncludeBinary "fondo.png"
pallina_N: IncludeBinary "x_n.png"
pallina_NE: IncludeBinary "x_ne.png"
pallina_E: IncludeBinary "x_e.png"
pallina_SE: IncludeBinary "x_se.png"
pallina_S: IncludeBinary "x_s.png"
pallina_SW: IncludeBinary "x_sw.png"
pallina_W: IncludeBinary "x_w.png"
pallina_NW: IncludeBinary "x_nw.png"
pad: IncludeBinary "pad.png"
punchcard: IncludeBinary "punchcard.png"
hit: IncludeBinary "lightswitch1_mono.wav"
miss:IncludeBinary "cartoon3.wav"
hop:IncludeBinary "pop.wav"
slip:IncludeBinary "ping.wav"