Pure GameCard

Spiele, Demos, Grafikzeug und anderes unterhaltendes.
Burstnibbler
Beiträge: 55
Registriert: 04.10.2008 12:10

Pure GameCard

Beitrag von Burstnibbler »

Hi,

ich hau mal´n bisschen alten code raus, vielleicht kann ja jemand was damit anfangen.
Der code ist nicht kommentiert und entspricht auch sonst nicht den gängigen coding-conventions
(aber das ist ja bei PB auch schnuppe :mrgreen: ).
FF!


Pure Gamecard:
Der name setzt sich zusammen aus Game + Greeting-Card und das Pure... naja.

Das Spielprinzip:
Man schiesst ballons ab und bekommt dafür punkte.
Einige ballons decken einen buchstaben des grußes auf.
Ziel ist es den gesamten gruß -mit möglichst geringer punktzahl- aufzudecken.
Sprich: Je weniger punkte man am ende hat, desto besser.

Die Punkte:
Ballon: +10 punkte
Ballon(spezial): -(10*geschwindigkeitsstufe) punkte
Nachladen: +5 punkte

Steuerung:
Linke Maustaste: schiessen
Rechte Maustaste: nachladen
Escape(Esc): beenden
F1: fenster minimieren / pause


SFX:
Da ich nicht mehr weiss, wo ich die Sound-Effekte her habe,
werde ich sie hier auch vorsichtshalber nicht mit anbieten.

Bugs:
Bei mir nicht. Aber wenn jemand einen findet, dann darf er ihn gerne entfernen.

Sonstiges:
Der code wird von mir nicht mehr weiterentwickelt!

Code: Alles auswählen

;Compiler  : PureBasic v4.41 (x86)
;Platform  : Win XP (x86),...
;Native PB : Yes, 100%
;D.o.C     : April 2011
;Version   : v.0.1.0
;Creator   : Burstnibbler
;Licence   : None(Do whatever you want with it!)
;#**************************** WIDE LOAD 100 *****************************************************#
EnableExplicit
;
#WIN       = 0
#WIN_W     = 800
#WIN_H     = 600
#WIN_T     = "Pure Gamecard"
#WIN_F     = #PB_Window_ScreenCentered
#FONT      = 0
#FONTNAME$ = "Comic Sans MS" 
#CROSS_W   = 20
#CROSS_H   = 20
#AMMO_W    = 15
#AMMO_H    = 25
#BALLOON_W = 100
#BALLOON_H = 105
#BALLOONS  = 12
#FPS_LIMIT = 16 ;1000 ms/ 60 FPS
;
#LINE_1    = "Hello"
#LINE_2    = "Pure Basic"
;
;Name Your SFX-Files Here
#MY_GUN_SHOT     = ".wav"
#MY_GUN_RELOAD   = ".wav"
#MY_BALLOON_BANG = ".wav"
#MY_APPLAUSE     = ".wav"
; 
Enumeration ;Sprites
  #SPR_BG
  #SPR_CROSS
  #SPR_AMMO
  #SPR_BALLOON
EndEnumeration
;
Enumeration ;SFX
  #SFX_GUN_SHOT
  #SFX_GUN_RELOAD
  #SFX_BALLOON_BANG
  #SFX_APPLAUSE
EndEnumeration
;
Enumeration ;Errors
  #ERR_DX
  #ERR_SCREEN
  #ERR_GFX
  #ERR_FONT
  #ERR_TEXT_1
  #ERR_TEXT_2
EndEnumeration
;
Structure RUBBER
  X.i
  Y.i
  Sprite.i
  Special.i
  Speed.i
EndStructure
;
Structure STUFF
  Timer.i
  Timewaste.i
  Accelerator.i
  PointFontID.i
  TextFontID.i
  Points.i
  Complete.i
  SpecialItem.i
  NoSound.i
  Mx.i
  My.i
  Ammo.i
  Quit.i
  Belt.POINT[5]
EndStructure
;
Define  Game.STUFF
NewList Balloon.RUBBER()
NewList Text.i()
NewList Sound.i()
;
Procedure Error(ErrorCode.i)
Protected Msg.s
;
Select ErrorCode
  Case #ERR_DX     : Msg="DirectX doesn´t work correctly."
  Case #ERR_SCREEN : Msg="Failed to create a Windowed-Screen."
  Case #ERR_GFX    : Msg="Failed to create graphics"
  Case #ERR_FONT   : Msg="Failed to load font: " + #FONTNAME$
  Case #ERR_TEXT_1 : Msg="Text1 oversized."
  Case #ERR_TEXT_2 : Msg="Text2 oversized."
EndSelect
MessageRequester("Error", Msg)
End
EndProcedure
;
Procedure Create_Background()
If (Not CreateImage(0,#WIN_W,#WIN_H)) : ProcedureReturn : EndIf
StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Gradient)      
  BackColor(RGB(0,64,255))
  FrontColor(RGB(60,225,225))
  LinearGradient(0,0,0,#WIN_H)
  Box(0,0,#WIN_W,#WIN_H) 
StopDrawing()
;
If (Not CreateSprite(#SPR_BG,#WIN_W,#WIN_H))
  FreeImage(0) : ProcedureReturn
EndIf
;
StartDrawing(SpriteOutput(#SPR_BG)) 
  DrawImage(ImageID(0),0,0)
StopDrawing()
FreeImage(0)
;
ProcedureReturn #True
EndProcedure
;
Procedure Modify_Background(X.i, Y.i, Char.s)
Shared Game.STUFF
;
StartDrawing(SpriteOutput(#SPR_BG))
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(Game\TextFontID)
  DrawText(X-1,Y-1,Char,#Black)
  DrawText(X-1,Y+1,Char,#Black)
  DrawText(X+1,Y-1,Char,#Black)
  DrawText(X+1,Y+1,Char,#Black)
  DrawText(X,Y,Char,RGB(Random(160)+60,Random(160)+60,Random(160)+60))
StopDrawing()
EndProcedure
;
Procedure Create_Crosshair()
If (Not CreateSprite(#SPR_CROSS,#CROSS_W,#CROSS_H)) : ProcedureReturn : EndIf
StartDrawing(SpriteOutput(#SPR_CROSS))
  Box(0,0,#CROSS_W,#CROSS_H,RGB(255,0,255))
  Box(0,8,20,5,#Black)
  Box(1,9,18,3,RGB(200,200,200))
  Box(8,0,5,20,#Black)
  Box(9,1,3,18,RGB(200,200,200))
  Box(8,8,5,5,RGB(255,0,255))
StopDrawing()
;
ProcedureReturn #True
EndProcedure
;
Procedure Create_Ammunition()
If (Not CreateSprite(#SPR_AMMO,#AMMO_W,#AMMO_H)) : ProcedureReturn : EndIf
StartDrawing(SpriteOutput(#SPR_AMMO))
  Box(0,0,#AMMO_W,#AMMO_H,RGB(255,0,255))
  Ellipse(7,8,5,8,RGB(127,127,127))
  Box(1,8,13,15,RGB(210,160,60))
  Box(0,23,15,2,RGB(200,140,50))
StopDrawing()
;
ProcedureReturn #True
EndProcedure
;
Procedure Balloon_Create(Sprite.i, Color.l)
Protected.l PixCol
;
If (Not CreateImage(0,#BALLOON_W,#BALLOON_H)) : ProcedureReturn : EndIf
StartDrawing(ImageOutput(0)) 
  Box(0,0,#BALLOON_W,#BALLOON_H,RGB(255,0,255))
  DrawingMode(#PB_2DDrawing_Gradient)
  FrontColor(#Black)
  BackColor(Color)
  EllipticalGradient(70,30,80,100)
  Ellipse(50,50,40,50,Color)
  DrawingMode(#PB_2DDrawing_Default)
  PixCol=Point(50,70)
  LineXY(48,101,52,101,PixCol)
  LineXY(47,102,53,102,PixCol)
  LineXY(46,103,54,103,PixCol)
  LineXY(45,104,55,104,PixCol)
  LineXY(44,105,56,105,PixCol)
StopDrawing()
;
If (Not CreateSprite(Sprite,#BALLOON_W,#BALLOON_H))
  FreeImage(0) : ProcedureReturn
EndIf
;
StartDrawing(SpriteOutput(Sprite)) 
  DrawImage(ImageID(0),0,0)
StopDrawing()
FreeImage(0)
;
ProcedureReturn #True
EndProcedure    
;
Procedure Create_TextList()
Protected.i Loop
Shared Text()
;
For Loop=1 To Len(#LINE_1)
  If (Mid(#LINE_1,Loop,1)<>" ")
    AddElement(Text())
    Text()=Loop
  EndIf  
Next
For Loop=1 To Len(#LINE_2)
  If (Mid(#LINE_2,Loop,1)<>" ")
    AddElement(Text())
    Text()=100+Loop
  EndIf  
Next
;
EndProcedure
;
Procedure.i Balloon_Special()
Protected.i Element, Items, Result
Shared Game.STUFF
Shared Text()
;
Items   = ListSize(Text())-1
Element = Random(Items)
SelectElement(Text(),Element)
Result  = Text()
Game\SpecialItem = Element
;
ProcedureReturn Result
EndProcedure
;
Procedure Balloon_Add(X.i)
Static.i LastSprite, NextSpecial, Init
Shared Game.STUFF
Shared Balloon()
;
AddElement(Balloon())
Balloon()\X = X
Balloon()\Y = #Win_H
Balloon()\Speed = (Random(2)+Game\Accelerator)
;
Repeat
  Balloon()\Sprite = Random(#BALLOONS-1)
Until Balloon()\Sprite <> LastSprite
LastSprite = Balloon()\Sprite
;
If (Not NextSpecial)
  NextSpecial = Random(10)+10 
  If (Init) : Balloon()\Special = Balloon_Special() : Else : Init=#True : EndIf    
EndIf
NextSpecial-1
EndProcedure
;
Procedure Balloon_New()
Protected.i X, OK, Max
Shared Balloon()
;
Repeat
  X=Random(#WIN_W-#BALLOON_W)
    ForEach Balloon()
      If ((X >= Balloon()\X+(#BALLOON_W-30)) Or (X <= Balloon()\X-(#BALLOON_W+30)))
        OK = #True
      Else
        OK = #False : Break
      EndIf 
    Next
  Max+1
Until ((OK) Or (Max=30))
;
If (OK) : Balloon_Add(X) : EndIf
EndProcedure
;
;-
Procedure Ministate()
Shared Game.STUFF
; 
ReleaseMouse(#True)
SetWindowState(#WIN,#PB_Window_Minimize)
;
Repeat  
  If (WaitWindowEvent()=#PB_Event_CloseWindow) : End : EndIf 
  If (GetWindowState(#WIN)=#PB_Window_Normal)
    Game\Timer = ElapsedMilliseconds()
    ReleaseMouse(#False) : Break
  EndIf
ForEver
EndProcedure
;
Procedure TextControl(CharNr.i)
Protected.i Tx, Ty, Tw
Protected.s Text, Char
Static.i Init, X1, X2
Shared Game.STUFF
Shared Text()
Shared Sound()
;
If (Not Init)
  StartDrawing(ScreenOutput())
    DrawingFont(Game\TextFontID)
    X1 = (#WIN_W-TextWidth(#LINE_1))/2
    X2 = (#WIN_W-TextWidth(#LINE_2))/2
  StopDrawing()
  Init!1
EndIf
;
If (CharNr<100)
  Text = #LINE_1
  Ty   = 200
  Tx   = X1
ElseIf (CharNr>100)
  CharNr-100
  Text = #LINE_2
  Ty   = 300
  Tx   = X2
EndIf
;
Char = Mid(Text,CharNr,1)
Text = Left(Text,CharNr-1)
StartDrawing(ScreenOutput())
  DrawingFont(Game\TextFontID)
  Tw = TextWidth(Text)
StopDrawing()
Tx+Tw
;
Modify_Background(Tx,Ty,Char)
;
SelectElement(Text(),Game\SpecialItem)
DeleteElement(Text())
If (ListSize(Text())=0)
  Game\Complete=#True
  AddElement(Sound()) : Sound()=#SFX_APPLAUSE
EndIf
EndProcedure
;
Procedure KeyControl()
Shared Game.STUFF
;
ExamineKeyboard()
If (KeyboardReleased(#PB_Key_Escape)) : Game\Quit=#True : EndIf
If (KeyboardReleased(#PB_Key_F1))     : Ministate() : EndIf 
EndProcedure
;
Procedure MouseControl()
Static.i RMB, LMB, RMB_Down, LMB_Down
Shared Game.STUFF
Shared Balloon()
Shared Sound()
;
ExamineMouse()
Game\Mx = MouseX()
Game\My = MouseY()
LMB = MouseButton(#PB_MouseButton_Left)
RMB = MouseButton(#PB_MouseButton_Right)
;
If ((Not LMB) And (Not RMB))
  LMB_Down=#False : RMB_Down=#False
  ProcedureReturn
EndIf
If ((LMB) And (LMB_Down)) : ProcedureReturn 
  Else : LMB_Down=#True
EndIf
If ((RMB) And (RMB_Down)) : ProcedureReturn 
  Else : RMB_Down=#True
EndIf 
;
If ((LMB) And (Game\Ammo))
  ForEach Balloon()
    If ((Game\Mx >=Balloon()\X) And (Game\Mx <=(Balloon()\X+#BALLOON_W)))
      If ((Game\My >=Balloon()\Y) And (Game\My <=(Balloon()\Y+#BALLOON_H)))
        If (Balloon()\Special)
          Game\Points-(10*Game\Accelerator+10)
          TextControl(Balloon()\Special)
        EndIf
        DeleteElement(Balloon())  : AddElement(Sound())
        Sound()=#SFX_BALLOON_BANG : Game\Points+10
      EndIf  
    EndIf
  Next
  AddElement(Sound()) : Sound()=#SFX_GUN_SHOT   : Game\Ammo-1
ElseIf ((RMB) And (Not Game\Ammo))
  AddElement(Sound()) : Sound()=#SFX_GUN_RELOAD : Game\Ammo=5
  If (Not Game\Complete) : Game\Points+5 : EndIf
EndIf
;
If (Game\Points<0) : Game\Points=0 : EndIf
Select Game\Points
  Case    0 To  250 : Game\Accelerator = 2
  Case  251 To  500 : Game\Accelerator = 3 
  Case  501 To 1500 : Game\Accelerator = 4
  Case 1501 To 3500 : Game\Accelerator = 5
  Default           : Game\Accelerator = 6  
EndSelect
;
EndProcedure
;
Procedure SoundControl()
Shared Game.STUFF
Shared Sound()
;
If (Not Game\NoSound)
  ForEach Sound()
    If (Sound() = #SFX_BALLOON_BANG)
      SoundVolume(Sound(),Random(50)+50)
    EndIf
    PlaySound(Sound(),#PB_Sound_MultiChannel)
    DeleteElement(Sound())
  Next
Else
  ClearList(Sound())  
EndIf  
EndProcedure
;
Procedure Display()
Static.i Loop
Shared Game.STUFF
Shared Balloon()
;
DisplaySprite(#SPR_BG,0,0)
;
If (Not Game\Complete)
  If (LastElement(Balloon()))
    If (Balloon()\Y < #WIN_H-(#BALLOON_H+Random(30)+10)) : Balloon_New() : EndIf
  Else
    Balloon_Add(Random(#WIN_W-#BALLOON_W))
  EndIf
EndIf    
;
ForEach Balloon()
  DisplayTransparentSprite(Balloon()\Sprite+#SPR_BALLOON,Balloon()\X,Balloon()\Y)
  Balloon()\Y - Balloon()\Speed
  If (Balloon()\Y < -#BALLOON_H) : DeleteElement(Balloon()) : EndIf
Next
;
If (Game\Ammo)
  For Loop=(5-Game\Ammo) To 4 
    DisplayTransparentSprite(#SPR_AMMO,Game\Belt[Loop]\x,Game\Belt[Loop]\y)
  Next
EndIf    
;
StartDrawing(ScreenOutput())
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(Game\PointFontID)
  DrawText(0,0,Str(Game\Points),RGB(200,200,200))
StopDrawing()
;
DisplayTransparentSprite(#SPR_CROSS,Game\Mx-10,Game\My-10)
EndProcedure
;
Procedure Init()
Shared Game.STUFF
;
If (Not InitSprite())   : Error(#ERR_DX) : EndIf
If (Not InitKeyboard()) : Error(#ERR_DX) : EndIf
If (Not InitMouse())    : Error(#ERR_DX) : EndIf
If (Not InitSound())    : Error(#ERR_DX) : EndIf
OpenWindow(#WIN,0,0,#WIN_W,#WIN_H,#WIN_T,#WIN_F)
If (Not OpenWindowedScreen(WindowID(#WIN),0,0,#WIN_W,#WIN_H,0,0,0)) : Error(#ERR_SCREEN) : EndIf
TransparentSpriteColor(#PB_Default,RGB(255,0,255))
If (Not LoadFont(#FONT,#FONTNAME$,20)) : Error(#ERR_FONT) : EndIf
If (Not LoadFont(#FONT+1,#FONTNAME$,30,#PB_Font_Bold)) : Error(#ERR_FONT) : EndIf
Game\PointFontID = FontID(#FONT)
Game\TextFontID  = FontID(#FONT+1)
StartDrawing(ScreenOutput())
  DrawingFont(Game\TextFontID)
  If (TextWidth(#LINE_1) > #WIN_W) : Error(#ERR_TEXT_1) : EndIf
  If (TextWidth(#LINE_2) > #WIN_W) : Error(#ERR_TEXT_2) : EndIf
StopDrawing()
;  
If (Not LoadSound(#SFX_GUN_SHOT,#MY_GUN_SHOT))         : Game\NoSound=#True : EndIf
If (Not LoadSound(#SFX_GUN_RELOAD,#MY_GUN_RELOAD))     : Game\NoSound=#True : EndIf
If (Not LoadSound(#SFX_BALLOON_BANG,#MY_BALLOON_BANG)) : Game\NoSound=#True : EndIf
If (Not LoadSound(#SFX_APPLAUSE,#MY_APPLAUSE))         : Game\NoSound=#True : EndIf
;
Game\Accelerator = 1
Game\Ammo = 5
Game\Belt[0]\x = #WIN_W-100
Game\Belt[0]\y =  10
Game\Belt[1]\x = #WIN_W-80
Game\Belt[1]\y =  10
Game\Belt[2]\x = #WIN_W-60
Game\Belt[2]\y =  10
Game\Belt[3]\x = #WIN_W-40
Game\Belt[3]\y =  10
Game\Belt[4]\x = #WIN_W-20
Game\Belt[4]\y =  10
;
Create_TextList()
;
If (Not Create_Crosshair())  : Error(#ERR_GFX) : EndIf
If (Not Create_Ammunition()) : Error(#ERR_GFX) : EndIf
If (Not Create_Background()) : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON,   RGB(0,0,200)))    : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+1, RGB(0,200,0)))    : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+2, RGB(200,0,0)))    : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+3, RGB(200,0,200)))  : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+4, RGB(200,200,0)))  : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+5, RGB(0,200,200)))  : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+6, RGB(200,100,50))) : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+7, RGB(100,200,50))) : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+8, RGB(50,100,200))) : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+9, RGB(50,200,100))) : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+10,RGB(100,50,200))) : Error(#ERR_GFX) : EndIf
If (Not Balloon_Create(#SPR_BALLOON+11,RGB(200,50,100))) : Error(#ERR_GFX) : EndIf
;
RandomSeed(ElapsedMilliseconds())
ReleaseMouse(#False)
MouseLocate(#WIN_W/2,#WIN_H/2)
Balloon_New()
EndProcedure
;-
Procedure Mainloop()
Shared Game.STUFF
;
Repeat
  Game\Timer = ElapsedMilliseconds()
  While WindowEvent() : Wend
  KeyControl()
  MouseControl()
  SoundControl()
  Display()
  FlipBuffers()
  Game\Timewaste = ElapsedMilliseconds()-Game\Timer
  If (Game\Timewaste < #FPS_LIMIT) : Delay(#FPS_LIMIT-Game\Timewaste) : EndIf
Until Game\Quit
;
EndProcedure
;
Init()
Mainloop()
End
;   

Bye.
Benutzeravatar
RSBasic
Admin
Beiträge: 8022
Registriert: 05.10.2006 18:55
Wohnort: Gernsbach
Kontaktdaten:

Re: Pure GameCard

Beitrag von RSBasic »

:allright:
Aus privaten Gründen habe ich leider nicht mehr so viel Zeit wie früher. Bitte habt Verständnis dafür.
Bild
Bild
Benutzeravatar
kapege
Beiträge: 39
Registriert: 28.12.2004 17:35
Computerausstattung: AMD Ryzen 7 3700X 8-Core Processor 3.60 GHz
Windows 10 Pro 64bit
14 GB Ram

PureBasic 6.00 LTS (Windows - x64)
Wohnort: Trostberg

Re: Pure GameCard

Beitrag von kapege »

:allright:

funktioniert auch unter win7 64bit mit PB 4.60 x64 kompiliert.

sehr schönes Spiel und sauberer Code (meine Meinung)

LG Peter
Antworten