SlideShare a Scribd company logo
Game Programming with Groovy James Williams  @ecspike Sr. Software Engineer, BT/Ribbit
About Me Sr. Software Engineer at BT/Ribbit Co-creator of Griffon, a desktop framework for Swing using Groovy Contributer to several open source projects Blogger and aspiring writer
About Ribbit Based in Mountain View, California, USA Subsidiary of British Telecom (BT) Provides a programmable telephony API Products and services include: Ribbit Mobile Ribbit for Salesforce Ribbit for Oracle CRM
Agenda What is Groovy? Why Groovy for Gaming? What games are good for Groovy? Game Loop Enhancing Java Applications/Tooling User Input Alternative Controllers Connecting users
What is Groovy? Dynamically typed language for the JVM Superset of Java Inspired by Python, Ruby, and Smalltak Was designed for Java developers in mind Integrates seamlessless with Java objects and libraries
Why Groovy for Gaming? reduces the amount of code  can use Domain Specific Languages to provide fluent APIs provides robust libraries for reading/writing from XML all your Java code just works
Types of games are good for Groovy Turn-based games Side-scrollers Card games Simple arcade classics from the old days 
Gaming in Java JavaMonkeyEngine (JME) Supports JOGL and LWJGL   Full stack providing sound, graphics, and input Lightweight Java Graphics Library Exposes OpenGL, OpenAL, as well as input controller support JOGL JOAL JInput
Slick Provides a simple 2D API over LWJGL Enables Webstart distribution without the drama Extensible framework Helps with rendering, sound, and collision detection but doesn't overpower Doesn't lock you in
Is it fast enough? Yes! Bubblemark capped at 80fps runs @ 12% CPU utilization Uncapped it devours 90% CPU for 840-1100 fps
BasicGame Self-contained instance of a game Implements init update render   Great for single frame games
BasicGame example public class SimpleGame extends BasicGame{      public SimpleGame() { super("SimpleGame"); }        @Override      public void init(GameContainer gc) throws SlickException {  }        @Override      public void update(GameContainer gc, int delta) throws SlickException{  }        public void render(GameContainer gc, Graphics g) throws SlickException{ }        public static void main(args) throws SlickException {           def app = new AppGameContainer(new SimpleGame())           app.setDisplayMode 800, 600, false           app.start()      } }
GameState Useful when there are multiple states like start screen, credits, levels, etc Sort of MVC for games Allows you to decouple your code Supports using visual transitions to move between states 
Making things move Frame independent movement Calculates based on delta time Same experience on slow and fast computers Built into Slick @Override public void update(GameContainer gc, int delta)                throws SlickException {  }
Bubblemark Demo
Tilemaps Think Legend of Zelda for the NES series of images arranged in a grid format can be of arbitrary size and layer multiple levels Slick supports TileD for import ( http://www.mapeditor.org/ )
Images Support via ImageIO for: PNG JPG GIF TGA support via a pure Java loader Image img =  new   Image ("res/myimage.png");  
Sounds and Music SoundFX Supports WAV and OGG Non-spatial sounds         def fx = new Sound("resources/scream.wav")         fx.play()         //or fx.play(1.0f, 0.5f) to set volume and pitch Spatial sounds         fx.playAt(-1, 0, 0) Music Supports WAV, OGG, and MOD/XM tracks         def music = new Music("resources/coolThemeSong.ogg")         music.loop()
Input Handlers uses Input class and builds on the existing LWJGL support Retrieving input: can be polled just as in LWJGL can register InputListeners to handle notifications BasicGame has convenience methods for keyboard, mouse, and controller input
Bluetooth Support on Java (Bluecove) Apache 2 Licensed Implementation of JSR 82 Linux version requires GPL library http://code.google.com/p/bluecove/  
Nintendo Wiimote Controller for Nintendo's Wii console Uses Bluetooth for communication IR Camera X, Y, Z accelerometer Can use IR triangulation to determine distance Can use IR to derive roll, pitch, and yaw
Using the Wiimote with Groovy(Java) Motej ( http://motej.sourceforge.net/ ) pure Java / no native C libs Supports Wiimote Nunchuk Balance Board Classic Controller wiiusej ( http://code.google.com/p/wiiusej/ ) wiimote-simple ( http://code.google.com/p/wiimote-simple/ )
Motej setup Install Bluetooth native libs Install Bluecove JSR 82 libs Linux: requires an extra bluecove-gpl jar OSX SL: needs to compile from src unless using 32-bit JVM On the application classpath, include: motej-0.9 bluecove jars   slf4j-api-1.5.8 slf4j-simple-1.5.8
Motej Sample def listener = [moteFound:{Mote mote->      System.out.println("Found mote: " + mote.getBluetoothAddress())      mote.setPlayerLeds([false, true, false, true] as boolean[])      mote.rumble(2000l)      motes.add(mote) }]                  MoteFinder finder = MoteFinder.getMoteFinder() finder.addMoteFinderListener(listener)                  finder.startDiscovery() Thread.sleep(30000l) finder.stopDiscovery()
Wiimote Demo
How the Pitcher Demo works On button press, the app starts tracking the X motion with slight filtering On button release, the app stops tracking X motion The change in X over time is used to calculate acceleration The X acceleration is used with the distance from the plate to calculate the speed*
Deployment Applets Can be done but can be flaky Operates in a sandbox Webstart Can have full rights for the system Simple deployment updates Slick/lwjgl jnlp targets to auto-include native files
Scripting (JSR 223) Exposes third-party script engines to be embedded in Java apps Script Engines available for: Java/BeanShell Groovy Javascript JRuby Jython et al
Scripting API Example def factory = new ScriptEngineManager();  def engine = factory.getEngineByName("groovy");  // basic example  println(engine.eval("(1..10).sum()"));  // example showing scripting variables  engine.put("first", "HELLO");  engine.put("second", "world"); println(engine.eval("first.toLowerCase() + second.toUpperCase()"));
JSR 223 Demo
Connecting with users (Red Dwarf) open source fork of Project Darkstar built to support all the features needed for a MMOG Provides: persistent data storage transactions channel communications cpu load balancing Client drivers exist in Java, C#, and Python
Questions?
Links LWJGL:  http://lwjgl.org JME:  http://www.jmonkeyengine.com JOGL: https://jogl.dev.java.net/ JOAL: https://joal.dev.java.net/ JInput: https://jinput.dev.java.net/ Slick:  http://slick.cokeandcode.com Red Dwarf:  http://www.reddwarfserver.org/ Source code for all apps: http://github.com/jwill/geecon-demos

More Related Content

PDF
Introduction to Game programming with PyGame Part 1
PDF
PyGame Tutorial | PyGame Python Tutorial For Beginners | Python Certification...
PPT
Programming simple games with a raspberry pi and
PPTX
Pandaboard
PPTX
Panda board
PDF
RMOUG QEW Family Coding Event- Raspberry PI
PPTX
JCrete Embedded Java Workshop
PDF
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Introduction to Game programming with PyGame Part 1
PyGame Tutorial | PyGame Python Tutorial For Beginners | Python Certification...
Programming simple games with a raspberry pi and
Pandaboard
Panda board
RMOUG QEW Family Coding Event- Raspberry PI
JCrete Embedded Java Workshop
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)

What's hot (20)

PDF
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
PDF
Stupid Video Tricks, CocoaConf Las Vegas
PDF
Stupid Video Tricks, CocoaConf Seattle 2014
PDF
Stupid Video Tricks
PPT
Data Driven Game development
PPTX
Optimizing mobile applications - Ian Dundore, Mark Harkness
ODP
Fedora 14 overview
PDF
How to Hack Edison
PDF
Embedded Objective-C
PDF
Introduction to the Roku SDK
PPTX
RetroPi Handheld Raspberry Pi Gaming Console
PDF
Stupid Video Tricks (CocoaConf DC, March 2014)
PPTX
Java on Raspberry Pi Lab
PDF
Building Modern Audio Apps with AVAudioEngine
PDF
【Unite Tokyo 2018】“100 Must-see Assets for 2018” by Virtual YouTuber, Cyber G...
PDF
Get On The Audiobus (CocoaConf Atlanta, November 2013)
PDF
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
PPTX
Devoxx4Kids Lego Workshop
PPTX
Oracle IoT Kids Workshop
PDF
Composing and Editing Media with AV Foundation
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Stupid Video Tricks, CocoaConf Las Vegas
Stupid Video Tricks, CocoaConf Seattle 2014
Stupid Video Tricks
Data Driven Game development
Optimizing mobile applications - Ian Dundore, Mark Harkness
Fedora 14 overview
How to Hack Edison
Embedded Objective-C
Introduction to the Roku SDK
RetroPi Handheld Raspberry Pi Gaming Console
Stupid Video Tricks (CocoaConf DC, March 2014)
Java on Raspberry Pi Lab
Building Modern Audio Apps with AVAudioEngine
【Unite Tokyo 2018】“100 Must-see Assets for 2018” by Virtual YouTuber, Cyber G...
Get On The Audiobus (CocoaConf Atlanta, November 2013)
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Devoxx4Kids Lego Workshop
Oracle IoT Kids Workshop
Composing and Editing Media with AV Foundation
Ad

Similar to Game programming with Groovy (20)

PDF
Introduction to android (and mobile) game development
PDF
Android game engine
PDF
LibGDX: Cross Platform Game Development
PDF
BeJUG JavaFx In Practice
PPTX
Introduction to Game Engine: Concepts & Components
PDF
Game software development trends presentation
PPT
Griffon - Making Swing Fun Again
PDF
Useful Tools for Making Video Games - Irrlicht (2008)
PPT
A Taste of Java ME
DOCX
Funky game engines
PPTX
Developing Multi Platform Games using PlayN and TriplePlay Framework
PDF
Mono for Game Developers - AltDevConf 2012
PPTX
PRESENTATION ON Game Engine
PDF
Introduction to 2D Game Development on Nokia Series 40 Asha Phones
PPTX
XNA Intro Workshop
PDF
Introduction to Box2D Physics Engine
PDF
Google kick ass-game_programming_with_gwt
PPT
MIDP: Game API
PPT
Gdc09 Minigames
PDF
How to build Kick Ass Games in the Cloud
Introduction to android (and mobile) game development
Android game engine
LibGDX: Cross Platform Game Development
BeJUG JavaFx In Practice
Introduction to Game Engine: Concepts & Components
Game software development trends presentation
Griffon - Making Swing Fun Again
Useful Tools for Making Video Games - Irrlicht (2008)
A Taste of Java ME
Funky game engines
Developing Multi Platform Games using PlayN and TriplePlay Framework
Mono for Game Developers - AltDevConf 2012
PRESENTATION ON Game Engine
Introduction to 2D Game Development on Nokia Series 40 Asha Phones
XNA Intro Workshop
Introduction to Box2D Physics Engine
Google kick ass-game_programming_with_gwt
MIDP: Game API
Gdc09 Minigames
How to build Kick Ass Games in the Cloud
Ad

More from James Williams (17)

KEY
Introduction to WebGL and Three.js
PDF
Intro to HTML5 Game Programming
PPT
Ratpack - Classy and Compact Groovy Web Apps
PDF
Introduction to Griffon
PDF
Griffon for the Enterprise
PDF
Java development with MongoDB
PDF
Enterprise Griffon
PDF
Porting legacy apps to Griffon
PPT
Using MongoDB With Groovy
PDF
Creating Voice Powered Apps with Ribbit
PDF
Griffon: Swing just got fun again
PPT
Griffon: Swing just got fun again
PPT
Extending Groovys Swing User Interface in Builder to Build Richer Applications
PPT
Boosting Your Testing Productivity with Groovy
ODP
Griffon: Re-imaging Desktop Java Technology
ODP
Android Development
ODP
SVCC Intro to Grails
Introduction to WebGL and Three.js
Intro to HTML5 Game Programming
Ratpack - Classy and Compact Groovy Web Apps
Introduction to Griffon
Griffon for the Enterprise
Java development with MongoDB
Enterprise Griffon
Porting legacy apps to Griffon
Using MongoDB With Groovy
Creating Voice Powered Apps with Ribbit
Griffon: Swing just got fun again
Griffon: Swing just got fun again
Extending Groovys Swing User Interface in Builder to Build Richer Applications
Boosting Your Testing Productivity with Groovy
Griffon: Re-imaging Desktop Java Technology
Android Development
SVCC Intro to Grails

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Unlocking AI with Model Context Protocol (MCP)
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Empathic Computing: Creating Shared Understanding
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
Network Security Unit 5.pdf for BCA BBA.
Unlocking AI with Model Context Protocol (MCP)
The AUB Centre for AI in Media Proposal.docx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Encapsulation theory and applications.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
“AI and Expert System Decision Support & Business Intelligence Systems”
20250228 LYD VKU AI Blended-Learning.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Dropbox Q2 2025 Financial Results & Investor Presentation
Empathic Computing: Creating Shared Understanding
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Game programming with Groovy

  • 1. Game Programming with Groovy James Williams  @ecspike Sr. Software Engineer, BT/Ribbit
  • 2. About Me Sr. Software Engineer at BT/Ribbit Co-creator of Griffon, a desktop framework for Swing using Groovy Contributer to several open source projects Blogger and aspiring writer
  • 3. About Ribbit Based in Mountain View, California, USA Subsidiary of British Telecom (BT) Provides a programmable telephony API Products and services include: Ribbit Mobile Ribbit for Salesforce Ribbit for Oracle CRM
  • 4. Agenda What is Groovy? Why Groovy for Gaming? What games are good for Groovy? Game Loop Enhancing Java Applications/Tooling User Input Alternative Controllers Connecting users
  • 5. What is Groovy? Dynamically typed language for the JVM Superset of Java Inspired by Python, Ruby, and Smalltak Was designed for Java developers in mind Integrates seamlessless with Java objects and libraries
  • 6. Why Groovy for Gaming? reduces the amount of code  can use Domain Specific Languages to provide fluent APIs provides robust libraries for reading/writing from XML all your Java code just works
  • 7. Types of games are good for Groovy Turn-based games Side-scrollers Card games Simple arcade classics from the old days 
  • 8. Gaming in Java JavaMonkeyEngine (JME) Supports JOGL and LWJGL   Full stack providing sound, graphics, and input Lightweight Java Graphics Library Exposes OpenGL, OpenAL, as well as input controller support JOGL JOAL JInput
  • 9. Slick Provides a simple 2D API over LWJGL Enables Webstart distribution without the drama Extensible framework Helps with rendering, sound, and collision detection but doesn't overpower Doesn't lock you in
  • 10. Is it fast enough? Yes! Bubblemark capped at 80fps runs @ 12% CPU utilization Uncapped it devours 90% CPU for 840-1100 fps
  • 11. BasicGame Self-contained instance of a game Implements init update render   Great for single frame games
  • 12. BasicGame example public class SimpleGame extends BasicGame{      public SimpleGame() { super("SimpleGame"); }        @Override      public void init(GameContainer gc) throws SlickException {  }        @Override      public void update(GameContainer gc, int delta) throws SlickException{  }        public void render(GameContainer gc, Graphics g) throws SlickException{ }        public static void main(args) throws SlickException {          def app = new AppGameContainer(new SimpleGame())          app.setDisplayMode 800, 600, false          app.start()      } }
  • 13. GameState Useful when there are multiple states like start screen, credits, levels, etc Sort of MVC for games Allows you to decouple your code Supports using visual transitions to move between states 
  • 14. Making things move Frame independent movement Calculates based on delta time Same experience on slow and fast computers Built into Slick @Override public void update(GameContainer gc, int delta)                throws SlickException {  }
  • 16. Tilemaps Think Legend of Zelda for the NES series of images arranged in a grid format can be of arbitrary size and layer multiple levels Slick supports TileD for import ( http://www.mapeditor.org/ )
  • 17. Images Support via ImageIO for: PNG JPG GIF TGA support via a pure Java loader Image img = new Image ("res/myimage.png");  
  • 18. Sounds and Music SoundFX Supports WAV and OGG Non-spatial sounds        def fx = new Sound("resources/scream.wav")        fx.play()        //or fx.play(1.0f, 0.5f) to set volume and pitch Spatial sounds        fx.playAt(-1, 0, 0) Music Supports WAV, OGG, and MOD/XM tracks        def music = new Music("resources/coolThemeSong.ogg")        music.loop()
  • 19. Input Handlers uses Input class and builds on the existing LWJGL support Retrieving input: can be polled just as in LWJGL can register InputListeners to handle notifications BasicGame has convenience methods for keyboard, mouse, and controller input
  • 20. Bluetooth Support on Java (Bluecove) Apache 2 Licensed Implementation of JSR 82 Linux version requires GPL library http://code.google.com/p/bluecove/  
  • 21. Nintendo Wiimote Controller for Nintendo's Wii console Uses Bluetooth for communication IR Camera X, Y, Z accelerometer Can use IR triangulation to determine distance Can use IR to derive roll, pitch, and yaw
  • 22. Using the Wiimote with Groovy(Java) Motej ( http://motej.sourceforge.net/ ) pure Java / no native C libs Supports Wiimote Nunchuk Balance Board Classic Controller wiiusej ( http://code.google.com/p/wiiusej/ ) wiimote-simple ( http://code.google.com/p/wiimote-simple/ )
  • 23. Motej setup Install Bluetooth native libs Install Bluecove JSR 82 libs Linux: requires an extra bluecove-gpl jar OSX SL: needs to compile from src unless using 32-bit JVM On the application classpath, include: motej-0.9 bluecove jars   slf4j-api-1.5.8 slf4j-simple-1.5.8
  • 24. Motej Sample def listener = [moteFound:{Mote mote->      System.out.println("Found mote: " + mote.getBluetoothAddress())      mote.setPlayerLeds([false, true, false, true] as boolean[])      mote.rumble(2000l)      motes.add(mote) }]                  MoteFinder finder = MoteFinder.getMoteFinder() finder.addMoteFinderListener(listener)                  finder.startDiscovery() Thread.sleep(30000l) finder.stopDiscovery()
  • 26. How the Pitcher Demo works On button press, the app starts tracking the X motion with slight filtering On button release, the app stops tracking X motion The change in X over time is used to calculate acceleration The X acceleration is used with the distance from the plate to calculate the speed*
  • 27. Deployment Applets Can be done but can be flaky Operates in a sandbox Webstart Can have full rights for the system Simple deployment updates Slick/lwjgl jnlp targets to auto-include native files
  • 28. Scripting (JSR 223) Exposes third-party script engines to be embedded in Java apps Script Engines available for: Java/BeanShell Groovy Javascript JRuby Jython et al
  • 29. Scripting API Example def factory = new ScriptEngineManager();  def engine = factory.getEngineByName("groovy");  // basic example  println(engine.eval("(1..10).sum()"));  // example showing scripting variables  engine.put("first", "HELLO");  engine.put("second", "world"); println(engine.eval("first.toLowerCase() + second.toUpperCase()"));
  • 31. Connecting with users (Red Dwarf) open source fork of Project Darkstar built to support all the features needed for a MMOG Provides: persistent data storage transactions channel communications cpu load balancing Client drivers exist in Java, C#, and Python
  • 33. Links LWJGL: http://lwjgl.org JME:  http://www.jmonkeyengine.com JOGL: https://jogl.dev.java.net/ JOAL: https://joal.dev.java.net/ JInput: https://jinput.dev.java.net/ Slick:  http://slick.cokeandcode.com Red Dwarf: http://www.reddwarfserver.org/ Source code for all apps: http://github.com/jwill/geecon-demos