2009-01-29 00:18:34 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
# You can notice that here we use PySFML.sf instead of just PySFML
|
|
|
|
# Therefore it won't be needed to put sf. in front of SFML classes
|
|
|
|
|
2009-12-07 19:53:38 +08:00
|
|
|
from PySFML import sf
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
def Main():
|
2009-12-07 19:53:38 +08:00
|
|
|
Buffer = sf.SoundBuffer()
|
2009-01-29 00:18:34 +08:00
|
|
|
if not Buffer.LoadFromFile("data/fart.wav"): # Loads the sound
|
|
|
|
return
|
2009-12-07 19:53:38 +08:00
|
|
|
Fart = sf.Sound(Buffer, False)
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
WindowWidth, WindowHeight = 640, 480
|
2009-12-07 19:53:38 +08:00
|
|
|
App = sf.RenderWindow(sf.VideoMode(WindowWidth,WindowHeight,32), "Sound with PySFML", sf.Style.Close, sf.ContextSettings(24,8,0))
|
2009-01-29 00:18:34 +08:00
|
|
|
App.SetFramerateLimit(30)
|
|
|
|
|
2009-12-07 19:53:38 +08:00
|
|
|
EventHandler = sf.Event()
|
2009-01-29 00:18:34 +08:00
|
|
|
InputHandler = App.GetInput()
|
|
|
|
|
2009-12-07 19:53:38 +08:00
|
|
|
Text = sf.Text("Turn the sound on.\nClick anywhere on the screen.\nMove the mouse. Click again.\nTry clicking in the corners.")
|
2009-01-29 00:18:34 +08:00
|
|
|
Text.SetX(30.)
|
|
|
|
Text.SetY(20.)
|
2009-12-07 19:53:38 +08:00
|
|
|
Text.SetColor(sf.Color(150, 100, 10, 255))
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
while App.IsOpened(): # Main loop
|
|
|
|
while App.GetEvent(EventHandler): # Event Handler
|
2009-12-07 19:53:38 +08:00
|
|
|
if EventHandler.Type == sf.Event.Closed:
|
2009-01-29 00:18:34 +08:00
|
|
|
App.Close()
|
2009-12-07 19:53:38 +08:00
|
|
|
if EventHandler.Type == sf.Event.KeyPressed and EventHandler.Key.Code == sf.Key.Escape:
|
2009-01-29 00:18:34 +08:00
|
|
|
App.Close()
|
2009-12-07 19:53:38 +08:00
|
|
|
if EventHandler.Type == sf.Event.MouseButtonPressed and EventHandler.MouseButton.Button == sf.Mouse.Left:
|
2009-01-29 00:18:34 +08:00
|
|
|
Fart.SetPitch(1.5 - 1.*InputHandler.GetMouseY()/WindowHeight)
|
|
|
|
Fart.SetPosition( 1.*(InputHandler.GetMouseX() - WindowWidth/2)/(WindowWidth/20), 2., -2.)
|
|
|
|
Fart.Play()
|
|
|
|
App.Draw(Text)
|
|
|
|
App.Display()
|
2009-12-07 19:53:38 +08:00
|
|
|
App.Clear(sf.Color.Black)
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
Main()
|
|
|
|
|