├── test.txt ├── rapanui-test ├── lunatest │ ├── .gitignore │ ├── test-error_handler.lua │ ├── suite-hooks.lua │ ├── suite-hooks-fail.lua │ ├── lunatest-0.9.1-0.rockspec │ ├── test-teardown_fail.lua │ ├── test_hamcrest.lua │ ├── README.md │ └── index.html ├── RNFactory-hooks.lua └── mockobjects │ ├── MockConstants.lua │ ├── MockRNLayer.lua │ ├── MockMOAIPartition.lua │ ├── MockMOAIViewport.lua │ ├── MockRNInputManager.lua │ ├── MockMOAILayer2D.lua │ ├── MockRNGroup.lua │ ├── MockPartition.lua │ ├── MockMOAISim.lua │ ├── MockRNScreen.lua │ ├── MockViewport.lua │ ├── MockRNObject.lua │ └── MockLayer.lua ├── dwarves.TTF ├── arial-rounded.TTF ├── images ├── blank.png ├── char.png ├── char2.png ├── ektor.png ├── image.png ├── image2.png ├── image3.png ├── image4.png ├── lilia.png ├── tile0.png ├── tile1.png ├── tile2.png ├── tile3.png ├── tile4.png ├── tile5.png ├── tile6.png ├── tile7.png ├── tile8.png ├── tile9.png ├── khsprite.png ├── kromasky.png ├── allsprite.png ├── button-over.png ├── hex-pattern.png ├── TPAtlasSample.png ├── button-plain.png ├── catsprite_01.png ├── catsprite_02.png ├── sceneButtons.png ├── background-blue.png ├── background-green.png ├── button-disabled.png ├── rapanui_circles.png ├── background-metric.png ├── background-purple.png ├── TexturePackerSample.tps ├── background-landscape.png └── background-landscape-hd.png ├── rapanui-samples ├── physics │ ├── ball.png │ ├── box.png │ ├── char.png │ ├── poly.png │ ├── floor.png │ ├── c_shape1.png │ ├── c_shape2.png │ ├── c_shape3.png │ ├── c_shape4.png │ ├── background-purple.png │ ├── complex_shapes_editor.pes │ ├── rn-physics-types.lua │ ├── rn-physics-touchMove.lua │ ├── rn-physics-forces.lua │ ├── rn-physics-animation.lua │ ├── rn-physics-filters.lua │ ├── rn-physics-shapes.lua │ ├── rn-physics-fixtures.lua │ └── rn-physics-setup.lua ├── maps │ ├── platformbck.png │ ├── rpgtileset.png │ ├── tilesetdemo.png │ ├── platformtiles.png │ ├── platformtileset.png │ ├── rn-tiledmap-parser-lua.lua │ ├── rn-tiledmap-parser-xml.lua │ ├── rn-basic-map.lua │ ├── rn-basic-map-alpha.lua │ ├── rn-tileset.lua │ ├── rn-basic-map-autodraw.lua │ ├── rn-physics-map.lua │ ├── rn-physics-map-alpha.lua │ ├── rn-tile.lua │ ├── rn-basic-map-properties.lua │ ├── rn-scrolling-map.lua │ └── rn-scrolling-physics-map.lua ├── games │ ├── SunGolf │ │ ├── gball.png │ │ ├── grass.png │ │ ├── hole.png │ │ └── obstacle.png │ ├── brick2d │ │ ├── ball.png │ │ ├── brick1.png │ │ ├── brick2.png │ │ ├── brick3.png │ │ └── paddle.png │ └── AngryDogsAgainstMoais │ │ ├── dog.png │ │ ├── hole.png │ │ ├── moai.png │ │ ├── gball.png │ │ ├── grass.png │ │ ├── moaianim.png │ │ ├── obstacle.png │ │ └── restButt.png ├── groups │ ├── tilesetdemo.png │ ├── rn-groups-rnbutton-move.lua │ ├── rn-groups-rnbutton.lua │ ├── mapone.tmx │ ├── mapthree.tmx │ ├── maptwo.tmx │ ├── rn-map-group.lua │ └── rn-groups.lua ├── basic │ ├── rn-images.lua │ ├── rn-shapes.lua │ ├── rn-text-special.lua │ ├── rn-shapes-penColor.lua │ ├── rn-images-rotate.lua │ ├── rn-images-scale.lua │ ├── rn-text.lua │ └── rn-levels.lua ├── landscape │ └── rn-images.lua ├── timer │ ├── rn-timer.lua │ ├── rn-timer-iteration.lua │ ├── rn-timer-stop.lua │ └── rn-timer-remove.lua ├── menu │ ├── rn-menu-director.lua │ ├── rn-menu-popup.lua │ ├── scene4m.lua │ ├── scene2m.lua │ ├── scene3m.lua │ └── popup.lua ├── test │ └── memory │ │ ├── map-mem-test.lua │ │ ├── rnbutton-mem-test.lua │ │ └── rnbitmaptext-mem-test.lua ├── transition │ ├── rn-transition-map-move.lua │ ├── rn-transition-rotate.lua │ ├── rn-transition-text-rotate.lua │ ├── rn-transition-alpha.lua │ ├── rn-transition-text-alpha.lua │ ├── rn-transition-map-rotate.lua │ ├── rn-transition-text-move.lua │ ├── rn-transition-text-scale.lua │ ├── rn-transition-map-scale.lua │ ├── rn-transition-move.lua │ ├── rn-transition-map-alpha.lua │ ├── rn-transition-combined.lua │ ├── rn-transition-bitmaptext-alpha.lua │ ├── rn-transition-bitmaptext-move.lua │ ├── rn-transition-scale.lua │ ├── rn-transition-map-physics-alpha.lua │ ├── rn-transition-rnbutton-alpha.lua │ ├── rn-transition-rnbutton-move.lua │ ├── rn-transition-rnbutton-disabled-move.lua │ └── rn-transition-pauseResumeStop.lua ├── touch │ ├── rn-touch-buttons-globaltouchlistener.lua │ ├── rn-touch-rnobject.lua │ ├── rn-touch-global-rnobject.lua │ ├── rn-touch.lua │ ├── rn-touch-buttons-one-callback.lua │ ├── rn-touch-buttons.lua │ ├── rn-touch-buttons-untouchable.lua │ └── rn-buttons-animated.lua ├── bitmaptext │ ├── rn-bitmaptext.lua │ └── rn-bitmaptext-settext.lua ├── contribution │ ├── rntext-scissorrect.lua │ ├── rnmap-scissorrect.lua │ ├── rnbutton-scissorrect.lua │ ├── rnobject-scissorrect.lua │ ├── contribution-readme.txt │ ├── rnbitmaptext-scissorrect.lua │ └── rngroup-scissorrect.lua ├── director │ ├── rn-director-rnbutton.lua │ ├── rn-director-touch.lua │ ├── rn-director-touch-listener.lua │ ├── scene4.lua │ ├── scene3.lua │ ├── scene2button.lua │ ├── scene1.lua │ └── scene2.lua ├── layers │ ├── rn-layers-multilayerHud.lua │ └── rn-layers-putOnLayer.lua ├── atlas │ └── rn-atlas-texture-packer.lua ├── listeners │ ├── rn-listener-touch-remove.lua │ └── rn-listener-enterFrame-remove.lua ├── buttons │ ├── rn-button-visibility.lua │ └── rn-button-disabled.lua └── anim │ └── rn-anim.lua ├── .gitignore ├── rapanui-sdk ├── RNGlobals.lua ├── RNLogger.lua ├── RNMapFactory.lua ├── RNEvent.lua ├── RNMainThread.lua ├── RNMapObject.lua ├── RNListeners.lua ├── RNMapObjectGroup.lua ├── RNUnit.lua ├── RNWrappedEventListener.lua ├── RNLayer.lua └── rapanui.lua ├── config.lua └── README /test.txt: -------------------------------------------------------------------------------- 1 | test 2 | test 3 | test -------------------------------------------------------------------------------- /rapanui-test/lunatest/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea/ 3 | out/ 4 | 5 | -------------------------------------------------------------------------------- /dwarves.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/dwarves.TTF -------------------------------------------------------------------------------- /arial-rounded.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/arial-rounded.TTF -------------------------------------------------------------------------------- /images/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/blank.png -------------------------------------------------------------------------------- /images/char.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/char.png -------------------------------------------------------------------------------- /images/char2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/char2.png -------------------------------------------------------------------------------- /images/ektor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/ektor.png -------------------------------------------------------------------------------- /images/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/image.png -------------------------------------------------------------------------------- /images/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/image2.png -------------------------------------------------------------------------------- /images/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/image3.png -------------------------------------------------------------------------------- /images/image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/image4.png -------------------------------------------------------------------------------- /images/lilia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/lilia.png -------------------------------------------------------------------------------- /images/tile0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/tile0.png -------------------------------------------------------------------------------- /images/tile1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/tile1.png -------------------------------------------------------------------------------- /images/tile2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/tile2.png -------------------------------------------------------------------------------- /images/tile3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/tile3.png -------------------------------------------------------------------------------- /images/tile4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/tile4.png -------------------------------------------------------------------------------- /images/tile5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/tile5.png -------------------------------------------------------------------------------- /images/tile6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/tile6.png -------------------------------------------------------------------------------- /images/tile7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/tile7.png -------------------------------------------------------------------------------- /images/tile8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/tile8.png -------------------------------------------------------------------------------- /images/tile9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/tile9.png -------------------------------------------------------------------------------- /images/khsprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/khsprite.png -------------------------------------------------------------------------------- /images/kromasky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/kromasky.png -------------------------------------------------------------------------------- /images/allsprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/allsprite.png -------------------------------------------------------------------------------- /images/button-over.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/button-over.png -------------------------------------------------------------------------------- /images/hex-pattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/hex-pattern.png -------------------------------------------------------------------------------- /images/TPAtlasSample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/TPAtlasSample.png -------------------------------------------------------------------------------- /images/button-plain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/button-plain.png -------------------------------------------------------------------------------- /images/catsprite_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/catsprite_01.png -------------------------------------------------------------------------------- /images/catsprite_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/catsprite_02.png -------------------------------------------------------------------------------- /images/sceneButtons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/sceneButtons.png -------------------------------------------------------------------------------- /images/background-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/background-blue.png -------------------------------------------------------------------------------- /images/background-green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/background-green.png -------------------------------------------------------------------------------- /images/button-disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/button-disabled.png -------------------------------------------------------------------------------- /images/rapanui_circles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/rapanui_circles.png -------------------------------------------------------------------------------- /images/background-metric.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/background-metric.png -------------------------------------------------------------------------------- /images/background-purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/background-purple.png -------------------------------------------------------------------------------- /images/TexturePackerSample.tps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/TexturePackerSample.tps -------------------------------------------------------------------------------- /images/background-landscape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/background-landscape.png -------------------------------------------------------------------------------- /rapanui-samples/physics/ball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/ball.png -------------------------------------------------------------------------------- /rapanui-samples/physics/box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/box.png -------------------------------------------------------------------------------- /rapanui-samples/physics/char.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/char.png -------------------------------------------------------------------------------- /rapanui-samples/physics/poly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/poly.png -------------------------------------------------------------------------------- /images/background-landscape-hd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/images/background-landscape-hd.png -------------------------------------------------------------------------------- /rapanui-samples/physics/floor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/floor.png -------------------------------------------------------------------------------- /rapanui-samples/maps/platformbck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/maps/platformbck.png -------------------------------------------------------------------------------- /rapanui-samples/maps/rpgtileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/maps/rpgtileset.png -------------------------------------------------------------------------------- /rapanui-samples/maps/tilesetdemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/maps/tilesetdemo.png -------------------------------------------------------------------------------- /rapanui-samples/physics/c_shape1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/c_shape1.png -------------------------------------------------------------------------------- /rapanui-samples/physics/c_shape2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/c_shape2.png -------------------------------------------------------------------------------- /rapanui-samples/physics/c_shape3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/c_shape3.png -------------------------------------------------------------------------------- /rapanui-samples/physics/c_shape4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/c_shape4.png -------------------------------------------------------------------------------- /rapanui-samples/games/SunGolf/gball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/SunGolf/gball.png -------------------------------------------------------------------------------- /rapanui-samples/games/SunGolf/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/SunGolf/grass.png -------------------------------------------------------------------------------- /rapanui-samples/games/SunGolf/hole.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/SunGolf/hole.png -------------------------------------------------------------------------------- /rapanui-samples/games/brick2d/ball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/brick2d/ball.png -------------------------------------------------------------------------------- /rapanui-samples/groups/tilesetdemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/groups/tilesetdemo.png -------------------------------------------------------------------------------- /rapanui-samples/maps/platformtiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/maps/platformtiles.png -------------------------------------------------------------------------------- /rapanui-samples/games/SunGolf/obstacle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/SunGolf/obstacle.png -------------------------------------------------------------------------------- /rapanui-samples/games/brick2d/brick1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/brick2d/brick1.png -------------------------------------------------------------------------------- /rapanui-samples/games/brick2d/brick2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/brick2d/brick2.png -------------------------------------------------------------------------------- /rapanui-samples/games/brick2d/brick3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/brick2d/brick3.png -------------------------------------------------------------------------------- /rapanui-samples/games/brick2d/paddle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/brick2d/paddle.png -------------------------------------------------------------------------------- /rapanui-samples/maps/platformtileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/maps/platformtileset.png -------------------------------------------------------------------------------- /rapanui-samples/physics/background-purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/background-purple.png -------------------------------------------------------------------------------- /rapanui-samples/physics/complex_shapes_editor.pes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/physics/complex_shapes_editor.pes -------------------------------------------------------------------------------- /rapanui-samples/games/AngryDogsAgainstMoais/dog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/AngryDogsAgainstMoais/dog.png -------------------------------------------------------------------------------- /rapanui-samples/games/AngryDogsAgainstMoais/hole.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/AngryDogsAgainstMoais/hole.png -------------------------------------------------------------------------------- /rapanui-samples/games/AngryDogsAgainstMoais/moai.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/AngryDogsAgainstMoais/moai.png -------------------------------------------------------------------------------- /rapanui-samples/games/AngryDogsAgainstMoais/gball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/AngryDogsAgainstMoais/gball.png -------------------------------------------------------------------------------- /rapanui-samples/games/AngryDogsAgainstMoais/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/AngryDogsAgainstMoais/grass.png -------------------------------------------------------------------------------- /rapanui-samples/games/AngryDogsAgainstMoais/moaianim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/AngryDogsAgainstMoais/moaianim.png -------------------------------------------------------------------------------- /rapanui-samples/games/AngryDogsAgainstMoais/obstacle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/AngryDogsAgainstMoais/obstacle.png -------------------------------------------------------------------------------- /rapanui-samples/games/AngryDogsAgainstMoais/restButt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ymobe/rapanui/HEAD/rapanui-samples/games/AngryDogsAgainstMoais/restButt.png -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-tiledmap-parser-lua.lua: -------------------------------------------------------------------------------- 1 | map = RNMapFactory.loadMap(RNMapFactory.TILEDLUA, "rapanui-samples/maps/testMap.lua") 2 | 3 | require("rapanui-samples/maps/rn-tiledmap-parser-assertions") 4 | -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-tiledmap-parser-xml.lua: -------------------------------------------------------------------------------- 1 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/testMap.tmx") 2 | 3 | require("rapanui-samples/maps/rn-tiledmap-parser-assertions") 4 | -------------------------------------------------------------------------------- /rapanui-test/RNFactory-hooks.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 12/2/12 3 | 4 | function suite_setup() 5 | require("RNFactory") 6 | end 7 | 8 | function suite_teardown() 9 | end 10 | 11 | function test_ok() 12 | assert_true(true) 13 | end 14 | -------------------------------------------------------------------------------- /rapanui-test/lunatest/test-error_handler.lua: -------------------------------------------------------------------------------- 1 | require "lunatest" 2 | 3 | -- This should error out with a more meaningful error message 4 | -- than "./lunatest.lua:608: attempt to index local 'e' (a function value)". 5 | function test_foo() 6 | error(function() return 2 end) 7 | end 8 | 9 | lunatest.run() 10 | -------------------------------------------------------------------------------- /rapanui-test/lunatest/suite-hooks.lua: -------------------------------------------------------------------------------- 1 | module(..., package.seeall) 2 | 3 | function suite_setup() 4 | print "\n\n-- running suite setup hook" 5 | end 6 | 7 | function suite_teardown() 8 | print "\n\n-- running suite teardown hook" 9 | end 10 | 11 | function test_ok() 12 | assert_true(true) 13 | end 14 | -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockConstants.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 12/2/12 3 | 4 | MockConstants = { 5 | WIDTH = 1, 6 | HEIGHT = 2, 7 | SCREENWIDTH = 3, 8 | SCREENHEIGHT = 4, 9 | OFFSET_X = -1, 10 | OFFSET_Y = 1, 11 | ORIGINALWIDTH = 4, 12 | ORIGINALHEIGHT = 6, 13 | WINDOWNAME = "mainwindow", 14 | MAIN_LAYER = "mainlayer" 15 | } -------------------------------------------------------------------------------- /rapanui-test/lunatest/suite-hooks-fail.lua: -------------------------------------------------------------------------------- 1 | module(..., package.seeall) 2 | 3 | -- Either returning false or erroring out in suite_setup() 4 | -- will prevent the suite from running. 5 | function suite_setup() 6 | print "\n\n-- (about to fail and abort suite)" 7 | if true then return false end 8 | error("don't run this suite") 9 | end 10 | 11 | function test_never_run() 12 | assert_true(false, "this suite should never be run") 13 | end 14 | -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockRNLayer.lua: -------------------------------------------------------------------------------- 1 | function createMockRNLayer(expectGetBytName) 2 | 3 | MockRNLayer = { 4 | getCalled = 0, 5 | expectName = expectGetBytName, 6 | MAIN_LAYER = "mainlayer" 7 | } 8 | 9 | function MockRNLayer.new() 10 | return MockRNLayer 11 | end 12 | function MockRNLayer:get(name) 13 | assert_that(name,is(equal_to(self.expectName))) 14 | return createTestLayer("main",{},{}) 15 | end 16 | 17 | return MockRNLayer 18 | end 19 | 20 | -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockMOAIPartition.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 11/30/12 3 | 4 | function createMockMOAIPartition(partition) 5 | local MockMOAIPartition = { 6 | newCalled = 0, 7 | PARTITION = partition 8 | } 9 | 10 | function MockMOAIPartition.new() 11 | MockMOAIPartition.newCalled = MockMOAIPartition.newCalled + 1 12 | return MockMOAIPartition.PARTITION 13 | end 14 | 15 | function MockMOAIPartition:reset() 16 | self.newCalled = 0 17 | end 18 | 19 | return MockMOAIPartition 20 | end 21 | 22 | -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockMOAIViewport.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 11/30/12 3 | 4 | function createMockMOAIViewport(viewport) 5 | 6 | MockMOAIViewport = { 7 | newCalled = 0, 8 | VIEWPORT = viewport, 9 | name="testViewport" 10 | } 11 | 12 | MockMOAIViewport.new = function() 13 | MockMOAIViewport.newCalled = MockMOAIViewport.newCalled + 1 14 | return MockMOAIViewport.VIEWPORT 15 | end 16 | 17 | function MockMOAIViewport:reset() 18 | self.newCalled = 0 19 | end 20 | 21 | return MockMOAIViewport 22 | end -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockRNInputManager.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 12/2/12 3 | 4 | function createMockRNInputManager() 5 | MockRNInputManager = { 6 | setGlobalRNScreenCalled = 0 7 | } 8 | 9 | function MockRNInputManager.setGlobalRNScreen(screen) 10 | assert_true(screen == RNScreen) 11 | MockRNInputManager.setGlobalRNScreenCalled = MockRNInputManager.setGlobalRNScreenCalled + 1 12 | return self 13 | end 14 | 15 | function MockRNInputManager:reset() 16 | MockRNInputManager.setGlobalRNScreenCalled = 0 17 | end 18 | 19 | return MockRNInputManager 20 | end -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockMOAILayer2D.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 11/30/12 3 | 4 | function createMockMOAILayer2D(...) 5 | 6 | local MockMOAILayer2D = { 7 | newCalled = 0, 8 | i=0, 9 | layers = arg 10 | } 11 | 12 | MockMOAILayer2D.new = function() 13 | MockMOAILayer2D.newCalled = MockMOAILayer2D.newCalled + 1 14 | MockMOAILayer2D.i = MockMOAILayer2D.i + 1 15 | return MockMOAILayer2D.layers[MockMOAILayer2D.i] 16 | end 17 | 18 | function MockMOAILayer2D:reset() 19 | self.newCalled = 0; 20 | self.i=0 21 | end 22 | 23 | return MockMOAILayer2D 24 | end -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockRNGroup.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 12/2/12 3 | 4 | function createMockRNGroup() 5 | MockRNGroup = { 6 | newCalled = 0, 7 | insertCalled = 0 8 | } 9 | 10 | function MockRNGroup:new() 11 | self.newCalled = self.newCalled + 1 12 | return self 13 | end 14 | 15 | function MockRNGroup:insert(rnobject) 16 | assert_equal(rnobject,RNObject) 17 | self.insertCalled = self.insertCalled + 1 18 | end 19 | 20 | function MockRNGroup:reset() 21 | self.newCalled = 0 22 | self.insertCalled = 0 23 | end 24 | 25 | return MockRNGroup 26 | end -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | lua/ 3 | *.DS_Store 4 | docs 5 | copyrect.lua 6 | moai-config.lua 7 | sample-spike 8 | moai-build 9 | rapanui-samples/.DS_Store 10 | rapanui-samples/games/.DS_Store 11 | rapanui-samples/maps/reference.tmx 12 | rapanui-samples/maps/rn-map-spike.lua 13 | images/cathead.png 14 | moai-build 15 | rapanui.iml 16 | rapanui.ipr 17 | rapanui.iws 18 | runrapanui.sh 19 | testCopyRect.sh 20 | testmap.sh 21 | .idea/ 22 | Doxyfile 23 | DoxyfileEXAMPLE 24 | doc/ 25 | rapanui-sdk/RNDirector_edit.lua 26 | run.sh 27 | tmp/ 28 | mainmoai.lua 29 | moai-samples 30 | runmoai.sh 31 | testproplist.lua 32 | # testtest.lua 33 | -------------------------------------------------------------------------------- /rapanui-sdk/RNGlobals.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | SWAP = 1 18 | SLIDE_TO_LEFT = 2 19 | SLIDE_TO_RIGHT = 3 20 | SLIDE_TO_BOTTOM = 4 21 | SLIDE_TO_TOP = 5 22 | FADE_OUT_FADE_IN = 6 23 | CROSSFADE = 7 -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockPartition.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 11/30/12 3 | 4 | function createPartition(name) 5 | local MockPartition = { 6 | insertPropCalled = 0, 7 | removePropCalled = 0, 8 | name="TEST_PARTITION" 9 | } 10 | 11 | function MockPartition:insertProp(prop) 12 | self.insertPropCalled = self.insertPropCalled + 1 13 | end 14 | 15 | function MockPartition:removeProp(prop) 16 | self.removePropCalled = self.removePropCalled + 1 17 | end 18 | 19 | MockPartition.name = name 20 | 21 | function MockPartition:reset() 22 | self.insertPropCalled = 0 23 | self.removePropCalled = 0 24 | end 25 | 26 | return MockPartition 27 | end 28 | 29 | -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-basic-map.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- tiles by Daniel Cook (http://www.lostgarden.com) 16 | 17 | local map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/rpgmap.tmx") 18 | 19 | local aTileset = map:getTileset(0) 20 | aTileset:updateImageSource("rapanui-samples/maps/rpgtileset.png") 21 | 22 | map:drawMapAt(0, 0, aTileset) -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-basic-map-alpha.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- tiles by Daniel Cook (http://www.lostgarden.com) 16 | 17 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/rpgmap.tmx") 18 | 19 | aTileset = map:getTileset(0) 20 | aTileset:updateImageSource("rapanui-samples/maps/rpgtileset.png") 21 | 22 | map:drawMapAt(0, 0, aTileset) 23 | map:setAlpha(0.5) -------------------------------------------------------------------------------- /rapanui-samples/basic/rn-images.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | anImage = RNFactory.createImage("images/image2.png") 18 | 19 | anImage = RNFactory.createImage("images/image3.png", { top = 130, left = 130 }) 20 | 21 | anImage = RNFactory.createImage("images/image4.png", { top = 194, left = 194 }) 22 | 23 | anImage:setAlpha(0.5) -------------------------------------------------------------------------------- /rapanui-sdk/RNLogger.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | RNLogger = {} 16 | 17 | -- Create a new RNSprite Object 18 | function RNLogger:new(o) 19 | 20 | o = o or { 21 | enabled = true 22 | } 23 | setmetatable(o, self) 24 | self.__index = self 25 | return o 26 | end 27 | 28 | function RNLogger:log(text) 29 | if self.enabled then 30 | print(text) 31 | end 32 | end 33 | 34 | -------------------------------------------------------------------------------- /rapanui-samples/landscape/rn-images.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-landscape-hd.png") 16 | 17 | anImage = RNFactory.createImage("images/image2.png") 18 | 19 | anImage = RNFactory.createImage("images/image3.png", { top = 130, left = 130 }) 20 | 21 | anImage = RNFactory.createImage("images/image4.png", { top = 194, left = 194 }) 22 | 23 | anImage:setAlpha(0.5) -------------------------------------------------------------------------------- /rapanui-samples/basic/rn-shapes.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | background:sendToBottom() 18 | 19 | rect = RNFactory.createRect(20, 50, 70, 50, { rgb = { 190, 120, 190 } }) 20 | 21 | rect.rotation = 30 22 | 23 | circle = RNFactory.createCircle(0, 0, 30, { rgb = { 100, 120, 100 } }) 24 | 25 | circle.x = 50 26 | circle.y = 150 27 | circle:setAlpha(0.5) 28 | -------------------------------------------------------------------------------- /rapanui-samples/timer/rn-timer.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | times = 0 16 | local background = RNFactory.createImage("images/background-purple.png") 17 | 18 | text = RNFactory.createText("Times 0", { size = 20, top = 5, left = 5, width = 200, height = 50 }) 19 | 20 | local function count() 21 | times = times + 1 22 | text:setText("Times " .. times) 23 | end 24 | 25 | local actionId = RNMainThread.addTimedAction(0.5, count) 26 | -------------------------------------------------------------------------------- /rapanui-test/lunatest/lunatest-0.9.1-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lunatest" 2 | version = "0.9.1-0" 3 | source = { 4 | url = "git://github.com/silentbicycle/lunatest.git", 5 | tag = "v0.9.1" 6 | } 7 | description = { 8 | summary = "xUnit-style + randomized unit testing framework", 9 | detailed = [[ 10 | 11 | Lunatest is an xUnit-style unit testing framework, with 12 | additional support for randomized testing (a la QuickCheck). 13 | 14 | It's upwardly compatible from lunit, except it does not change any 15 | functions in the standard library (by using assert_true() instead 16 | of assert()). 17 | ]], 18 | homepage = "http://github.com/silentbicycle/lunatest", 19 | license = "MIT/X11" 20 | } 21 | dependencies = { 22 | "lua >= 5.1" 23 | } 24 | build = { 25 | type = "builtin", 26 | modules = { 27 | lunatest = "lunatest.lua" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /rapanui-samples/menu/rn-menu-director.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | --setting up director 18 | director = RNDirector:new() 19 | 20 | 21 | director:addScene("rapanui-samples/menu/scene1m") 22 | director:addScene("rapanui-samples/menu/scene2m") 23 | director:addScene("rapanui-samples/menu/scene3m") 24 | director:addScene("rapanui-samples/menu/scene4m") 25 | 26 | --show scene1m with fade in 27 | 28 | director:showScene("rapanui-samples/menu/scene1m", "fade") -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockMOAISim.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 11/30/12 3 | 4 | function createMockMOAISim() 5 | 6 | local MockMOAISim = { 7 | pushRenderPassCalled = 0, 8 | openWindowCalled = 0 9 | } 10 | 11 | MockMOAISim.pushRenderPass = function(layer) 12 | assert_not_nil(layer) 13 | MockMOAISim.pushRenderPassCalled = MOAISim.pushRenderPassCalled + 1 14 | end 15 | 16 | function MockMOAISim.openWindow(name, screenlwidth, screenHeight) 17 | assert_that(screenlwidth,is(equal_to(MockConstants.SCREENWIDTH))) 18 | assert_that(screenHeight,is(equal_to(MockConstants.SCREENHEIGHT))) 19 | assert_that(name,is(equal_to(MockConstants.WINDOWNAME))) 20 | MockMOAISim.openWindowCalled = MockMOAISim.openWindowCalled + 1 21 | end 22 | 23 | function MockMOAISim:reset() 24 | self.pushRenderPassCalled = 0 25 | self.openWindowCalled = 0 26 | end 27 | 28 | return MockMOAISim 29 | end -------------------------------------------------------------------------------- /rapanui-samples/test/memory/map-mem-test.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | --]] 14 | 15 | 16 | 17 | for i = 0, 1000 do 18 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/rpgmap.tmx") 19 | 20 | aTileset = map:getTileset(0) 21 | aTileset:updateImageSource("rapanui-samples/maps/rpgtileset.png") 22 | 23 | map:drawMapAt(0, 0, aTileset) 24 | memestatus(true) 25 | map:remove() 26 | collectgarbage("collect") 27 | end 28 | 29 | 30 | print("End") 31 | memestatus(true) -------------------------------------------------------------------------------- /rapanui-samples/timer/rn-timer-iteration.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | times = 0 16 | local background = RNFactory.createImage("images/background-purple.png") 17 | 18 | local iterations = 10 19 | 20 | text = RNFactory.createText("Gone run: ", { size = 20, top = 5, left = 5, width = 200, height = 50 }) 21 | 22 | local function count() 23 | times = times + 1 24 | text:setText("Gone run: " .. times) 25 | end 26 | 27 | local actionId = RNMainThread.addTimedAction(0.5, count, iterations) 28 | -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-tileset.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- tiles by Daniel Cook (http://www.lostgarden.com) 16 | 17 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/demomap.tmx") 18 | 19 | aTileset = map:getTileset(0) 20 | 21 | aTileset:updateImageSource("rapanui-samples/maps/tilesetdemo.png") 22 | 23 | for i = 0, 6 do 24 | aTile = aTileset:getTileImage(i) 25 | aTile.x = 40 * i + 40 26 | end 27 | 28 | aTile = aTileset:getTileImage(13) 29 | aTile.y = 40 * 3 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /rapanui-test/lunatest/test-teardown_fail.lua: -------------------------------------------------------------------------------- 1 | require "lunatest" 2 | 3 | function busywait(n) 4 | n = n or 10000 5 | for i=1,n do 6 | for j=1,n do 7 | -- no-op 8 | end 9 | end 10 | end 11 | 12 | function setup(n) 13 | -- show that test case time does not include setup 14 | busywait() 15 | end 16 | 17 | local teardown_count = 0 18 | 19 | function teardown(n) 20 | teardown_count = teardown_count + 1 21 | if teardown_count > 1 then error("*boom*") end 22 | end 23 | 24 | function test_fail_but_expect_teardown() 25 | error("fail whale") 26 | end 27 | 28 | function test_fail_but_expect_teardown_2() 29 | error("boom") 30 | end 31 | 32 | local caught_teardown_error = false 33 | 34 | xpcall(lunatest.run(), function(x) 35 | print("ARGH", x) 36 | caught_teardown_error = true 37 | end) 38 | 39 | assert(caught_teardown_error, "Didn't catch teardown failure.") 40 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-map-move.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/rpgmap.tmx") 18 | aTileset = map:getTileset(0) 19 | aTileset:updateImageSource("rapanui-samples/maps/rpgtileset.png") 20 | map:drawMapAt(0, 0, aTileset) 21 | 22 | trn = RNTransition:new() 23 | 24 | function move() 25 | trn:run(map, { type = "move", time = 1500, alpha = 0, x = math.random(0, 320), y = math.random(0, 480), onComplete = move }) 26 | end 27 | 28 | move() 29 | 30 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-rotate.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | anImage = RNFactory.createImage("images/tile1.png", { top = 64, left = 64 }) 18 | 19 | trn = RNTransition:new() 20 | 21 | function first() 22 | trn:run(anImage, { type = "rotate", time = 1500, angle = 360, onComplete = second }) 23 | end 24 | 25 | function second() 26 | trn:run(anImage, { type = "rotate", time = 1500, angle = -360, onComplete = first }) 27 | end 28 | 29 | first() -------------------------------------------------------------------------------- /rapanui-samples/touch/rn-touch-buttons-globaltouchlistener.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | text = RNFactory.createText("Touch on buttons", { size = 9, top = 200, left = 5, width = 250, height = 50 }) 16 | 17 | back = RNFactory.createImage("images/background-purple.png") 18 | back:sendToBottom() 19 | 20 | buttonOne = RNFactory.createImage("images/tile1.png", { top = 50, left = 50 }) 21 | 22 | 23 | function callMeBack(event) 24 | text:setText("Called! event phase: [" .. event.phase .. "]") 25 | end 26 | 27 | buttonOne:setGlobalTouchListener(callMeBack) -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-basic-map-autodraw.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- tiles by Daniel Cook (http://www.lostgarden.com) 16 | 17 | require("RNMapFactory") 18 | require("RNMap") 19 | require("RNMapLayer") 20 | require("RNMapObject") 21 | require("RNMapObjectGroup") 22 | require("RNMapTileset") 23 | require("RNUtil") 24 | 25 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/demomap.tmx") 26 | 27 | aTileset = map:getTileset(0) 28 | aTileset:updateImageSource("rapanui-samples/maps/tilesetdemo.png") 29 | 30 | map:drawMapAt(0, 0, aTileset) 31 | -------------------------------------------------------------------------------- /rapanui-samples/bitmaptext/rn-bitmaptext.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | --[[  16 | -- Free bitmap fonts by SpicyPixel.NET 17 | -- ]] 18 | 19 | local background = RNFactory.createImage("images/background-purple.png") 20 | 21 | 22 | 23 | text1 = RNFactory.createBitmapText("HELLO BITMAP WORLD!", { 24 | image = "images/kromasky.png", 25 | charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!\"%',.", 26 | top = 55, 27 | left = 10, 28 | charWidth = 16, 29 | charHeight = 16 30 | }) 31 | 32 | 33 | text1.y=200 34 | 35 | background:sendToBottom() 36 | 37 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-text-rotate.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | text = RNFactory.createText("Hello world!", { size = 20, top = 50, left = 50, width = 200, height = 50 }) 18 | 19 | trn = RNTransition:new() 20 | 21 | function first() 22 | trn:run(text, { type = "rotate", time = 3000, angle = 90, onComplete = second }) 23 | end 24 | 25 | function second() 26 | trn:run(text, { type = "rotate", time = 3000, angle = -90, onComplete = first }) 27 | end 28 | 29 | first() 30 | 31 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-alpha.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | anImage = RNFactory.createImage("images/tile1.png", { top = 64, left = 64 }) 18 | 19 | trn = RNTransition:new() 20 | 21 | function setAlphaToZero() 22 | trn:run(anImage, { type = "alpha", alpha = 0, time = 1000, onComplete = setAlphaToOne }) 23 | end 24 | 25 | function setAlphaToOne() 26 | trn:run(anImage, { type = "alpha", alpha = 1, time = 1000, onComplete = setAlphaToZero }) 27 | end 28 | 29 | setAlphaToZero() 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-text-alpha.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | text = RNFactory.createText("Hello world!", { size = 20, top = 0, left = 0, width = 200, height = 50 }) 18 | 19 | trn = RNTransition:new() 20 | 21 | function setAlphaToZero() 22 | trn:run(text, { type = "alpha", alpha = 0, time = 1000, onComplete = setAlphaToOne }) 23 | end 24 | 25 | function setAlphaToOne() 26 | trn:run(text, { type = "alpha", alpha = 1, time = 1000, onComplete = setAlphaToZero }) 27 | end 28 | 29 | setAlphaToZero() 30 | 31 | -------------------------------------------------------------------------------- /rapanui-samples/basic/rn-text-special.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | local background = RNFactory.createImage("images/background-purple.png") 17 | 18 | local text1 = RNFactory.createText("Hello world!\n this is a special text\n full of special features!\n Have fun!", { size = 25, top = 5, left = 5, width = 320, height = 480 }) 19 | text1:spool() 20 | text1:highlight(6, 6, 0, 255, 255, 0.8) 21 | text1:addStyle("style1", "dwarves.TTF", 30) 22 | text1:addStyle("style2", "dwarves.TTF", 40, { 255, 255, 0, 100 }) 23 | 24 | print(text1.text) 25 | 26 | --text1:remove() 27 | 28 | 29 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-map-rotate.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | 18 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/rpgmap.tmx") 19 | aTileset = map:getTileset(0) 20 | aTileset:updateImageSource("rapanui-samples/maps/rpgtileset.png") 21 | map:drawMapAt(0, 0, aTileset) 22 | 23 | trn = RNTransition:new() 24 | 25 | function first() 26 | trn:run(map, { type = "rotate", time = 1500, angle = 360, onComplete = second }) 27 | end 28 | 29 | function second() 30 | trn:run(map, { type = "rotate", time = 1500, angle = -360, onComplete = first }) 31 | end 32 | 33 | first() -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-text-move.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | text = RNFactory.createText("Hello world!", { size = 20, top = 0, left = 0, width = 200, height = 50 }) 18 | 19 | trn = RNTransition:new() 20 | 21 | function goToPointA() 22 | trn:run(text, { type = "move", time = 1500, alpha = 0, x = 200, y = 200, onComplete = goToPointB }) 23 | end 24 | 25 | function goToPointB() 26 | trn:run(text, { type = "move", time = 1500, alpha = 0, x = 0, y = 0, onComplete = goToPointA }) 27 | end 28 | 29 | goToPointA() 30 | 31 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-text-scale.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | text = RNFactory.createText("Hello world!", { size = 20, top = 0, left = 0, width = 200, height = 50 }) 18 | 19 | trn = RNTransition:new() 20 | trn = RNTransition:new() 21 | 22 | function first() 23 | trn:run(text, { type = "scale", xScale = 1, yScale = 1, time = 1000, onComplete = second }) 24 | end 25 | 26 | function second() 27 | trn:run(text, { type = "scale", xScale = -1, yScale = -1, time = 1000, onComplete = first }) 28 | end 29 | 30 | first() 31 | 32 | -------------------------------------------------------------------------------- /rapanui-samples/contribution/rntext-scissorrect.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-purple.png") 16 | 17 | text1 = RNFactory.createText("Hello world!", { size = 25, top = 5, left = 5, width = 200, height = 50 }) 18 | 19 | text2 = RNFactory.createText("Left world!", { alignment = MOAITextBox.LEFT_JUSTIFY, size = 20, top = 50, left = 5, width = 200, height = 50, font="dwarves.TTF"}) 20 | text2:setTextSize(40) 21 | text2:setTextColor(15, 40, 200) 22 | text2:setAlpha(0.8) 23 | 24 | local scissorRect = MOAIScissorRect.new() 25 | scissorRect:setRect( 5, 50, 205, 65) 26 | text2:setScissorRect(scissorRect) -------------------------------------------------------------------------------- /rapanui-samples/touch/rn-touch-rnobject.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | eventNumber = 0 16 | 17 | text = RNFactory.createText("Touch on buttons", { size = 18, top = 200, left = 5, width = 250, height = 50 }) 18 | 19 | back = RNFactory.createImage("images/background-purple.png") 20 | back:sendToBottom() 21 | 22 | buttonOne = RNFactory.createImage("images/tile1.png", { top = 50, left = 50 }) 23 | 24 | function button1Touch(event) 25 | text:setText("Call back touch! " .. eventNumber) 26 | eventNumber = eventNumber + 1 27 | print(event.phase) 28 | print(event.target) 29 | end 30 | 31 | 32 | buttonOne:addEventListener("touch", button1Touch) -------------------------------------------------------------------------------- /rapanui-samples/touch/rn-touch-global-rnobject.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | eventNumber = 0 16 | 17 | text = RNFactory.createText("Touch on buttons", { size = 18, top = 200, left = 5, width = 250, height = 50 }) 18 | 19 | back = RNFactory.createImage("images/background-purple.png") 20 | back:sendToBottom() 21 | 22 | buttonOne = RNFactory.createImage("images/tile1.png", { top = 50, left = 50 }) 23 | 24 | function button1Touch(event) 25 | text:setText("Call back touch! " .. eventNumber) 26 | eventNumber = eventNumber + 1 27 | print(event.phase) 28 | print(event.target) 29 | end 30 | 31 | 32 | buttonOne:addGlobalEventListener("touch", button1Touch) -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-map-scale.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | 18 | 19 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/rpgmap.tmx") 20 | aTileset = map:getTileset(0) 21 | aTileset:updateImageSource("rapanui-samples/maps/rpgtileset.png") 22 | map:drawMapAt(0, 0, aTileset) 23 | 24 | trn = RNTransition:new() 25 | 26 | function first() 27 | trn:run(map, { type = "scale", xScale = 1, yScale = 1, time = 1000, onComplete = second }) 28 | end 29 | 30 | function second() 31 | trn:run(map, { type = "scale", xScale = -1, yScale = -1, time = 1000, onComplete = first }) 32 | end 33 | 34 | first() 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-move.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | anImage = RNFactory.createImage("images/tile1.png", { top = 64, left = 64 }) 18 | 19 | trn = RNTransition:new() 20 | 21 | function goToPointA() 22 | --you can also set ease mode. Use Moais. 23 | trn:run(anImage, { type = "move", time = 1500, alpha = 0, x = 200, y = 200, onComplete = goToPointB, mode = MOAIEaseType.LINEAR }) 24 | end 25 | 26 | function goToPointB() 27 | trn:run(anImage, { type = "move", time = 1500, alpha = 0, x = 64, y = 64, onComplete = goToPointA }) 28 | end 29 | 30 | goToPointA() 31 | 32 | -------------------------------------------------------------------------------- /rapanui-samples/touch/rn-touch.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | sprite1 = RNFactory.createImage("images/tile1.png") 16 | 17 | back = RNFactory.createImage("images/background-purple.png") 18 | back:sendToBottom() 19 | 20 | local w, h = RNFactory.stageWidth, RNFactory.stageHeight 21 | 22 | function onTouchEvent(event) 23 | if event.phase == "began" then 24 | sprite1.x = event.x 25 | sprite1.y = event.y 26 | end 27 | 28 | if event.phase == "moved" then 29 | sprite1.x = event.x 30 | sprite1.y = event.y 31 | end 32 | end 33 | 34 | local listenerId = RNListeners:addEventListener("touch", onTouchEvent) 35 | print("Listener ID", listenerId) 36 | -------------------------------------------------------------------------------- /rapanui-samples/basic/rn-shapes-penColor.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | local r, g, b = 0, 255, 0 18 | 19 | background:sendToBottom() 20 | 21 | rect = RNFactory.createRect(120, 120, 70, 50, { rgb = { 190, 120, 190 } }) 22 | 23 | rect.rotation = 23 24 | 25 | 26 | --handling enterFrame 27 | function changeColor() 28 | 29 | rect:setPenColor(r, g, b) 30 | 31 | if r < 255 then 32 | r, g, b = r + 1, g - 1, b + 1 33 | else 34 | r, g, b = 0, 255, 0 35 | end 36 | end 37 | 38 | --set a listener for enterFrame 39 | listenerId = RNListeners:addEventListener("enterFrame", changeColor) 40 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-map-alpha.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- tiles by Daniel Cook (http://www.lostgarden.com) 16 | 17 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/rpgmap.tmx") 18 | aTileset = map:getTileset(0) 19 | aTileset:updateImageSource("rapanui-samples/maps/rpgtileset.png") 20 | map:drawMapAt(0, 0, aTileset) 21 | 22 | trn = RNTransition:new() 23 | 24 | function setAlphaToZero() 25 | trn:run(map, { type = "alpha", alpha = 0, time = 1000, onComplete = setAlphaToOne }) 26 | end 27 | 28 | function setAlphaToOne() 29 | trn:run(map, { type = "alpha", alpha = 1, time = 1000, onComplete = setAlphaToZero }) 30 | end 31 | 32 | setAlphaToZero() 33 | -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-physics-map.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- start physic simulation 16 | 17 | RNPhysics.start() 18 | 19 | 20 | --same as rn map basic map 21 | -- tiles by Daniel Cook (http://www.lostgarden.com) 22 | 23 | 24 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/physicmap.tmx") 25 | 26 | 27 | aTileset = map:getTileset(0) 28 | 29 | aTileset:updateImageSource("rapanui-samples/maps/platformtileset.png") 30 | 31 | 32 | local layersSize = map:getLayersSize() 33 | 34 | print("Layers", layersSize) 35 | local layers = map:getLayers() 36 | 37 | 38 | map:drawMapAt(0, 0, aTileset) 39 | 40 | 41 | --Debug Draw if you want 42 | --RNPhysics.setDebugDraw(RNFactory.screen) -------------------------------------------------------------------------------- /rapanui-samples/director/rn-director-rnbutton.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | effects = { "slidetoleft", "slidetoright", "crossfade", "slidetotop", "slidetobottom", "pop", "fade" } 16 | 17 | function getRandomTransition() 18 | return effects[math.random(1, table.getn(effects) + 1)] 19 | end 20 | 21 | director = RNDirector:new() 22 | 23 | director:addScene("rapanui-samples/director/scene1button") 24 | director:addScene("rapanui-samples/director/scene2button") 25 | 26 | --check if they are inside the director 27 | for i, v in ipairs(director.scenes) do 28 | print(i, v) 29 | end 30 | 31 | --Set director's time 32 | director:setTime(1000) 33 | 34 | director:showScene("rapanui-samples/director/scene1button", "slidetotop") 35 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-combined.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | anImage = RNFactory.createImage("images/tile1.png") 18 | 19 | trn = RNTransition:new() 20 | 21 | function goToPointA() 22 | trn:run(anImage, { type = "rotate", time = 1500, angle = 720, onComplete = goToPointB }) 23 | trn:run(anImage, { type = "move", time = 1500, alpha = 0, x = 200, y = 400 }) 24 | end 25 | 26 | function goToPointB() 27 | trn:run(anImage, { type = "rotate", time = 1500, angle = -720, onComplete = goToPointA }) 28 | trn:run(anImage, { type = "move", time = 1500, alpha = 0, x = 32, y = 32 }) 29 | end 30 | 31 | goToPointA() 32 | 33 | 34 | -------------------------------------------------------------------------------- /rapanui-samples/contribution/rnmap-scissorrect.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- Map without scissor rectangle 16 | local map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/rpgmap.tmx") 17 | local aTileset = map:getTileset(0) 18 | aTileset:updateImageSource("rapanui-samples/maps/rpgtileset.png") 19 | map:drawMapAt(200, 200, aTileset) 20 | 21 | -- Map with scissor rectangle 22 | local map2 = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/rpgmap.tmx") 23 | local aTileset2 = map:getTileset(0) 24 | aTileset2:updateImageSource("rapanui-samples/maps/rpgtileset.png") 25 | map2:drawMapAt(25, 25, aTileset2) 26 | 27 | local scissorRect = MOAIScissorRect.new () 28 | scissorRect:setRect( 25, 25, 125, 125) 29 | map2:setScissorRect(scissorRect) -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockRNScreen.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 12/2/12 3 | 4 | function createMockRNScreen() 5 | MockRNScreen = { 6 | newCalled = 0, 7 | initWithCalled = 0, 8 | addRNObjectCalled = 0, 9 | layers = MockRNLayer.new() 10 | } 11 | 12 | function MockRNScreen:new() 13 | self.newCalled = self.newCalled + 1 14 | return self 15 | end 16 | 17 | function MockRNScreen:initWith(lwidth, lheight, screenlwidth, screenHeight) 18 | assert_that(lwidth,is(equal_to(MockConstants.SCREENWIDTH))) 19 | assert_that(lheight,is(equal_to(MockConstants.SCREENHEIGHT))) 20 | assert_that(screenlwidth,is(equal_to(MockConstants.SCREENWIDTH))) 21 | assert_that(screenHeight,is(equal_to(MockConstants.SCREENHEIGHT))) 22 | 23 | self.initWithCalled = self.initWithCalled + 1 24 | end 25 | 26 | function MockRNScreen:addRNObject(rnobject,mode,layer) 27 | assert_true(rnobject == RNObject) 28 | assert_nil(mode) 29 | self.addRNObjectCalled = self.addRNObjectCalled + 1 30 | end 31 | 32 | function MockRNScreen:reset() 33 | --MockRNScreen.newCalled = 0 34 | MockRNScreen.initWithCalled = 0 35 | self.addRNObjectCalled = 0 36 | end 37 | 38 | return MockRNScreen 39 | end -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-physics-map-alpha.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- start physic simulation 16 | 17 | RNPhysics.start() 18 | 19 | 20 | --same as rn map basic map 21 | -- tiles by Daniel Cook (http://www.lostgarden.com) 22 | 23 | 24 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/physicmap.tmx") 25 | 26 | 27 | aTileset = map:getTileset(0) 28 | 29 | aTileset:updateImageSource("rapanui-samples/maps/platformtileset.png") 30 | 31 | 32 | local layersSize = map:getLayersSize() 33 | 34 | print("Layers", layersSize) 35 | local layers = map:getLayers() 36 | 37 | 38 | map:drawMapAt(0, 0, aTileset) 39 | 40 | map:setAlpha(0.5) 41 | 42 | 43 | --Debug Draw if you want 44 | --RNPhysics.setDebugDraw(RNFactory.screen) 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /rapanui-sdk/RNMapFactory.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | RNMapFactory = {} 17 | 18 | RNMapFactory.TILED = "tiled" 19 | RNMapFactory.TILEDLUA = "tiledlua" 20 | MAP_DRAW_MODE_FULLIMAGE = "FullImage" 21 | MAP_DRAW_MODE_BIGTILED = "BigTiled" 22 | MAP_DRAW_MODE_TESSELLATED = "Tessellated" 23 | 24 | 25 | function RNMapFactory.loadMap(type, filename, drawmode) 26 | 27 | local map = RNMap:new() 28 | 29 | if type == RNMapFactory.TILED then 30 | 31 | RNTiledMapParser.load(map, filename) 32 | end 33 | 34 | if type == RNMapFactory.TILEDLUA then 35 | RNTiledLuaMapParser.load(map, filename) 36 | end 37 | 38 | map:init(RNFactory.getCurrentScreen()) 39 | 40 | return map 41 | end 42 | 43 | return RNMapFactory 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /rapanui-samples/contribution/rnbutton-scissorrect.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | button = RNFactory.createButton("images/button-plain.png", { 18 | text = "Button1", 19 | imageOver = "images/button-over.png", 20 | top = 150, 21 | left = 10, 22 | size = 16, 23 | width = 200, 24 | height = 50 25 | }) 26 | button2 = RNFactory.createButton("images/button-plain.png", { 27 | text = "Button2", 28 | imageOver = "images/button-over.png", 29 | top = 200, 30 | left = 10, 31 | size = 16, 32 | width = 200, 33 | height = 50 34 | }) 35 | 36 | local scissorRect = MOAIScissorRect.new() 37 | scissorRect:setRect( 10, 200, 410, 225) 38 | button2:setScissorRect(scissorRect) 39 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-bitmaptext-alpha.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | text = RNFactory.createBitmapText("BITMAP TRANSITION!", { 18 | image = "images/kromasky.png", 19 | charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!\"%',.", 20 | top = 10, 21 | left = 10, 22 | charWidth = 16, 23 | charHeight = 16 24 | }) 25 | 26 | trn = RNTransition:new() 27 | 28 | function setAlphaToZero() 29 | trn:run(text, { type = "alpha", alpha = 0, time = 1000, onComplete = setAlphaToOne }) 30 | end 31 | 32 | function setAlphaToOne() 33 | trn:run(text, { type = "alpha", alpha = 1, time = 1000, onComplete = setAlphaToZero }) 34 | end 35 | 36 | setAlphaToZero() 37 | 38 | background:sendToBottom() -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-bitmaptext-move.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | text = RNFactory.createBitmapText("BITMAP TRANSITION!", { 18 | image = "images/kromasky.png", 19 | charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!\"%',.", 20 | top = 10, 21 | left = 10, 22 | charWidth = 16, 23 | charHeight = 16 24 | }) 25 | trn = RNTransition:new() 26 | 27 | function goToPointA() 28 | trn:run(text, { type = "move", time = 1500, alpha = 0, x = 200, y = 200, onComplete = goToPointB }) 29 | end 30 | 31 | function goToPointB() 32 | trn:run(text, { type = "move", time = 1500, alpha = 0, x = 0, y = 0, onComplete = goToPointA }) 33 | end 34 | 35 | goToPointA() 36 | 37 | background:sendToBottom() -------------------------------------------------------------------------------- /rapanui-samples/contribution/rnobject-scissorrect.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- Blue background with scissorRect 16 | local background = RNFactory.createImage("images/background-blue.png") 17 | background:sendToBottom() 18 | local scissorRect = MOAIScissorRect.new () 19 | scissorRect:setRect( 50, 50, 250, 250) 20 | background:setScissorRect(scissorRect) 21 | 22 | -- Circle using the same scissor rectangle as background 23 | local circle = RNFactory.createCircle(250, 0, 125, { rgb = { 100, 120, 100 } }) 24 | circle:setScissorRect(scissorRect) 25 | 26 | -- Circle with it's own scissor rectangle 27 | local circle2 = RNFactory.createCircle(250, 250, 250, { rgb = { 100, 120, 100 } }) 28 | local scissorRect2 = MOAIScissorRect.new() 29 | scissorRect2:setRect( 250, 250, 500, 500) 30 | circle2:setScissorRect(scissorRect2) -------------------------------------------------------------------------------- /rapanui-sdk/RNEvent.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | RNEvent = {} 16 | 17 | function RNEvent:new(o) 18 | o = o or { 19 | name = "" 20 | } 21 | setmetatable(o, self) 22 | self.__index = self 23 | self.x = 0 24 | self.y = 0 25 | self.phase = "" 26 | return o 27 | end 28 | 29 | function RNEvent:initWithEventType(eventType) 30 | 31 | if (eventType == MOAITouchSensor.TOUCH_DOWN) then 32 | self.phase = "began" 33 | end 34 | 35 | if (eventType == MOAITouchSensor.TOUCH_MOVE) then 36 | self.phase = "moved" 37 | end 38 | 39 | if (eventType == MOAITouchSensor.TOUCH_UP) then 40 | self.phase = "ended" 41 | end 42 | 43 | if (eventType == MOAITouchSensor.TOUCH_CANCEL) then 44 | self.phase = "cancelled" 45 | end 46 | end 47 | 48 | return RNEvent 49 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-scale.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | anImage = RNFactory.createImage("images/tile1.png", { top = 64, left = 64 }) 18 | anImage2 = RNFactory.createImage("images/tile2.png", { top = 64, left = 192 }) 19 | 20 | trn = RNTransition:new() 21 | 22 | function first() 23 | trn:run(anImage, { type = "scale", xScale = 1, yScale = 1, time = 1000, onComplete = second }) 24 | trn:run(anImage2, { type = "scale", xScale = -0.5, yScale = -0.5, time = 1000 }) 25 | end 26 | 27 | function second() 28 | trn:run(anImage, { type = "scale", xScale = -1, yScale = -1, time = 1000, onComplete = first }) 29 | trn:run(anImage2, { type = "scale", xScale = 0.5, yScale = 0.5, time = 1000 }) 30 | end 31 | 32 | first() 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-map-physics-alpha.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | -- start physic simulation 18 | RNPhysics.start() 19 | 20 | 21 | --same as rn map basic map 22 | -- tiles by Daniel Cook (http://www.lostgarden.com) 23 | 24 | 25 | 26 | map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/physicmap.tmx") 27 | aTileset = map:getTileset(0) 28 | aTileset:updateImageSource("rapanui-samples/maps/platformtileset.png") 29 | map:drawMapAt(0, 0, aTileset) 30 | 31 | trn = RNTransition:new() 32 | 33 | function setAlphaToZero() 34 | trn:run(map, { type = "alpha", alpha = 0, time = 1000, onComplete = setAlphaToOne }) 35 | end 36 | 37 | function setAlphaToOne() 38 | trn:run(map, { type = "alpha", alpha = 1, time = 1000, onComplete = setAlphaToZero }) 39 | end 40 | 41 | setAlphaToZero() 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockViewport.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 11/30/12 3 | 4 | require('MockConstants') 5 | function createViewport(name) 6 | local MockViewport = { 7 | setSizeCalled = 0, 8 | setScaleCalled = 0, 9 | setOffsetCalled = 0 10 | } 11 | 12 | function MockViewport:setSize(screenWidth,screenHeight) 13 | assert_that(screenWidth,is(equal_to(MockConstants.SCREENWIDTH))) 14 | assert_that(screenHeight,is(equal_to(MockConstants.SCREENHEIGHT))) 15 | MockViewport.setSizeCalled = MockViewport.setSizeCalled + 1 16 | end 17 | 18 | function MockViewport:setScale(width,height) 19 | assert_that(width,is(equal_to(MockConstants.WIDTH))) 20 | assert_that(height,is(equal_to(-MockConstants.HEIGHT))) 21 | MockViewport.setScaleCalled = MockViewport.setScaleCalled + 1 22 | end 23 | 24 | function MockViewport:setOffset(offset_x,offset_y) 25 | assert_that(offset_x,is(equal_to(MockConstants.OFFSET_X))) 26 | assert_that(offset_y,is(equal_to(MockConstants.OFFSET_Y))) 27 | MockViewport.setOffsetCalled = MockViewport.setOffsetCalled + 1 28 | end 29 | 30 | function MockViewport:reset() 31 | MockViewport.setSizeCalled = 0 32 | MockViewport.setScaleCalled = 0 33 | MockViewport.setOffsetCalled = 0 34 | end 35 | 36 | MockViewport.name=name 37 | 38 | return MockViewport 39 | end -------------------------------------------------------------------------------- /rapanui-samples/basic/rn-images-rotate.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | anImage = RNFactory.createImage("images/image.png") 16 | 17 | print(anImage.y) 18 | print(anImage.x) 19 | 20 | print(anImage.y) 21 | print(anImage.x) 22 | 23 | local background = RNFactory.createImage("images/background-blue.png") 24 | 25 | anImage = RNFactory.createImage("images/image2.png", { top = 64, left = 64 }) 26 | anImage.rotation = 10 27 | anImage = RNFactory.createImage("images/image3.png", { top = 130, left = 130 }) 28 | anImage.rotation = 20 29 | anImage = RNFactory.createImage("images/image4.png", { top = 194, left = 194 }) 30 | anImage.rotation = 30 31 | 32 | --aText = RNFactory.createImage("Hello World!", 0, 0, native.systemFont, 16) 33 | --aText.x = 50 34 | --aText.y = 100 35 | --aText:setTextColor(255, 255, 255) 36 | 37 | --print("Objects in game: " .. display.getCurrentStage().numChildren) -------------------------------------------------------------------------------- /rapanui-samples/basic/rn-images-scale.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- any image, animation or image or animation from atlas or image from physics can be scaled, mirrored or flipped. 16 | 17 | local background = RNFactory.createImage("images/background-blue.png") 18 | 19 | anImage = RNFactory.createImage("images/image2.png", { top = 64, left = 64 }) 20 | --scale 21 | anImage.scaleX = 1.5 22 | anImage.scaleY = 0.5 23 | anImage = RNFactory.createImage("images/image2.png", { top = 204, left = 64 }) 24 | --scale 25 | anImage.scaleX = 0.5 26 | anImage.scaleY = 2.5 27 | anImage = RNFactory.createImage("images/image3.png", { top = 130, left = 130 }) 28 | --mirror and scale 29 | anImage.scaleX = -0.3 30 | anImage.scaleY = -0.4 31 | anImage = RNFactory.createImage("images/image4.png", { top = 194, left = 194 }) 32 | --flip 33 | anImage:flipHorizontal() 34 | anImage:flipVertical() 35 | -------------------------------------------------------------------------------- /rapanui-samples/contribution/contribution-readme.txt: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- _____ _ _ _ 4 | -- | __ \ | \ | | (_) 5 | -- | |__) |__ _ _ __ __ _| \| |_ _ _ 6 | -- | _ // _` | '_ \ / _` | . ` | | | | | 7 | -- | | \ \ (_| | |_) | (_| | |\ | |_| | | 8 | -- |_| \_\__,_| .__/ \__,_|_| \_|\__,_|_| 9 | -- | | 10 | -- |_| 11 | -- 12 | -- RapaNui 13 | -- 14 | -- by Ymobe ltd (http://ymobe.co.uk) 15 | -- 16 | -- LICENSE: 17 | -- 18 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 19 | -- CPAL is an Open Source Initiative approved 20 | -- license based on the Mozilla Public License, with the added requirement that you attribute 21 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 22 | 23 | If you want to contribute to RapaNui with a great code sample, feel free to create sample in a sub folder ,here in rapanui-samples/contribution/. 24 | 25 | Then simply open a pull request! 26 | 27 | Just remember to add all the assets needed to run your sample in your sample folder. 28 | 29 | 30 | Note: 31 | It would be better if all of us could read and follow this little contribution line guide, thanks: 32 | https://github.com/ymobe/rapanui/wiki/Perfomance-guide -------------------------------------------------------------------------------- /rapanui-test/lunatest/test_hamcrest.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Author: Janne Sinivirta 3 | -- Date: 9/19/12 4 | -- 5 | require('lunatest') 6 | require('lunahamcrest') 7 | 8 | function test_equal_to() 9 | assert_that(4, equal_to(4)) 10 | assert_that("ok", equal_to("ok")) 11 | end 12 | 13 | function test_not() 14 | assert_that(4, is_not(equal_to(5))) 15 | assert_that(5, is_not(is_nil())) 16 | end 17 | 18 | function test_syntactic_sugars() 19 | assert_that(4, is(equal_to(4))) 20 | assert_that(nil, is_nil()) 21 | end 22 | 23 | function test_of_type() 24 | assert_that("test", is(of_type("string"))) 25 | assert_that(4, is(of_type("number"))) 26 | end 27 | 28 | function test_contains_string() 29 | assert_that("testable", contains_string("test")) 30 | assert_that("testable", contains_string("tab")) 31 | assert_that("testable", contains_string("testable")) 32 | end 33 | 34 | function test_starts_with() 35 | assert_that("testable", starts_with("tes")) 36 | assert_that("testable", starts_with("testable")) 37 | end 38 | 39 | function test_starts_with() 40 | assert_that("testable", equals_ignoring_case("tesTaBlE")) 41 | end 42 | 43 | function test_greater_than() 44 | assert_that(3, greater_than(2)) 45 | assert_that(-1, greater_than(-2)) 46 | end 47 | 48 | lunatest.run() 49 | -------------------------------------------------------------------------------- /rapanui-samples/basic/rn-text.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | local background = RNFactory.createImage("images/background-purple.png") 17 | 18 | text1 = RNFactory.createText("Hello world!", { size = 25, top = 5, left = 5, width = 200, height = 50 }) 19 | 20 | text2 = RNFactory.createText("Left world!", { alignment = MOAITextBox.LEFT_JUSTIFY, size = 20, top = 50, left = 5, width = 200, height = 50, font="dwarves.TTF"}) 21 | text2:setTextSize(40) 22 | text2:setTextColor(15, 40, 200) 23 | text2:setAlpha(0.8) 24 | 25 | text3 = RNFactory.createText("Right world!", { alignment = MOAITextBox.RIGHT_JUSTIFY, size = 30, top = 100, left = 5, width = 200, height = 50 }) 26 | text3:setTextColor(200, 40, 40) 27 | text3:setTextSize(30) 28 | 29 | text4 = RNFactory.createText("Hello world", { size = 20*1.25, top = 200, left = 5, width = 200, height = 50, font="dwarves.TTF" }) 30 | text4:setText("Hello RapaNui!") 31 | -------------------------------------------------------------------------------- /rapanui-samples/groups/rn-groups-rnbutton-move.lua: -------------------------------------------------------------------------------- 1 | freeImage = RNFactory.createImage("images/background-blue.png") 2 | 3 | freeImage = RNFactory.createImage("images/image.png") 4 | 5 | group = RNGroup:new() 6 | 7 | button = RNFactory.createButton("images/button-plain.png", { text = "Button 1", imageOver = "images/button-over.png", top = 250, left = 10, size = 16, width = 200, height = 50 }) 8 | --button.x = 10 9 | button.y = 90 10 | 11 | button2 = RNFactory.createButton("images/button-plain.png", { text = "Button 2", imageOver = "images/button-over.png", top = 150, left = 10, size = 16, width = 200, height = 50 }) 12 | --button2.x = 10 13 | --button2.y = 96 14 | 15 | 16 | group:insert(button) 17 | group:insert(button2) 18 | 19 | 20 | print("group one size: " .. group:getSize()) 21 | 22 | 23 | 24 | local myListener = function(event) 25 | group.x = event.x 26 | group.y = event.y 27 | 28 | -- print("group x: " .. group.x .. " y: " .. group.y) 29 | 30 | -- print("anImageTest1 x: " .. anImageTest1.x .. " y: " .. anImageTest1.y) 31 | -- print("anImageTest2 x: " .. anImageTest2.x .. " y: " .. anImageTest2.y) 32 | -- print("anImageTest3 x: " .. anImageTest3.x .. " y: " .. anImageTest3.y) 33 | -- print("anImageTest4 x: " .. anImageTest4.x .. " y: " .. anImageTest4.y) 34 | end 35 | 36 | RNListeners:addEventListener("touch", myListener) 37 | -------------------------------------------------------------------------------- /rapanui-samples/test/memory/rnbutton-mem-test.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | --]] 14 | local background = RNFactory.createImage("images/background-blue.png") 15 | 16 | text = RNFactory.createText("Touch on buttons", { size = 9, top = 200, left = 5, width = 250, height = 50 }) 17 | 18 | 19 | for i = 0, 1000 do 20 | 21 | button = RNFactory.createButton("images/button-plain.png", { text = "Button 1", top = 130, left = 10, size = 10, width = 200, height = 50 }) 22 | 23 | local function button1TouchDown(event) 24 | text:setText("Button touch down!") 25 | end 26 | 27 | local function button1UP(event) 28 | text:setText("Button touch up") 29 | end 30 | 31 | button:setOnTouchDown(button1TouchDown) 32 | button:setOnTouchUp(button1UP) 33 | 34 | memestatus(true) 35 | button:remove() 36 | button = nil 37 | collectgarbage("collect") 38 | end 39 | 40 | print("End") 41 | memestatus(true) -------------------------------------------------------------------------------- /rapanui-sdk/RNMainThread.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | RNMainThread = {} 16 | 17 | RNMainThread.rnThread = RNThread:new() 18 | 19 | function RNMainThread.addTimedAction(delay, func, iterations) 20 | --local actionid = RNMainThread.rnThread:runFunction(delay, func, iterations) 21 | --return actionid 22 | local timerObject = RNTimer:new() 23 | delay = 1 / delay 24 | timerObject:init(delay, func, iterations) 25 | return timerObject 26 | end 27 | 28 | function RNMainThread.suspendAction(actionid) 29 | actionid:pause() 30 | end 31 | 32 | function RNMainThread.resumeAction(actionId) 33 | actionId:unpause() 34 | end 35 | 36 | function RNMainThread.removeAction(actionid) 37 | actionid:remove() 38 | end 39 | 40 | function RNMainThread.getMainThread() 41 | return RNMainThread.rnThread 42 | end 43 | 44 | function RNMainThread.startMainThread() 45 | RNMainThread.rnThread:start() 46 | end 47 | 48 | return RNMainThread -------------------------------------------------------------------------------- /rapanui-samples/test/memory/rnbitmaptext-mem-test.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | --]] 14 | local background = RNFactory.createImage("images/background-blue.png") 15 | 16 | text1 = RNFactory.createBitmapText("SCENE 1", { 17 | image = "images/kromasky.png", 18 | charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!\"%',.", 19 | top = 55, 20 | left = 10, 21 | charWidth = 16, 22 | charHeight = 16 23 | }) 24 | 25 | text1:remove() 26 | 27 | for i = 0, 1000 do 28 | 29 | 30 | text1 = RNFactory.createBitmapText("ISTANCE " .. i, { 31 | image = "images/kromasky.png", 32 | charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!\"%',.", 33 | top = 55, 34 | left = 10, 35 | charWidth = 16, 36 | charHeight = 16 37 | }) 38 | 39 | memestatus(true) 40 | text1:remove() 41 | text1 = nil 42 | collectgarbage("collect") 43 | end 44 | 45 | print("End") 46 | collectgarbage("collect") 47 | memestatus(true) -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockRNObject.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 11/30/12 3 | 4 | function createRNObject(name,prop) 5 | local MockRNObject = { 6 | setLocatingModeCalled = 0, 7 | setParentSceneCalled = 0, 8 | updateLocationCalled = 0, 9 | newCalled = 0, 10 | initWithImage2Called = 0, 11 | MOAIPROP = prop, 12 | name = name, 13 | originalWidth = MockConstants.ORIGINALWIDTH, 14 | originalHeight = MockConstants.ORIGINALHEIGHT 15 | } 16 | 17 | function MockRNObject:new() 18 | self.newCalled = self.newCalled + 1 19 | return self 20 | end 21 | 22 | function MockRNObject:initWithImage2(image) 23 | self.initWithImage2Called = self.initWithImage2Called + 1 24 | return self,{} 25 | 26 | end 27 | 28 | function MockRNObject:getProp() 29 | return self.MOAIPROP 30 | end 31 | 32 | function MockRNObject:setLocatingMode(mode) 33 | self.setLocatingModeCalled = self.setLocatingModeCalled + 1 34 | end 35 | 36 | function MockRNObject:setParentScene(object) 37 | self.setParentSceneCalled = self.setParentSceneCalled + 1 38 | end 39 | 40 | function MockRNObject:updateLocation() 41 | self.updateLocationCalled = self.updateLocationCalled + 1 42 | end 43 | 44 | function MockRNObject:reset() 45 | self.setLocatingModeCalled = 0 46 | self.setParentSceneCalled = 0 47 | self.updateLocationCalled = 0 48 | self.newCalled = 0 49 | end 50 | 51 | return MockRNObject 52 | end 53 | -------------------------------------------------------------------------------- /rapanui-test/mockobjects/MockLayer.lua: -------------------------------------------------------------------------------- 1 | -- Author: Marko Pukari 2 | -- Date: 11/30/12 3 | 4 | function createTestLayer(name,viewport,partition) 5 | local MockLayer = { 6 | setPartitionCalled = 0, 7 | setViewportCalled = 0, 8 | clearCalled = 0, 9 | insertPropCalled = 0, 10 | MOAIVIEWPORT = viewport, 11 | MOAIPARTITION = partition, 12 | name = name 13 | } 14 | 15 | function MockLayer:setViewport(viewport) 16 | MockLayer.setViewportCalled = MockLayer.setViewportCalled + 1 17 | assert_that(viewport.name,is(equal_to(MockLayer.MOAIVIEWPORT.name))) 18 | end 19 | 20 | function MockLayer:setPartition(partition) 21 | assert_that(partition.name,is(equal_to(MockLayer.MOAIPARTITION.name))) 22 | MockLayer.setPartitionCalled = MockLayer.setPartitionCalled + 1 23 | end 24 | 25 | function MockLayer:clear() 26 | MockLayer.clearCalled=MockLayer.clearCalled + 1 27 | end 28 | 29 | function MockLayer:insertProp(prop) 30 | self.insertPropCalled = self.insertPropCalled + 1 31 | self.MOAIPARTITION:insertProp(prop) 32 | end 33 | 34 | function MockLayer:reset() 35 | self.setPartitionCalled = 0 36 | self.setViewportCalled = 0 37 | self.clearCalled = 0 38 | self.insertPropCalled = 0 39 | self.removePropCalled = 0 40 | end 41 | 42 | function MockLayer:removeProp(prop) 43 | self.removePropCalled = self.removePropCalled + 1 44 | self.MOAIPARTITION:removeProp(prop) 45 | end 46 | 47 | 48 | return MockLayer 49 | end 50 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-rnbutton-alpha.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | button = RNFactory.createButton("images/button-plain.png", { 18 | text = "Main Button 1", 19 | imageOver = "images/button-over.png", 20 | top = 50, 21 | left = 10, 22 | size = 16, 23 | width = 200, 24 | height = 50 25 | }) 26 | 27 | trn = RNTransition:new() 28 | 29 | function setAlphaToZero() 30 | trn:run(button, { type = "alpha", alpha = 0, time = 1000, onComplete = setAlphaToOne }) 31 | end 32 | 33 | function setAlphaToOne() 34 | trn:run(button, { type = "alpha", alpha = 1, time = 1000, onComplete = setAlphaToZero }) 35 | end 36 | 37 | setAlphaToZero() 38 | 39 | 40 | function button1TouchDown(event) 41 | print("Button 1 touch down!") 42 | end 43 | 44 | function button1UP(event) 45 | print("Button 1 touch up") 46 | end 47 | 48 | button:setOnTouchDown(button1TouchDown) 49 | button:setOnTouchUp(button1UP) 50 | 51 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-rnbutton-move.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | 17 | button = RNFactory.createButton("images/button-plain.png", { 18 | text = "Main Button 1", 19 | imageOver = "images/button-over.png", 20 | top = 50, 21 | left = 10, 22 | size = 16, 23 | width = 200, 24 | height = 50 25 | }) 26 | 27 | trn = RNTransition:new() 28 | 29 | function goToPointA() 30 | trn:run(button, { type = "move", time = 1500, alpha = 0, x = 200, y = 200, onComplete = goToPointB }) 31 | end 32 | 33 | function goToPointB() 34 | trn:run(button, { type = "move", time = 1500, alpha = 0, x = 0, y = 0, onComplete = goToPointA }) 35 | end 36 | 37 | goToPointA() 38 | 39 | 40 | function button1TouchDown(event) 41 | print("Button 1 touch down!") 42 | end 43 | 44 | function button1UP(event) 45 | print("Button 1 touch up") 46 | end 47 | 48 | button:setOnTouchDown(button1TouchDown) 49 | button:setOnTouchUp(button1UP) 50 | -------------------------------------------------------------------------------- /rapanui-samples/groups/rn-groups-rnbutton.lua: -------------------------------------------------------------------------------- 1 | freeImage = RNFactory.createImage("images/background-blue.png") 2 | 3 | 4 | 5 | groupY = 100 6 | 7 | 8 | group = RNGroup:new() 9 | 10 | text = RNFactory.createText("Touch on buttons", { size = 18, top = 400, left = 5, width = 250, height = 50 }) 11 | 12 | nextText = "Click to move Down" 13 | 14 | button = RNFactory.createButton("images/button-plain.png", { text = nextText, imageOver = "images/button-over.png", top = 20, left = 10, size = 16, width = 200, height = 50 }) 15 | --button.x = 10 16 | 17 | 18 | button2 = RNFactory.createButton("images/button-plain.png", { text = "Button 2", imageOver = "images/button-over.png", top = 90, left = 10, size = 16, width = 200, height = 50 }) 19 | --button2.x = 10 20 | --button2.y = 96 21 | 22 | 23 | group:insert(button) 24 | group:insert(button2) 25 | 26 | 27 | print("group one size: " .. group:getSize()) 28 | 29 | 30 | function button1TouchDown(event) 31 | text:setText("Button 1 touch down!") 32 | group.y = group.y + groupY 33 | groupY = -groupY 34 | if nextText == "Click to move Down" then 35 | nextText = "Click to move Up" 36 | elseif nextText == "Click to move Up" then 37 | nextText = "Click to move Down" 38 | end 39 | button:setText(nextText) 40 | end 41 | 42 | function button1UP(event) 43 | 44 | text:setText("Button 1 touch Up!") 45 | end 46 | 47 | 48 | button:setOnTouchDown(button1TouchDown) 49 | button:setOnTouchUp(button1UP) 50 | -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-tile.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | -- 40 , 40, 80, 80, 0, 0 15 | 16 | local params = { 17 | top = 50, 18 | left = 160, 19 | srcXMin = 40, 20 | srcYMin = 40, 21 | srcXMax = 80, 22 | srcYMax = 80, 23 | destXMin = 0, 24 | destYMin = 0 25 | } 26 | 27 | --destXMax ( number ) Optional. Default value is destXMin + srcXMax - srcXMin; 28 | --destYMax ( number ) Optional. Default value is destYMin + srcYMax - srcYMin; 29 | --filter ( number ) Optional. One of MOAIImage.FILTER_LINEAR, MOAIImage.FILTER_NEAREST. Default value is MOAIImage.FILTER_LINEAR. 30 | 31 | anImage = RNFactory.createCopyRect("rapanui-samples/maps/tilesetdemo.png", params) 32 | 33 | 34 | local params = { 35 | top = 150, 36 | left = 160, 37 | srcXMin = 80, 38 | srcYMin = 80, 39 | srcXMax = 120, 40 | srcYMax = 120, 41 | destXMin = 0, 42 | destYMin = 0, 43 | } 44 | src = RNFactory.createMoaiImage("rapanui-samples/maps/tilesetdemo.png") 45 | 46 | print(src:getSize()) 47 | anImage = RNFactory.createCopyRect(src, params) 48 | -------------------------------------------------------------------------------- /rapanui-samples/timer/rn-timer-stop.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | times = 0 16 | local background = RNFactory.createImage("images/background-purple.png") 17 | 18 | text = RNFactory.createText("Times 0", { size = 20, top = 180, left = 50, width = 200, height = 50 }) 19 | textinfo = RNFactory.createText("Touch button1 to stop/start timer", { size = 18, top = 10, left = 5, width = 300, height = 50 }) 20 | 21 | counting = true 22 | 23 | local function count() 24 | times = times + 1 25 | 26 | text:setText("Times " .. times) 27 | 28 | if times == 100 then 29 | times = 0 30 | end 31 | end 32 | 33 | actionId = RNMainThread.addTimedAction(0.5, count) 34 | 35 | function button1UP(event) 36 | if counting then 37 | RNMainThread.suspendAction(actionId) 38 | counting = false 39 | else 40 | RNMainThread.resumeAction(actionId) 41 | counting = true 42 | end 43 | end 44 | 45 | 46 | buttonOne = RNFactory.createImage("images/tile1.png", { top = 50, left = 120 }) 47 | buttonOne:setOnTouchUp(button1UP) 48 | 49 | 50 | -------------------------------------------------------------------------------- /rapanui-samples/bitmaptext/rn-bitmaptext-settext.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | --[[  16 | -- Free bitmap fonts by SpicyPixel.NET 17 | -- ]] 18 | 19 | local background = RNFactory.createImage("images/background-purple.png") 20 | 21 | 22 | text = RNFactory.createBitmapText("CLICK!", { 23 | image = "images/kromasky.png", 24 | charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!\"%',.", 25 | top = 55, 26 | left = 50, 27 | charWidth = 16, 28 | charHeight = 16 29 | }) 30 | 31 | 32 | text.y = 200 33 | 34 | function buttonUP(event) 35 | text:setText("TOUCH UP") 36 | end 37 | 38 | function buttonTouchDown(event) 39 | text:setText("TOUCH DOWN") 40 | end 41 | 42 | button = RNFactory.createButton("images/button-plain.png", { 43 | text = "Main Button 1", 44 | imageOver = "images/button-over.png", 45 | top = 50, 46 | left = 10, 47 | size = 16, 48 | width = 200, 49 | height = 50, 50 | onTouchDown = buttonTouchDown, 51 | onTouchUp = buttonUP, 52 | font = "arial-rounded.TTF" 53 | }) 54 | 55 | background:sendToBottom() -------------------------------------------------------------------------------- /rapanui-test/lunatest/README.md: -------------------------------------------------------------------------------- 1 | Lunatest is an xUnit-style, Lua-based unit testing framework with 2 | additional support for randomized testing (a la QuickCheck). 3 | 4 | It's largely upwardly compatible from [lunit][], with the following changes: 5 | 6 | * Where lunit uses assert(), lunatest uses assert_true(). lunatest does 7 | not change any functions from the standard library. 8 | * If running tests in only one file, no module declaration is necessary. 9 | * For multiple suites, register them with lunatest.suite("file"). 10 | This uses require to load the suite, and uses the same methods to 11 | match filenames with modules. 12 | * It doesn't have any dependencies except Lua, though if present, it 13 | will use lhf's [lrandom][] module (for consistent pseudorandom numbers 14 | across operating systems) and [luasocket][]'s gettime() for timestamps). 15 | 16 | The main (or only) test file should end in lunatest.run(), and can be 17 | run as a normal lua script. The following command-line arguments are 18 | supported: 19 | 20 | * -v: verbose mode, which lists every test's name, result, and runtime. 21 | * -s / --suite *pattern*: Only run suite(s) with names matching the pattern. 22 | * -t / --test *pattern*: Only run test(s) with names matching the pattern. 23 | 24 | [lunit]: http://www.nessie.de/mroth/lunit/ 25 | [lrandom]: http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lrandom 26 | [luasocket]: http://luaforge.net/projects/luasocket/ 27 | 28 | For further examples, see the API documentation and included test suite. 29 | -------------------------------------------------------------------------------- /rapanui-samples/contribution/rnbitmaptext-scissorrect.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-purple.png") 16 | 17 | 18 | text = RNFactory.createBitmapText("CLICK!", { 19 | image = "images/kromasky.png", 20 | charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!\"%',.", 21 | top = 55, 22 | left = 50, 23 | charWidth = 16, 24 | charHeight = 16, 25 | }) 26 | text.y = 200 27 | 28 | function buttonUP(event) 29 | text:setText("TOUCH UP") 30 | end 31 | 32 | function buttonTouchDown(event) 33 | text:setText("TOUCH DOWN") 34 | end 35 | 36 | button = RNFactory.createButton("images/button-plain.png", { 37 | text = "Main Button 1", 38 | imageOver = "images/button-over.png", 39 | top = 50, 40 | left = 10, 41 | size = 16, 42 | width = 200, 43 | height = 50, 44 | onTouchDown = buttonTouchDown, 45 | onTouchUp = buttonUP, 46 | font = "arial-rounded.TTF" 47 | }) 48 | background:sendToBottom() 49 | 50 | local scissorRect = MOAIScissorRect.new() 51 | scissorRect:setRect( 50, 100, 250, 205) 52 | text:setScissorRect(scissorRect) -------------------------------------------------------------------------------- /rapanui-samples/touch/rn-touch-buttons-one-callback.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | text = RNFactory.createText("Touch on buttons", { size = 18, top = 200, left = 5, width = 250, height = 50 }) 16 | 17 | back = RNFactory.createImage("images/background-purple.png") 18 | back:sendToBottom() 19 | 20 | buttonOne = RNFactory.createImage("images/tile1.png", { top = 50, left = 50 }) 21 | buttonOne.name = "Button1" 22 | 23 | buttonTwo = RNFactory.createImage("images/tile2.png", { top = 50, left = 150 }) 24 | buttonTwo.name = "Button2" 25 | 26 | function buttonTouchDown(event) 27 | text:setText("Button " .. event.target.name .. " touch down!") 28 | end 29 | 30 | function buttonMoved(event) 31 | text:setText("Button " .. event.target.name .. " moved!") 32 | end 33 | 34 | function buttonUP(event) 35 | text:setText("Button " .. event.target.name .. " touch up") 36 | end 37 | 38 | buttonOne:setOnTouchDown(buttonTouchDown) 39 | buttonOne:setOnTouchMove(buttonMoved) 40 | buttonOne:setOnTouchUp(buttonUP) 41 | 42 | buttonTwo:setOnTouchDown(buttonTouchDown) 43 | buttonTwo:setOnTouchMove(buttonMoved) 44 | buttonTwo:setOnTouchUp(buttonUP) -------------------------------------------------------------------------------- /rapanui-samples/timer/rn-timer-remove.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | times = 0 16 | local background = RNFactory.createImage("images/background-purple.png") 17 | 18 | text = RNFactory.createText("Times 0", { size = 20, top = 180, left = 50, width = 200, height = 50 }) 19 | textinfo = RNFactory.createText("Touch button1 to remove/add timer", { size = 16, top = 10, left = 5, width = 300, height = 50 }) 20 | 21 | counting = true 22 | 23 | local function count() 24 | times = times + 1 25 | 26 | text:setText("Times " .. times) 27 | 28 | if times == 100 then 29 | times = 0 30 | end 31 | end 32 | 33 | actionId = RNMainThread.addTimedAction(0.5, count) 34 | 35 | function button1UP(event) 36 | if counting then 37 | RNMainThread.removeAction(actionId) 38 | print("removing", actionId) 39 | counting = false 40 | else 41 | actionId = RNMainThread.addTimedAction(0.5, count) 42 | print("adding", actionId) 43 | counting = true 44 | end 45 | end 46 | 47 | 48 | buttonOne = RNFactory.createImage("images/tile1.png", { top = 50, left = 120 }) 49 | buttonOne:setOnTouchUp(button1UP) 50 | 51 | 52 | -------------------------------------------------------------------------------- /rapanui-samples/physics/rn-physics-types.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | --We create 3 objects, one for type and one with default type. One is removed. 16 | 17 | 18 | --add images 19 | background = RNFactory.createImage("rapanui-samples/physics/background-purple.png") 20 | box = RNFactory.createImage("rapanui-samples/physics/box.png"); box.x = 160; box.y = 80; 21 | box2 = RNFactory.createImage("rapanui-samples/physics/box.png"); box2.x = 230; box2.y = 80; 22 | box3 = RNFactory.createImage("rapanui-samples/physics/box.png"); box3.x = 80; box3.y = 80; box3.rotation = 190 23 | floor = RNFactory.createImage("rapanui-samples/physics/floor.png"); floor.x = 160; floor.y = 400; 24 | 25 | --starts simulation 26 | RNPhysics.start() 27 | 28 | 29 | --set images as physics objects 30 | RNPhysics.createBodyFromImage(box) 31 | RNPhysics.createBodyFromImage(box2, "dynamic") 32 | RNPhysics.createBodyFromImage(box3, "kinematic") 33 | RNPhysics.createBodyFromImage(floor, "static") 34 | 35 | --remove the object 36 | box:remove() 37 | 38 | --[[ 39 | 40 | type can be "dynamic" "static" or "kinematic". 41 | default type is "dynamic" 42 | 43 | please check other samples 44 | 45 | ]] -- -------------------------------------------------------------------------------- /rapanui-samples/physics/rn-physics-touchMove.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | --simple code to move a physical object under mouse 17 | 18 | 19 | RNPhysics.start() 20 | 21 | 22 | local touchedObject 23 | 24 | function letterTouchDown(event) 25 | touchedObject = event.target 26 | end 27 | 28 | function touch(event) 29 | if touchedObject ~= nil then 30 | touchedObject.x = event.x 31 | touchedObject.y = event.y 32 | touchedObject:setLinearVelocity(0, 0) 33 | end 34 | end 35 | 36 | function create_letter() 37 | local letter = RNFactory.createImage("images/tile0.png"); letter.x = math.random(45, 300); letter.y = 40; 38 | RNPhysics.createBodyFromImage(letter) 39 | letter.restitution = 0.5 40 | letter:setOnTouchDown(letterTouchDown) 41 | end 42 | 43 | 44 | function create_floor() 45 | local floor = RNFactory.createImage("rapanui-samples/physics/floor.png") 46 | floor.x = 160 47 | floor.y = 400 48 | RNPhysics.createBodyFromImage(floor, "static") 49 | end 50 | 51 | 52 | RNListeners:addEventListener("touch", touch) 53 | RNFactory.createImage("images/background-purple.png") 54 | create_floor() 55 | create_letter() -------------------------------------------------------------------------------- /rapanui-sdk/RNMapObject.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | RNMapObject = {} 16 | 17 | function RNMapObject:new(o) 18 | o = o or { 19 | name = "" 20 | } 21 | setmetatable(o, self) 22 | self.__index = self 23 | self.objects = {} 24 | return o 25 | end 26 | 27 | function RNMapObject:getName() 28 | return self.name 29 | end 30 | 31 | function RNMapObject:getProperties() 32 | return self.properties 33 | end 34 | 35 | function RNMapObject:getPropertiesSize() 36 | return self.propertiesSize 37 | end 38 | 39 | 40 | function RNMapObject:getGid() 41 | return self.gid 42 | end 43 | 44 | function RNMapObject:getX() 45 | return self.x 46 | end 47 | 48 | function RNMapObject:getY() 49 | return self.y 50 | end 51 | 52 | function RNMapObject:getType() 53 | return self.type 54 | end 55 | 56 | function RNMapObject:getProperty(key) 57 | if self.propertiesSize > 0 then 58 | for lkey, lvalue in pairs(self.properties) do 59 | if lkey == key then 60 | return lvalue 61 | end 62 | end 63 | end 64 | return "" 65 | end 66 | 67 | return RNMapObject 68 | -------------------------------------------------------------------------------- /rapanui-samples/groups/mapone.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /rapanui-samples/groups/mapthree.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /rapanui-samples/groups/maptwo.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /rapanui-samples/layers/rn-layers-multilayerHud.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | ------------------------------------------------------------------------- 3 | -- Date: 12/05/2012 4 | -- @Author: Marko Pukari 5 | -- Multilayer is used to create HUD layer which stays stationary. 6 | -- all objects added to he HUD layer will move with the camera movement 7 | -- 8 | -------------------------------------------------------------------------- 9 | --]] 10 | 11 | -- variables to make our work easier 12 | local screen = RNFactory.screen 13 | local viewport = screen.viewport 14 | local layers = screen.layers 15 | local mainlayer = layers:get(RNFactory.MAIN_LAYER) 16 | 17 | -- create camera and place it to the main layer 18 | local camera = MOAICamera2D.new() 19 | 20 | layers:get(RNLayer.MAIN_LAYER):setCamera(camera) 21 | 22 | --create new layer for hud 23 | local hudlayer = layers:createLayerWithPartition(RNLayer.HUD_LAYER, viewport) 24 | 25 | --create backgroud 26 | --if you don't give the layer to the create, the image will be added to the mainlayer 27 | local background = RNFactory.createImageFrom("images/background-landscape-hd.png", mainlayer) 28 | local gamegroup = RNGroup:new() 29 | 30 | --create new image to the game/mainlayer 31 | local gameobject = RNFactory.createImageFrom("images/tile0.png", mainlayer) 32 | gameobject.x = 100 33 | gameobject.y = 100 34 | 35 | --create new image to the hudlayer 36 | local hudobject = RNFactory.createImageFrom("images/tile1.png", hudlayer) 37 | hudobject.x = 200 38 | hudobject.y = 300 39 | 40 | --move camera. Hud image stays on the same place while the camera moves acros the 41 | --background. Images on game/mainlayer stays where they where placed 42 | camera:seekLoc(100, 100, 5) 43 | -------------------------------------------------------------------------------- /rapanui-samples/menu/rn-menu-popup.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local isShown = false 16 | 17 | 18 | --add things to sceneGroup 19 | local background = RNFactory.createImage("images/background-purple.png", { parentGroup = sceneGroup }); background.x = 160; background.y = 240; 20 | local text1 = RNFactory.createText("Touch the button to show popup!", { size = 20, top = 100, left = 50, width = 200, height = 500 }) 21 | local button1 = RNFactory.createAnim("images/rapanui_circles.png", 64, 64, 100, 200, 1, 1) button1.frame = 1 22 | button1.x = 200; button1.y = 100 23 | 24 | 25 | local popup = require("rapanui-samples/menu/popup") 26 | 27 | 28 | function showPopup() 29 | popup.onShow() 30 | end 31 | 32 | function hidePopup() 33 | popup.onHide() 34 | end 35 | 36 | 37 | 38 | 39 | function b1touchdown(event) 40 | event.target.frame = 5 41 | end 42 | 43 | 44 | button1:setOnTouchDown(b1touchdown) 45 | 46 | function b1touchup(event) 47 | event.target.frame = 1 48 | if popup.isTransitioning == false then 49 | if isShown == false then 50 | showPopup() 51 | isShown = true 52 | else 53 | hidePopup() 54 | isShown = false 55 | end 56 | end 57 | end 58 | 59 | 60 | button1:setOnTouchUp(b1touchup) -------------------------------------------------------------------------------- /rapanui-samples/atlas/rn-atlas-texture-packer.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | --Rapanui sample on how to use atlases exported for moai with Texture Packer 17 | 18 | --simple image 19 | RNFactory.createImage("images/image.png") 20 | 21 | --atlas creations 22 | RNFactory.createAtlasFromTexturePacker("images/TPAtlasSample.png", "images/TPAtlasSample.lua") 23 | --create some images from atlas 24 | --create tile1 and scale it 25 | local a = RNFactory.createImage("tile1.png", { left = 100 }) 26 | a.scaleX = 0.4 27 | a.scaleY = 0.4 28 | --create tile 2 and scale it horizontally and vertically 29 | local b = RNFactory.createImage("tile2.png", { left = 200 }) 30 | --flips b 31 | b:flipHorizontal() 32 | b:flipVertical() 33 | local c = RNFactory.createImage("tile3.png", { left = 200, top = 100 }) 34 | c.scaleX = -0.3 35 | c.scaleY = -0.7 36 | local d = RNFactory.createImage("tile4.png", { left = 100, top = 100 }) 37 | d.scaleX = 0.8 38 | d.scaleY = 0.8 39 | 40 | 41 | 42 | --atlas can be used as spritesheet for animations 43 | --in fact images created from atlas are animations. 44 | local img = RNFactory.createImage("drink.png", { top = 250, left = 150 }) 45 | --indexes are images in atlas ordered as exported from Texture Packer 46 | img:newSequence("seq", { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 3, 5) 47 | img:play("seq") 48 | -------------------------------------------------------------------------------- /rapanui-sdk/RNListeners.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | RNRuntime = {} 16 | 17 | function RNRuntime:new(o) 18 | o = o or { 19 | name = "" 20 | } 21 | setmetatable(o, self) 22 | self.__index = self 23 | 24 | self.objects = {} 25 | return o 26 | end 27 | 28 | function RNRuntime:addEventListener(eventName, listener, name) 29 | 30 | local listenerId 31 | 32 | if eventName == "enterFrame" then 33 | 34 | if type(listener) == "table" then 35 | listenerId = RNMainThread.getMainThread():addEnterFrame(listener.enterFrame, listener) 36 | end 37 | 38 | if type(listener) == "function" then 39 | listenerId = RNMainThread.getMainThread():addEnterFrame(listener) 40 | end 41 | 42 | elseif eventName == "touch" then 43 | listenerId = RNInputManager.addGlobalListenerToEvent(eventName, listener, { name = name }) 44 | end 45 | 46 | return listenerId 47 | end 48 | 49 | function RNRuntime:removeEventListener(eventName, id) 50 | if eventName == "enterFrame" then 51 | RNMainThread.getMainThread():removeAction(id) 52 | elseif eventName == "touch" then 53 | RNInputManager.removeGlobalListenerToEvent(eventName, id) 54 | end 55 | end 56 | 57 | 58 | RNListeners = RNRuntime:new() 59 | 60 | return RNListeners -------------------------------------------------------------------------------- /rapanui-samples/touch/rn-touch-buttons.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | text = RNFactory.createText("Touch on buttons", { size = 18, top = 200, left = 5, width = 250, height = 50 }) 16 | 17 | back = RNFactory.createImage("images/background-purple.png") 18 | back:sendToBottom() 19 | 20 | buttonOne = RNFactory.createImage("images/tile1.png", { top = 50, left = 50 }) 21 | 22 | 23 | buttonTwo = RNFactory.createImage("images/tile2.png", { top = 50, left = 150 }) 24 | 25 | buttonTwo.rotation = 30 26 | 27 | 28 | 29 | function button1TouchDown(event) 30 | text:setText("Button one touch down!") 31 | end 32 | 33 | function button1Moved(event) 34 | text:setText("Button one moved!") 35 | end 36 | 37 | function button1UP(event) 38 | text:setText("Button one touch up") 39 | end 40 | 41 | buttonOne:setOnTouchDown(button1TouchDown) 42 | buttonOne:setOnTouchMove(button1Moved) 43 | buttonOne:setOnTouchUp(button1UP) 44 | 45 | 46 | function button2TouchDown(event) 47 | text:setText("Button two touch down!") 48 | end 49 | 50 | function button2Moved(event) 51 | text:setText("Button two moved!") 52 | end 53 | 54 | function button2Up(event) 55 | text:setText("Button two touch up") 56 | end 57 | 58 | buttonTwo:setOnTouchDown(button2TouchDown) 59 | buttonTwo:setOnTouchMove(button2Moved) 60 | buttonTwo:setOnTouchUp(button2Up) -------------------------------------------------------------------------------- /rapanui-samples/touch/rn-touch-buttons-untouchable.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- by default RNObject aren't touchable only when a listener it's set they start to be touchable. 16 | 17 | text = RNFactory.createText("Touch on buttons", { size = 18, top = 200, left = 5, width = 250, height = 50 }) 18 | 19 | back = RNFactory.createImage("images/background-purple.png") 20 | back:sendToBottom() 21 | 22 | 23 | buttonOne = RNFactory.createImage("images/tile1.png", { top = 50, left = 50 }) 24 | 25 | hex = RNFactory.createImage("images/hex-pattern.png") 26 | hex:bringToFront() 27 | text:bringToFront() 28 | 29 | function button1TouchDown(event) 30 | text:setText("Button one touch down!") 31 | end 32 | 33 | function button1Moved(event) 34 | text:setText("Button one moved!") 35 | end 36 | 37 | function button1UP(event) 38 | text:setText("Button one touch up") 39 | end 40 | 41 | buttonOne:setOnTouchDown(button1TouchDown) 42 | buttonOne:setOnTouchMove(button1Moved) 43 | buttonOne:setOnTouchUp(button1UP) 44 | 45 | trn = RNTransition:new() 46 | 47 | function goToPointA() 48 | trn:run(buttonOne, { type = "move", time = 3000, alpha = 0, x = 200, y = 100, onComplete = goToPointB }) 49 | end 50 | 51 | function goToPointB() 52 | trn:run(buttonOne, { type = "move", time = 3000, alpha = 0, x = 200, y = 400, onComplete = goToPointA }) 53 | end 54 | 55 | goToPointA() -------------------------------------------------------------------------------- /rapanui-samples/physics/rn-physics-forces.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | --We create 3 objects and apply forces and impulses to them 16 | 17 | 18 | --add images 19 | background = RNFactory.createImage("rapanui-samples/physics/background-purple.png") 20 | box = RNFactory.createImage("rapanui-samples/physics/box.png"); box.x = 170; box.y = 80; 21 | ball = RNFactory.createImage("rapanui-samples/physics/ball.png"); ball.x = 270; ball.y = 80; 22 | triangle = RNFactory.createImage("rapanui-samples/physics/poly.png"); triangle.x = 80; triangle.y = 80; triangle.rotation = 190 23 | floor = RNFactory.createImage("rapanui-samples/physics/floor.png"); floor.x = 160; floor.y = 400; 24 | 25 | --starts simulation 26 | RNPhysics.start() 27 | 28 | 29 | --set images as physics objects 30 | RNPhysics.createBodyFromImage(box) 31 | RNPhysics.createBodyFromImage(ball, { shape = "circle", restitution = 0.2 }) 32 | RNPhysics.createBodyFromImage(triangle, { shape = { -32, 32, 0, -32, 32, 32 }, restitution = 0.2 }) 33 | RNPhysics.createBodyFromImage(floor, "static") 34 | 35 | box.restitution = 0.2 36 | box:applyAngularImpulse(1000000) 37 | 38 | ball:applyLinearImpulse(-10000, -100000, ball.x, ball.y) 39 | 40 | triangle:applyForce(0, -100000, triangle.x, triangle.y) 41 | 42 | --check RNBody.lua for all methods available! 43 | 44 | 45 | --[[ 46 | 47 | please check other samples 48 | 49 | ]] -- -------------------------------------------------------------------------------- /rapanui-samples/basic/rn-levels.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | -- this sample shows how to set image levels. 17 | -- it only works for images in the same group because each group has its own priority set to 1. 18 | 19 | IMG_POS_Y = 0 20 | IMG_POS_X = 0 21 | 22 | SHIFT_X = 20 23 | SHIFT_Y = 20 24 | 25 | local background = RNFactory.createImage("images/background-purple.png") 26 | 27 | anImage1 = RNFactory.createImage("images/tile1.png", { top = IMG_POS_X + SHIFT_X * 4, left = IMG_POS_Y + SHIFT_Y * 4 }) 28 | anImage2 = RNFactory.createImage("images/tile2.png", { top = IMG_POS_X + SHIFT_X * 3, left = IMG_POS_Y + SHIFT_Y * 3 }) 29 | anImage3 = RNFactory.createImage("images/tile3.png", { top = IMG_POS_X + SHIFT_X * 2, left = IMG_POS_Y + SHIFT_Y * 2 }) 30 | anImage4 = RNFactory.createImage("images/tile4.png", { top = IMG_POS_X + SHIFT_X, left = IMG_POS_Y + SHIFT_Y }) 31 | anImage5 = RNFactory.createImage("images/tile5.png", { top = IMG_POS_X, left = IMG_POS_X }) 32 | 33 | anImage5:sendToBottom() 34 | 35 | anImage1:bringToFront() 36 | 37 | IMG_POS_Y = 150 38 | 39 | anImage_B6 = RNFactory.createImage("images/tile6.png", { top = IMG_POS_X + SHIFT_X * 2, left = IMG_POS_Y }) 40 | anImage_B7 = RNFactory.createImage("images/tile7.png", { top = IMG_POS_X + SHIFT_X, left = IMG_POS_Y }) 41 | anImage_B8 = RNFactory.createImage("images/tile8.png", { top = IMG_POS_X, left = IMG_POS_Y }) 42 | 43 | anImage_B7:putOver(anImage_B8) 44 | 45 | -------------------------------------------------------------------------------- /rapanui-samples/director/rn-director-touch.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | effects = { "slidetoleft", "slidetoright", "crossfade", "slidetotop", "slidetobottom", "pop", "fade" } 16 | 17 | function getRandomTransition() 18 | return effects[math.random(1, table.getn(effects) + 1)] 19 | end 20 | 21 | director = RNDirector:new() 22 | 23 | director:addScene("rapanui-samples/director/scene1") 24 | director:addScene("rapanui-samples/director/scene2") 25 | 26 | --check if they are inside the director 27 | for i, v in ipairs(director.scenes) do 28 | print(i, v) 29 | end 30 | 31 | --Set director's time 32 | director:setTime(1000) 33 | 34 | director:showScene("rapanui-samples/director/scene1", getRandomTransition()) 35 | 36 | text1 = RNFactory.createText("Touch to swap!", { size = 20, top = 5, left = 5, width = 200, height = 50 }) 37 | text1:setLevel(1000) 38 | 39 | local scene1 = "rapanui-samples/director/scene1" 40 | local scene2 = "rapanui-samples/director/scene2" 41 | local sceneToShow = scene1 42 | 43 | function onTouchEvent(event) 44 | if event.phase == "began" and director:isTransitioning() == false then 45 | 46 | if sceneToShow == scene1 then 47 | sceneToShow = scene2 48 | else 49 | sceneToShow = scene1 50 | end 51 | 52 | transition = getRandomTransition() 53 | director:showScene(sceneToShow, transition) 54 | end 55 | end 56 | 57 | RNListeners:addEventListener("touch", onTouchEvent) -------------------------------------------------------------------------------- /rapanui-samples/listeners/rn-listener-touch-remove.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | back = RNFactory.createImage("images/background-purple.png") 16 | back:sendToBottom() 17 | 18 | text = RNFactory.createText("Touch and drag to update coords", { size = 18, top = 400, left = 5, width = 200, height = 50 }) 19 | 20 | coords = RNFactory.createText("0,0", { size = 18, top = 400, left = 150, width = 200, height = 50 }) 21 | 22 | textinfo = RNFactory.createText("Touch button1 to remove/add listener", { size = 16, top = 10, left = 5, width = 300, height = 50 }) 23 | 24 | buttonOne = RNFactory.createImage("images/tile1.png", { top = 60, left = 120 }) 25 | 26 | 27 | local w, h = RNFactory.stageWidth, RNFactory.stageHeight 28 | local removed = false 29 | listenerId = nil 30 | 31 | function button1UP(event) 32 | if removed == false then 33 | text:setText("Removed listener: " .. listenerId) 34 | RNListeners:removeEventListener("touch", listenerId) 35 | removed = true 36 | else 37 | listenerId = RNListeners:addEventListener("touch", onTouchEvent) 38 | text:setText("Added listener: " .. listenerId) 39 | removed = false 40 | end 41 | end 42 | 43 | buttonOne:setOnTouchUp(button1UP) 44 | 45 | 46 | function onTouchEvent(event) 47 | if event.phase == "moved" then 48 | coords:setText("" .. event.x .. ", " .. event.y) 49 | end 50 | end 51 | 52 | listenerId = RNListeners:addEventListener("touch", onTouchEvent) 53 | print(listenerId) 54 | -------------------------------------------------------------------------------- /rapanui-sdk/RNMapObjectGroup.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | RNMapObjectGroup = {} 16 | 17 | function RNMapObjectGroup:new(o) 18 | o = o or { 19 | name = "" 20 | } 21 | setmetatable(o, self) 22 | self.__index = self 23 | self.objects = {} 24 | return o 25 | end 26 | 27 | function RNMapObjectGroup:getName() 28 | return self.name 29 | end 30 | 31 | function RNMapObjectGroup:getObjects() 32 | return self.objects 33 | end 34 | 35 | function RNMapObjectGroup:getObject(index) 36 | return self.objects[index] 37 | end 38 | 39 | function RNMapObjectGroup:getFirstObjectByName(name) 40 | for key, value in pairs(self.objects) do 41 | if value.name == name then 42 | return value 43 | end 44 | end 45 | 46 | return nil 47 | end 48 | 49 | function RNMapObjectGroup:getPropertiesSize() 50 | return self.propertiesSize 51 | end 52 | 53 | function RNMapObjectGroup:getObjectsSize() 54 | return self.objectsSize 55 | end 56 | 57 | 58 | function RNMapObjectGroup:getProperties() 59 | return self.properties 60 | end 61 | 62 | function RNMapObjectGroup:getProperty(key) 63 | if self.propertiesSize > 0 then 64 | for lkey, lvalue in pairs(self.properties) do 65 | if lkey == key then 66 | return lvalue 67 | end 68 | end 69 | end 70 | return "" 71 | end 72 | 73 | return RNMapObjectGroup 74 | -------------------------------------------------------------------------------- /rapanui-samples/menu/scene4m.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | 18 | --[[ 19 | 20 | SCENES MUST HAVE 21 | 1)a sceneGroup where all instances are inserted 22 | 2)onCreate function in which we create everything 23 | 3)onEnd function in which we clean the instance 24 | 25 | ]] -- 26 | 27 | aScene = {} 28 | 29 | local sceneGroup = RNGroup:new() 30 | 31 | 32 | 33 | --init Scene 34 | function aScene.onCreate() 35 | --add things to sceneGroup 36 | local background = RNFactory.createImage("images/background-blue.png", { parentGroup = sceneGroup }); background.x = 160; background.y = 240; 37 | local button1 = RNFactory.createAnim("images/sceneButtons.png", 128, 64) 38 | local text1 = RNFactory.createText("This is the scene four.", { size = 16, top = 150, left = 50, width = 200, height = 500 }) 39 | sceneGroup:insert(text1) 40 | button1.frame = 1 41 | sceneGroup:insert(button1) 42 | button1.x = 100; button1.y = 100 43 | 44 | 45 | 46 | button1:setOnTouchDown(button1Down) 47 | 48 | 49 | button1:setOnTouchUp(button1Up) 50 | 51 | 52 | --return sceneGroup 53 | return sceneGroup 54 | end 55 | 56 | function button1Down(event) 57 | event.target.frame = 2 58 | end 59 | 60 | function button1Up(event) 61 | event.target.frame = 1 62 | director:showScene("rapanui-samples/menu/scene1m", "slidetotop") 63 | end 64 | 65 | 66 | 67 | function aScene.onEnd() 68 | sceneGroup:remove() 69 | end 70 | 71 | return aScene 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /rapanui-samples/menu/scene2m.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | 18 | --[[ 19 | 20 | SCENES MUST HAVE 21 | 1)a sceneGroup where all instances are inserted 22 | 2)onCreate function in which we create everything 23 | 3)onEnd function in which we clean the instance 24 | 25 | ]] -- 26 | 27 | aScene = {} 28 | 29 | local sceneGroup = RNGroup:new() 30 | 31 | 32 | 33 | --init Scene 34 | function aScene.onCreate() 35 | --add things to sceneGroup 36 | local background = RNFactory.createImage("images/background-blue.png", { parentGroup = sceneGroup }); background.x = 160; background.y = 240; 37 | local text1 = RNFactory.createText("This is the scene two.", { size = 16, top = 150, left = 50, width = 200, height = 500 }) 38 | sceneGroup:insert(text1) 39 | local button1 = RNFactory.createAnim("images/sceneButtons.png", 128, 64) 40 | button1.frame = 1 41 | sceneGroup:insert(button1) 42 | button1.x = 100; button1.y = 100 43 | 44 | 45 | 46 | button1:setOnTouchDown(button1Down) 47 | 48 | 49 | button1:setOnTouchUp(button1Up) 50 | 51 | 52 | --return sceneGroup 53 | return sceneGroup 54 | end 55 | 56 | function button1Down(event) 57 | event.target.frame = 2 58 | end 59 | 60 | function button1Up(event) 61 | event.target.frame = 1 62 | director:showScene("rapanui-samples/menu/scene1m", "slidetoright") 63 | end 64 | 65 | 66 | 67 | function aScene.onEnd() 68 | sceneGroup:remove() 69 | end 70 | 71 | return aScene 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /rapanui-samples/menu/scene3m.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | 18 | --[[ 19 | 20 | SCENES MUST HAVE 21 | 1)a sceneGroup where all instances are inserted 22 | 2)onCreate function in which we create everything 23 | 3)onEnd function in which we clean the instance 24 | 25 | ]] -- 26 | 27 | aScene = {} 28 | 29 | local sceneGroup = RNGroup:new() 30 | 31 | 32 | 33 | --init Scene 34 | function aScene.onCreate() 35 | --add things to sceneGroup 36 | local background = RNFactory.createImage("images/background-blue.png", { parentGroup = sceneGroup }); background.x = 160; background.y = 240; 37 | local text1 = RNFactory.createText("This is the scene three.", { size = 16, top = 150, left = 50, width = 200, height = 500 }) 38 | sceneGroup:insert(text1) 39 | local button1 = RNFactory.createAnim("images/sceneButtons.png", 128, 64) 40 | button1.frame = 1 41 | sceneGroup:insert(button1) 42 | button1.x = 100; button1.y = 100 43 | 44 | 45 | 46 | button1:setOnTouchDown(button1Down) 47 | 48 | 49 | button1:setOnTouchUp(button1Up) 50 | 51 | 52 | --return sceneGroup 53 | return sceneGroup 54 | end 55 | 56 | function button1Down(event) 57 | event.target.frame = 2 58 | end 59 | 60 | function button1Up(event) 61 | event.target.frame = 1 62 | director:showScene("rapanui-samples/menu/scene1m", "slidetobottom") 63 | end 64 | 65 | 66 | 67 | function aScene.onEnd() 68 | sceneGroup:remove() 69 | end 70 | 71 | return aScene 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /rapanui-sdk/RNUnit.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | RNUnit = {} 15 | 16 | function RNUnit.assertEquals(expected, actual, message) 17 | 18 | local fullMessage = "expected and actual are different" 19 | 20 | if (type(actual) == "string" or type(actual) == "number" or type(actual) == "nil") and 21 | (type(expected) == "string" or type(expected) == "number" or type(expected) == "nil") then 22 | 23 | local actualMessage = actual 24 | local expectedMessage = expected 25 | 26 | if actual == nil then 27 | actualMessage = "nil" 28 | end 29 | 30 | if expected == nil then 31 | expectedMessage = "nil" 32 | end 33 | 34 | fullMessage = "expected [" .. expectedMessage .. "] actual [" .. actualMessage .. "]" 35 | end 36 | 37 | if message ~= nil then 38 | fullMessage = fullMessage .. ": " .. message 39 | end 40 | assert(actual == expected, fullMessage) 41 | end 42 | 43 | function RNUnit.assertNil(actual, message) 44 | 45 | local fullMessage = "actual should be nil" 46 | 47 | if message ~= nil then 48 | fullMessage = fullMessage .. ": " .. message 49 | end 50 | assert(actual == nil, fullMessage) 51 | end 52 | 53 | function RNUnit.assertNotNil(actual, message) 54 | 55 | local fullMessage = "actual should not be nil" 56 | 57 | if message ~= nil then 58 | fullMessage = fullMessage .. ": " .. message 59 | end 60 | assert(actual ~= nil, fullMessage) 61 | end 62 | 63 | return RNUnit -------------------------------------------------------------------------------- /rapanui-samples/director/rn-director-touch-listener.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | effects = { "slidetoleft", "slidetoright", "crossfade", "slidetotop", "slidetobottom", "pop", "fade" } 16 | 17 | function getRandomTransition() 18 | return effects[math.random(1, table.getn(effects) + 1)] 19 | end 20 | 21 | director = RNDirector:new() 22 | 23 | director:addScene("rapanui-samples/director/scene1") 24 | director:addScene("rapanui-samples/director/scene2") 25 | 26 | --check if they are inside the director 27 | for i, v in ipairs(director.scenes) do 28 | print(i, v) 29 | end 30 | 31 | --Set director's time 32 | director:setTime(1000) 33 | 34 | 35 | 36 | director:showScene("rapanui-samples/director/scene1", getRandomTransition()) 37 | 38 | text1 = RNFactory.createText("Touch to swap!", { size = 20, top = 5, left = 5, width = 200, height = 50 }) 39 | text1:setLevel(1000) 40 | 41 | local scene1 = "rapanui-samples/director/scene1" 42 | local scene2 = "rapanui-samples/director/scene2" 43 | local sceneToShow = scene1 44 | 45 | function callMeBack(event) 46 | print("Called Back!") 47 | end 48 | 49 | function onTouchEvent(event) 50 | if event.phase == "began" and director:isTransitioning() == false then 51 | if sceneToShow == scene1 then 52 | sceneToShow = scene2 53 | else 54 | sceneToShow = scene1 55 | end 56 | 57 | director:showScene(sceneToShow, getRandomTransition(), callMeBack) 58 | end 59 | end 60 | 61 | 62 | 63 | RNListeners:addEventListener("touch", onTouchEvent) -------------------------------------------------------------------------------- /rapanui-samples/physics/rn-physics-animation.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | --Animations can become physic objects... 16 | 17 | 18 | --add images 19 | background = RNFactory.createImage("rapanui-samples/physics/background-purple.png") 20 | box = RNFactory.createImage("rapanui-samples/physics/box.png"); box.x = 170; box.y = 80; 21 | ball = RNFactory.createImage("rapanui-samples/physics/ball.png"); ball.x = 240; ball.y = 80; 22 | triangle = RNFactory.createImage("rapanui-samples/physics/poly.png"); triangle.x = 80; triangle.y = 80; triangle.rotation = 190 23 | floor = RNFactory.createImage("rapanui-samples/physics/floor.png"); floor.x = 160; floor.y = 400; 24 | 25 | --starts simulation 26 | RNPhysics.start() 27 | 28 | 29 | --set images as physics objects 30 | RNPhysics.createBodyFromImage(box) 31 | RNPhysics.createBodyFromImage(ball, { shape = "circle" }) 32 | RNPhysics.createBodyFromImage(triangle, { shape = { -32, 32, 0, -32, 32, 32 }, restitution = 0.3, friction = 0.1 }) 33 | RNPhysics.createBodyFromImage(floor, "static") 34 | box.restitution = 0.5 35 | ball.restitution = 0.3 36 | triangle.restitution = 0.3 37 | 38 | 39 | --simple animation which plays the default sequence 40 | char = RNFactory.createAnim("rapanui-samples/physics/char.png", 42, 32) 41 | char.x = 100; char.y = 100; 42 | char.scaleX = 0.5; char.scaleY = 1 43 | char:play("default", 12, -1) 44 | 45 | RNPhysics.createBodyFromImage(char) 46 | char.restitution = 0.8 47 | 48 | 49 | 50 | 51 | --[[ 52 | 53 | Check other samples for complete animation tutorials. 54 | 55 | ]] -- -------------------------------------------------------------------------------- /rapanui-samples/director/scene4.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | --[[ 17 | 18 | SCENES MUST HAVE 19 | 1)a sceneGroup where all instances are inserted 20 | 2)onCreate function in which we create everything 21 | 3)onEnd function in which we clean the instance 22 | 23 | ]] -- 24 | 25 | 26 | local sceneGroup = RNGroup:new() 27 | 28 | aScene = {} 29 | 30 | 31 | --init Scene 32 | function aScene.onCreate() 33 | --add things to sceneGroup 34 | local background = RNFactory.createImage("images/background-green.png", { parentGroup = sceneGroup }); background.x = 160; background.y = 240; 35 | local tile1a = RNFactory.createImage("images/tile4.png", { parentGroup = sceneGroup }); tile1a.x = 160; tile1a.y = 320; 36 | local tile1b = RNFactory.createImage("images/tile4.png", { parentGroup = sceneGroup }); tile1b.x = 100; tile1b.y = 140; 37 | local tile1c = RNFactory.createImage("images/tile4.png", { parentGroup = sceneGroup }); tile1c.x = 260; tile1c.y = 340; 38 | -- for i = 1, table.getn(RNFactory.sceneGroup.displayObjects), 1 do 39 | -- RNFactory.sceneGroup:removeChild(1); 40 | -- end 41 | --sceneGroup:insert(background) 42 | -- sceneGroup:insert(tile1a) 43 | --sceneGroup:insert(tile1b) 44 | --sceneGroup:insert(tile1c) 45 | --return sceneGroup 46 | return sceneGroup 47 | end 48 | 49 | 50 | function aScene.onEnd() 51 | for i = 1, table.getn(sceneGroup.displayObjects), 1 do 52 | sceneGroup.displayObjects[1]:remove(); 53 | end 54 | end 55 | 56 | return aScene 57 | 58 | 59 | -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-basic-map-properties.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- tiles by Daniel Cook (http://www.lostgarden.com) 16 | 17 | --so now we want to get properties for the tiles we touch 18 | -- from our "mountains" layer in rpgmap-properties.tmx map 19 | 20 | --we create a map 21 | local map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/rpgmap-properties.tmx") 22 | 23 | local aTileset = map:getTileset(0) 24 | aTileset:updateImageSource("rapanui-samples/maps/rpgtileset.png") 25 | 26 | map:drawMapAt(0, 0, aTileset) 27 | 28 | 29 | --we get the layer we are interested in 30 | local mountainslayer = map:getLayerByName("mountains") 31 | 32 | 33 | --we set a callback for touch 34 | function touch(event) 35 | if event.phase == "began" then 36 | --we get properties 37 | local properties = mountainslayer:getTilePropertiesAt(event.x, event.y, aTileset) 38 | if properties ~= nil then 39 | --we print them 40 | for i, v in pairs(properties) do 41 | print(i, v) 42 | end 43 | end 44 | end 45 | end 46 | 47 | --set a touch listener 48 | RNListeners:addEventListener("touch", touch) 49 | 50 | 51 | --i've set properties only for "mountains" layer and only for the 4 center tiles on the top of the mountain 52 | -- and for the vines I've set two values. 53 | -- 54 | --this way we can get whether a tile is solid so maybe a character can't walk over it 55 | --or maybe we want to get when a character walks on a specific tile which will generate an event in the game. 56 | -------------------------------------------------------------------------------- /rapanui-samples/director/scene3.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | --[[ 18 | 19 | SCENES MUST HAVE 20 | 1)a sceneGroup where all instances are inserted 21 | 2)onCreate function in which we create everything 22 | 3)onEnd function in which we clean the instance 23 | 24 | ]] -- 25 | 26 | aScene = {} 27 | 28 | local sceneGroup = RNGroup:new() 29 | 30 | 31 | 32 | --init Scene 33 | function aScene.onCreate() 34 | --add things to sceneGroup 35 | local background = RNFactory.createImage("images/background-blue.png", { parentGroup = sceneGroup }); background.x = 160; background.y = 240; 36 | local tile1a = RNFactory.createImage("images/tile3.png", { parentGroup = sceneGroup }); tile1a.x = 100; tile1a.y = 340; 37 | local tile1b = RNFactory.createImage("images/tile3.png", { parentGroup = sceneGroup }); tile1b.x = 100; tile1b.y = 240; 38 | local tile1c = RNFactory.createImage("images/tile3.png", { parentGroup = sceneGroup }); tile1c.x = 260; tile1c.y = 140; 39 | --for i = 1, table.getn(RNFactory.sceneGroup.displayObjects), 1 do 40 | -- RNFactory.sceneGroup:removeChild(1); 41 | --end 42 | -- sceneGroup:insert(background) 43 | -- sceneGroup:insert(tile1a) 44 | -- sceneGroup:insert(tile1b) 45 | -- sceneGroup:insert(tile1c) 46 | --return sceneGroup 47 | return sceneGroup 48 | end 49 | 50 | 51 | 52 | function aScene.onEnd() 53 | for i = 1, table.getn(sceneGroup.displayObjects), 1 do 54 | sceneGroup.displayObjects[1]:remove(); 55 | end 56 | end 57 | 58 | return aScene 59 | 60 | 61 | -------------------------------------------------------------------------------- /rapanui-samples/buttons/rn-button-visibility.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | local toShow = true 17 | 18 | function button1TouchDown(event) 19 | text:setText("Main Button touch down!") 20 | end 21 | 22 | function button1UP(event) 23 | text:setText("Main Button touch up") 24 | end 25 | 26 | mainButton = RNFactory.createButton("images/button-plain.png", { 27 | text = "Main Button", 28 | imageOver = "images/button-over.png", 29 | imageDisabled = "images/button-disabled.png", 30 | top = 50, 31 | left = 10, 32 | size = 22, 33 | width = 200, 34 | height = 50, 35 | onTouchDown = button1TouchDown, 36 | onTouchUp = button1UP, 37 | font = "arial-rounded.TTF" 38 | }) 39 | 40 | -- second button to show different text alignments 41 | 42 | button2 = RNFactory.createButton("images/button-plain.png", { 43 | text = "Hide Main Button", 44 | top = 150, 45 | left = 10, 46 | size = 22, 47 | width = 200, 48 | height = 50 49 | }) 50 | 51 | 52 | 53 | text = RNFactory.createText("Touch on buttons 1", { size = 18, top = 400, left = 5, width = 250, height = 50 }) 54 | 55 | 56 | 57 | 58 | function button2UP(event) 59 | if toShow == true then 60 | button2:setText("View Main Button") 61 | mainButton:setVisible(false) 62 | toShow = false 63 | 64 | else 65 | button2:setText("Hide Main Button") 66 | mainButton:setVisible(true) 67 | toShow = true 68 | end 69 | end 70 | 71 | button2:setOnTouchUp(button2UP) 72 | -------------------------------------------------------------------------------- /rapanui-samples/director/scene2button.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | --[[ 17 | 18 | SCENES MUST HAVE 19 | 1)a sceneGroup where all instances are inserted 20 | 2)onCreate function in which we create everything 21 | 3)onEnd function in which we clean the instance 22 | 23 | ]] -- 24 | 25 | aScene = {} 26 | 27 | local sceneGroup = RNGroup:new() 28 | 29 | 30 | --init Scene 31 | function aScene.onCreate() 32 | --add things to sceneGroup 33 | local background = RNFactory.createImage("images/background-green.png", { parentGroup = sceneGroup }); background.x = 160; background.y = 240; 34 | 35 | local tile1a = RNFactory.createImage("images/tile2.png", { parentGroup = sceneGroup }); tile1a.x = 160; tile1a.y = 240; 36 | 37 | local button2 = RNFactory.createButton("images/button-plain.png", 38 | 39 | { 40 | text = "Go back scene 1", 41 | parentGroup = sceneGroup, 42 | imageOver = "images/button-over.png", 43 | top = 50, 44 | left = 10, 45 | size = 16, 46 | width = 200, 47 | height = 50 48 | }) 49 | 50 | 51 | button2:setOnTouchUp(buttonScene2Up) 52 | 53 | return sceneGroup 54 | end 55 | 56 | 57 | function buttonScene2Up(event) 58 | if not director:isTransitioning() then 59 | director:showScene("rapanui-samples/director/scene1button", "fade") 60 | end 61 | end 62 | 63 | 64 | function aScene.onEnd() 65 | for i = 1, table.getn(sceneGroup.displayObjects), 1 do 66 | sceneGroup.displayObjects[1]:remove(); 67 | end 68 | end 69 | 70 | 71 | return aScene -------------------------------------------------------------------------------- /rapanui-samples/director/scene1.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | 18 | --[[ 19 | 20 | SCENES MUST HAVE 21 | 1)a sceneGroup where all instances are inserted 22 | 2)onCreate function in which we create everything 23 | 3)onEnd function in which we clean the instance 24 | 25 | ]] -- 26 | 27 | aScene = {} 28 | 29 | local sceneGroup = RNGroup:new() 30 | 31 | 32 | 33 | --init Scene 34 | function aScene.onCreate() 35 | --add things to sceneGroup 36 | local background = RNFactory.createImage("images/background-purple.png", { parentGroup = sceneGroup }); background.x = 160; background.y = 240; 37 | local tile1a = RNFactory.createImage("images/tile1.png", { parentGroup = sceneGroup }); tile1a.x = 160; tile1a.y = 240; 38 | local tile1b = RNFactory.createImage("images/tile1.png", { parentGroup = sceneGroup }); tile1b.x = 100; tile1b.y = 340; 39 | local tile1c = RNFactory.createImage("images/tile1.png", { parentGroup = sceneGroup }); tile1c.x = 260; tile1c.y = 240; 40 | 41 | local text1 = RNFactory.createBitmapText("SCENE 1", { 42 | parentGroup = sceneGroup, 43 | image = "images/kromasky.png", 44 | charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!\"%',.", 45 | top = 55, 46 | left = 10, 47 | charWidth = 16, 48 | charHeight = 16 49 | }) 50 | 51 | 52 | --return sceneGroup 53 | return sceneGroup 54 | end 55 | 56 | 57 | 58 | function aScene.onEnd() 59 | for i = 1, table.getn(sceneGroup.displayObjects), 1 do 60 | sceneGroup.displayObjects[1]:remove(); 61 | end 62 | end 63 | 64 | return aScene 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /rapanui-samples/physics/rn-physics-filters.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | --The triangle and the box can't collide! 16 | 17 | 18 | --add images 19 | background = RNFactory.createImage("rapanui-samples/physics/background-purple.png") 20 | box = RNFactory.createImage("rapanui-samples/physics/box.png"); box.x = 170; box.y = 80; 21 | ball = RNFactory.createImage("rapanui-samples/physics/ball.png"); ball.x = 200; ball.y = -50; 22 | triangle = RNFactory.createImage("rapanui-samples/physics/poly.png"); triangle.x = 80; triangle.y = 80; triangle.rotation = 190 23 | floor = RNFactory.createImage("rapanui-samples/physics/floor.png"); floor.x = 160; floor.y = 400; 24 | 25 | --starts simulation 26 | RNPhysics.start() 27 | 28 | 29 | --set images as physics objects 30 | RNPhysics.createBodyFromImage(box, { filter = { groupIndex = -1 } }) 31 | RNPhysics.createBodyFromImage(ball, { shape = "circle" }) 32 | RNPhysics.createBodyFromImage(triangle, { shape = { -32, 32, 0, -32, 32, 32 }, restitution = 0.3, friction = 0.1, filter = { groupIndex = -1 } }) 33 | RNPhysics.createBodyFromImage(floor, "static", { density = 1, friction = 0.3, restitution = 0, sensor = false, shape = { -128, -16, 128, -16, 128, 16, -128, 16 } }, { density = 1, friction = 0.3, restitution = 0.5, sensor = true, shape = { -32, 32 - 100, 32, 32 - 100, 0, 64 - 100 } }) 34 | 35 | box.restitution = 0.5 36 | ball.restitution = 0.3 37 | triangle.restitution = 0.3 38 | 39 | --[[ 40 | 41 | For this sample we use the groupIndex. 42 | but in filter table we can also specify 43 | 44 | {categoryBits=value,maskBits=value,groupIndex=value} 45 | 46 | see box2d docs. 47 | 48 | 49 | 50 | ]] -- -------------------------------------------------------------------------------- /rapanui-samples/touch/rn-buttons-animated.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | 17 | --simple demo, a little bit buggy to show how to create a dragable animated button 18 | back = RNFactory.createImage("images/background-purple.png") 19 | back:sendToBottom() 20 | 21 | text = RNFactory.createText("Touch on button and drag it", { size = 18, top = 100, left = 5, width = 250, height = 50 }) 22 | 23 | 24 | --physical animation with many sequences 25 | --newAnim(file,sizeX,sizeY[,posx,posy,scaleX,scaleY]) 26 | button1 = RNFactory.createAnim("images/rapanui_circles.png", 64, 64, 100, 200, 1, 1) 27 | --newSequence(name,frameOrder,speed,repeatTimes,onStopFunction) 28 | button1:newSequence("default", { 1, 2, 3, 4, 3, 2 }, 12, -1) 29 | button1:newSequence("down", { 5, 6, 7, 8 }, 12, -1) 30 | button1:newSequence("moved", { 9, 10, 11, 12, 11, 10 }, 12, -1) 31 | button1:play("default") 32 | --flag 33 | isMoved = false 34 | 35 | 36 | 37 | --handle local touch listeners 38 | function button1TouchDown(event) 39 | text:setText("touch down") 40 | button1:play("down") 41 | end 42 | 43 | function button1Moved(event) 44 | text:setText("touch moved") 45 | if isMoved == false then 46 | button1:play("moved") 47 | isMoved = true 48 | else 49 | button1.x = event.x 50 | button1.y = event.y 51 | end 52 | end 53 | 54 | function button1UP(event) 55 | text:setText("touch up") 56 | button1:play("default") 57 | isMoved = false 58 | end 59 | 60 | 61 | --call listeners 62 | button1:setOnTouchDown(button1TouchDown) 63 | button1:setOnTouchMove(button1Moved) 64 | button1:setOnTouchUp(button1UP) 65 | 66 | 67 | -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-rnbutton-disabled-move.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | local toDisable = false 17 | 18 | button = RNFactory.createButton("images/button-plain.png", { 19 | text = "Main Button 1", 20 | imageOver = "images/button-over.png", 21 | imageDisabled = "images/button-disabled.png", 22 | top = 50, 23 | left = 10, 24 | size = 16, 25 | width = 200, 26 | height = 50 27 | }) 28 | 29 | button:disable() 30 | 31 | trn = RNTransition:new() 32 | 33 | function goToPointA() 34 | trn:run(button, { type = "move", time = 1500, alpha = 0, x = 200, y = 200, onComplete = goToPointB }) 35 | end 36 | 37 | function goToPointB() 38 | trn:run(button, { type = "move", time = 1500, alpha = 0, x = 0, y = 0, onComplete = goToPointA }) 39 | end 40 | 41 | goToPointA() 42 | 43 | 44 | function button1TouchDown(event) 45 | print("Button 1 touch down!") 46 | end 47 | 48 | function button1UP(event) 49 | print("Button 1 touch up") 50 | end 51 | 52 | button:setOnTouchDown(button1TouchDown) 53 | button:setOnTouchUp(button1UP) 54 | 55 | 56 | 57 | button2 = RNFactory.createButton("images/button-plain.png", { 58 | text = "Disable Main Button", 59 | top = 250, 60 | left = 10, 61 | size = 16, 62 | width = 200, 63 | height = 50 64 | }) 65 | 66 | 67 | 68 | function button2UP(event) 69 | if toDisable == true then 70 | button:disable() 71 | toDisable = false 72 | else 73 | button:enable() 74 | toDisable = true 75 | end 76 | end 77 | 78 | button2:setOnTouchUp(button2UP) 79 | -------------------------------------------------------------------------------- /rapanui-sdk/RNWrappedEventListener.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | require"socket" 16 | RNWrappedEventListener = {} 17 | 18 | 19 | function RNWrappedEventListener:new(o) 20 | o = o or { 21 | name = "", 22 | scheduleRemove = false 23 | } 24 | setmetatable(o, self) 25 | self.__index = self 26 | self.wrappedFunction = nil 27 | return o 28 | end 29 | 30 | function RNWrappedEventListener:getFunction() 31 | return self.wrappedFunction 32 | end 33 | 34 | function RNWrappedEventListener:setTarget(object) 35 | self.target = object 36 | end 37 | 38 | function RNWrappedEventListener:getTarget() 39 | return self.target 40 | end 41 | 42 | function RNWrappedEventListener:scheduleForRemoval() 43 | self.scheduleRemove = true 44 | end 45 | 46 | function RNWrappedEventListener:isToRemove() 47 | return self.scheduleRemove 48 | end 49 | 50 | function RNWrappedEventListener:setFunction(func) 51 | self.wrappedFunction = func 52 | end 53 | 54 | function RNWrappedEventListener:isToCall(x, y) 55 | if self.target ~= nil then 56 | return self.target:isInRange(x, y) 57 | end 58 | return nil 59 | end 60 | 61 | function RNWrappedEventListener:call(event) 62 | 63 | local func = self.wrappedFunction 64 | 65 | event.target = self.target 66 | 67 | if event ~= nil and func ~= nil then 68 | func(event) 69 | else 70 | if event == nil then 71 | print("[WARN] RNWrappedEventListener: Event was nil") 72 | end 73 | 74 | if func == nil then 75 | print("[WARN] RNWrappedEventListener: function was nil") 76 | end 77 | end 78 | end 79 | 80 | return RNWrappedEventListener 81 | -------------------------------------------------------------------------------- /rapanui-samples/physics/rn-physics-shapes.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | --We create 4 objects, one for shape type and one with default shape 16 | 17 | 18 | --add images 19 | background = RNFactory.createImage("rapanui-samples/physics/background-purple.png") 20 | box = RNFactory.createImage("rapanui-samples/physics/box.png"); box.x = 170; box.y = 80; 21 | box2 = RNFactory.createImage("rapanui-samples/physics/box.png"); box2.x = 170; box2.y = 0; 22 | ball = RNFactory.createImage("rapanui-samples/physics/ball.png"); ball.x = 240; ball.y = 80; 23 | triangle = RNFactory.createImage("rapanui-samples/physics/poly.png"); triangle.x = 80; triangle.y = 80; triangle.rotation = 190 24 | floor = RNFactory.createImage("rapanui-samples/physics/floor.png"); floor.x = 160; floor.y = 400; 25 | 26 | --starts simulation 27 | RNPhysics.start() 28 | 29 | 30 | --set images as physics objects 31 | RNPhysics.createBodyFromImage(box) 32 | RNPhysics.createBodyFromImage(box2, { shape = "rectangle" }) 33 | RNPhysics.createBodyFromImage(ball, { shape = "circle" }) 34 | RNPhysics.createBodyFromImage(triangle, { shape = { -32, 32, 0, -32, 32, 32 } }) 35 | RNPhysics.createBodyFromImage(floor, "static") 36 | 37 | 38 | --[[ 39 | 40 | RNPhysics.createBodyFromImage(image[,type,fixture1,fixture2...fixtureN]) 41 | or 42 | RNPhysics.createBodyFromImage(image[,fixture1,fixture2...fixtureN]) 43 | 44 | "fixture" should be a table containing 45 | {density=number,friction=number,shape=string or table,filter=table,restitution=number,sensor=boolean} 46 | 47 | shape can be "circle" , "rectangle" or an array containg vertex coordinate components in clockwise order 48 | shape is "rectangle" for default 49 | 50 | please check other samples 51 | 52 | ]] -- -------------------------------------------------------------------------------- /rapanui-samples/transition/rn-transition-pauseResumeStop.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | RNFactory.createText("Touch buttons to toggle\n or stop transition.\nStop will also call\n the onComplete callback", { size = 20, top = -100, left = 5, width = 340, height = 480, alignment = MOAITextBox.CENTER_JUSTIFY }) 16 | 17 | 18 | local image = RNFactory.createImage("images/image.png") 19 | local transition = RNTransition:new() 20 | local toggle = 0 21 | 22 | local ACTION = transition:run(image, { type = "move", x = 500, y = 500, time = 10000, onComplete = onComplete }) 23 | 24 | function onComplete() 25 | print("Transition completed") 26 | ACTION = nil 27 | end 28 | 29 | 30 | function callbackStop(event) 31 | if event.phase == "began" then 32 | ACTION:stop() 33 | end 34 | end 35 | 36 | function callbackToggle(event) 37 | if event.phase == "began" then 38 | if toggle == 0 then 39 | ACTION:pause() 40 | toggle = 1 41 | else 42 | ACTION:start() 43 | toggle = 0 44 | end 45 | end 46 | end 47 | 48 | 49 | 50 | RNFactory.createButton("images/button-plain.png", { 51 | text = "Toggle", 52 | imageOver = "images/button-over.png", 53 | top = 300, 54 | left = 10, 55 | size = 16, 56 | width = 200, 57 | height = 50, 58 | onTouchDown = callbackToggle, 59 | font = "arial-rounded.TTF" 60 | }) 61 | 62 | 63 | RNFactory.createButton("images/button-plain.png", { 64 | text = "Stop", 65 | imageOver = "images/button-over.png", 66 | top = 350, 67 | left = 10, 68 | size = 16, 69 | width = 200, 70 | height = 50, 71 | onTouchDown = callbackStop, 72 | font = "arial-rounded.TTF" 73 | }) 74 | 75 | -------------------------------------------------------------------------------- /rapanui-samples/buttons/rn-button-disabled.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | local background = RNFactory.createImage("images/background-blue.png") 16 | local toEnable = true 17 | 18 | function button1TouchDown(event) 19 | text:setText("Main Button touch down!") 20 | end 21 | 22 | function button1UP(event) 23 | text:setText("Main Button touch up") 24 | end 25 | 26 | mainButton = RNFactory.createButton("images/button-plain.png", { 27 | text = "Main Button", 28 | imageOver = "images/button-over.png", 29 | imageDisabled = "images/button-disabled.png", 30 | top = 50, 31 | left = 10, 32 | size = 16, 33 | width = 200, 34 | height = 50, 35 | onTouchDown = button1TouchDown, 36 | onTouchUp = button1UP, 37 | font = "arial-rounded.TTF" 38 | }) 39 | 40 | -- second button to show different text alignments 41 | 42 | button2 = RNFactory.createButton("images/button-plain.png", { 43 | text = "Disable Main Button", 44 | top = 150, 45 | left = 10, 46 | size = 16, 47 | width = 200, 48 | height = 50 49 | }) 50 | 51 | function button4TouchDown(event) 52 | event.target:setText("Button 4 touched!") 53 | end 54 | 55 | function button4UP(event) 56 | event.target:setText("") 57 | end 58 | 59 | 60 | text = RNFactory.createText("Touch on buttons 1", { size = 18, top = 400, left = 5, width = 250, height = 50 }) 61 | 62 | 63 | function button2UP(event) 64 | if toEnable == true then 65 | button2:setText("Enabled Main Button") 66 | mainButton:disable() 67 | toEnable = false 68 | 69 | else 70 | button2:setText("Disabled Main Button") 71 | mainButton:enable() 72 | toEnable = true 73 | end 74 | end 75 | 76 | button2:setOnTouchUp(button2UP) 77 | -------------------------------------------------------------------------------- /rapanui-samples/layers/rn-layers-putOnLayer.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- you may want to load objects first and put them on layer later. 16 | 17 | -- variables to make our work easier 18 | local screen = RNFactory.screen 19 | local layers = screen.layers 20 | local mainlayer = layers:get(RNFactory.MAIN_LAYER) 21 | 22 | --create images 23 | local image1 = RNFactory.loadImage("images/image.png") 24 | image1.x = 30 25 | local image2 = RNFactory.loadImage("images/image2.png") 26 | image2.x = 90 27 | 28 | --put them on screen 29 | screen:putOnLayer(image1) 30 | --or put them in a specified layer 31 | screen:putOnLayer(image2, mainlayer) 32 | 33 | --we can also remove them from layer 34 | --uncomment to check: 35 | --[[ 36 | screen:removeFromLayer(image1) 37 | screen:removeFromLayer(image2, mainlayer) 38 | ]] -- 39 | 40 | 41 | --this is the same for 42 | --TEXTS: 43 | local text1 = RNFactory.loadText("Hello world!", { size = 25, top = 5, left = 5, width = 200, height = 50 }) 44 | screen:putOnLayer(text1) 45 | 46 | --BUTTONS: 47 | local button = RNFactory.loadButton("images/button-plain.png", { 48 | text = "Main Button 1", 49 | imageOver = "images/button-over.png", 50 | top = 50, 51 | left = 10, 52 | size = 16, 53 | width = 200, 54 | height = 50, 55 | onTouchDown = button1TouchDown, 56 | onTouchUp = button1UP, 57 | font = "arial-rounded.TTF" 58 | }) 59 | screen:putOnLayer(button) 60 | 61 | 62 | --or 63 | --GROUPS 64 | 65 | local group = RNGroup:new() 66 | local image3 = RNFactory.loadImage("images/image3.png") 67 | image3.y = 200 68 | local image4 = RNFactory.loadImage("images/image4.png") 69 | image4.y = 300 70 | 71 | group:insert(image3) 72 | group:insert(image4) 73 | 74 | screen:putOnLayer(group) 75 | 76 | -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-scrolling-map.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | -- 14 | -- Tiles of the map from: 15 | -- 16 | -- gfxlib 17 | -- 18 | -- Product : gfxlib-fuzed.zip 19 | -- Website : http://www.spicypixel.net 20 | -- Author : Marc Russell 21 | -- Released: 10th January 2008 22 | -- 23 | -- 24 | -- gfxlib is under Common Public License (http://www.opensource.org/licenses/cpl1.0.php) 25 | ]] 26 | 27 | require("socket") 28 | 29 | --socket.gettime() 30 | 31 | local background = RNFactory.createImage("rapanui-samples/maps/platformbck.png") 32 | background:setLevel(-1) 33 | 34 | local map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/platformmap.tmx") 35 | 36 | aTileset = map:getTileset(0) 37 | 38 | aTileset:updateImageSource("rapanui-samples/maps/platformtileset.png") 39 | 40 | local layersSize = map:getLayersSize() 41 | 42 | tilesCreated = 0 43 | map:drawMapAt(0, 0, aTileset) 44 | 45 | 46 | aLayer = map:getFirstLayerByName("platforms") 47 | --aLayer:printToAscii() 48 | 49 | 50 | local lastx = 0 51 | local delta = -3 52 | 53 | lastTime = socket.gettime() 54 | 55 | local intervalForFps = 1 / 60 56 | 57 | print(intervalForFps) 58 | local currentTime = socket.gettime() 59 | local diff = currentTime - lastTime 60 | 61 | function update(enterFrame) 62 | currentTime = socket.gettime() 63 | diff = currentTime - lastTime 64 | if diff >= intervalForFps then 65 | map:drawMapAt(lastx, 0, 0, aTileset) 66 | lastx = lastx + delta 67 | 68 | if lastx <= -1280 then 69 | delta = delta * -1 70 | end 71 | 72 | if lastx >= 0 then 73 | delta = delta * -1 74 | end 75 | lastTime = currentTime 76 | end 77 | end 78 | 79 | RNListeners:addEventListener("enterFrame", update) -------------------------------------------------------------------------------- /rapanui-samples/groups/rn-map-group.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- tiles by Daniel Cook (http://www.lostgarden.com) 16 | 17 | 18 | 19 | mapOne = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/groups/mapone.tmx") 20 | aTileset = mapOne:getTileset(0) 21 | aTileset:updateImageSource("rapanui-samples/groups/tilesetdemo.png") 22 | mapOne:drawMapAt(0, 0, aTileset) 23 | 24 | 25 | mapTwo = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/groups/maptwo.tmx") 26 | aTileset = mapTwo:getTileset(0) 27 | aTileset:updateImageSource("rapanui-samples/groups/tilesetdemo.png") 28 | mapTwo:drawMapAt(0, 160, aTileset) 29 | 30 | 31 | mapThree = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/groups/mapthree.tmx") 32 | aTileset = mapThree:getTileset(0) 33 | aTileset:updateImageSource("rapanui-samples/groups/tilesetdemo.png") 34 | mapThree:drawMapAt(0, 320, aTileset) 35 | 36 | 37 | --add maps in groups, with a little bit of nesting, too ^^ 38 | 39 | group = RNGroup:new() 40 | group2 = RNGroup:new() 41 | 42 | group:insert(mapOne) 43 | group2:insert(mapTwo) 44 | group:insert(mapThree) 45 | group:insert(group2) 46 | group2:removeChild(mapTwo.idInGroup) 47 | 48 | print("group one size: " .. group:getSize()) 49 | 50 | 51 | 52 | local myListener = function(event) 53 | group.x = event.x 54 | group.y = event.y 55 | 56 | -- print("group x: " .. group.x .. " y: " .. group.y) 57 | 58 | -- print("anImageTest1 x: " .. anImageTest1.x .. " y: " .. anImageTest1.y) 59 | -- print("anImageTest2 x: " .. anImageTest2.x .. " y: " .. anImageTest2.y) 60 | -- print("anImageTest3 x: " .. anImageTest3.x .. " y: " .. anImageTest3.y) 61 | -- print("anImageTest4 x: " .. anImageTest4.x .. " y: " .. anImageTest4.y) 62 | end 63 | 64 | RNListeners:addEventListener("touch", myListener) -------------------------------------------------------------------------------- /config.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- width Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | --]] 14 | 15 | --module(..., package.seeall) 16 | 17 | config = {} 18 | config.sizes = {} 19 | 20 | -- Preset for some devices you can add as many as you want 21 | -- WARNING 22 | -- if the size of the moai window it's bigger than your real screen size (the computer on which you dev) 23 | -- there are bugs on RNObject placement and on touch input x,y coords so try to stay in your computer resolution 24 | -- 25 | 26 | config.sizes["iPadDev"] = { 768, 1024, 384, 512 } -- shrunk for easier viewing 27 | config.sizes["iPad"] = { 768, 1024, 768, 1024 } -- 1:1 pixel iPad 28 | config.sizes["iPhone3G"] = { 320, 480, 320, 480 } 29 | config.sizes["iPhone4Full"] = { 640, 960, 640, 960 } 30 | config.sizes["iPhone3G_500_750"] = { 320, 480, 500, 750 } -- 3G screen ratio upscaled to 500x750 31 | config.sizes["AcerLiquidMetal"] = { 480, 800, 480, 800 } 32 | config.sizes["test"] = { 700, 1024, 700, 1024 } 33 | config.sizes["test2"] = { 200, 400, 200, 400 } 34 | config.sizes["test3"] = { 100, 500, 100, 500 } 35 | 36 | 37 | 38 | --set lanscape mode and device 39 | config.landscape = false 40 | config.device = "iPhone3G" 41 | 42 | --set stretch and graphics design 43 | --this will stretch your graphics to fit device screen size 44 | --but you need to set for which sizes your assets are originally designed for 45 | --letterbox is to enable letterboxing 46 | --drawOnBlackBars is to writing on blackBars 47 | --change values with care if you are on landscape 48 | 49 | 50 | config.stretch = { status = false, letterbox = false, drawOnBlackBars = false, graphicsDesign = { w = 640, h = 960 } } 51 | 52 | --this is for iOS. Set it to true if you enabled the status bar in your Moai xCode Project, to keep screen touch configured properly. 53 | config.iosStatusBar = false 54 | 55 | return config 56 | -------------------------------------------------------------------------------- /rapanui-sdk/RNLayer.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | -- Author: niom 16 | -- Date: 11/25/12 17 | 18 | RNLayer = { 19 | LAYER_WITH_SAME_NAME_EXISTS = "layer with same name already exists", 20 | MAIN_LAYER = "mainlayer" 21 | } 22 | 23 | function RNLayer:new() 24 | local layers = {} 25 | setmetatable(layers,self) 26 | self.__index = self 27 | return layers 28 | end 29 | 30 | function RNLayer:createLayer(name,viewport) 31 | local layer = MOAILayer2D.new() 32 | local index = table.getn(self) + 1 33 | 34 | if self:get(name) then 35 | return nil, RNLayer.LAYER_WITH_SAME_NAME_EXISTS 36 | end 37 | 38 | self[index] = {} 39 | self[index].layer = layer 40 | self[index].name = name 41 | layer:setViewport(viewport) 42 | MOAISim.pushRenderPass(layer) 43 | 44 | return layer 45 | end 46 | 47 | function RNLayer:get(name) 48 | for i,container in pairs(self) do 49 | if container.name == name then 50 | return container.layer 51 | end 52 | end 53 | end 54 | 55 | function RNLayer:createLayerWithPartition(name,viewport) 56 | local layer = self:createLayer(name,viewport) 57 | local partition = MOAIPartition.new() 58 | layer:setPartition(partition) 59 | return layer,partition 60 | end 61 | 62 | function RNLayer:remove(layer) 63 | for i, container in pairs(self) do 64 | if container.layer == layer then 65 | self:clearContainer(container) 66 | table.remove(self, i) 67 | end 68 | end 69 | end 70 | 71 | function RNLayer:removeAll() 72 | while table.getn(self) > 0 do 73 | self:clearContainer(self[1]) 74 | table.remove(self, 1) 75 | end 76 | end 77 | 78 | function RNLayer:clearContainer(container) 79 | container.layer:clear() 80 | container.layer = nil 81 | container.name = nil 82 | end 83 | 84 | return RNLayer -------------------------------------------------------------------------------- /rapanui-test/lunatest/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | Reference 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 |
14 | 15 |
16 |
17 |
18 | 19 |
20 | 21 | 62 | 63 |
64 | 65 | 66 | 67 |

Modules

68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
lunatestUnit testing module, with extensions for random testing.
77 | 78 | 79 | 80 | 81 | 82 |

Files

83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 |
lunatest.lua
92 | 93 | 94 |
95 | 96 |
97 | 98 |
99 |

Valid XHTML 1.0!

100 |
101 | 102 |
103 | 104 | 105 | -------------------------------------------------------------------------------- /rapanui-samples/menu/popup.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | -- Let's see how to have a popup script loaded in RapaNui. 17 | -- it's a simple script returning a table containing all the functions we need to be loaded. 18 | -- (it's a basic lua class creation, the other choice we have is to use metatables and register a lookup 19 | -- for each instance, but check like RNObject or RNPageSwipe for this) 20 | 21 | -- in this samples, for testing purpose, transitions are manually add to background and text. 22 | -- it would be better to add both text and background to a group and then apply the transition to a group. 23 | 24 | 25 | popup = { isTransitioning = false } 26 | 27 | local trn = RNTransition:new() 28 | local trn = RNTransition:new() 29 | 30 | 31 | 32 | function popup.onShow() 33 | local background = RNFactory.createImage("images/background-blue.png", { parentGroup = sceneGroup }); background.x = 160; background.y = 720; 34 | local text1 = RNFactory.createText("Hey there,\n I'm a popup!\n\nPlay with me!", { size = 20, top = 480, left = 0, width = 200, height = 500 }) 35 | trn:run(background, { type = "move", time = 1000, y = 440, onComplete = showThings }) 36 | trn:run(text1, { type = "move", time = 1000, y = 100 }) 37 | popup.group = {} 38 | popup.group[1] = background 39 | popup.group[2] = text1 40 | popup.isTransitioning = true 41 | end 42 | 43 | function showThings() 44 | popup.isTransitioning = false 45 | end 46 | 47 | function removeThings() 48 | popup.isTransitioning = false 49 | popup.group[1]:remove() 50 | popup.group[2]:remove() 51 | end 52 | 53 | 54 | function popup.onHide() 55 | trn:run(popup.group[1], { type = "move", time = 1000, y = 720, onComplete = removeThings }) 56 | trn:run(popup.group[2], { type = "move", time = 1000, y = 480 }) 57 | popup.isTransitioning = true 58 | end 59 | 60 | 61 | 62 | return popup -------------------------------------------------------------------------------- /rapanui-samples/listeners/rn-listener-enterFrame-remove.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | back = RNFactory.createImage("images/background-purple.png") 16 | back:sendToBottom() 17 | 18 | 19 | delta = -2 20 | 21 | textinfo = RNFactory.createText("Touch button1 to remove/add listener and stop button2", { size = 16, top = 10, left = 5, width = 300, height = 50 }) 22 | text = RNFactory.createText("", { size = 18, top = 400, left = 5, width = 200, height = 50 }) 23 | 24 | buttonOne = RNFactory.createImage("images/tile1.png", { top = 60, left = 120 }) 25 | buttonTwo = RNFactory.createImage("images/tile2.png", { top = 220, left = 16 }) 26 | 27 | 28 | local w, h = RNFactory.stageWidth, RNFactory.stageHeight 29 | local removed = false 30 | listenerId = nil 31 | 32 | function button1UP(event) 33 | if removed == false then 34 | text:setText("Removed listener: " .. listenerId) 35 | RNListeners:removeEventListener("enterFrame", listenerId) 36 | removed = true 37 | else 38 | listenerId = RNListeners:addEventListener("enterFrame", doIt) 39 | text:setText("Added listener: " .. listenerId) 40 | removed = false 41 | end 42 | end 43 | 44 | buttonOne:setOnTouchUp(button1UP) 45 | 46 | 47 | --handling enterFrame 48 | function doIt() 49 | if buttonTwo.x >= 320 then 50 | delta = -delta 51 | end 52 | 53 | if buttonTwo.x <= 0 then 54 | delta = -delta 55 | end 56 | 57 | buttonTwo.x = buttonTwo.x + delta 58 | end 59 | 60 | --set a listener for enterFrame 61 | listenerId = RNListeners:addEventListener("enterFrame", doIt) 62 | print("action", listenerId) 63 | text:setText("Added listener: " .. listenerId) 64 | 65 | --since enterFrame listener is handled inside a while = true cycle, use it carefully 66 | --to save CPU usage. The use of timers (RNMainThread.addTimedAction(seconds, funct)) 67 | --is highly recommend, when possible. 68 | -------------------------------------------------------------------------------- /rapanui-samples/anim/rn-anim.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | background = RNFactory.createImage("images/background-purple.png") 16 | 17 | 18 | 19 | liliaChar = RNFactory.createAnim("images/lilia.png", 32, 32, 140, 50, 2, 2) 20 | 21 | function onEndS1() 22 | liliaChar:play("walkBack") 23 | end 24 | 25 | function onEndS2() 26 | liliaChar:play("walkLeft") 27 | end 28 | 29 | function onEndS3() 30 | liliaChar:play("walkRight") 31 | end 32 | 33 | function onEndS4() 34 | liliaChar:stop() 35 | end 36 | 37 | 38 | liliaChar:newSequence("walkFront", { 1, 2, 3, 2 }, 6, 2, onEndS1) 39 | liliaChar:newSequence("walkBack", { 10, 11, 12, 11 }, 6, 2, onEndS2) 40 | liliaChar:newSequence("walkLeft", { 4, 5, 6, 5 }, 6, 2, onEndS3) 41 | liliaChar:newSequence("walkRight", { 7, 8, 9, 8 }, 6, 2, onEndS4) 42 | 43 | liliaChar:play("walkFront") 44 | liliaChar.frame = 1 45 | 46 | 47 | 48 | 49 | ektorChar = RNFactory.createAnim("images/ektor.png", 32, 32) 50 | ektorChar2 = RNFactory.createAnim("images/ektor.png", 32, 32) 51 | ektorChar3 = RNFactory.createAnim("images/ektor.png", 32, 32) 52 | ektorChar2.x = 100 53 | ektorChar2.y = 100 54 | ektorChar3.x = 164 55 | ektorChar3.y = 100 56 | ektorChar2.scaleX = -4 57 | ektorChar2.scaleY = -4 58 | ektorChar2.scaleX = -2 59 | ektorChar2.scaleY = -2 60 | ektorChar2.scaleX = 1 61 | ektorChar2.scaleY = 1 62 | ektorChar2.scaleX = 3 63 | ektorChar2.scaleY = 3 64 | ektorChar2.scaleX = 1 65 | ektorChar2.scaleY = 1 66 | ektorChar2.scaleX = -0.5 67 | ektorChar2.scaleY = -0.5 68 | 69 | 70 | 71 | function onEndSEktor() 72 | ektorChar:flipVertical() 73 | 74 | ektorChar:play("walkFront") 75 | end 76 | 77 | 78 | ektorChar:newSequence("walkFront", { 1, 2, 3, 2 }, 6, 10, onEndSEktor) 79 | 80 | ektorChar.x = 200 81 | ektorChar.y = 250 82 | 83 | 84 | ektorChar:flipHorizontal() 85 | ektorChar:flipVertical() 86 | 87 | ektorChar:play() 88 | 89 | ektorChar:play("walkFront", 12, 5) -------------------------------------------------------------------------------- /rapanui-samples/physics/rn-physics-fixtures.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | --We create 4 objects and change their fixture properties during creation and/or after 16 | 17 | 18 | --add images 19 | background = RNFactory.createImage("rapanui-samples/physics/background-purple.png") 20 | box = RNFactory.createImage("rapanui-samples/physics/box.png"); box.x = 170; box.y = 80; 21 | ball = RNFactory.createImage("rapanui-samples/physics/ball.png"); ball.x = 240; ball.y = 80; 22 | triangle = RNFactory.createImage("rapanui-samples/physics/poly.png"); triangle.x = 80; triangle.y = 80; triangle.rotation = 190 23 | floor = RNFactory.createImage("rapanui-samples/physics/floor.png"); floor.x = 160; floor.y = 400; 24 | 25 | --starts simulation 26 | RNPhysics.start() 27 | 28 | 29 | --set images as physics objects 30 | RNPhysics.createBodyFromImage(box) 31 | RNPhysics.createBodyFromImage(ball, { shape = "circle" }) 32 | RNPhysics.createBodyFromImage(triangle, { shape = { -32, 32, 0, -32, 32, 32 }, restitution = 0.3, friction = 0.1 }) 33 | RNPhysics.createBodyFromImage(floor, "static") 34 | 35 | box.density = 1.5 36 | box.friction = 0.5 37 | box.restitution = 0.7 38 | 39 | ball.sensor = true --the ball become a sensor (check other samples) 40 | 41 | --[[ 42 | 43 | "fixture" should be a table containing 44 | {density=number,friction=number,shape=string or table,filter=table,restitution=number,sensor=boolean} 45 | 46 | 47 | default values are 48 | 49 | density=1 50 | friction=0.3 51 | sensor=false 52 | filter={categoryBits = 1, maskBits = nil, groupIndex = nil} 53 | shape="rectangle" 54 | 55 | you can't change shape and type after creation. 56 | 57 | 58 | 59 | and we can change this also after creation. 60 | Changes made after creation will affect all fixtures in the body. 61 | If you want to change a specific fixture in the body you should use lists. 62 | please check other samples for lists tutorials 63 | 64 | ]] -- -------------------------------------------------------------------------------- /rapanui-samples/maps/rn-scrolling-physics-map.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | -- 14 | -- Tiles of the map from: 15 | -- 16 | -- gfxlib 17 | -- 18 | -- Product : gfxlib-fuzed.zip 19 | -- Website : http://www.spicypixel.net 20 | -- Author : Marc Russell 21 | -- Released: 10th January 2008 22 | -- 23 | -- 24 | -- gfxlib is under Common Public License (http://www.opensource.org/licenses/cpl1.0.php) 25 | ]] 26 | 27 | require("socket") 28 | 29 | -- start physic simulation 30 | 31 | RNPhysics.start() 32 | 33 | 34 | local map = RNMapFactory.loadMap(RNMapFactory.TILED, "rapanui-samples/maps/platformmapphysics.tmx") 35 | 36 | aTileset = map:getTileset(0) 37 | 38 | aTileset:updateImageSource("rapanui-samples/maps/platformtileset.png") 39 | 40 | local layersSize = map:getLayersSize() 41 | 42 | tilesCreated = 0 43 | map:drawMapAt(0, 0, aTileset) 44 | 45 | 46 | local lastx = 0 47 | local delta = -3 48 | 49 | lastTime = socket.gettime() 50 | 51 | local intervalForFps = 1 / 60 52 | 53 | print(intervalForFps) 54 | local currentTime = socket.gettime() 55 | local diff = currentTime - lastTime 56 | 57 | 58 | 59 | 60 | 61 | function update(enterFrame) 62 | currentTime = socket.gettime() 63 | diff = currentTime - lastTime 64 | if diff >= intervalForFps then 65 | map:drawMapAt(lastx, 0, aTileset) 66 | lastx = lastx + delta 67 | 68 | if lastx <= -1280 then 69 | delta = delta * -1 70 | end 71 | 72 | if lastx >= 0 then 73 | delta = delta * -1 74 | end 75 | lastTime = currentTime 76 | end 77 | end 78 | 79 | -- scrolling can be done either with enterFrame and Timer. 80 | -- timer is recommend due to enterFrame massive consume of device's CPU. 81 | 82 | --RNListeners:addEventListener("enterFrame", update) 83 | local actionId = RNMainThread.addTimedAction(0.009, update) 84 | 85 | 86 | 87 | --Debug Draw if you want 88 | --RNPhysics.setDebugDraw(RNFactory.screen) -------------------------------------------------------------------------------- /rapanui-samples/contribution/rngroup-scissorrect.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | --]] 14 | 15 | freeImage = RNFactory.createImage("images/background-blue.png") 16 | 17 | freeImage = RNFactory.createImage("images/image.png") 18 | 19 | group = RNGroup:new() 20 | 21 | anImageTest1 = RNFactory.createImage("images/tile1.png") 22 | anImageTest1.x = 96 23 | anImageTest1.y = 96 24 | 25 | anImageTest2 = RNFactory.createImage("images/tile2.png", { top = 15, left = 115 }) 26 | 27 | anImageTest3 = RNFactory.createImage("images/tile3.png", { top = 77, left = 132 }) 28 | anImageTest3.x = 96 29 | anImageTest3.y = 96 30 | 31 | anImageTest4 = RNFactory.createImage("images/tile4.png", { top = 0, left = 180 }) 32 | 33 | anImageTest4.x = 160 34 | anImageTest4.y = 240 35 | 36 | group:insert(anImageTest1) 37 | group:insert(anImageTest2) 38 | group:insert(anImageTest3) 39 | 40 | print("anImageTest1 x: " .. anImageTest1.x .. " y: " .. anImageTest1.y) 41 | print("anImageTest2 x: " .. anImageTest2.x .. " y: " .. anImageTest2.y) 42 | print("anImageTest3 x: " .. anImageTest3.x .. " y: " .. anImageTest3.y) 43 | print("anImageTest3 x: " .. anImageTest4.x .. " y: " .. anImageTest4.y) 44 | print("group one size: " .. group:getSize()) 45 | 46 | local scissorRect = MOAIScissorRect.new() 47 | scissorRect:setRect( 50, 100, 350, 300) 48 | group:setScissorRect(scissorRect) 49 | 50 | group:insert(anImageTest4) 51 | 52 | 53 | local myListener = function(event) 54 | group.x = event.x 55 | group.y = event.y 56 | 57 | print("group x: " .. group.x .. " y: " .. group.y) 58 | 59 | -- print("anImageTest1 x: " .. anImageTest1.x .. " y: " .. anImageTest1.y) 60 | -- print("anImageTest2 x: " .. anImageTest2.x .. " y: " .. anImageTest2.y) 61 | -- print("anImageTest3 x: " .. anImageTest3.x .. " y: " .. anImageTest3.y) 62 | -- print("anImageTest4 x: " .. anImageTest4.x .. " y: " .. anImageTest4.y) 63 | end 64 | 65 | RNListeners:addEventListener("touch", myListener) 66 | -------------------------------------------------------------------------------- /rapanui-samples/groups/rn-groups.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | --]] 14 | 15 | freeImage = RNFactory.createImage("images/background-blue.png") 16 | 17 | freeImage = RNFactory.createImage("images/image.png") 18 | 19 | group = RNGroup:new() 20 | group2 = RNGroup:new() 21 | 22 | anImageTest1 = RNFactory.createImage("images/tile1.png") 23 | anImageTest1.x = 96 24 | anImageTest1.y = 96 25 | 26 | anImageTest2 = RNFactory.createImage("images/tile2.png", { top = 15, left = 115 }) 27 | 28 | anImageTest3 = RNFactory.createImage("images/tile3.png", { top = 77, left = 132 }) 29 | anImageTest3.x = 96 30 | anImageTest3.y = 96 31 | 32 | anImageTest4 = RNFactory.createImage("images/tile4.png", { top = 0, left = 180 }) 33 | 34 | 35 | anImageTest4.x = 160 36 | anImageTest4.y = 240 37 | 38 | 39 | 40 | --group.x = 160 41 | --group.y = 240 42 | 43 | 44 | 45 | --group:insert(anImageTest1) 46 | group:insert(anImageTest2) 47 | group:insert(anImageTest3) 48 | 49 | group2:insert(anImageTest1) 50 | group2:insert(anImageTest4) 51 | 52 | 53 | print("anImageTest1 x: " .. anImageTest1.x .. " y: " .. anImageTest1.y) 54 | print("anImageTest2 x: " .. anImageTest2.x .. " y: " .. anImageTest2.y) 55 | print("anImageTest3 x: " .. anImageTest3.x .. " y: " .. anImageTest3.y) 56 | print("anImageTest4 x: " .. anImageTest4.x .. " y: " .. anImageTest4.y) 57 | print("anImageTest1 x: " .. anImageTest1.x .. " y: " .. anImageTest1.y) 58 | 59 | 60 | --print_r(group.displayObjects) 61 | --print_r(group2.displayObjects) 62 | 63 | print("group one size: " .. group:getSize()) 64 | 65 | 66 | 67 | local myListener = function(event) 68 | group.x = event.x 69 | group.y = event.y 70 | 71 | -- print("group x: " .. group.x .. " y: " .. group.y) 72 | 73 | -- print("anImageTest1 x: " .. anImageTest1.x .. " y: " .. anImageTest1.y) 74 | -- print("anImageTest2 x: " .. anImageTest2.x .. " y: " .. anImageTest2.y) 75 | -- print("anImageTest3 x: " .. anImageTest3.x .. " y: " .. anImageTest3.y) 76 | -- print("anImageTest4 x: " .. anImageTest4.x .. " y: " .. anImageTest4.y) 77 | end 78 | 79 | RNListeners:addEventListener("touch", myListener) 80 | -------------------------------------------------------------------------------- /rapanui-sdk/rapanui.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | config = require("config") 15 | 16 | 17 | RNObject = require("rapanui-sdk/RNObject") 18 | 19 | RNText = require("rapanui-sdk/RNText") 20 | 21 | RNButton = require("rapanui-sdk/RNButton") 22 | 23 | RNEvent = require("rapanui-sdk/RNEvent") 24 | RNScreen = require("rapanui-sdk/RNScreen") 25 | RNWrappedEventListener = require("rapanui-sdk/RNWrappedEventListener") 26 | RNLayer = require("rapanui-sdk/RNLayer") 27 | 28 | -- Touch Listeners requires 29 | 30 | RNListeners = require("rapanui-sdk/RNListeners") 31 | RNInputManager = require("rapanui-sdk/RNInputManager") 32 | 33 | RNUtil = require("rapanui-sdk/RNUtil") 34 | RNUnit = require("rapanui-sdk/RNUnit") 35 | RNGroup = require("rapanui-sdk/RNGroup") 36 | 37 | 38 | RNTransition = require("rapanui-sdk/RNTransition") 39 | RNPhysics = require("rapanui-sdk/RNPhysics") 40 | 41 | RNBody = require("rapanui-sdk/RNBody") 42 | RNJoint = require("rapanui-sdk/RNJoint") 43 | RNFixture = require("rapanui-sdk/RNFixture") 44 | 45 | 46 | -- Threads requires 47 | 48 | RNThread = require("rapanui-sdk/RNThread") 49 | RNMainThread = require("rapanui-sdk/RNMainThread") 50 | 51 | -- Director requires 52 | 53 | RNDirector = require("rapanui-sdk/RNDirector") 54 | 55 | -- Maps requires 56 | 57 | RNMap = require("rapanui-sdk/RNMap") 58 | RNMapLayer = require("rapanui-sdk/RNMapLayer") 59 | RNMapObject = require("rapanui-sdk/RNMapObject") 60 | RNMapObjectGroup = require("rapanui-sdk/RNMapObjectGroup") 61 | RNMapTileset = require("rapanui-sdk/RNMapTileset") 62 | RNTiledMapParser = require("rapanui-sdk/RNTiledMapParser") 63 | RNTiledLuaMapParser = require("rapanui-sdk/RNTiledLuaMapParser") 64 | 65 | RNMapFactory = require("rapanui-sdk/RNMapFactory") 66 | RNFactory = require("rapanui-sdk/RNFactory") 67 | 68 | RNListView = require("rapanui-sdk/RNListView") 69 | 70 | RNPageSwipe = require("rapanui-sdk/RNPageSwipe") 71 | 72 | RNTimer = require("rapanui-sdk/RNTimer") 73 | 74 | RNGraphicsManager = require("rapanui-sdk/RNGraphicsManager") 75 | 76 | RNBitmapText = require("rapanui-sdk/RNBitmapText") 77 | --starts main thread 78 | RNMainThread.startMainThread() 79 | 80 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- _____ _ _ _ 4 | -- | __ \ | \ | | (_) 5 | -- | |__) |__ _ _ __ __ _| \| |_ _ _ 6 | -- | _ // _` | '_ \ / _` | . ` | | | | | 7 | -- | | \ \ (_| | |_) | (_| | |\ | |_| | | 8 | -- |_| \_\__,_| .__/ \__,_|_| \_|\__,_|_| 9 | -- | | 10 | -- |_| 11 | --]] 12 | 13 | RapaNui 14 | 15 | by Ymobe ltd (http://ymobe.co.uk) 16 | 17 | LICENSE: 18 | 19 | RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 20 | CPAL is an Open Source Initiative approved 21 | license based on the Mozilla Public License, with the added requirement that you attribute 22 | Moai (http://getmoai.com/) and RapaNui in the credits of your program. 23 | 24 | How to use RapaNui in your project: 25 | 26 | 1) Copy rapanui-sdk under your project dir 27 | 2) Copy config.lua from rapanui directory under your project 28 | 3) Add a require "config" into your main.lua 29 | 4) Add a require "rapanui-sdk.rapanui" into your main.lua 30 | 31 | Now your main.lua should look something like this 32 | require "config" 33 | require "rapanui-sdk.rapanui" 34 | 35 | 36 | 37 | How to test RapaNui in Moai distribution for Mac iOS: 38 | 39 | 1) under your moai dir find the dir "samples" create a new dir "RapaNui" 40 | 2) copy all the file of RapaNui (including sub subdirectories) in the new [YOUR_MOAI_DIR]/samples/RapaNui 41 | 42 | in Moai's xcode ios SampleMoai project: 43 | 44 | 1) find the file named "moai-target" (should be under Resources -> build -> moai-target) 45 | 2) change the content to "../../samples/RapaNui" 46 | 47 | now run the project 48 | 49 | 50 | 51 | How to test RapaNui in Moai distribution for Windows: 52 | 53 | 1)download or clone RapaNui as is. 54 | 55 | 2)Find these files in the Moai distribution: 56 | - moai.exe from Moai's bin folder 57 | - config.lua from Moai's samples\config folder 58 | 59 | 3)Now create .bat file in the RapaNui root directory. 60 | Use the paths of those files and set the lua file to run. 61 | 62 | Example .bat file (in this example Moai distribution is under C:\moai-sdk directory): 63 | 64 | "C:\moai-sdk\bin\win32\moai.exe" 65 | "C:\moai-sdk\samples\config\config.lua" 66 | "main.lua" 67 | 68 | 4)Now run the .bat file you've just created. 69 | 70 | 71 | 72 | To change the demo of RapaNui 73 | 74 | 1) find and edit the main.lua under [YOUR_MOAI_DIR]/samples/RapaNui/main.lua 75 | 2) comment current sample with "--" 76 | 3) uncomment the sample you want to test. 77 | 4) run the project 78 | 79 | 80 | enjoy, 81 | The RapaNui team -------------------------------------------------------------------------------- /rapanui-samples/director/scene2.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | 16 | --[[ 17 | 18 | SCENES MUST HAVE 19 | 1)a sceneGroup where all instances are inserted 20 | 2)onCreate function in which we create everything 21 | 3)onEnd function in which we clean the instance 22 | 23 | ]] -- 24 | 25 | aScene = {} 26 | 27 | local sceneGroup = RNGroup:new() 28 | 29 | 30 | 31 | --init Scene 32 | function aScene.onCreate() 33 | --add things to sceneGroup 34 | local background = RNFactory.createImage("images/background-green.png", { parentGroup = sceneGroup }); background.x = 160; background.y = 240; 35 | local tile1a = RNFactory.createImage("images/tile2.png"); tile1a.x = 160; tile1a.y = 240; 36 | local tile1b = RNFactory.createImage("images/tile2.png"); tile1b.x = 100; tile1b.y = 140; 37 | local tile1c = RNFactory.createImage("images/tile2.png"); tile1c.x = 260; tile1c.y = 240; 38 | 39 | local group1 = RNGroup:new() 40 | local group2 = RNGroup:new() 41 | 42 | 43 | 44 | 45 | -- also buttons can be inserted in groups and scenes. 46 | 47 | local button = RNFactory.createButton("images/button-plain.png", { 48 | text = "Main Button 1", 49 | imageOver = "images/button-over.png", 50 | top = 400, 51 | left = 10, 52 | size = 16, 53 | width = 200, 54 | height = 50, 55 | onTouchDown = button1TouchDown, 56 | onTouchUp = button1UP 57 | }) 58 | 59 | group2:insert(button) 60 | 61 | print(group2.displayObjects[1]:getType()) 62 | 63 | 64 | group1:insert(tile1a) 65 | group1:insert(tile1b) 66 | group2:insert(tile1c) 67 | print(group2.displayObjects[1]:getType()) 68 | print(group2.displayObjects[2]:getType()) 69 | group1:insert(group2) 70 | 71 | sceneGroup:insert(group1) 72 | --return sceneGroup 73 | return sceneGroup 74 | end 75 | 76 | function button1TouchDown(event) 77 | event.target:setText("Button 1 touch down!") 78 | end 79 | 80 | function button1UP(event) 81 | event.target:setText("Button 1 touch up") 82 | end 83 | 84 | function aScene.onEnd() 85 | sceneGroup:remove() 86 | end 87 | 88 | return aScene 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /rapanui-samples/physics/rn-physics-setup.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- 3 | -- RapaNui 4 | -- 5 | -- by Ymobe ltd (http://ymobe.co.uk) 6 | -- 7 | -- LICENSE: 8 | -- 9 | -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0. 10 | -- CPAL is an Open Source Initiative approved 11 | -- license based on the Mozilla Public License, with the added requirement that you attribute 12 | -- Moai (http://getmoai.com/) and RapaNui in the credits of your program. 13 | ]] 14 | 15 | --World Settings tutorial 16 | 17 | 18 | --add images 19 | background = RNFactory.createImage("rapanui-samples/physics/background-purple.png") 20 | box = RNFactory.createImage("rapanui-samples/physics/box.png"); box.x = 170; box.y = 80; 21 | ball = RNFactory.createImage("rapanui-samples/physics/ball.png"); ball.x = 240; ball.y = 80; 22 | triangle = RNFactory.createImage("rapanui-samples/physics/poly.png"); triangle.x = 80; triangle.y = 80; triangle.rotation = 190 23 | floor = RNFactory.createImage("rapanui-samples/physics/floor.png"); floor.x = 160; floor.y = 400; 24 | 25 | --starts and stops simulation 26 | RNPhysics.start() 27 | --RNPhysics.stop() 28 | 29 | --filter collisions 30 | --you may want to set a global filter for collision types: all, begin, end, pre_solve or post_solve 31 | --to register all fixtures in the game to call back only for one kind of collision (to optimize game speed) 32 | --by default its set to "all" 33 | RNPhysics.setCollisions("all") --optional 34 | 35 | --setting up gravity 36 | RNPhysics.setGravity(0, 10) 37 | print(RNPhysics.getGravity) 38 | 39 | --Other Methods 40 | --Changing this after bodies creation will result buggy 41 | RNPhysics.setMeters(6) 42 | RNPhysics.setIterations(1, 1) 43 | print(RNPhysics.getMeters()) 44 | RNPhysics.setAutoClearForces(true) 45 | print(RNPhysics.getAutoClearForces()) 46 | --after-update methods 47 | RNPhysics.setAngularSleepTolerance(1) 48 | RNPhysics.setLinearSleepTolerance(1) 49 | RNPhysics.setTimeToSleep(1) 50 | print(RNPhysics.getAngularSleepTolerance()) 51 | print(RNPhysics.getLinearSleepTolerance()) 52 | print(RNPhysics.getTimeToSleep()) 53 | 54 | 55 | 56 | --set images as physics objects 57 | RNPhysics.createBodyFromImage(box) 58 | RNPhysics.createBodyFromImage(ball, { shape = "circle" }) 59 | RNPhysics.createBodyFromImage(triangle, { shape = { -32, 32, 0, -32, 32, 32 }, restitution = 0.3, friction = 0.1 }) 60 | RNPhysics.createBodyFromImage(floor, "static") 61 | box.restitution = 0.5 62 | ball.restitution = 0.3 63 | triangle.restitution = 0.3 64 | 65 | 66 | 67 | --after update some bodies methods 68 | box:setMassData(5) 69 | print(box:getInertia()) 70 | print(box:getMass()) 71 | 72 | 73 | 74 | --------------------------------------------------------------------------------