Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- --
- --
- Pong = {
- RUNNING_GAMES = {},
- __CLIENT = [=[
- user = game:service 'Players'.localPlayer;
- mouse = user:getMouse (0);
- playerGui = user:findFirstChildOfClass 'PlayerGui';
- character = user.Character;
- remote = script:waitForChild 'Remote'.Value;
- pcall (function ()character.Parent = nil; end);
- gui = Instance.new 'ScreenGui';
- frame = Instance.new 'Frame';
- paddleLeft = Instance.new 'Frame';
- paddleRight = Instance.new 'Frame';
- ball = Instance.new 'Frame';
- plrLeft = Instance.new 'TextLabel';
- plrRight = Instance.new 'TextLabel';
- gui.Parent = playerGui;
- gui.Name = 'Pong!';
- frame.Parent = gui;
- frame.BackgroundColor3 = Color3.new (1, 1, 1);
- frame.Size = UDim2.new (0, 200, 0, 200);
- frame.Position = UDim2.new (0.5, -100, 0.5, -100);
- winner = Instance.new 'TextLabel';
- winner.Size = UDim2.new (1, 0, 0, 50);
- winner.BackgroundTransparency = 1;
- winner.Font = 'SourceSansBold';
- winner.FontSize = 'Size24';
- winner.Text = ''
- paddleLeft.Parent = frame;
- paddleLeft.Position = UDim2.new (0, 5, 0, 75);
- paddleLeft.Size = UDim2.new (0, 2, 0, 50);
- paddleRight.Parent = frame;
- paddleRight.Position = UDim2.new (1, -5, 0, 75);
- paddleRight.Size = UDim2.new (0, 2, 0, 50);
- ball.Parent = frame;
- ball.Size = UDim2.new (0, 2, 0, 2);
- ball.Position = UDim2.new (0.5, 0, 0.5, 0);
- ball.BackgroundColor3 = Color3.new();
- plrLeft.Text = 'Player1';
- plrLeft.Parent = frame;
- plrLeft.Rotation = -90;
- plrLeft.Position = UDim2.new (-0.5, -20, 0.5, 0);
- plrLeft.Size = UDim2.new (1, 0, 0, 10);
- plrLeft.TextStrokeTransparency = 0;
- plrLeft.TextStrokeColor3 = Color3.new (1, 1, 1);
- plrLeft.BackgroundTransparency = 1;
- plrRight.Text = 'Player2';
- plrRight.Parent = frame;
- plrRight.Rotation = 90;
- plrRight.Position = UDim2.new (0.5, 20, 0.5, 0);
- plrRight.Size = UDim2.new (1, 0, 0, 10);
- plrRight.TextStrokeTransparency = 0;
- plrRight.TextStrokeColor3 = Color3.new (1, 1, 1);
- plrRight.BackgroundTransparency = 1;
- remote.OnClientEvent:connect (function (req, ...)
- if (req == 'set') then
- local data, owner = ...;
- if (owner == user) then
- ourPaddle = ...;
- if (ourPaddle == 1) then
- plrLeft.Text = owner.Name;
- else
- plrRight.Text = owner.Name;
- end;
- else
- if (ourPaddle == 1) then
- plrRight.Text = owner.Name;
- else
- plrLeft.Text = owner.Name;
- end;
- end;
- elseif (... == 'paddle') then
- local owner = req;
- local req, data = ...;
- if (owner == user) then
- --[[
- if (ourPaddle == 1) then
- paddleLeft.Position = UDim2.new (0, 5, 0, data);
- else
- paddleRight.Position = UDim2.new (1, -5, 0, data);
- end;
- --]]
- else
- if (ourPaddle == 1) then
- paddleRight.Position = UDim2.new (1, -5, 0, data);
- else
- paddleLeft.Position = UDim2.new (0, 5, 0, data);
- end;
- end;
- elseif (req == 'ball') then
- local x, y = ...;
- local our = ourPaddle == 1 and paddleLeft or paddleRight;
- ball.Position = UDim2.new (0, x, 0, y);
- if ((x < 6 and ourPaddle == 1) or (x > 194 and ourPaddle == 2)) then
- if (y > our.Position.Y.Offset and y < (our.Position.Y.Offset + 50)) then
- remote:FireServer ('Bump');
- else
- remote:FireServer ('Eof');
- end;
- end;
- elseif (req == 'over') then
- if (winner.Parent) then return 0 end;
- frame:ClearAllChildren ();
- winner.Parent = frame;
- winner.Text = 'You ' .. (... == user and 'lose' or 'win') .. '!';
- character.Parent = workspace;
- character:MakeJoints ();
- wait (3);
- gui:destroy ();
- end;
- end);
- keys = {};
- mouse.KeyDown:connect (function (s)
- if (not ourPaddle) then return 0 end;
- keys [tostring (s)] = true;
- end);
- mouse.KeyUp:connect (function (s)
- keys [tostring (s)] = false;
- end);
- remote:FireServer();
- game:service 'RunService'.RenderStepped:connect (function()
- local our = ourPaddle == 1 and paddleLeft or paddleRight;
- if (keys.w and not keys.s) then
- if (our.Position.Y.Offset > 0) then
- our.Position = UDim2.new (
- 0, 5, 0, our.Position.Y.Offset - 2
- );
- end;
- remote:FireServer ('paddle', our.Position.Y.Offset);
- end;
- if (keys.s and not keys.w) then
- if (our.Position.Y.Offset < 150) then
- our.Position = UDim2.new (
- 0, 5, 0, our.Position.Y.Offset + 2
- );
- end;
- remote:FireServer ('paddle', our.Position.Y.Offset);
- end;
- end);
- ]=],
- __this = {
- users = {},
- ball = {99, 99, math.random (1, 2) == 1 and -1 or 1, math.random (1, 2) == 1 and -1 or 1},
- running = true,
- addPlayer = function (self, n)
- if (#self.users >= 2) then
- return error ('Game full');
- end;
- if (self.remote == nil) then
- self.remote = Instance.new 'RemoteEvent';
- self.remote.Parent = game.ReplicatedStorage;
- end;
- local p = game:service 'Players':findFirstChild (n);
- if (p and p:isA 'Player') then
- local scr = NLS (Pong.__CLIENT, p.Backpack);
- local rem = Instance.new 'ObjectValue';
- rem.Name = 'Remote';
- rem.Value = self.remote;
- rem.Parent = scr;
- while true do
- local u = self.remote.OnServerEvent:wait ();
- if (u == p) then break end;
- end;
- self.remote:FireAllClients ('set', #self.users + 1, p);
- self.users [#self.users + 1] = {p, 100};
- else
- print ('unable to find', n, p);
- end;
- end,
- waitForReady = function (self)
- while (#self.users ~= 2) do wait() end;
- wait (5);
- end,
- start = function (self)
- if (#self.users ~= 2) then
- return error ('not enough players');
- end;
- self.remote.OnServerEvent:connect (function (client, req, data)
- if (req == 'paddle') then
- self.remote:FireAllClients (client, req, data);
- elseif (req == 'Bump') then
- self.ball [3] = -self.ball [3];
- elseif (req == 'Eof') then
- self.remote:FireAllClients ('over', client);
- self.running = false;
- end;
- end);
- local lastBeat = tick();
- game:service 'RunService'.Heartbeat:connect (function()
- if (not self.running or (self.ball [1] < 1 or self.ball [1] > 199)) then
- return;
- end;
- local currentBeat = tick();
- if (not ((currentBeat - lastBeat) > 1/30)) then
- return;
- end;
- lastBeat = currentBeat;
- self.ball [1] = self.ball [1] + self.ball [3];
- self.ball [2] = self.ball [2] + self.ball [4];
- if (self.ball [2] >= 200 or self.ball [2] <= 0) then
- self.ball [4] = -self.ball [4];
- end;
- self.remote:FireAllClients ('ball', self.ball [1], self.ball [2]);
- end);
- end,
- },
- new = function ()
- local m = {};
- for k, v in next, Pong.__this do
- if (type (v) == 'table') then
- local n = {};
- for k, v in next, v do
- n [k] = v;
- end;
- m [k] = n;
- else
- m [k] = v;
- end;
- end;
- return m;
- end
- };
- g = Pong.new();
- spawn (function()g:addPlayer (owner.Chatted:wait());end);
- spawn (function()g:addPlayer ('tusKOr661');end);
- g:waitForReady ();
- g:start ();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement