GlyEngine 0.2.6
Create games and apps with lua
Loading...
Searching...
No Matches
Ping Pong

@pong

https://pong.gamely.com.br

Author
RodrigoDornelles
Version
1.0.0
Brief

simple pong

Reference

This Pong game is inspired by "Paredao" a game from the first-generation Brazilian console Philco-Ford Telejogo. (1977)

Source Code
local function init(self, std)
self.highscore = self.highscore or 0
self.player_pos = self.height/2
self.ball_pos_x = self.width/2
self.ball_pos_y = self.height/2
self.ball_spd_x = 50
self.ball_spd_y = 30
self.score = 0
end
local function loop(self, std)
-- moves
self.ball_size = std.math.max(self.width, self.height) / 160
self.player_size = (std.math.min(self.width, self.height) / 8) + 2
self.ball_pos_x = std.math.clamp(self.ball_pos_x + (self.width * self.ball_spd_x * std.delta)/100000, 0, self.width)
self.ball_pos_y = std.math.clamp(self.ball_pos_y + (self.height * self.ball_spd_y * std.delta)/100000, 0, self.height)
self.player_pos = std.math.clamp(self.player_pos + (std.key.axis.y * self.ball_size), 0, self.height - self.player_size)
-- colisions
if self.ball_pos_x >= (self.width - self.ball_size) then
self.ball_spd_x = -std.math.abs(self.ball_spd_x)
end
if self.ball_pos_y >= (self.height - self.ball_size) then
self.ball_spd_y = -std.math.abs(self.ball_spd_y)
end
if self.ball_pos_y <= 0 then
self.ball_spd_y = std.math.abs(self.ball_spd_y)
end
if self.ball_pos_x <= 0 then
if std.math.clamp(self.ball_pos_y, self.player_pos, self.player_pos + self.player_size) == self.ball_pos_y then
self.ball_spd_y = self.ball_spd_y + self.ball_spd_x - (std.milis % (self.ball_spd_x*2))
self.ball_spd_x = std.math.abs(self.ball_spd_x + (self.ball_spd_x/10))
self.score = self.score + 1
else
std.app.reset()
end
end
end
local function draw(self, std)
std.draw.clear(std.color.black)
std.draw.color(std.color.white)
std.draw.rect2(0, self.ball_size, self.player_pos, self.ball_size, self.player_size, self.ball_size)
std.draw.rect2(0, self.ball_pos_x, self.ball_pos_y, self.ball_size, self.ball_size, self.ball_size)
std.text.put(20, 1, self.score)
std.text.put(60, 1, self.highscore)
end
local function exit(self, std)
self.highscore = std.math.max(self.highscore, self.score)
end
local P = {
meta={
title='Ping Pong',
author='RodrigoDornelles',
description='simple pong',
version='1.0.0'
},
init=init,
loop=loop,
}
}
return P;
local function exit()
local function title(window_name)
local function draw(src, pos_x, pos_y)
local function callbacks(handler)