<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,4 @@
-Copyright (c) 2008 Stephen Paul Weber.
+Copyright (c) 2008 Stephen Paul Weber, Christopher Vollick.
 
 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation</diff>
      <filename>COPYING</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 $LOAD_PATH &lt;&lt; File.dirname(__FILE__) + '/../lib/'
 require 'xgame'
 
-XGame('Two Pandas!') { |screen, background, world, listeners|
+XGame('Two Pandas!') { |screen, world, listeners|
 
 	class Panda &lt; Rubygame::Sprites::ChipmunkPhysicsSprite
 		def default_image; Rubygame::Surface['panda.png']; end;
@@ -40,6 +40,9 @@ XGame('Two Pandas!') { |screen, background, world, listeners|
 	world.bound(screen, [:top, :bottom, :left, :right]) # Keep sprites on the screen
 	world.damping = 0.5 # Set up basic air resistance
 	world.gravity = 100 # Set a gravity constant
+	
+	#Set the background
+	Rubygame::Surface['xback.png'].zoom_to(screen.width, screen.height).blit(world.background, [0, 0])
 
 	# Instantiate sprites and push them onto the world
 </diff>
      <filename>examples/2panda</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 $LOAD_PATH &lt;&lt; File.dirname(__FILE__) + '/../lib/'
 require 'xgame'
 
-XGame('The Panda') { |screen, background, world, listeners|
+XGame('The Panda') { |screen, world, listeners|
 
 	# Set up the world
 	world.extend(Rubygame::Sprites::ChipmunkPhysicsSpaceGroup) # The world has physics
@@ -12,11 +12,7 @@ XGame('The Panda') { |screen, background, world, listeners|
 	world.gravity = 100 # Set a gravity constant
 	
 	#Set the background
-	world.background=Rubygame::Surface[&quot;xback.png&quot;].zoom_to(screen.size[0],screen.size[1])
-
-	unless world.background
-		puts &quot;PROBLEM WITH IMAGE&quot;
-	end
+	Rubygame::Surface['xback.png'].zoom_to(screen.width, screen.height).blit(world.background, [0, 0])
 
 	# Create a sprite and push it into the world
 	# It's important to have the world set up *before* you do this</diff>
      <filename>examples/panda</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 $LOAD_PATH &lt;&lt; File.dirname(__FILE__) + '/../lib/'
 require 'xgame'
 
-XGame('Spider Panda') { |screen, background, world, listeners|
+XGame('Spider Panda') { |screen, world, listeners|
 
 	class Panda &lt; Rubygame::Sprites::ChipmunkPhysicsSprite
 </diff>
      <filename>examples/spiderpanda</filename>
    </modified>
    <modified>
      <diff>@@ -66,8 +66,9 @@ module Rubygame
 
 	# This class defines an easy way to manage callbacks
 	class ListenerList &lt; Hash
-		def world=(w)
-			@world = w
+		def initialize(world=nil)
+			super()
+			@world = world
 		end
 
 		def addEventListener(event, callback=nil, &amp;block)
@@ -323,6 +324,24 @@ module Rubygame
 
 		end # ChipmunkPhysicsSpaceGroup
 
+		module BackgroundGroup
+			attr_reader :background
+
+			def initialize(size)
+				super()
+				@background = Rubygame::Surface.new(size)
+			end
+
+			def draw_background_onto(screen)
+				@background.blit(screen, [0, 0])
+				screen.update
+			end
+
+			def undraw(screen)
+				super(screen, @background)
+			end
+		end
+
 	end # module Sprites
 
 	# Default rubygame clock sucks the CPU. We can do better.
@@ -344,12 +363,18 @@ end # module Rubygame
 module XGame
 	# NOTE: Remember to update this in ./configure as well as xgame.gemspec
 	VERSION = [0,1,0] # MAJOR, MINOR, PATCH
+
+	class World &lt; Rubygame::Sprites::Group
+		include Rubygame::Sprites::UpdateGroup # The world can undraw and draw its Sprites
+		include Rubygame::Sprites::DepthSortGroup # Let them get in front of each other
+		include Rubygame::Sprites::BackgroundGroup # Let there be a background
+	end
 end
 
 # This method is the heart of XGame. Call it with a block that sets up your program.
 def XGame(title = 'XGame', size = [], frametime = 15, ignore_events = [], &amp;block)
 
-	Rubygame.init() # Set stuff up
+	Rubygame::init # Set stuff up
 
 	if Rubygame::Screen.respond_to?(:get_resolution)
 		size[0] = Rubygame::Screen.get_resolution[0] unless size[0]
@@ -360,64 +385,51 @@ def XGame(title = 'XGame', size = [], frametime = 15, ignore_events = [], &amp;block
 	end
 
 	# The events queue gets filled up with all user input into our window
-	events = Rubygame::EventQueue.new()
+	events = Rubygame::EventQueue.new
 	events.ignore = ignore_events # Let's save cycles by ignoring events of some types
 
 	# The clock keeps us from eating the CPU
-	clock = Rubygame::Clock.new()
+	clock = Rubygame::Clock.new
 	clock.target_frametime = frametime # Let's aim to render at some framerate
 
-	# Set up autoloading for Surfaces. Surfaces will be loaded automatically the first time you use Surface[&quot;filename&quot;].
+	# Set up autoloading for Surfaces. Surfaces will be loaded automatically the first time you use Rubygame::Surface[&quot;filename&quot;].
 	Rubygame::Surface.autoload_dirs = [ File.dirname($0) ] # XXX: this should include other paths depending on the platform
 
-	# Create a world for sprites to live in
-	#world = Rubygame::Sprites::Group.new
-	world= ImageSpriteGroup.new
-
-	background=Rubygame::Surface.new(size)
-	world.background=background
-
-	#world.extend(Rubygame::Sprites::UpdateGroup) # The world can undraw and draw its Sprites
-	#world.extend(Rubygame::Sprites::DepthSortGroup) # Let them get in front of each other
-
 	# Grab the screen and create a background
 	screen = Rubygame::Screen.new(size, 0, [Rubygame::HWSURFACE, Rubygame::NOFRAME])
 	screen.title = title # Set the window title
-	#background = Rubygame::Surface.new(screen.size)
-
+	
+	# Create a world for sprites to live in
+	world = XGame::World.new(screen.size)
+	
 	# This is where event handlers will get stored
-	listeners = Rubygame::ListenerList.new
-	listeners.world = world
+	listeners = Rubygame::ListenerList.new(world)
 
 	# Include the user code
-	yield screen, background, world, listeners
+	yield screen, world, listeners
 
 	# Reset jumps when landing on walls
 	listeners.addEventListener(Rubygame::CollisionEvent.new(:wall)) { |by, to|
 		to.reset_jumps if to.respond_to?:reset_jumps
 	}
 
-	#Update the background
-	background=world.background
-
-	background.blit(screen,screen.size)
-
-	# Refresh the screen once. During the loop, we'll use 'dirty rect' updating
+	# Draw background and Refresh the screen once.
+	# During the loop, we'll use 'dirty rect' updating
 	# to refresh only the parts of the screen that have changed.
-	screen.update()
+	world.draw_background_onto screen
 
 	catch(:quit) do
 		loop do
 
-			world.undraw(screen, background)
+			world.undraw screen
 
-			events.push Rubygame::LoopEvent.new
+			events &lt;&lt; Rubygame::LoopEvent.new
 			events.each do |event|
 				case event
 				when Rubygame::ActiveEvent
 					# ActiveEvent appears when the window gains or loses focus.
 					# This helps to ensure everything is refreshed after the Rubygame window has been covered up by a different window.
-					screen.update()
+					screen.update
 				when Rubygame::QuitEvent
 					# QuitEvent appears when the user closes the window, or otherwise signals they wish to quit
 					throw :quit
@@ -434,45 +446,6 @@ def XGame(title = 'XGame', size = [], frametime = 15, ignore_events = [], &amp;block
 	end
 
 	puts &quot;#{title} is Quitting!&quot;
-	Rubygame.quit()
+	Rubygame.quit
 
 end #XGame
-
-class ImageSpriteGroup &lt; Rubygame::Sprites::Group
-	attr_accessor :background
-	include Rubygame::Sprites::UpdateGroup
-	include Rubygame::Sprites::DepthSortGroup
-
-	alias :spriteDraw :draw
-	alias :spriteUnDraw :undraw
-
-	def draw(dest)
-		#self.background.blit(dest,[0,0])
-		spriteDraw(dest)
-	end
-
-	def undraw(dest, bg)
-			self.background.blit(dest,[0,0])
-	end
-end
-
-#This mix-in module is for sprites that are in a moving world.
-#Their screen co-ordinates and their world co-ordinates will be different
-module RelativeSprite
-	#This version of draw takes in an offset that represents the position of the world
-	def draw(dest,offset)
-		rect[0]-=offset[0];
-		rect[1]-=offset[1];
-		draw(dest);
-		rect[0]+=offset[0];
-		rect[1]+=offset[1];
-	end
-	#This is the counterpart to the new draw
-	def undraw(dest,background,offset)
-		rect[0]-=offset[0];
-		rect[1]-=offset[1];
-		undraw(dest);
-		rect[0]+=offset[0];
-		rect[1]+=offset[1];
-	end
-end</diff>
      <filename>lib/xgame.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,12 +8,12 @@ puts 'XGame loaded'
 
 puts 'Running XGame. If it does not close automatically, event handlers are broken.'
 
-XGame('TITLE', [1,1], 20) { |screen, background, world, listeners|
+XGame('TITLE', [1, 1], 20) { |screen, world, listeners|
 	puts 'In XGame'
 
 	raise 'Screen title is set wrong' unless screen.title == 'TITLE'
 	raise 'Screen size is set wrong' unless screen.height == 1 and screen.width == 1
-	raise 'Background is of wrong type' unless background.is_a?Rubygame::Surface
+	raise &quot;Bad type for Background: #{world.background.class}&quot; unless world.background.is_a?Rubygame::Surface 
 
 	# This should work, the image should load, etc
 	world.push Rubygame::Sprites::ImageSprite.new(0,0,'panda.png')
@@ -24,7 +24,7 @@ XGame('TITLE', [1,1], 20) { |screen, background, world, listeners|
 	world.damping = 0.5 # Set up basic air resistance
 	world.gravity = 100 # Set a gravity constant
 
-	panda = Rubygame::Sprites::ChipmunkPhysicsSprite.new(10, screen.height-60, 5, CP::INFINITY, 'panda.png')
+	panda = Rubygame::Sprites::ChipmunkPhysicsSprite.new(0, 0, 5, CP::INFINITY, 'panda.png')
 	world.push panda
 	world.each { |sprite| sprite.go([10,10]) if sprite.respond_to?:go }
 	panda.stop(:up)</diff>
      <filename>tests/xgame_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8dd475df6294dfe9bc45d57ffb8529f1b3e8a409</id>
    </parent>
  </parents>
  <author>
    <name>Christopher Vollick</name>
    <email>psycotica0@gmail.com</email>
  </author>
  <url>http://github.com/singpolyma/xgame/commit/d4c429609128f24ed5b956402f261be0235b0535</url>
  <id>d4c429609128f24ed5b956402f261be0235b0535</id>
  <committed-date>2008-11-25T19:46:11-08:00</committed-date>
  <authored-date>2008-11-25T19:46:11-08:00</authored-date>
  <message>Backgrounds

Stephen and I have repaired backgrounds such that they function.

A lot of code was restructured, and it ended up being much cleaner.
The background variable is no longer passed in to xGame, but is included in world.

The ImageSpriteGroup was removed and the BackgroundGroup module was added in its place.

A World class was created that is to contain everything that makes an xGame world.

The examples were all updated to reflect this new interface.
Some even have backgrounds.</message>
  <tree>36e8022ada24babcbca937705562fc211da5afa7</tree>
  <committer>
    <name>Christopher Vollick</name>
    <email>psycotica0@gmail.com</email>
  </committer>
</commit>
