Created
January 26, 2013 00:40
-
-
Save NexusGameStudio/4639241 to your computer and use it in GitHub Desktop.
OUYA Pong
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
settings = | |
{ | |
orientation = | |
{ | |
default = "landscapeRight" | |
}, | |
android = | |
{ | |
versionCode = "1" | |
}, | |
androidPermissions = | |
{ | |
"android.permission.WRITE_EXTERNAL_STORAGE" | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--/// OUYA - Corona SDK Sample Code - Nexus Game Studio, 2013 /// | |
--/// www.nexusgamestudio.com | www.twitter.com/NexusGameStudio /// | |
------------------------------------------------------------------------------------------------------------------------- | |
--/// Code samples are free to use and modify without permission. /// | |
--/// Sample code is provided "as is" and takes no responsibility over any software / hardware complications that may occur. /// | |
--/// Credit is appreciated but is not manditory. Go make awesome games! /// | |
------------------------------------------------------------------------------------------------------------------------- | |
--/// Config File Ver 1.0/// | |
application = | |
{ | |
content = | |
{ | |
fps = 60, --Framerate for your game [default = 30 fps]. | |
antialias = false, --Turns on / off anti-aliasing for vector based objects [false = off, true = on]. Note that turing it on will use more system resource. | |
width = 720, --Standard height for 720p TV. Do not change this. ***Remember, mobile displays are normally in portrait mode, so we have to reverse width and height.*** | |
height = 1280, --Standard width for 720p TV. Do not change this. | |
scale = "letterbox", --Scales all content evenly for 720p or 1080p. | |
xAlign = "center", --Sets the x axis in the center of the screen. | |
yAlign = "center", --Sets the y axis in the center of the screen. | |
}, | |
} | |
--/// Notes /// | |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
--We use 1280x720 since it is the lowest base resolution for HD, because we use "letterbox" scaling, this will format all images evenly to higher resolutions such as 1366x768 | |
--and 1920x1080. Corona requires the config to use the lowest resolution as it's foundation and the engine will do the scaling, setting it too high will make everything small. | |
--Also note, when designing images, create them for a 1080p display, that way the engine will scale down your images and will remain sharp, instead of blurry / pixelated if you | |
--designed them at 720p from being upscaled. | |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--/// OUYA - Corona SDK Sample Code - Nexus Game Studio, 2013 /// | |
--/// www.nexusgamestudio.com | www.twitter.com/NexusGameStudio /// | |
------------------------------------------------------------------------------------------------------------------------- | |
--/// Code samples are free to use and modify without permission. /// | |
--/// Sample code is provided "as is" and takes no responsibility over any software / hardware complications that may occur. /// | |
--/// Credit is appreciated but is not manditory. Go make awesome games! /// | |
------------------------------------------------------------------------------------------------------------------------- | |
--/// OUYA Pong Ver 1.0 /// | |
local W = display.contentWidth | |
local H = display.contentHeight | |
local physics = require("physics") --Call the physics engine | |
physics.start() --Initialize physics | |
physics.setGravity( 0, 0 ) --Gravity by default is on the Y-axis, we disable that and turn off gravity all together | |
local left = display.newRect(0, 0, 10 , H) --Create the four boundries | |
local right = display.newRect(W - 10, 0, W, H) | |
local top = display.newRect(0, 0, W, 10) | |
local bottom = display.newRect(0, H - 10, W, 10) | |
physics.addBody(left, "static", { bounce = 0.1} ) --Add physics bodies to the walls so the ball can bounce off them. | |
physics.addBody(right, "static", { bounce = 0.1} ) | |
physics.addBody(top, "static", { bounce = 0.1} ) | |
physics.addBody(bottom, "static", { bounce = 0.1} ) | |
local centerCourt = display.newRect(0, 0, 10, H) --Draws the center court line. | |
centerCourt.x = W/2 | |
local paddle = display.newRect(0,10,20,100) --Player paddle. | |
paddle.x = 30; paddle.y = H/2 --Position the paddle. | |
physics.addBody(paddle, "static", { friction = 1.0, density=5, bounce=.2}) --Adds a physics body to the paddle. | |
local ball = display.newRect(50,H/2,50, 50) --Ball | |
physics.addBody( ball, { density=1, friction=-1, bounce=1, radius = 30} ) --Adds a physics body to the ball. | |
ball:setLinearVelocity( 800, yVelocity ) --Instead of physics movement, we set a constant velocity so there are no crazy speed effects. | |
ball.isFixedRotation = true --Keeps the boxed shape "ball" from rotating, looks more like classic Pong. | |
function controlPaddle(e) --Paddle controls | |
if (e.keyName == "up") then --If the user presses "up" on the Dpad or left analog, the paddle will move up. | |
if (e.phase == "down") then | |
function moveUp() | |
paddle.y = (paddle.y - 20) --Set the value in which the number of pixels the paddle moves at. To move up, use a negative value. | |
end | |
Runtime:addEventListener("enterFrame", moveUp) | |
end | |
if (e.phase == "up") then | |
Runtime:removeEventListener("enterFrame", moveUp) --When the player releases the button, it will remove the Runtime listener. | |
end | |
end | |
if (e.keyName == "down") then --If the user presses "down" on the Dpad or left analog, the paddle will move down. | |
if (e.phase == "down") then | |
function moveDown() | |
paddle.y = (paddle.y + 20) --Set the value in which the number of pixels the paddle moves at. To move down, use a positive value. | |
end | |
Runtime:addEventListener("enterFrame", moveDown) | |
end | |
if (e.phase == "up") then | |
Runtime:removeEventListener("enterFrame", moveDown) --When the player releases the button, it will remove the Runtime listener. | |
end | |
end | |
if (paddle.y < 50) then --If the paddle goes outside the screen at the top, it will reset back at the boundry. | |
paddle.y = 50 | |
end | |
if (paddle.y > H - 50) then --If the paddle goes outside the screen at the bottom, it will reset back at the boundry. | |
paddle.y = H-50 | |
end | |
if (ball.x < 0) then --Stops the ball from getting glitched behind the paddle. Just a fail-safe. | |
ball.x = 80 | |
end | |
end | |
Runtime:addEventListener("key", controlPaddle) --Runtime listener for the controller. | |
--/// Notes /// | |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
--This is a 1 player sample of Pong in which the player can bounce the ball around the court. There are no victory conditions, nor scores. A simple demo to show how all the | |
--sample files work together. | |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment