-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22976aa
commit 9737979
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
-- This code is under the authority of the GNU 3.0 Public License | ||
-- Created by SpechtD, modified by Gabriel | ||
-- Modified 2024 with a higher gameplay speed | ||
|
||
local xVel = 0 | ||
local yVel = 0 | ||
|
||
local xPos = 0 | ||
local yPos = 0 | ||
|
||
local ballSize = LCD_W / 50 | ||
|
||
local scoreA = 0 | ||
local scoreB = 0 | ||
|
||
local aPadPos = 0 | ||
local bPadPos = 0 | ||
|
||
local function startBall() | ||
xPos = LCD_W/2 - ballSize/2 | ||
yPos = LCD_H/2 - ballSize/2 | ||
yVel = math.random(0, 30) - 15 | ||
xVel = (math.random() > 0.5) and 10 or -10 | ||
end | ||
|
||
local function init() | ||
startBall() | ||
end | ||
|
||
local function run() | ||
|
||
lcd.clear() | ||
|
||
aPadPos = (getValue("thr") - 1024) / 2048 * -(LCD_H - ballSize*4) | ||
bPadPos = (getValue("ele") - 1024) / 2048 * -(LCD_H - ballSize*4) | ||
|
||
if xPos < ballSize and (yPos + ballSize) >= aPadPos and yPos <= (aPadPos + ballSize * 4) then | ||
xVel = -xVel | ||
xPos = ballSize + 1 | ||
yVel = math.random(0, 6) - 3 | ||
elseif xPos > (LCD_W - ballSize*2) and (yPos + ballSize) >= bPadPos and yPos <= (bPadPos + ballSize * 4) then | ||
xVel = -xVel | ||
xPos = LCD_W - ballSize*2 - 1 | ||
yVel = math.random(0, 6) - 3 | ||
end | ||
|
||
if xPos >= LCD_W - ballSize then | ||
scoreA = scoreA + 1 | ||
startBall() | ||
elseif xPos <= 0 then | ||
scoreB = scoreB + 1 | ||
startBall() | ||
elseif yPos >= LCD_H - ballSize or yPos <= 0 then | ||
yVel = -yVel | ||
end | ||
|
||
xPos = xPos + xVel | ||
yPos = yPos + yVel | ||
|
||
lcd.drawFilledRectangle(xPos,yPos,ballSize,ballSize) | ||
|
||
lcd.drawFilledRectangle(0, aPadPos, ballSize, ballSize*4) | ||
lcd.drawFilledRectangle(LCD_W - ballSize, bPadPos, ballSize, ballSize*4) | ||
|
||
lcd.drawLine(LCD_W/2, 0, LCD_W/2, LCD_H, DOTTED, 0) | ||
lcd.drawNumber(LCD_W * 0.25, ballSize, scoreA, 0) | ||
lcd.drawNumber(LCD_W * 0.75, ballSize, scoreB, 0) | ||
|
||
lcd.refresh() | ||
|
||
return 0 | ||
|
||
end | ||
|
||
return {init=init, run=run} |