Skip to content

Commit c530501

Browse files
authored
Add files via upload
1 parent 00f3570 commit c530501

File tree

19 files changed

+283
-0
lines changed

19 files changed

+283
-0
lines changed

lua_note.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,12 @@ love2D 3 main function
7171
> -- display graphics on the screen
7272
>end
7373
74+
## Attempt to index local 'self' (a nil value)
75+
76+
> self.fucntion(self, dt) => self:function(dt)
77+
78+
## Windows Distribution
79+
80+
1. Make sure to select all scripts and assets and create a "Zip" file
81+
2. Rename ".zip" to ".love"
82+
3. Using cmd with this command `copy /b love.exe+SuperGame.love SuperGame.exe`

pong/ball.lua

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Ball = {}
2+
3+
function Ball:load()
4+
self.x = love.graphics.getWidth() / 2
5+
self.y = love.graphics.getHeight() / 2
6+
self.width = 20
7+
self.height = 20
8+
self.speed = 200
9+
self.xVel = -self.speed
10+
self.yVel = 0
11+
end
12+
13+
function Ball:update(dt)
14+
self:move(dt)
15+
self:collide()
16+
end
17+
18+
function Ball:collide()
19+
if checkCollision(self, Player) then
20+
self.xVel = self.speed
21+
local middleBall = self.y + self.height / 2
22+
local middlePlayer = Player.y + Player.height / 2
23+
local collisionPosion = middleBall - middlePlayer
24+
self.yVel = collisionPosion * 5
25+
end
26+
self:checkBoundaries('vertical')
27+
self:checkBoundaries('horizontal')
28+
end
29+
30+
function Ball:checkBoundaries(direction)
31+
if direction == 'vertical' then
32+
if self.y < 0 then
33+
self.y = 0
34+
self.yVel = -self.yVel
35+
elseif self.y + self.height > love.graphics.getHeight() then
36+
self.y = love.graphics.getHeight() - self.height
37+
self.yVel = -self.yVel
38+
end
39+
elseif direction == 'horizontal' then
40+
if self.x < 0 then
41+
self.x = 0
42+
self.xVel = -self.xVel
43+
elseif self.x + self.width > love.graphics.getWidth() then
44+
self.x = love.graphics.getWidth() - self.width
45+
self.xVel = -self.xVel
46+
end
47+
end
48+
end
49+
50+
function Ball:move(dt)
51+
self.x = self.x + self.xVel * dt
52+
self.y = self.y + self.yVel * dt
53+
end
54+
55+
function Ball:draw()
56+
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
57+
end

pong/conf.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function love.conf(t)
2+
t.title = "Pong"
3+
-- the title of the window of the game is in (string)
4+
t.version = "11.4"
5+
-- The love version this game was made for (string)
6+
t.console = true
7+
-- attach a console (boolean, windows only)
8+
t.window.width = 1280
9+
-- the window width (number)
10+
t.window.height = 720
11+
-- the window height (number)
12+
end

pong/main.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require('player')
2+
require('ball')
3+
4+
function love.load()
5+
Player:load()
6+
Ball:load()
7+
end
8+
9+
function love.update(dt)
10+
Player:update(dt)
11+
Ball:update(dt)
12+
end
13+
14+
function love.draw()
15+
Player:draw()
16+
Ball:draw()
17+
end
18+
19+
function checkCollision(a, b)
20+
if a.x + a.width > b.x and a.x < b.x + b.width and a.y + a.height > b.y and a.y < b.y + b.height then
21+
return true
22+
else
23+
return false
24+
end
25+
end

pong/player.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Player = {}
2+
3+
function Player:load()
4+
self.x = 50
5+
self.y = love.graphics.getHeight() / 2
6+
self.width = 20
7+
self.height = 100
8+
self.speed = 500
9+
end
10+
11+
function Player:update(dt)
12+
self:move(dt)
13+
self:checkBoundaries()
14+
end
15+
16+
function Player:move(dt)
17+
if love.keyboard.isDown('w') then
18+
self.y = self.y - self.speed * dt
19+
elseif love.keyboard.isDown('s') then
20+
self.y = self.y + self.speed * dt
21+
end
22+
end
23+
24+
function Player:checkBoundaries()
25+
if self.y < 0 then
26+
self.y = 0
27+
elseif self.y + self.height > love.graphics.getHeight() then
28+
self.y = love.graphics.getHeight() - self.height
29+
end
30+
end
31+
32+
function Player:draw()
33+
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
34+
end

pong/run.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@ECHO
2+
3+
start "" "E:\GameRelated\GameDevelop\Love2D\IDE\love-11.4-win64\love" .

windows_cube/backup/ball.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Ball = {}
2+
3+
function Ball:load()
4+
self.x = love.graphics.getWidth() / 2
5+
self.y = love.graphics.getHeight() / 2
6+
self.width = 40
7+
self.height = 40
8+
self.speed = 200
9+
self.xVel = -self.speed
10+
self.yVel = -self.speed
11+
end
12+
13+
function Ball:update(dt)
14+
self:move(dt)
15+
self:checkBoundaries("vertical")
16+
self:checkBoundaries("horizontal")
17+
end
18+
19+
function Ball:checkBoundaries(direction)
20+
if direction == "vertical" then
21+
if self.y < 0 then
22+
self.y = 0
23+
self.yVel = -self.yVel
24+
elseif self.y + self.height > love.graphics.getHeight() then
25+
self.y = love.graphics.getHeight() - self.height
26+
self.yVel = -self.yVel
27+
end
28+
elseif direction == "horizontal" then
29+
if self.x < 0 then
30+
self.x = 0
31+
self.xVel = -self.xVel
32+
elseif self.x + self.width > love.graphics.getWidth() then
33+
self.x = love.graphics.getWidth() - self.width
34+
self.xVel = -self.xVel
35+
end
36+
end
37+
end
38+
39+
function Ball:move(dt)
40+
self.x = self.x + self.xVel * dt
41+
self.y = self.y + self.yVel * dt
42+
end
43+
44+
function Ball:draw()
45+
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
46+
end

windows_cube/backup/conf.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function love.conf(t)
2+
t.title = "Window Cube"
3+
-- the title of the window of the game is in (string)
4+
t.version = "11.4"
5+
-- The love version this game was made for (string)
6+
t.console = false
7+
-- attach a console (boolean, windows only)
8+
t.window.width = 1280
9+
-- the window width (number)
10+
t.window.height = 720
11+
-- the window height (number)
12+
end

windows_cube/backup/main.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require("ball")
2+
3+
function love.load()
4+
Ball:load()
5+
end
6+
7+
function love.update(dt)
8+
Ball:update(dt)
9+
end
10+
11+
function love.draw()
12+
Ball:draw()
13+
end

windows_cube/conf.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function love.conf(t)
2+
t.title = "Window Cube"
3+
-- the title of the window of the game is in (string)
4+
t.version = "11.4"
5+
-- The love version this game was made for (string)
6+
t.console = false
7+
-- attach a console (boolean, windows only)
8+
t.window.width = 1280
9+
-- the window width (number)
10+
t.window.height = 720
11+
-- the window height (number)
12+
end

0 commit comments

Comments
 (0)