Bladeren bron

Started on Lua examples

Ivan Safrin 14 jaren geleden
bovenliggende
commit
c3c534c822
56 gewijzigde bestanden met toevoegingen van 659 en 0 verwijderingen
  1. 28 0
      Examples/Lua/2DAudio/2DAudio.lua
  2. 7 0
      Examples/Lua/2DAudio/2DAudio.xml
  3. BIN
      Examples/Lua/2DAudio/test.wav
  4. 34 0
      Examples/Lua/2DParticles/2DParticles.lua
  5. 7 0
      Examples/Lua/2DParticles/2DParticles.xml
  6. BIN
      Examples/Lua/2DParticles/particle.png
  7. 12 0
      Examples/Lua/2DPhysics_Basic/2DPhysics_Basic.lua
  8. 7 0
      Examples/Lua/2DPhysics_Basic/2DPhysics_Basic.xml
  9. 44 0
      Examples/Lua/2DPhysics_CollisionOnly/2DPhysics_CollisionOnly.lua
  10. 7 0
      Examples/Lua/2DPhysics_CollisionOnly/2DPhysics_CollisionOnly.xml
  11. 34 0
      Examples/Lua/2DPhysics_Contacts/2DPhysics_Contacts.lua
  12. 10 0
      Examples/Lua/2DPhysics_Contacts/2DPhysics_Contacts.xml
  13. BIN
      Examples/Lua/2DPhysics_Contacts/collision.wav
  14. 36 0
      Examples/Lua/2DPhysics_Joints/2DPhysics_Joints.lua
  15. 7 0
      Examples/Lua/2DPhysics_Joints/2DPhysics_Joints.xml
  16. 20 0
      Examples/Lua/2DPhysics_PointCollision/2DPhysics_PointCollision.lua
  17. 7 0
      Examples/Lua/2DPhysics_PointCollision/2DPhysics_PointCollision.xml
  18. 9 0
      Examples/Lua/2DTransforms/2DTransforms.lua
  19. 7 0
      Examples/Lua/2DTransforms/2DTransforms.xml
  20. BIN
      Examples/Lua/2DTransforms/polycode_logo.png
  21. 26 0
      Examples/Lua/3DAudio/3DAudio.lua
  22. 7 0
      Examples/Lua/3DAudio/3DAudio.xml
  23. BIN
      Examples/Lua/3DAudio/test.wav
  24. 13 0
      Examples/Lua/3DBasics/3DBasics.lua
  25. 8 0
      Examples/Lua/3DBasics/3DBasics.xml
  26. BIN
      Examples/Lua/3DBasics/green_texture.png
  27. BIN
      Examples/Lua/3DBasics/pink_texture.png
  28. 50 0
      Examples/Lua/AdvancedLighting/AdvancedLighting.lua
  29. 7 0
      Examples/Lua/AdvancedLighting/AdvancedLighting.xml
  30. 26 0
      Examples/Lua/AdvancedLighting/Resources/example.mat
  31. BIN
      Examples/Lua/AdvancedLighting/Resources/green_texture.png
  32. BIN
      Examples/Lua/AdvancedLighting/Resources/pink_texture.png
  33. 3 0
      Examples/Lua/BasicImage/BasicImage.lua
  34. 7 0
      Examples/Lua/BasicImage/BasicImage.xml
  35. BIN
      Examples/Lua/BasicImage/polycode_logo.png
  36. 18 0
      Examples/Lua/BasicLighting/BasicLighting.lua
  37. 7 0
      Examples/Lua/BasicLighting/BasicLighting.xml
  38. 26 0
      Examples/Lua/BasicLighting/Resources/example.mat
  39. BIN
      Examples/Lua/BasicLighting/Resources/green_texture.png
  40. BIN
      Examples/Lua/BasicLighting/Resources/pink_texture.png
  41. 3 0
      Examples/Lua/BasicText/BasicText.lua
  42. 4 0
      Examples/Lua/BasicText/BasicText.xml
  43. 22 0
      Examples/Lua/EventHandling/EventHandling.lua
  44. 7 0
      Examples/Lua/EventHandling/EventHandling.xml
  45. BIN
      Examples/Lua/EventHandling/polycode_logo.png
  46. 46 0
      Examples/Lua/KeyboardInput/KeyboardInput.lua
  47. 7 0
      Examples/Lua/KeyboardInput/KeyboardInput.xml
  48. BIN
      Examples/Lua/KeyboardInput/polycode_logo.png
  49. 33 0
      Examples/Lua/MouseInput/MouseInput.lua
  50. 7 0
      Examples/Lua/MouseInput/MouseInput.xml
  51. BIN
      Examples/Lua/MouseInput/polycode_logo.png
  52. 17 0
      Examples/Lua/PlayingSounds/PlayingSounds.lua
  53. 7 0
      Examples/Lua/PlayingSounds/PlayingSounds.xml
  54. BIN
      Examples/Lua/PlayingSounds/test.wav
  55. 28 0
      Examples/Lua/ScreenEntities/ScreenEntities.lua
  56. 4 0
      Examples/Lua/ScreenEntities/ScreenEntities.xml

+ 28 - 0
Examples/Lua/2DAudio/2DAudio.lua

@@ -0,0 +1,28 @@
+screen = Screen()
+
+sourceEntity = ScreenEntity()
+testSound = ScreenSound("test.wav", 200, 600)
+testSound:getSound():Play(true)
+sourceEntity:addChild(testSound)
+soundShape = ScreenShape(SHAPE_CIRCLE, 20,20,10)
+sourceEntity:addChild(soundShape)
+screen:addChild(sourceEntity)
+
+listenerEntity = ScreenEntity()
+soundListener = ScreenSoundListener()
+listenerEntity:addChild(soundListener)
+soundShape = ScreenShape(SHAPE_CIRCLE, 20,20,10)
+soundShape:setColor(0.0, 1.0, 0.0, 1.0)
+listenerEntity:addChild(soundShape)
+screen:addChild(listenerEntity)
+
+listenerPositionValue = 0
+positionValue = 0
+
+function Update(elapsed)
+        positionValue = positionValue + elapsed
+        listenerPositionValue = listenerPositionValue + elapsed * 0.3
+
+        sourceEntity:setPosition(300 + (sin(positionValue) * 300), 250 + cos(positionValue) * 100)
+        listenerEntity:setPosition(300 + (sin(listenerPositionValue) * 300), 250)
+end

+ 7 - 0
Examples/Lua/2DAudio/2DAudio.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>2DAudio.lua</entryPoint>
+	<packedItems>
+		<item path="test.wav" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/2DAudio/test.wav


+ 34 - 0
Examples/Lua/2DParticles/2DParticles.lua

@@ -0,0 +1,34 @@
+screen = Screen()
+emitter = ScreenParticleEmitter("particle.png", screen, BILLBOARD_PARTICLE,
+	CONTINUOUS_EMITTER, 4, 200, Vector3(0.0,-50.0,0.0), Vector3(0.0,0.0,0.0),
+	Vector3(20.5, 40.0, 0.0))
+
+emitter:getEmitter().useScaleCurves = true
+emitter:getEmitter().scaleCurve:addControlPoint2d(0, 0.3)
+emitter:getEmitter().scaleCurve:addControlPoint2d(0.5, 1)
+emitter:getEmitter().scaleCurve:addControlPoint2d(1, 0)
+
+emitter:getEmitter().useColorCurves = true
+emitter:getEmitter().colorCurveR:addControlPoint2d(0, 0.3)
+emitter:getEmitter().colorCurveR:addControlPoint2d(0.1, 1)
+emitter:getEmitter().colorCurveR:addControlPoint2d(0.4, 1)
+emitter:getEmitter().colorCurveR:addControlPoint2d(0.5, 0)
+emitter:getEmitter().colorCurveR:addControlPoint2d(1, 0)
+
+emitter:getEmitter().colorCurveG:addControlPoint2d(0, 0.3)
+emitter:getEmitter().colorCurveG:addControlPoint2d(0.1, 0.6)
+emitter:getEmitter().colorCurveG:addControlPoint2d(0.4, 0.6)
+emitter:getEmitter().colorCurveG:addControlPoint2d(0.5, 0)
+emitter:getEmitter().colorCurveG:addControlPoint2d(1, 0.0)
+
+emitter:getEmitter().colorCurveB:addControlPoint2d(0, 1)
+emitter:getEmitter().colorCurveB:addControlPoint2d(0.1, 0)
+emitter:getEmitter().colorCurveB:addControlPoint2d(1, 0)
+
+emitter:getEmitter().colorCurveA:addControlPoint2d(0, 0)
+emitter:getEmitter().colorCurveA:addControlPoint2d(0.05, 1)
+emitter:getEmitter().colorCurveA:addControlPoint2d(0.6, 1)
+emitter:getEmitter().colorCurveA:addControlPoint2d(1, 0)
+
+emitter:setPosition(640/2, 400)
+screen:addChild(emitter)

+ 7 - 0
Examples/Lua/2DParticles/2DParticles.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>2DParticles.lua</entryPoint>
+	<packedItems>
+		<item path="particle.png" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/2DParticles/particle.png


+ 12 - 0
Examples/Lua/2DPhysics_Basic/2DPhysics_Basic.lua

@@ -0,0 +1,12 @@
+screen = PhysicsScreen(10, 60)
+shape = ScreenShape(SHAPE_RECT, 600,30)
+shape:setColor(0.0,0.0,0.0,1.0)
+shape:setPosition(640/2, 400)
+screen:addPhysicsChild(shape, ENTITY_RECT, true)
+
+for i=0,200 do
+        shape = ScreenShape(SHAPE_RECT, 20,5)
+        shape:setRotation(random(360))
+        shape:setPosition(random(640), random(300))
+        screen:addPhysicsChild(shape, ENTITY_RECT, false);
+end

+ 7 - 0
Examples/Lua/2DPhysics_Basic/2DPhysics_Basic.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>2DPhysics_Basic.lua</entryPoint>
+	<modules>
+		<module>Physics2D</module>
+	</modules>
+</PolycodeProject>

+ 44 - 0
Examples/Lua/2DPhysics_CollisionOnly/2DPhysics_CollisionOnly.lua

@@ -0,0 +1,44 @@
+class "Detector" (EventHandler)
+
+function Detector:Detector(shape)
+        self.shape = shape
+        self:EventHandler()
+end
+
+function Detector:handleEvent(e)
+        if e:getDispatcher() == screen then
+                local pe = PhysicsScreenEvent(e)
+                if e:getEventCode() == EVENT_NEW_SHAPE_COLLISION then
+                        if pe:getFirstEntity() == self.shape or pe:getSecondEntity() == self.shape then
+                                pe:getFirstEntity():setColor(1.0, 0.0, 0.0, 1.0)
+                                pe:getSecondEntity():setColor(1.0, 0.0, 0.0, 1.0)
+                        end
+                elseif e:getEventCode() == EVENT_END_SHAPE_COLLISION then
+                        pe:getFirstEntity():setColor(1.0, 1.0, 1.0, 1.0)
+                        pe:getSecondEntity():setColor(1.0, 1.0, 1.0, 1.0)
+                end
+        end
+end
+
+screen = PhysicsScreen(10, 60)
+
+checkShape = ScreenShape(SHAPE_RECT, 90,10)
+screen:addCollisionChild(checkShape, ENTITY_RECT)
+
+for i=0,50 do
+        shape = ScreenShape(SHAPE_RECT, 30,15)
+        shape:setRotation(random(360))
+        shape:setPosition(random(640), random(480))
+        screen:addCollisionChild(shape, ENTITY_RECT)
+end
+
+detector = Detector(checkShape)
+screen:addEventListener(detector, EVENT_NEW_SHAPE_COLLISION)
+screen:addEventListener(detector, EVENT_END_SHAPE_COLLISION)
+
+function Update(e)
+        local mouse = Services.Core:getInput():getMousePosition()
+        checkShape:setPosition(mouse.x, mouse.y)
+        checkShape:setRotation(checkShape:getRotation() + (e*100))
+        delete(mouse)
+end

+ 7 - 0
Examples/Lua/2DPhysics_CollisionOnly/2DPhysics_CollisionOnly.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>2DPhysics_CollisionOnly.lua</entryPoint>
+	<modules>
+		<module>Physics2D</module>
+	</modules>
+</PolycodeProject>

+ 34 - 0
Examples/Lua/2DPhysics_Contacts/2DPhysics_Contacts.lua

@@ -0,0 +1,34 @@
+class "ImpactNoise" (EventHandler)
+
+function ImpactNoise:ImpactNoise()
+        self.collisionSound = Sound("collision.wav")
+        self:EventHandler()
+end
+
+function ImpactNoise:handleEvent(e)
+        if e:getDispatcher() == screen then
+                local pe = PhysicsScreenEvent(e)
+                if e:getEventCode() == EVENT_NEW_SHAPE_COLLISION then
+                        if pe.impactStrength > 5 then
+                                self.collisionSound:Play()
+                        end
+                end
+        end
+end
+
+screen = PhysicsScreen(10, 60)
+shape = ScreenShape(SHAPE_RECT, 600,30)
+shape:setColor(0.0,0.0,0.0,1.0)
+shape:setPosition(640/2, 400)
+screen:addPhysicsChild(shape, ENTITY_RECT, true)
+
+for i=0,50 do
+        shape = ScreenShape(SHAPE_RECT, 20,5)
+        shape:setRotation(random(360))
+        shape:setPosition(random(640), random(300))
+        screen:addPhysicsChild(shape, ENTITY_RECT, false)
+end
+
+noiseMaker = ImpactNoise()
+
+screen:addEventListener(noiseMaker, EVENT_NEW_SHAPE_COLLISION)

+ 10 - 0
Examples/Lua/2DPhysics_Contacts/2DPhysics_Contacts.xml

@@ -0,0 +1,10 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>2DPhysics_Contacts.lua</entryPoint>
+	<modules>
+		<module>Physics2D</module>
+	</modules>
+	<packedItems>
+		<item path="collision.wav" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/2DPhysics_Contacts/collision.wav


+ 36 - 0
Examples/Lua/2DPhysics_Joints/2DPhysics_Joints.lua

@@ -0,0 +1,36 @@
+screen = PhysicsScreen(10, 50)
+
+ceiling = ScreenShape(SHAPE_RECT, 640, 20)
+ceiling:setColor(0.0, 0.0, 0.0, 1.0)
+ceiling:setPosition(640/2, 10)
+screen:addPhysicsChild(ceiling, ENTITY_RECT, true)
+
+-- Revolute Joint
+shape = ScreenShape(SHAPE_RECT, 10, 30)
+shape:setPosition(150, 20+15)
+screen:addPhysicsChild(shape, ENTITY_RECT, false)
+screen:createRevoluteJoint(shape, ceiling, 0, -15)
+screen:applyImpulse(shape, 10, 0)
+
+-- Distance Joint
+shape = ScreenShape(SHAPE_RECT, 10, 30)
+shape:setPosition(250, 20+25)
+screen:addPhysicsChild(shape, ENTITY_RECT, false)
+screen:createDistanceJoint(shape, ceiling, false)
+screen:applyImpulse(shape, 200, 0)
+
+line = ScreenLine(shape, ceiling)
+line:setColor(1.0, 0.0, 0.0, 1.0)
+screen:addChild(line)
+
+-- Prismatic Joint
+shape = ScreenShape(SHAPE_RECT, 10, 30)
+shape:setPosition(450, 20+25)
+screen:addPhysicsChild(shape, ENTITY_RECT, false)
+screen:createPrismaticJoint(ceiling, shape, Vector2(0,1), 0,0, false, 100, 0, true)
+
+lineAnchor = ScreenEntity()
+lineAnchor:setPosition(450,10)
+line = ScreenLine(shape, lineAnchor)
+line:setColor(0.0, 1.0, 0.0, 1.0)
+screen:addChild(line)

+ 7 - 0
Examples/Lua/2DPhysics_Joints/2DPhysics_Joints.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>2DPhysics_Joints.lua</entryPoint>
+	<modules>
+		<module>Physics2D</module>
+	</modules>
+</PolycodeProject>

+ 20 - 0
Examples/Lua/2DPhysics_PointCollision/2DPhysics_PointCollision.lua

@@ -0,0 +1,20 @@
+screen = PhysicsScreen(10, 60)
+lastEntity = nil
+
+for i=0,50 do
+        shape = ScreenShape(SHAPE_RECT, 30,15)
+        shape:setRotation(random(360))
+        shape:setPosition(random(640), random(480))
+        screen:addCollisionChild(shape, ENTITY_RECT)
+end
+
+function Update(e)
+        if lastEntity ~= nil then lastEntity:setColor(1.0,1.0,1.0,1.0) end
+        local mouse = Services.Core:getInput():getMousePosition()
+        local entity = screen:getEntityAtPosition(mouse.x, mouse.y)
+        if entity ~= nil then
+                entity:setColor(1.0, 0.0, 0.0, 1.0)
+                lastEntity = entity
+        end
+        delete(mouse)
+end

+ 7 - 0
Examples/Lua/2DPhysics_PointCollision/2DPhysics_PointCollision.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>2DPhysics_PointCollision.lua</entryPoint>
+	<modules>
+		<module>Physics2D</module>
+	</modules>
+</PolycodeProject>

+ 9 - 0
Examples/Lua/2DTransforms/2DTransforms.lua

@@ -0,0 +1,9 @@
+screen = Screen()
+for i=0,9 do
+        image = ScreenImage("polycode_logo.png")
+        screen:addChild(image)
+        image:setPosition(160+(42*i), 230)
+        image:setPositionMode(POSITION_CENTER)
+        image:setRotation(45*i)
+        image:setScale(1.0-(0.1*i),1.0-(0.1*i))
+end

+ 7 - 0
Examples/Lua/2DTransforms/2DTransforms.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>2DTransforms.lua</entryPoint>
+	<packedItems>
+		<item path="polycode_logo.png" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/2DTransforms/polycode_logo.png


+ 26 - 0
Examples/Lua/3DAudio/3DAudio.lua

@@ -0,0 +1,26 @@
+scene = Scene()
+
+sourceEntity = SceneEntity()
+testSound = SceneSound("test.wav", 20, 50)
+testSound:getSound():Play(true)
+sourceEntity:addChild(testSound)
+soundShape = ScenePrimitive(TYPE_BOX, 1,1,1)
+soundShape:setMaterialByName("Default")
+sourceEntity:addChild(soundShape)
+scene:addEntity(sourceEntity)
+
+light = SceneLight(AREA_LIGHT, scene, 300, 0,0)
+scene:addLight(light)
+soundListener = SceneSoundListener()
+scene:addEntity(soundListener)
+
+positionValue = 0
+
+
+function Update(elapsed)
+        positionValue = positionValue + elapsed
+
+        sourceEntity:setPosition((sin(positionValue) * 20), 0, cos(positionValue) * 50)
+        sourceEntity:Roll(elapsed * 120)
+        sourceEntity:Pitch(elapsed * 120)
+end

+ 7 - 0
Examples/Lua/3DAudio/3DAudio.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>3DAudio.lua</entryPoint>
+	<packedItems>
+		<item path="test.wav" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/3DAudio/test.wav


+ 13 - 0
Examples/Lua/3DBasics/3DBasics.lua

@@ -0,0 +1,13 @@
+scene = Scene()
+ground = ScenePrimitive(TYPE_PLANE, 5,5)
+ground:loadTexture("green_texture.png")
+scene:addEntity(ground)
+
+box =  ScenePrimitive(TYPE_BOX, 1,1,1)
+box:loadTexture("pink_texture.png")
+box:setPosition(0.0, 0.5, 0.0)
+scene:addEntity(box)
+
+scene:getDefaultCamera():setPosition(7,7,7)
+scene:getDefaultCamera():lookAt(Vector3(0,0,0), Vector3(0,1,0))
+

+ 8 - 0
Examples/Lua/3DBasics/3DBasics.xml

@@ -0,0 +1,8 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>3DBasics.lua</entryPoint>
+	<packedItems>
+		<item path="pink_texture.png" type="file"/>
+		<item path="green_texture.png" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/3DBasics/green_texture.png


BIN
Examples/Lua/3DBasics/pink_texture.png


+ 50 - 0
Examples/Lua/AdvancedLighting/AdvancedLighting.lua

@@ -0,0 +1,50 @@
+Services.ResourceManager:addDirResource("Resources", false)
+
+scene = Scene()
+ground = ScenePrimitive(TYPE_PLANE, 5,5)
+ground:setMaterialByName("GroundMaterial")
+scene:addEntity(ground)
+
+box =  ScenePrimitive(TYPE_TORUS, 0.8,0.3,30,20)
+box:setMaterialByName("CubeMaterial")
+box:setPosition(0.0, 0.5, 0.0)
+scene:addEntity(box)
+
+light = SceneLight(AREA_LIGHT, scene, 20)
+light:setPosition(3,2,7)
+light:setLightColor(1,0,0)
+scene:addLight(light)
+
+light = SceneLight(AREA_LIGHT, scene, 20)
+light:setPosition(-3,2,7)
+light:setLightColor(0,1,0)
+scene:addLight(light)
+
+light = SceneLight(AREA_LIGHT, scene, 20)
+light:setPosition(-3,2,-7)
+light:setLightColor(0,0,1)
+scene:addLight(light)
+
+light = SceneLight(AREA_LIGHT, scene, 20)
+light:setPosition(3,2,-7)
+light:setLightColor(1,0,1)
+scene:addLight(light)
+
+light = SceneLight(SPOT_LIGHT, scene, 5)
+light:setPosition(0,2,2)
+light:setSpotlightProperties(30,6)
+light:setLightColor(1,1,0)
+scene:addLight(light)
+light:lookAt(Vector3(0,0,0), Vector3(0,1,0))
+light:enableShadows(true)
+
+light = SceneLight(SPOT_LIGHT, scene, 5)
+light:setPosition(0,2,-2)
+light:setSpotlightProperties(30,6)
+light:setLightColor(0,1,1)
+scene:addLight(light)
+light:lookAt(Vector3(0,0,0), Vector3(0,1,0))
+light:enableShadows(true)
+
+scene:getDefaultCamera():setPosition(7,7,7)
+scene:getDefaultCamera():lookAt(Vector3(0,0,0), Vector3(0,1,0))

+ 7 - 0
Examples/Lua/AdvancedLighting/AdvancedLighting.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>AdvancedLighting.lua</entryPoint>
+	<packedItems>
+		<item path="Resources" type="folder"/>
+        </packedItems>
+</PolycodeProject>

+ 26 - 0
Examples/Lua/AdvancedLighting/Resources/example.mat

@@ -0,0 +1,26 @@
+<?xml version="1.0" ?>
+<polycode>	
+	<materials>
+		<material name="TestParticle">
+			<shader name="DefaultParticleShader">
+				<textures>
+					<texture name="diffuse">particle.png</texture>
+				</textures>
+			</shader>
+		</material>	
+		<material name="CubeMaterial">
+			<shader name="DefaultShaderShadows">
+				<textures>
+					<texture name="diffuse">pink_texture.png</texture>
+				</textures>
+			</shader>
+		</material>			
+		<material name="GroundMaterial">
+			<shader name="DefaultShaderShadows">
+				<textures>
+					<texture name="diffuse">green_texture.png</texture>
+				</textures>
+			</shader>
+		</material>					
+	</materials>
+</polycode>

BIN
Examples/Lua/AdvancedLighting/Resources/green_texture.png


BIN
Examples/Lua/AdvancedLighting/Resources/pink_texture.png


+ 3 - 0
Examples/Lua/BasicImage/BasicImage.lua

@@ -0,0 +1,3 @@
+screen = Screen()
+image = ScreenImage("polycode_logo.png")
+screen:addChild(image)

+ 7 - 0
Examples/Lua/BasicImage/BasicImage.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>BasicImage.lua</entryPoint>
+	<packedItems>
+		<item path="polycode_logo.png" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/BasicImage/polycode_logo.png


+ 18 - 0
Examples/Lua/BasicLighting/BasicLighting.lua

@@ -0,0 +1,18 @@
+Services.ResourceManager:addDirResource("Resources", false)
+
+scene = Scene()
+ground = ScenePrimitive(TYPE_PLANE, 5,5)
+ground:setMaterialByName("GroundMaterial")
+scene:addEntity(ground)
+
+box =  ScenePrimitive(TYPE_TORUS, 0.8,0.3,30,20)
+box:setMaterialByName("CubeMaterial")
+box:setPosition(0.0, 0.5, 0.0)
+scene:addEntity(box)
+
+light = SceneLight(AREA_LIGHT, scene, 6)
+light:setPosition(1,2,1)
+scene:addLight(light)
+
+scene:getDefaultCamera():setPosition(7,7,7)
+scene:getDefaultCamera():lookAt(Vector3(0,0,0), Vector3(0,1,0))

+ 7 - 0
Examples/Lua/BasicLighting/BasicLighting.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>BasicLighting.lua</entryPoint>
+	<packedItems>
+		<item path="Resources" type="folder"/>
+        </packedItems>
+</PolycodeProject>

+ 26 - 0
Examples/Lua/BasicLighting/Resources/example.mat

@@ -0,0 +1,26 @@
+<?xml version="1.0" ?>
+<polycode>	
+	<materials>
+		<material name="TestParticle">
+			<shader name="DefaultParticleShader">
+				<textures>
+					<texture name="diffuse">particle.png</texture>
+				</textures>
+			</shader>
+		</material>	
+		<material name="CubeMaterial">
+			<shader name="DefaultShaderShadows">
+				<textures>
+					<texture name="diffuse">pink_texture.png</texture>
+				</textures>
+			</shader>
+		</material>			
+		<material name="GroundMaterial">
+			<shader name="DefaultShaderShadows">
+				<textures>
+					<texture name="diffuse">green_texture.png</texture>
+				</textures>
+			</shader>
+		</material>					
+	</materials>
+</polycode>

BIN
Examples/Lua/BasicLighting/Resources/green_texture.png


BIN
Examples/Lua/BasicLighting/Resources/pink_texture.png


+ 3 - 0
Examples/Lua/BasicText/BasicText.lua

@@ -0,0 +1,3 @@
+screen = Screen()
+label = ScreenLabel("Hello, Polycode!", 32)
+screen:addChild(label)

+ 4 - 0
Examples/Lua/BasicText/BasicText.xml

@@ -0,0 +1,4 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>BasicText.lua</entryPoint>
+</PolycodeProject>

+ 22 - 0
Examples/Lua/EventHandling/EventHandling.lua

@@ -0,0 +1,22 @@
+class "ImageRotator" (EventHandler)
+
+timer = Timer(true, 1000)
+
+function ImageRotator:ImageRotator(image)
+        self.image = image
+        self:EventHandler()
+end
+
+function ImageRotator:handleEvent(e)
+        if e:getDispatcher() == timer and e:getEventCode() == EVENT_TRIGGER then
+                self.image:setRotation(self.image:getRotation()+90)
+        end
+end
+
+screen = Screen()
+image = ScreenImage("polycode_logo.png")
+screen:addChild(image)
+
+rotator = ImageRotator(image)
+timer:addEventListener(rotator, EVENT_TRIGGER)
+

+ 7 - 0
Examples/Lua/EventHandling/EventHandling.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>EventHandling.lua</entryPoint>
+	<packedItems>
+		<item path="polycode_logo.png" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/EventHandling/polycode_logo.png


+ 46 - 0
Examples/Lua/KeyboardInput/KeyboardInput.lua

@@ -0,0 +1,46 @@
+
+class "ImageRotator" (EventHandler)
+
+function ImageRotator:ImageRotator(image)
+        self.image = image
+        self.rotationSpeed = 0
+        self:EventHandler()
+end
+
+function ImageRotator:rotate(e)
+        self.image:setRotation(self.image:getRotation() + e * self.rotationSpeed)
+end
+
+function ImageRotator:handleEvent(e)
+        if e:getDispatcher() == Services.Core:getInput() then
+                local inputEvent = InputEvent(e)
+                local key = inputEvent:keyCode()
+                if e:getEventCode() == EVENT_KEYDOWN then
+                        if key == KEY_LEFT then
+                                self.rotationSpeed = -200
+                        elseif key == KEY_RIGHT then
+                                self.rotationSpeed = 200
+                        end
+                elseif e:getEventCode() == EVENT_KEYUP then
+                        if key == KEY_LEFT or key == KEY_RIGHT then
+                                self.rotationSpeed = 0
+                        end
+                end
+        end
+end
+
+screen = Screen()
+image = ScreenImage("polycode_logo.png")
+image:setPositionMode(POSITION_CENTER)
+image:setPosition(640/2,480/2)
+screen:addChild(image)
+
+
+imageRotator = ImageRotator(image)
+
+Services.Core:getInput():addEventListener(imageRotator, EVENT_KEYDOWN)
+Services.Core:getInput():addEventListener(imageRotator, EVENT_KEYUP)
+
+function Update(elapsed)
+        imageRotator:rotate(elapsed)
+end

