Skip to content

Instantly share code, notes, and snippets.

@afk-mario
Last active September 26, 2018 14:50
Show Gist options
  • Save afk-mario/f35c253d6fa78cfdff7e04f1e866e0d3 to your computer and use it in GitHub Desktop.
Save afk-mario/f35c253d6fa78cfdff7e04f1e866e0d3 to your computer and use it in GitHub Desktop.
Cocos Laboratorio
-- ejercicio 04
function _init()
-- limpia la pantalla
cls()
-- calcula el centro
-- de la pantalla
center = flr(127/2)
-- a y b seran las coordendas
-- de los puntos del rectangulo
a = " "
b = " "
-- coordenadas [x,y] del punto
-- a y punto b
ax = center - 10
ay = center - 10
bx = center + 10
by = center + 10
end
function _update()
-- recibe el input para
-- modificar las coordenadas
if btn(0) then ax = ax - 1 end
if btn(2) then ay = ay - 1 end
if btn(1) then bx = bx + 1 end
if btn(3) then by = by + 1 end
-- actualiza el texto para
-- las coordenadas a y b
a = "["..ax..","..ay.."]"
b = "["..bx..","..by.."]"
end
function _draw()
-- limpia la pantalla con un
-- color diferente
rectfill(0, 0, 127, 127, 8)
-- dibuja un rectangulo con
-- los puntos a y b
rectfill(ax, ay, bx, by, 9)
-- dibuja las coordenadas del
-- punto a
print(a, ax - 27, ay - 5, 7)
-- dibuja las coordenadas del
-- punto b
print(b, bx + 1, by + 1, 7)
end
-- ejercicio 04 extra
function _init()
cls()
sprite = 0
inverted = false
center = flr(127/2)
a = " "
b = " "
ax = center - 10
ay = center - 10
bx = center + 10
by = center + 10
axi = ax
ayi = ay
bxi = bx
byi = by
min_limit = 27
max_limit = 127 - min_limit
bg_color = 12
end
function _update()
if btnp(4) then
inverted = not inverted
end
if btnp(5) then
inverted = not inverted
end
if inverted then
if btn(0) then bx = bx - 1 end
if btn(2) then by = by - 1 end
if btn(1) then ax = ax + 1 end
if btn(3) then ay = ay + 1 end
else
if btn(0) then ax = ax - 1 end
if btn(2) then ay = ay - 1 end
if btn(1) then bx = bx + 1 end
if btn(3) then by = by + 1 end
end
local m = 127 - 27
if ax > axi then ax = axi end
if ay > ayi then ay = ayi end
if bx < bxi then bx = bxi end
if by < byi then by = byi end
if ax < min_limit then
ax = min_limit
end
if ay < min_limit then
ay = min_limit
end
if bx > max_limit then
bx = max_limit
end
if by > max_limit then
by = max_limit
end
a = "["..ax..","..ay.."]"
b = "["..bx..","..by.."]"
if inverted then
sprite = 1
bg_color = 8
else
sprite = 2
bg_color = 9
end
if
ax == axi and
ay == ayi and
bx == bxi and
by == byi
then
sprite = 0
bg_color = 12
end
end
function _draw()
rectfill(0, 0, 127, 127, 12)
rectfill(ax, ay, bx, by, bg_color)
print(a, ax - 27, ay - 5, 7)
print(b, bx + 1, by + 1, 7)
spr(sprite, center - 3, center - 3)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment