Working pong using 3 diffrent windows (DefOS)

I just found the DefOS asset and just had to do this:image

2 Likes

GIF not working, link here

6 Likes

Cool! How was that made?

This is the intire script I used for Pong, a little bit messy and not very efficient. (Link)

function init(self)
math.randomseed(socket.gettime()) -- random
local test = math.random(1,100) -- for some reason random dosen't work for me if I dont do this
if gy1(self) == nil then self.y1 = 0 sy1(self, 0) end -- sets the posision of the padels if they are nil (First time you fire up the game)
if gy2(self) == nil then self.y2 = 0 sy2(self, 0) end
window.set_listener(window_callback) -- used to get screen resulution
self.v = 0
self.data = sys.load(path)
if self.data.v == 1 or self.data.v == nil then self.v = 1 si(self)
elseif self.data.v == 2 then self.v = 2 si(self)
elseif self.data.v == 3 then self.v = 3 si(self)
elseif self.data.v == 4 then ex(self) end
print(self.v) -- self.v is used to see what window doses what, so not every window is the ball for example
	
msg.post(".", "acquire_input_focus")

self.y = 0
self.y1 = gy1(self)  -- calls the previus posision of the padels
self.y2 = gy2(self)
self.x = 0 

defos.set_fullscreen(true) -- Fullscreen
if self.v == 3 then go(self) end -- starts the ball when spawned
local error = string.char(defos.get_window_size()) -- craches the DefOS and removes the resize window and exit button

function update(self, dt)
local h = 150 --dimensions of the padels
local w = 25
if self.v == 1 then self.x = 0 self.y = gy1(self) end -- sets the position of the left padle
if self.v == 2 then self.x = self.sx - w self.y = gy2(self) end --  sets the position of the right padle
if self.v == 3 then h = 50 w = 50 -- sets dimensions of the ball
self.y = gb(self).y --get the current position and uses that
self.x = gb(self).x
mb(self) -- Move ball
end
if self.v < 3 then -- used to make the padels not disappear outside the frame
if self.y < 0 then self.y = 0 end
if self.y > self.sy - h then self.y = self.sy - h end
end
defos.set_view_size(self.x, self.y, w, h) -- displays the position 
defos.disable_maximize_button() -- used if the error in the beginning dosen't work
defos.disable_minimize_button()
defos.disable_window_resize()
defos.set_window_title("")
self.data = sys.load(path)
if self.data.v == nil then ex(self) end -- exits the game if value not found, used to remove every padle at the same time

function on_input(self, action_id, action)
local speed = 15
if self.y1 < 0 then self.y1 = 0 end -- used to fix a "bug"
if self.y1 > self.sy then self.y1 = self.sy end
if self.y2 < 0 then self.y2 = 0 end
if self.y2 > self.sy then self.y2 = self.sy end

if action_id == hash("w") then self.y1 = self.y1 - speed sy1(self, self.y1) end -- just the controlls, made in such a way that you can controll every padle from every window
if action_id == hash("s") then self.y1 = self.y1 + speed sy1(self, self.y1) end
if action_id == hash("up") then self.y2 = self.y2 - speed sy2(self, self.y2) end
if action_id == hash("down") then self.y2 = self.y2 + speed sy2(self, self.y2) end
if action_id == hash("start") then go(self) end

The rest is just small functions. Everything is based on 4 save files I read from, each object can write to all savefiles (But only read from 2 of them). This makes it a little bit laggy, but I don’t know any other way it could be done.

2 Likes

you can upload it to the community and link it to us

1 Like

This is the code: https://github.com/VincentLagerros/Pong

Don’t work on HTML5, needs to be built before playing (must launch the game 3 times, it cant do that in the editor. This can be solved with os.execute([command]))

Don’t know if it works on MacOS

2 Likes