+ 7 - 0
Examples/Lua/KeyboardInput/KeyboardInput.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>KeyboardInput.lua</entryPoint>
+	<packedItems>
+		<item path="polycode_logo.png" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/KeyboardInput/polycode_logo.png


+ 33 - 0
Examples/Lua/MouseInput/MouseInput.lua

@@ -0,0 +1,33 @@
+class "MouseImage" (EventHandler)
+
+function MouseImage:MouseImage(image)
+        self.image = image
+        self:EventHandler()
+end
+
+function MouseImage:handleEvent(e)
+        if e:getDispatcher() == Services.Core:getInput() then
+                local inputEvent = InputEvent(e)
+                if e:getEventCode() == EVENT_MOUSEMOVE then
+                        local pos = inputEvent:getMousePosition()
+                        self.image:setPosition(pos.x, pos.y)
+                        delete(pos)
+                elseif e:getEventCode() == EVENT_MOUSEDOWN then
+                        self.image:setColor(1,0,0,1)
+                elseif e:getEventCode() == EVENT_MOUSEUP then
+                        self.image:setColor(1,1,1,1)
+                end
+        end
+end
+
+screen = Screen()
+image = ScreenImage("polycode_logo.png")
+image:setPositionMode(POSITION_CENTER)
+screen:addChild(image)
+
+mouseImage = MouseImage(image)
+
+
+Services.Core:getInput():addEventListener(mouseImage, EVENT_MOUSEMOVE)
+Services.Core:getInput():addEventListener(mouseImage, EVENT_MOUSEDOWN)
+Services.Core:getInput():addEventListener(mouseImage, EVENT_MOUSEUP)

+ 7 - 0
Examples/Lua/MouseInput/MouseInput.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>MouseInput.lua</entryPoint>
+	<packedItems>
+		<item path="polycode_logo.png" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/MouseInput/polycode_logo.png


+ 17 - 0
Examples/Lua/PlayingSounds/PlayingSounds.lua

@@ -0,0 +1,17 @@
+class "SoundApp" (EventHandler)
+
+function SoundApp:SoundApp(image)
+        self.sound = Sound("test.wav")
+        self:EventHandler()
+end
+
+function SoundApp:handleEvent(e)
+        if e:getDispatcher() == Services.Core:getInput() then
+               if e:getEventCode() == EVENT_MOUSEDOWN then
+                        self.sound:Play(false)
+                end
+        end
+end
+
+app = SoundApp()
+Services.Core:getInput():addEventListener(app, EVENT_MOUSEDOWN)

+ 7 - 0
Examples/Lua/PlayingSounds/PlayingSounds.xml

@@ -0,0 +1,7 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>PlayingSounds.lua</entryPoint>
+	<packedItems>
+		<item path="test.wav" type="file"/>
+        </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/PlayingSounds/test.wav


+ 28 - 0
Examples/Lua/ScreenEntities/ScreenEntities.lua

@@ -0,0 +1,28 @@
+screen = Screen()
+
+sun = ScreenShape(SHAPE_CIRCLE, 100,100, 30)
+sun:setPosition(640/2, 480/2)
+sun:setColor(1.0, 0.0, 0, 1)
+sun.colorAffectsChildren = false
+screen:addChild(sun)
+
+planet = ScreenShape(SHAPE_CIRCLE, 50,50, 30)
+planet:setPosition(150,0)
+planet:setColor(0.2, 0.8, 0, 1)
+planet.colorAffectsChildren = false
+sun:addChild(planet)
+
+moon = ScreenShape(SHAPE_CIRCLE, 20,20, 30)
+moon:setPosition(50,0)
+moon:setColor(1, 1, 0.6, 1)
+planet:addChild(moon)
+
+planetRotation = 0
+moonRotation = 0
+
+function Update(elapsed)
+        planetRotation = planetRotation + elapsed
+        moonRotation = moonRotation + (elapsed * 6)
+        planet:setPosition(cos(planetRotation)*150, sin(planetRotation)*150)
+        moon:setPosition(cos(moonRotation)*50, sin(moonRotation)*50)
+end

+ 4 - 0
Examples/Lua/ScreenEntities/ScreenEntities.xml

@@ -0,0 +1,4 @@
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0">
+	<backgroundColor red="0.25" green="0.25" blue="0.25" />
+	<entryPoint>ScreenEntities.lua</entryPoint>
+</PolycodeProject>