├── Camera └── Gamera Lesson │ ├── conf.lua │ ├── lib │ └── gamera.lua │ └── main.lua ├── Collisions ├── bump lesson 1 │ ├── MIT-LICENSE.txt │ ├── README.md │ ├── bump.lua │ ├── bump_debug.lua │ └── main.lua ├── bump lesson 2 │ ├── MIT-LICENSE.txt │ ├── README.md │ ├── bump.lua │ ├── bump_debug.lua │ └── main.lua └── bump lesson 3 │ ├── MIT-LICENSE.txt │ ├── README.md │ ├── bump.lua │ ├── bump_debug.lua │ ├── debug_console.lua │ └── main.lua ├── Fonts ├── main.lua ├── main_1.lua ├── main_2.lua ├── main_3.lua └── res │ ├── Bukhari_Script.ttf │ ├── Certege.ttf │ ├── MIROSLN.ttf │ └── imagefont.png ├── Lua language ├── funct_sugar.lua ├── if_statement.lua ├── if_while_repeat.lua ├── lesson 3.lua ├── math.lua ├── my_saturday.lua ├── random.lua ├── vars.lua └── занятие 3.lua ├── OOP ├── oop lesson 1 │ └── main.lua ├── oop lesson 4 │ └── main.lua ├── oop lessons 2-3 │ └── main.lua └── oop middleclass │ ├── metamethods.lua │ ├── middleclass.lua │ ├── mixins1.lua │ ├── mixins2included.lua │ └── quick look.lua ├── README.md ├── ROBLOX STUDIO ├── 2020 lessons │ ├── 1min guide RunService.rbxl │ ├── 1min guide Trails and Beams.rbxl │ ├── 1min guide switch light button door.rbxl │ ├── 3lightsBaseplate.rbxl │ ├── 3lightsBaseplate2.rbxl │ ├── BindableEvents.rbxl │ ├── Lesson Roblox API spawn.rbxl │ ├── Place1with3Spawns.rbxl │ ├── Tiny Question 1 2 parts touch Unanchored Baseplate.rbxl │ ├── clickDet.rbxl │ ├── contectActionServics 3.rbxl │ ├── contectActionServics.rbxl │ ├── debris roblox school 2020.rbxl │ ├── for loop pairs ipairs.rbxl │ ├── gameAAAstart.rbxl │ ├── houseDaySunMoonVillage.rbxl │ ├── howTo Move Car.rbxl │ ├── less6 soccer Baseplate.rbxl │ ├── lesson 0 pathfinding moving between points.rbxl │ ├── lesson 1 DataStore2 installation Roblox.rbxl │ ├── lesson 1 Roblox accessory.rbxl │ ├── lesson 1 Roblox leaderboard.rbxl │ ├── lesson 1 Roblox sound music.rbxl │ ├── lesson 1 anti-exploit Roblox.rbxl │ ├── lesson 1 pathfinding.rbxl │ ├── lesson 1-2 Roblox RemoteFunction.rbxl │ ├── lesson 16 magnitude roblox school 2020.rbxl │ ├── lesson 2 DataStore2 Roblox.rbxl │ ├── lesson 2 Roblox sound music.rbxl │ ├── lesson 2 part flags remoteEvents.rbxl │ ├── lesson 3 Roblox RemoteFunction.rbxl │ ├── lesson 3 Roblox sound music.rbxl │ ├── lesson 4 Roblox RemoteFunction on Client.rbxl │ ├── lesson 4 Roblox sound music.rbxl │ ├── lesson 5 roblox school 2020.rbxl │ ├── lesson 6 roblox school 2020.rbxl │ ├── lesson 8 roblox school 2020.rbxl │ ├── lesson 9 roblox school 2020.rbxl │ ├── lesson D1 efrect off.rbxl │ ├── lesson Donate Attach Part To Head roblox school 2020.rbxl │ ├── lesson T3 Save player data.rbxl │ ├── lesson T4 Roblox Lua Libraries.rbxl │ ├── lesson T6 Roblox DataTypes Enums.rbxl │ ├── lesson dialog.rbxl │ ├── lesson random stuff.rbxl │ ├── lesson seat 1 Roblox.rbxl │ ├── lesson13 remoteFunc.rbxl │ ├── lesson4 killblocks.rbxl │ ├── lsBaseplate.rbxl │ ├── modules lesson.rbxl │ ├── most rotate roblox school 2020.rbxl │ ├── movingPanel.rbxl │ ├── movingPlatform.rbxl │ ├── newLighting.rbxl │ ├── pyramPlace1.rbxl │ ├── r3 Baseplate.rbxl │ ├── rays rays everywhere remoteEvent.rbxl │ ├── rotating fan under ceiling.rbxl │ ├── soccerBaseplate.rbxl │ ├── streetsLightVars Baseplate.rbxl │ ├── t1 lesson Baseplate.rbxl │ ├── userinputservice mouse lessons 1-2.rbxl │ ├── vid less tables Baseplate.rbxl │ ├── vlesson 2.rbxl │ ├── vlesson 4.rbxl │ ├── vlesson12.rbxl │ ├── vlesson8 clone serverstorage Baseplate.rbxl │ └── wedge hinge motor.rbxl ├── 2021 lessons │ ├── 2021 1 начинающим Все виды кнопок и условия.rbxl │ ├── 2021 Урок 1 Advanced Atributes.rbxl │ ├── GetChildren IsA GetPartBoundsInRadius.rbxl │ ├── Делаем игру 1 Кролики Лисы и Капуста.rbxl │ ├── Делаем игру 1.5 Кролики Лисы и Капуста.rbxl │ ├── Делаем игру 2 Кролики Лисы и Капуста.rbxl │ ├── Делаем игру 2.1 Кролики Лисы и Капуста.rbxl │ ├── Потоки 1 функция SPAWN.rbxl │ └── Потоки 2 функция DELAY и генератор домов.rbxl ├── animation │ ├── 1min guide Animate NPC.rbxl │ └── 1min guide Animate Player.rbxl ├── camera │ └── camera 1.rbxl ├── debugger │ └── lesson T5 Roblox Lua Debugging.rbxl ├── teams │ ├── teams 1 roblox school 2020.rbxl │ ├── teams 2 roblox school 2020.rbxl │ ├── teams 3 roblox school 2020.rbxl │ ├── teams 4 roblox school 2020.rbxl │ └── teams roblox school 2020.rbxl ├── teleport │ ├── Lesson1 TeleportService 2nd place.rbxl │ ├── Lesson1 TeleportService.rbxl │ └── MainPlaceFromWhichWeTeleportToAnotherWith3Spawns.rbxl └── tools │ ├── Dispoisable Tool.rbxl │ ├── idCardToolPassword 4stream.rbxl │ ├── idCardToolPassword.rbxl │ ├── tools Mouse click Jumper and Lighter.rbxl │ └── tools test vl2.rbxl ├── Sprites ├── sprites lesson 1 │ ├── main.lua │ └── res │ │ ├── shipUp.png │ │ ├── shipUpFire.png │ │ └── spr1.png ├── sprites lesson 2 │ ├── main.lua │ └── res │ │ ├── shipUp.png │ │ ├── shipUpFire.png │ │ ├── spr0.png │ │ └── spr1.png ├── sprites lesson 3 │ ├── lq.lua │ ├── main.lua │ └── res │ │ ├── hero.lua │ │ ├── shipUp.png │ │ ├── shipUpFire.png │ │ ├── spr0.png │ │ ├── spr1.png │ │ └── spr3.png ├── sprites lesson 4 │ ├── anim8 │ │ ├── MIT-LICENSE.txt │ │ ├── README.md │ │ └── anim8.lua │ ├── main.lua │ └── res │ │ ├── 1945.png │ │ ├── hero.lua │ │ ├── shipUp.png │ │ ├── shipUpFire.png │ │ ├── spr0.png │ │ ├── spr1.png │ │ └── spr3.png └── sprites lesson 5 aseprite │ ├── lib │ ├── cron.lua │ └── json.lua │ ├── main.lua │ ├── peachy.lua │ ├── res │ └── spr │ │ ├── astst.json │ │ ├── astst.png │ │ ├── dude.json │ │ └── dude.png │ └── source │ ├── astst.aseprite │ └── dude.aseprite ├── Tween └── kikito tween │ ├── main.lua │ └── tween.lua ├── _config.yml ├── love.filesystem ├── fs Lesson 1 │ ├── conf.lua │ └── main.lua └── fs Lesson 2 │ ├── conf.lua │ ├── lib │ ├── LICENSE │ └── json.lua │ └── main.lua └── turtle ├── ch.lua ├── ch_test1.lua ├── dz ├── 8dz kuncov.lua ├── dz.lua ├── dz10_1_2_3.lua ├── dz6_1.lua ├── dz6_2.lua ├── dz6_3.lua ├── dz6_3a.lua ├── dz6_templ.lua ├── dz7_1.lua ├── dz7_2.lua ├── dz8 kornev.lua ├── dz8 ulian.lua ├── dz8 valeev.lua ├── dz8_1.lua ├── dz9_1.lua ├── dz9_2.lua ├── dz9_3.lua ├── dz_td1_1.lua ├── dz_td1_2.lua ├── dz_td1_3.lua └── turtle.lua ├── lesson1.lua ├── lesson3for.lua ├── lesson4.1.lua ├── lesson4okruzh.lua ├── lesson4okruzh_while.lua ├── lesson4spiral.lua ├── lesson4zvezda.lua ├── lesson4zvezda_func.lua ├── lesson5.lua ├── lesson5a.lua ├── pic1.png ├── pic_out.png ├── tmplt.lua ├── turtle.lua ├── turtleKletka4x4.lua ├── turtleKletka4x4_2.lua ├── z10.lua ├── z10_0.lua ├── z10_01prKv.lua ├── z10_02_1.lua ├── z10_02prKvOtst.lua ├── z11_0.lua ├── z11_1.lua ├── z11_2.lua ├── z11_3_.lua ├── z11_5.lua ├── z11_6.lua ├── z8_1.lua ├── z8_2.lua ├── z8_2a.lua ├── z8_3.lua ├── z8_3fract_tree.lua ├── z8_3simple_fract_tree.lua ├── z9_0.lua ├── z9_1.lua ├── z9_2.lua ├── z9_3.lua ├── z9_4.lua ├── z9___vl.lua └── z9_posn.lua /Camera/Gamera Lesson/conf.lua: -------------------------------------------------------------------------------- 1 | function love.conf(t) 2 | t.identity = nil -- The name of the save directory (string) 3 | t.version = "0.10.1" -- The LOVE version this game was made for (string) 4 | t.console = true -- Attach a console (boolean, Windows only) 5 | t.accelerometerjoystick = false -- Enable the accelerometer on iOS and Android by exposing it as a Joystick (boolean) 6 | t.gammacorrect = false -- Enable gamma-correct rendering, when supported by the system (boolean) 7 | 8 | t.window.title = "Камера для Love2D - Gamera" -- The window title (string) 9 | t.window.icon = nil -- Filepath to an image to use as the window's icon (string) 10 | t.window.width = 640 -- The window width (number) 11 | t.window.height = 480 -- The window height (number) 12 | t.window.borderless = false -- Remove all border visuals from the window (boolean) 13 | t.window.resizable = false -- Let the window be user-resizable (boolean) 14 | t.window.minwidth = 1 -- Minimum window width if the window is resizable (number) 15 | t.window.minheight = 1 -- Minimum window height if the window is resizable (number) 16 | t.window.fullscreen = false -- Enable fullscreen (boolean) 17 | t.window.fullscreentype = "desktop" -- Choose between "desktop" fullscreen or "exclusive" fullscreen mode (string) 18 | t.window.vsync = true -- Enable vertical sync (boolean) 19 | t.window.msaa = 0 -- The number of samples to use with multi-sampled antialiasing (number) 20 | t.window.display = 1 -- Index of the monitor to show the window in (number) 21 | t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean) 22 | t.window.x = nil -- The x-coordinate of the window's position in the specified display (number) 23 | t.window.y = nil -- The y-coordinate of the window's position in the specified display (number) 24 | end 25 | -------------------------------------------------------------------------------- /Camera/Gamera Lesson/lib/gamera.lua: -------------------------------------------------------------------------------- 1 | -- gamera.lua v1.0.1 2 | 3 | -- Copyright (c) 2012 Enrique García Cota 4 | -- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | -- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 7 | -- Based on YaciCode, from Julien Patte and LuaObject, from Sebastien Rocca-Serra 8 | 9 | local gamera = {} 10 | 11 | -- Private attributes and methods 12 | 13 | local gameraMt = {__index = gamera} 14 | local abs, min, max = math.abs, math.min, math.max 15 | 16 | local function clamp(x, minX, maxX) 17 | return x < minX and minX or (x>maxX and maxX or x) 18 | end 19 | 20 | local function checkNumber(value, name) 21 | if type(value) ~= 'number' then 22 | error(name .. " must be a number (was: " .. tostring(value) .. ")") 23 | end 24 | end 25 | 26 | local function checkPositiveNumber(value, name) 27 | if type(value) ~= 'number' or value <=0 then 28 | error(name .. " must be a positive number (was: " .. tostring(value) ..")") 29 | end 30 | end 31 | 32 | local function checkAABB(l,t,w,h) 33 | checkNumber(l, "l") 34 | checkNumber(t, "t") 35 | checkPositiveNumber(w, "w") 36 | checkPositiveNumber(h, "h") 37 | end 38 | 39 | local function getVisibleArea(self, scale) 40 | scale = scale or self.scale 41 | local sin, cos = abs(self.sin), abs(self.cos) 42 | local w,h = self.w / scale, self.h / scale 43 | w,h = cos*w + sin*h, sin*w + cos*h 44 | return min(w,self.ww), min(h, self.wh) 45 | end 46 | 47 | local function cornerTransform(self, x,y) 48 | local scale, sin, cos = self.scale, self.sin, self.cos 49 | x,y = x - self.x, y - self.y 50 | x,y = -cos*x + sin*y, -sin*x - cos*y 51 | return self.x - (x/scale + self.l), self.y - (y/scale + self.t) 52 | end 53 | 54 | local function adjustPosition(self) 55 | local wl,wt,ww,wh = self.wl, self.wt, self.ww, self.wh 56 | local w,h = getVisibleArea(self) 57 | local w2,h2 = w*0.5, h*0.5 58 | 59 | local left, right = wl + w2, wl + ww - w2 60 | local top, bottom = wt + h2, wt + wh - h2 61 | 62 | self.x, self.y = clamp(self.x, left, right), clamp(self.y, top, bottom) 63 | end 64 | 65 | local function adjustScale(self) 66 | local w,h,ww,wh = self.w, self.h, self.ww, self.wh 67 | local rw,rh = getVisibleArea(self, 1) -- rotated frame: area around the window, rotated without scaling 68 | local sx,sy = rw/ww, rh/wh -- vert/horiz scale: minimun scales that the window needs to occupy the world 69 | local rscale = max(sx,sy) 70 | 71 | self.scale = max(self.scale, rscale) 72 | end 73 | 74 | -- Public interface 75 | 76 | function gamera.new(l,t,w,h) 77 | 78 | local sw,sh = love.graphics.getWidth(), love.graphics.getHeight() 79 | 80 | local cam = setmetatable({ 81 | x=0, y=0, 82 | scale=1, 83 | angle=0, sin=math.sin(0), cos=math.cos(0), 84 | l=0, t=0, w=sw, h=sh, w2=sw*0.5, h2=sh*0.5 85 | }, gameraMt) 86 | 87 | cam:setWorld(l,t,w,h) 88 | 89 | return cam 90 | end 91 | 92 | function gamera:setWorld(l,t,w,h) 93 | checkAABB(l,t,w,h) 94 | 95 | self.wl, self.wt, self.ww, self.wh = l,t,w,h 96 | 97 | adjustPosition(self) 98 | end 99 | 100 | function gamera:setWindow(l,t,w,h) 101 | checkAABB(l,t,w,h) 102 | 103 | self.l, self.t, self.w, self.h, self.w2, self.h2 = l,t,w,h, w*0.5, h*0.5 104 | 105 | adjustPosition(self) 106 | end 107 | 108 | function gamera:setPosition(x,y) 109 | checkNumber(x, "x") 110 | checkNumber(y, "y") 111 | 112 | self.x, self.y = x,y 113 | 114 | adjustPosition(self) 115 | end 116 | 117 | function gamera:setScale(scale) 118 | checkNumber(scale, "scale") 119 | 120 | self.scale = scale 121 | 122 | adjustScale(self) 123 | adjustPosition(self) 124 | end 125 | 126 | function gamera:setAngle(angle) 127 | checkNumber(angle, "angle") 128 | 129 | self.angle = angle 130 | self.cos, self.sin = math.cos(angle), math.sin(angle) 131 | 132 | adjustScale(self) 133 | adjustPosition(self) 134 | end 135 | 136 | function gamera:getWorld() 137 | return self.wl, self.wt, self.ww, self.wh 138 | end 139 | 140 | function gamera:getWindow() 141 | return self.l, self.t, self.w, self.h 142 | end 143 | 144 | function gamera:getPosition() 145 | return self.x, self.y 146 | end 147 | 148 | function gamera:getScale() 149 | return self.scale 150 | end 151 | 152 | function gamera:getAngle() 153 | return self.angle 154 | end 155 | 156 | function gamera:getVisible() 157 | local w,h = getVisibleArea(self) 158 | return self.x - w*0.5, self.y - h*0.5, w, h 159 | end 160 | 161 | function gamera:getVisibleCorners() 162 | local x,y,w2,h2 = self.x, self.y, self.w2, self.h2 163 | 164 | local x1,y1 = cornerTransform(self, x-w2,y-h2) 165 | local x2,y2 = cornerTransform(self, x+w2,y-h2) 166 | local x3,y3 = cornerTransform(self, x+w2,y+h2) 167 | local x4,y4 = cornerTransform(self, x-w2,y+h2) 168 | 169 | return x1,y1,x2,y2,x3,y3,x4,y4 170 | end 171 | 172 | function gamera:draw(f) 173 | love.graphics.setScissor(self:getWindow()) 174 | 175 | love.graphics.push() 176 | local scale = self.scale 177 | love.graphics.scale(scale) 178 | 179 | love.graphics.translate((self.w2 + self.l) / scale, (self.h2+self.t) / scale) 180 | love.graphics.rotate(-self.angle) 181 | love.graphics.translate(-self.x, -self.y) 182 | 183 | f(self:getVisible()) 184 | 185 | love.graphics.pop() 186 | 187 | love.graphics.setScissor() 188 | end 189 | 190 | function gamera:toWorld(x,y) 191 | local scale, sin, cos = self.scale, self.sin, self.cos 192 | x,y = (x - self.w2 - self.l) / scale, (y - self.h2 - self.t) / scale 193 | x,y = cos*x - sin*y, sin*x + cos*y 194 | return x + self.x, y + self.y 195 | end 196 | 197 | function gamera:toScreen(x,y) 198 | local scale, sin, cos = self.scale, self.sin, self.cos 199 | x,y = x - self.x, y - self.y 200 | x,y = cos*x + sin*y, -sin*x + cos*y 201 | return scale * x + self.w2 + self.l, scale * y + self.h2 + self.t 202 | end 203 | 204 | return gamera 205 | 206 | 207 | 208 | 209 | -------------------------------------------------------------------------------- /Camera/Gamera Lesson/main.lua: -------------------------------------------------------------------------------- 1 | -- Камера Gamera 2 | 3 | function love.load() 4 | camera = require "lib.gamera" -- загрузим библиотеку Gamera 5 | cam = camera.new(0,0,1000,1000) -- создадим камеру (и сразу укажем размер большой картинки) 6 | cam:setWorld(0,0,2000,2000) -- в любой момент меняем размеры нашей огромной картинки 7 | cam:setWindow(0,0, 640,480) -- задаем размер окошка через которое будем смотреть на нашу картинку 8 | 9 | x, y = 0, 0 10 | scale = 1 11 | newAngle = 0 12 | end 13 | 14 | function love.draw() 15 | cam:draw(function(l,t,w,h) 16 | -- тут рисуем то, что покажет камера 17 | love.graphics.setColor(255,156,256) 18 | love.graphics.print("l,t,w,h:"..l..","..t..","..w..","..h, 200,170) 19 | love.graphics.circle("fill",x,y,32) 20 | love.graphics.setColor(0,156,256) 21 | love.graphics.rectangle("line", 10,10, 120, 20) 22 | love.graphics.rectangle("fill", 90,40, 820, 30) 23 | love.graphics.rectangle("line", 100,90, 20, 520) 24 | end) 25 | -- тут рисуем то, что всегда должно быть видно на экране. 26 | love.graphics.setColor(255,56,56) 27 | love.graphics.rectangle("line", 10,10, 40, 10) 28 | love.graphics.print("x,y:"..x..","..y, 10,30) 29 | end 30 | 31 | function love.update(dt) 32 | if love.keyboard.isDown("right") then 33 | x = x + 100 * dt 34 | end 35 | if love.keyboard.isDown("left") then 36 | x = x - 100 * dt 37 | end 38 | if love.keyboard.isDown("down") then 39 | y = y + 100 * dt 40 | end 41 | if love.keyboard.isDown("up") then 42 | y = y - 100 * dt 43 | end 44 | cam:setPosition(x, y) 45 | 46 | if love.keyboard.isDown("w") then 47 | scale = scale - 0.1 48 | end 49 | if love.keyboard.isDown("s") then 50 | scale = scale + 0.1 51 | end 52 | cam:setScale(scale) -- увеличить камеру в 2 раза (приблизить картинку) 53 | 54 | if love.keyboard.isDown("a") then 55 | newAngle = newAngle - 0.01 56 | end 57 | if love.keyboard.isDown("d") then 58 | newAngle = newAngle + 0.01 59 | end 60 | cam:setAngle(newAngle) -- поворот камеры на угол в радианах 61 | end -------------------------------------------------------------------------------- /Collisions/bump lesson 1/MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Enrique García Cota 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Collisions/bump lesson 1/README.md: -------------------------------------------------------------------------------- 1 | # bump.lua simple demo 2 | 3 | This is the simple demo of [bump.lua](http://github.com/kikito/bump.lua) 4 | 5 | It requires [LÖVE](http://love2d.org) to work properly. 6 | 7 | This simple demo creates a world populated by random boxes, and allows to move a player around using the keyboard arrow keys. The player has constant velocity 8 | and can will "slide" over the boxes without penetrating them, similarly to some classic games such as Zelda. 9 | 10 | Pressing TAB will display some debug information. 11 | 12 | ![simpledemo](https://kikito.github.io/bump.lua/img/bump-simpledemo.gif) 13 | 14 | 15 | -------------------------------------------------------------------------------- /Collisions/bump lesson 1/bump_debug.lua: -------------------------------------------------------------------------------- 1 | 2 | local bump = require 'bump' 3 | 4 | local bump_debug = {} 5 | 6 | local function getCellRect(world, cx,cy) 7 | local cellSize = world.cellSize 8 | local l,t = world:toWorld(cx,cy) 9 | return l,t,cellSize,cellSize 10 | end 11 | 12 | function bump_debug.draw(world) 13 | local cellSize = world.cellSize 14 | local font = love.graphics.getFont() 15 | local fontHeight = font:getHeight() 16 | local topOffset = (cellSize - fontHeight) / 2 17 | for cy, row in pairs(world.rows) do 18 | for cx, cell in pairs(row) do 19 | local l,t,w,h = getCellRect(world, cx,cy) 20 | local intensity = cell.itemCount * 12 + 16 21 | love.graphics.setColor(1,1,1,intensity/255) 22 | love.graphics.rectangle('fill', l,t,w,h) 23 | love.graphics.setColor(1,1,1, 64/255) 24 | love.graphics.printf(cell.itemCount, l, t+topOffset, cellSize, 'center') 25 | love.graphics.setColor(1,1,1,10/255) 26 | love.graphics.rectangle('line', l,t,w,h) 27 | end 28 | end 29 | end 30 | 31 | return bump_debug 32 | -------------------------------------------------------------------------------- /Collisions/bump lesson 1/main.lua: -------------------------------------------------------------------------------- 1 | local bump = require 'bump' 2 | local bump_debug = require 'bump_debug' 3 | 4 | local instructions = [[ 5 | bump.lua simple demo 6 | 7 | arrows: move 8 | tab: toggle debug info 9 | delete: run garbage collector 10 | ]] 11 | 12 | local cols_len = 0 -- how many collisions are happening 13 | 14 | -- World creation 15 | local world = bump.newWorld() 16 | 17 | 18 | -- Message/debug functions 19 | local function drawMessage() 20 | local msg = instructions:format(tostring(shouldDrawDebug)) 21 | love.graphics.setColor(1, 1, 1) 22 | love.graphics.print(msg, 550, 10) 23 | end 24 | 25 | local function drawDebug() 26 | bump_debug.draw(world) 27 | 28 | local statistics = ("fps: %d, mem: %dKB, collisions: %d, items: %d"):format(love.timer.getFPS(), collectgarbage("count"), cols_len, world:countItems()) 29 | love.graphics.setColor(1, 1, 1) 30 | love.graphics.printf(statistics, 0, 580, 790, 'right') 31 | end 32 | 33 | local consoleBuffer = {} 34 | local consoleBufferSize = 5 35 | for i=1,consoleBufferSize do consoleBuffer[i] = "" end 36 | local function consolePrint(msg) 37 | table.remove(consoleBuffer,1) 38 | consoleBuffer[consoleBufferSize] = msg 39 | end 40 | 41 | local function drawConsole() 42 | local str = table.concat(consoleBuffer, "\n") 43 | for i=1,consoleBufferSize do 44 | love.graphics.setColor(1,1,1, i/consoleBufferSize) 45 | love.graphics.printf(consoleBuffer[i], 10, 580-(consoleBufferSize - i)*12, 790, "left") 46 | end 47 | end 48 | 49 | -- helper function 50 | local function drawBox(box, r,g,b) 51 | love.graphics.setColor(r,g,b,70/255) 52 | love.graphics.rectangle("fill", box.x, box.y, box.w, box.h) 53 | love.graphics.setColor(r,g,b) 54 | love.graphics.rectangle("line", box.x, box.y, box.w, box.h) 55 | end 56 | 57 | 58 | local function myFilter(item, other) 59 | --print(item.name, " collides ", other.name) 60 | if other.kind and other.kind == "coin" then 61 | --coins = coins + 1 62 | -- other OFF 63 | return "cross" 64 | --return "bounce" 65 | end 66 | if other.kind and other.kind == "wall" then 67 | return "slide" 68 | --return "bounce" 69 | end 70 | return "slide" 71 | end 72 | 73 | -- Player functions 74 | local player = { x=50,y=50,w=20,h=20, speed = 180, name = "Player1", isCoin = true } 75 | 76 | local function updatePlayer(dt) 77 | local speed = player.speed 78 | 79 | local dx, dy = 0, 0 80 | if love.keyboard.isDown('right') then 81 | dx = speed * dt 82 | elseif love.keyboard.isDown('left') then 83 | dx = -speed * dt 84 | end 85 | if love.keyboard.isDown('down') then 86 | dy = speed * dt 87 | elseif love.keyboard.isDown('up') then 88 | dy = -speed * dt 89 | end 90 | 91 | if dx ~= 0 or dy ~= 0 then 92 | local cols 93 | player.x, player.y, cols, cols_len 94 | = world:move(player, player.x + dx, player.y + dy, myFilter) 95 | for i=1, #cols do 96 | local col = cols[i] 97 | consolePrint(("col.other = %s, col.type = %s, col.normal = %d,%d"):format(col.other, col.type, col.normal.x, col.normal.y)) 98 | end 99 | end 100 | end 101 | 102 | local function drawPlayer() 103 | drawBox(player, 0, 1, 0) 104 | end 105 | 106 | -- Block functions 107 | 108 | local blocks = {} 109 | 110 | local function addBlock(x,y,w,h) 111 | local block = {x=x,y=y,w=w,h=h, color = math.random(), kind = "wall", name = "Wall" .. #blocks+1} 112 | blocks[#blocks+1] = block 113 | world:add(block, x,y,w,h) 114 | end 115 | 116 | local function drawBlocks() 117 | for _,block in ipairs(blocks) do 118 | drawBox(block, 1,0, block.color) 119 | end 120 | end 121 | 122 | 123 | 124 | 125 | -- Main LÖVE functions 126 | 127 | function love.load() 128 | world:add(player, player.x, player.y, player.w, player.h) 129 | 130 | addBlock(0, 0, 800, 32) 131 | addBlock(0, 32, 32, 600-32*2) 132 | addBlock(800-32, 32, 32, 600-32*2) 133 | addBlock(0, 600-32, 800, 32) 134 | 135 | for i=1,30 do 136 | addBlock( math.random(100, 600), 137 | math.random(100, 400), 138 | math.random(10, 100), 139 | math.random(10, 100) 140 | ) 141 | end 142 | end 143 | 144 | function love.update(dt) 145 | cols_len = 0 146 | updatePlayer(dt) 147 | end 148 | 149 | function love.draw() 150 | drawBlocks() 151 | drawPlayer() 152 | if shouldDrawDebug then 153 | drawDebug() 154 | drawConsole() 155 | end 156 | drawMessage() 157 | end 158 | 159 | -- Non-player keypresses 160 | function love.keypressed(k) 161 | if k=="escape" then love.event.quit() end 162 | if k=="tab" then shouldDrawDebug = not shouldDrawDebug end 163 | if k=="delete" then collectgarbage("collect") end 164 | end 165 | -------------------------------------------------------------------------------- /Collisions/bump lesson 2/MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Enrique García Cota 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Collisions/bump lesson 2/README.md: -------------------------------------------------------------------------------- 1 | # bump.lua simple demo 2 | 3 | This is the simple demo of [bump.lua](http://github.com/kikito/bump.lua) 4 | 5 | It requires [LÖVE](http://love2d.org) to work properly. 6 | 7 | This simple demo creates a world populated by random boxes, and allows to move a player around using the keyboard arrow keys. The player has constant velocity 8 | and can will "slide" over the boxes without penetrating them, similarly to some classic games such as Zelda. 9 | 10 | Pressing TAB will display some debug information. 11 | 12 | ![simpledemo](https://kikito.github.io/bump.lua/img/bump-simpledemo.gif) 13 | 14 | 15 | -------------------------------------------------------------------------------- /Collisions/bump lesson 2/bump_debug.lua: -------------------------------------------------------------------------------- 1 | 2 | local bump = require 'bump' 3 | 4 | local bump_debug = {} 5 | 6 | local function getCellRect(world, cx,cy) 7 | local cellSize = world.cellSize 8 | local l,t = world:toWorld(cx,cy) 9 | return l,t,cellSize,cellSize 10 | end 11 | 12 | function bump_debug.draw(world) 13 | local cellSize = world.cellSize 14 | local font = love.graphics.getFont() 15 | local fontHeight = font:getHeight() 16 | local topOffset = (cellSize - fontHeight) / 2 17 | for cy, row in pairs(world.rows) do 18 | for cx, cell in pairs(row) do 19 | local l,t,w,h = getCellRect(world, cx,cy) 20 | local intensity = cell.itemCount * 12 + 16 21 | love.graphics.setColor(1,1,1,intensity/255) 22 | love.graphics.rectangle('fill', l,t,w,h) 23 | love.graphics.setColor(1,1,1, 64/255) 24 | love.graphics.printf(cell.itemCount, l, t+topOffset, cellSize, 'center') 25 | love.graphics.setColor(1,1,1,10/255) 26 | love.graphics.rectangle('line', l,t,w,h) 27 | end 28 | end 29 | end 30 | 31 | return bump_debug 32 | -------------------------------------------------------------------------------- /Collisions/bump lesson 2/main.lua: -------------------------------------------------------------------------------- 1 | local bump = require 'bump' 2 | local bump_debug = require 'bump_debug' 3 | 4 | local instructions = [[ 5 | bump.lua simple demo 6 | 7 | arrows: move 8 | tab: toggle debug info 9 | delete: run garbage collector 10 | ]] 11 | 12 | local cols_len = 0 -- how many collisions are happening 13 | 14 | -- World creation 15 | local world = bump.newWorld() 16 | qp_items = {} 17 | 18 | -- Message/debug functions 19 | local function drawMessage() 20 | local msg = instructions:format(tostring(shouldDrawDebug)) 21 | love.graphics.setColor(1, 1, 1) 22 | love.graphics.print(msg, 550, 10) 23 | --love.graphics.print( ""..#qp_items.." "..love.mouse.getX().." "..love.mouse.getY(), 10, 10) 24 | love.graphics.print( ""..#qp_items.." "..love.mouse.getX().." "..love.mouse.getY(), 10, 10) 25 | for y = 1, #qp_items do 26 | local it = qp_items[y] 27 | love.graphics.print( ""..it.item.name.." "..it.x1.." "..it.y1.." "..it.x2.." "..it.y2.." "..it.ti1.." "..it.ti2, 10, 10 + y * 10) 28 | end 29 | end 30 | 31 | local function drawDebug() 32 | bump_debug.draw(world) 33 | 34 | local statistics = ("fps: %d, mem: %dKB, collisions: %d, items: %d"):format(love.timer.getFPS(), collectgarbage("count"), cols_len, world:countItems()) 35 | love.graphics.setColor(1, 1, 1) 36 | love.graphics.printf(statistics, 0, 580, 790, 'right') 37 | end 38 | 39 | local consoleBuffer = {} 40 | local consoleBufferSize = 5 41 | for i=1,consoleBufferSize do consoleBuffer[i] = "" end 42 | local function consolePrint(msg) 43 | table.remove(consoleBuffer,1) 44 | consoleBuffer[consoleBufferSize] = msg 45 | end 46 | 47 | local function drawConsole() 48 | local str = table.concat(consoleBuffer, "\n") 49 | for i=1,consoleBufferSize do 50 | love.graphics.setColor(1,1,1, i/consoleBufferSize) 51 | love.graphics.printf(consoleBuffer[i], 10, 580-(consoleBufferSize - i)*12, 790, "left") 52 | end 53 | end 54 | 55 | -- helper function 56 | local function drawBox(box, r,g,b) 57 | love.graphics.setColor(r,g,b,70/255) 58 | love.graphics.rectangle("fill", box.x, box.y, box.w, box.h) 59 | love.graphics.setColor(r,g,b) 60 | love.graphics.rectangle("line", box.x, box.y, box.w, box.h) 61 | end 62 | 63 | 64 | local function myFilter(item, other) 65 | --print(item.name, " collides ", other.name) 66 | if other.kind and other.kind == "coin" then 67 | --coins = coins + 1 68 | -- other OFF 69 | return "cross" 70 | --return "bounce" 71 | end 72 | if other.kind and other.kind == "wall" then 73 | return "slide" 74 | --return "bounce" 75 | end 76 | return "slide" 77 | end 78 | 79 | -- Player functions 80 | local player = { x=50,y=50,w=20,h=20, speed = 180, name = "Player1", isPlayer = true } 81 | 82 | local function updatePlayer(dt) 83 | local speed = player.speed 84 | 85 | local dx, dy = 0, 0 86 | if love.keyboard.isDown('right') then 87 | dx = speed * dt 88 | elseif love.keyboard.isDown('left') then 89 | dx = -speed * dt 90 | end 91 | if love.keyboard.isDown('down') then 92 | dy = speed * dt 93 | elseif love.keyboard.isDown('up') then 94 | dy = -speed * dt 95 | end 96 | 97 | if dx ~= 0 or dy ~= 0 then 98 | local cols 99 | player.x, player.y, cols, cols_len 100 | = world:move(player, player.x + dx, player.y + dy, myFilter) 101 | for i=1, #cols do 102 | local col = cols[i] 103 | consolePrint(("col.other = %s, col.type = %s, col.normal = %d,%d"):format(col.other, col.type, col.normal.x, col.normal.y)) 104 | end 105 | end 106 | end 107 | 108 | local function drawPlayer() 109 | drawBox(player, 0, 1, 0) 110 | end 111 | 112 | -- Block functions 113 | 114 | local blocks = {} 115 | 116 | local function addBlock(x,y,w,h) 117 | local block = {x=x,y=y,w=w,h=h, color = math.random(), name = "Wall" .. #blocks+1, isWall = true } 118 | blocks[#blocks+1] = block 119 | world:add(block, x,y,w,h) 120 | end 121 | 122 | local function drawBlocks() 123 | for _,block in ipairs(blocks) do 124 | drawBox(block, 1,0, block.color) 125 | end 126 | end 127 | 128 | -- Main LÖVE functions 129 | 130 | function love.load() 131 | world:add(player, player.x, player.y, player.w, player.h) 132 | 133 | addBlock(0, 0, 800, 32) 134 | addBlock(0, 32, 32, 600-32*2) 135 | addBlock(800-32, 32, 32, 600-32*2) 136 | addBlock(0, 600-32, 800, 32) 137 | 138 | for i=1,30 do 139 | addBlock( math.random(100, 600), 140 | math.random(100, 400), 141 | math.random(10, 100), 142 | math.random(10, 100) 143 | ) 144 | end 145 | end 146 | 147 | local function filter_only_player( item ) 148 | return item.isPlayer 149 | end 150 | 151 | local function filter_not_player( item ) 152 | return not item.isPlayer 153 | end 154 | 155 | function love.update(dt) 156 | cols_len = 0 157 | updatePlayer(dt) 158 | 159 | --qp_items, _ = world:queryPoint( love.mouse.getX(), love.mouse.getY(), filter_not_player ) 160 | --qp_items, _ = world:queryRect( love.mouse.getX(), love.mouse.getY(), 20, 20, filter_not_player ) 161 | --qp_items, _ = world:querySegment( 0,0, love.mouse.getX(), love.mouse.getY() ) 162 | qp_items, _ = world:querySegmentWithCoords( 60,60, love.mouse.getX(), love.mouse.getY() ) 163 | 164 | end 165 | 166 | function love.draw() 167 | drawBlocks() 168 | drawPlayer() 169 | if shouldDrawDebug then 170 | drawDebug() 171 | drawConsole() 172 | end 173 | drawMessage() 174 | 175 | --love.graphics.rectangle("line", love.mouse.getX(), love.mouse.getY(), 20, 20 ) 176 | love.graphics.line(60,60, love.mouse.getX(), love.mouse.getY() ) 177 | end 178 | 179 | -- Non-player keypresses 180 | function love.keypressed(k) 181 | if k=="escape" then love.event.quit() end 182 | if k=="tab" then shouldDrawDebug = not shouldDrawDebug end 183 | if k=="delete" then collectgarbage("collect") end 184 | end 185 | -------------------------------------------------------------------------------- /Collisions/bump lesson 3/MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Enrique García Cota 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Collisions/bump lesson 3/README.md: -------------------------------------------------------------------------------- 1 | # bump.lua simple demo 2 | 3 | This is the simple demo of [bump.lua](http://github.com/kikito/bump.lua) 4 | 5 | It requires [LÖVE](http://love2d.org) to work properly. 6 | 7 | This simple demo creates a world populated by random boxes, and allows to move a player around using the keyboard arrow keys. The player has constant velocity 8 | and can will "slide" over the boxes without penetrating them, similarly to some classic games such as Zelda. 9 | 10 | Pressing TAB will display some debug information. 11 | 12 | ![simpledemo](https://kikito.github.io/bump.lua/img/bump-simpledemo.gif) 13 | 14 | 15 | -------------------------------------------------------------------------------- /Collisions/bump lesson 3/bump_debug.lua: -------------------------------------------------------------------------------- 1 | 2 | local bump = require 'bump' 3 | 4 | local bump_debug = {} 5 | 6 | local function getCellRect(world, cx,cy) 7 | local cellSize = world.cellSize 8 | local l,t = world:toWorld(cx,cy) 9 | return l,t,cellSize,cellSize 10 | end 11 | 12 | function bump_debug.draw(world) 13 | local cellSize = world.cellSize 14 | local font = love.graphics.getFont() 15 | local fontHeight = font:getHeight() 16 | local topOffset = (cellSize - fontHeight) / 2 17 | for cy, row in pairs(world.rows) do 18 | for cx, cell in pairs(row) do 19 | local l,t,w,h = getCellRect(world, cx,cy) 20 | local intensity = cell.itemCount * 12 + 16 21 | love.graphics.setColor(1,1,1,intensity/255) 22 | love.graphics.rectangle('fill', l,t,w,h) 23 | love.graphics.setColor(1,1,1, 64/255) 24 | love.graphics.printf(cell.itemCount, l, t+topOffset, cellSize, 'center') 25 | love.graphics.setColor(1,1,1,10/255) 26 | love.graphics.rectangle('line', l,t,w,h) 27 | end 28 | end 29 | end 30 | 31 | return bump_debug 32 | -------------------------------------------------------------------------------- /Collisions/bump lesson 3/debug_console.lua: -------------------------------------------------------------------------------- 1 | instructions = [[ 2 | bump.lua simple demo 3 | 4 | arrows: move 5 | tab: toggle debug info 6 | delete: run garbage collector 7 | ]] 8 | 9 | local consoleBuffer = {} 10 | local consoleBufferSize = 5 11 | 12 | for i=1,consoleBufferSize do consoleBuffer[i] = "" end 13 | 14 | function consolePrint(msg) 15 | table.remove(consoleBuffer,1) 16 | consoleBuffer[consoleBufferSize] = msg 17 | end 18 | 19 | function drawConsole() 20 | local str = table.concat(consoleBuffer, "\n") 21 | for i=1,consoleBufferSize do 22 | love.graphics.setColor(1,1,1, i/consoleBufferSize) 23 | love.graphics.printf(consoleBuffer[i], 10, 580-(consoleBufferSize - i)*12, 790, "left") 24 | end 25 | end 26 | 27 | -- Вывод отладочного текста на экране 28 | function drawMessage() 29 | local msg = instructions:format(tostring(shouldDrawDebug)) 30 | love.graphics.setColor(1, 1, 1) 31 | love.graphics.print(msg, 550, 10) 32 | love.graphics.print( ""..#qp_items.." "..love.mouse.getX().. 33 | " "..love.mouse.getY(), 10, 10) 34 | for y = 1, #qp_items do 35 | local it = qp_items[y] 36 | love.graphics.print( ""..it.item.name.." " 37 | ..it.x1.." "..it.y1.." "..it.x2.." "..it.y2 38 | .." "..it.ti1.." "..it.ti2, 10, 10 + y * 10) 39 | end 40 | end 41 | 42 | function drawDebug() 43 | bump_debug.draw(world) 44 | local statistics = ("fps: %d, mem: %dKB, collisions: %d, items: %d"):format(love.timer.getFPS(), collectgarbage("count"), cols_len, world:countItems()) 45 | love.graphics.setColor(1, 1, 1) 46 | love.graphics.printf(statistics, 0, 580, 790, 'right') 47 | end 48 | -------------------------------------------------------------------------------- /Collisions/bump lesson 3/main.lua: -------------------------------------------------------------------------------- 1 | local bump = require 'bump' 2 | bump_debug = require 'bump_debug' 3 | require "debug_console" 4 | 5 | cols_len = 0 -- сколько столкновений произошло 6 | coins = 0 7 | isGameOver = false 8 | 9 | -- Создаём мир 10 | world = bump.newWorld() 11 | qp_items = {} 12 | 13 | -- рисование прямоугольника выбранным цветом R G B 14 | local function drawBox(box, r,g,b) 15 | love.graphics.setColor(r,g,b,70/255) 16 | love.graphics.rectangle("fill", box.x, box.y, box.w, box.h) 17 | love.graphics.setColor(r,g,b) 18 | love.graphics.rectangle("line", box.x, box.y, box.w, box.h) 19 | end 20 | 21 | -- рисование круга выбранным цветом R G B 22 | local function drawCircle(box, r,g,b) 23 | love.graphics.setColor(r,g,b,70/255) 24 | love.graphics.circle("fill", box.x+box.w/2, box.y+box.w/2, box.w/2) 25 | love.graphics.setColor(r,g,b) 26 | love.graphics.circle("line", box.x+box.w/2, box.y+box.w/2, box.w/2) 27 | end 28 | 29 | local function myFilter(item, other) 30 | --print(item.name, " collides ", other.name) 31 | if other.isCoin then 32 | return "cross" 33 | end 34 | if other.isWall then 35 | return "slide" 36 | end 37 | return "cross" 38 | end 39 | 40 | -- Функции для игрока 41 | local player = { x=50,y=50,w=20,h=20, speed = 180, name = "Player1", isPlayer = true } 42 | 43 | local function updatePlayer(dt) 44 | local speed = player.speed 45 | 46 | local dx, dy = 0, 0 47 | if love.keyboard.isDown('right') then 48 | dx = speed * dt 49 | elseif love.keyboard.isDown('left') then 50 | dx = -speed * dt 51 | end 52 | if love.keyboard.isDown('down') then 53 | dy = speed * dt 54 | elseif love.keyboard.isDown('up') then 55 | dy = -speed * dt 56 | end 57 | 58 | if dx ~= 0 or dy ~= 0 then 59 | local cols 60 | player.x, player.y, cols, cols_len 61 | = world:move(player, player.x + dx, player.y + dy, myFilter) 62 | for i=1, #cols do 63 | local col = cols[i] 64 | consolePrint(("col.other = %s, col.type = %s, col.normal = %d,%d"):format(col.other, 65 | col.type, col.normal.x, col.normal.y)) 66 | if col.other.isCoin then 67 | coins = coins + 1 68 | col.other.isCoin = false 69 | end 70 | if col.other.isLava then 71 | isGameOver = true 72 | end 73 | end 74 | end 75 | end 76 | 77 | -- Рисование игрока. Можете спрайт сюда подставить потом 78 | local function drawPlayer() 79 | -- drawBox(player, 0, 1, 0) 80 | drawCircle(player, 0, 1, 0) 81 | end 82 | 83 | -- Функции создания объектов на уровне 84 | local blocks = {} 85 | 86 | local function addBlock(x,y,w,h) 87 | local block = {x=x,y=y,w=w,h=h, color = math.random(), 88 | name = "Wall" .. #blocks+1, isWall = true } 89 | blocks[#blocks+1] = block 90 | world:add(block, x,y,w,h) 91 | end 92 | 93 | local function addLava(x,y,w,h) 94 | local block = {x=x,y=y,w=w,h=h, 95 | name = "Lava" .. #blocks+1, isLava = true } 96 | blocks[#blocks+1] = block 97 | world:add(block, x,y,w,h) 98 | end 99 | 100 | local coinSize = 20 101 | local function addCoin(x,y) 102 | local block = {x=x,y=y,w=coinSize,h=coinSize, 103 | name = "Coin" .. #blocks+1, isCoin = true } 104 | blocks[#blocks+1] = block 105 | world:add(block, x,y,coinSize,coinSize) 106 | end 107 | 108 | local function drawBlocks() 109 | for _,block in ipairs(blocks) do 110 | if block.isCoin then 111 | drawCircle(block, 1, 1, 0 ) 112 | elseif block.isWall then 113 | drawBox(block, 0,1, block.color) 114 | elseif block.isLava then 115 | drawBox(block, 1,0,0) 116 | end 117 | end 118 | end 119 | 120 | -- Главные функции LÖVE 121 | function love.load() 122 | world:add(player, player.x, player.y, player.w, player.h) 123 | local result = world:hasItem(coinSize) 124 | print(result, world:countItems() ) 125 | 126 | addBlock(0, 0, 800, 32) 127 | addBlock(0, 32, 32, 600-32*2) 128 | addBlock(800-32, 32, 32, 600-32*2) 129 | addBlock(0, 600-32, 800, 32) 130 | 131 | print( world:countItems() ) 132 | 133 | for i=1,30 do 134 | addCoin( math.random(100, 600), 135 | math.random(100, 400), 136 | math.random(10, 100), 137 | math.random(10, 100) 138 | ) 139 | end 140 | 141 | for i=1,10 do 142 | addBlock( math.random(100, 600), 143 | math.random(100, 400), 144 | math.random(10, 100), 145 | math.random(10, 100) 146 | ) 147 | end 148 | 149 | for i=1, 5 do 150 | addLava( math.random(100, 600), 151 | math.random(100, 400), 152 | math.random(10, 100), 153 | math.random(10, 100) 154 | ) 155 | end 156 | end 157 | 158 | local function filter_only_player( item ) 159 | return item.isPlayer 160 | end 161 | 162 | local function filter_not_player( item ) 163 | return not item.isPlayer 164 | end 165 | 166 | function love.update(dt) 167 | cols_len = 0 168 | updatePlayer(dt) 169 | 170 | --qp_items, _ = world:queryPoint( love.mouse.getX(), love.mouse.getY(), filter_not_player ) 171 | --qp_items, _ = world:queryRect( love.mouse.getX(), love.mouse.getY(), 20, 20, filter_not_player ) 172 | --qp_items, _ = world:querySegment( 0,0, love.mouse.getX(), love.mouse.getY() ) 173 | qp_items, _ = world:querySegmentWithCoords( 60,60, love.mouse.getX(), love.mouse.getY() ) 174 | 175 | end 176 | 177 | function love.draw() 178 | drawBlocks() 179 | drawPlayer() 180 | if shouldDrawDebug then 181 | drawDebug() 182 | drawConsole() 183 | end 184 | drawMessage() 185 | love.graphics.print("COINS: "..coins, 10, 580) 186 | --love.graphics.rectangle("line", love.mouse.getX(), love.mouse.getY(), 20, 20 ) 187 | love.graphics.line(60,60, love.mouse.getX(), love.mouse.getY() ) 188 | if isGameOver then 189 | love.graphics.setColor(1,0,0, 0.7) 190 | love.graphics.rectangle("fill", 0, 0, 800, 600) 191 | end 192 | 193 | local x,y,w,h = world:getRect(player) 194 | love.graphics.setColor(1,0,0, 0.9) 195 | love.graphics.rectangle("fill", x, y, w, h) 196 | 197 | x,y = world:toCell(love.mouse.getX(), love.mouse.getY() ) 198 | love.graphics.setColor(0,0,1, 0.2) 199 | --love.graphics.rectangle("fill", (x - 1) * 64, (y - 1)* 64, 64, 64) 200 | x,y = world:toWorld(x, y) 201 | love.graphics.rectangle("fill", x, y, 64, 64) 202 | end 203 | 204 | -- кнопки управления, которые не имеют отношения к игроку 205 | function love.keypressed(k) 206 | if k=="escape" then love.event.quit() end 207 | if k=="tab" then shouldDrawDebug = not shouldDrawDebug end 208 | if k=="delete" then collectgarbage("collect") end 209 | end 210 | -------------------------------------------------------------------------------- /Fonts/main.lua: -------------------------------------------------------------------------------- 1 | -- Про Вывод Текста и Шрифты. УРОК 3 2 | function love.load() 3 | y2, y3 = 0, 50 4 | xLimit = 800 5 | speed = 40 6 | 7 | white = { 255, 255, 255 } 8 | red = { 255, 20, 20, 200 } 9 | green = { 0, 255, 20 } 10 | black = { 0, 0, 0, 255 } 11 | blue = { 0, 0, 130 } -- для фона экрана 12 | 13 | text1 = "ТЕКСТ ОДИН" 14 | text2 = "текст ДВА" 15 | textRed = "КРАСНЫЕ буквы" 16 | 17 | coloredText = { green, text1, black, text2, red, textRed } 18 | 19 | font = love.graphics.newFont( "res/Bukhari_Script.ttf", 40 ) 20 | love.graphics.setFont(font) -- Шрифт 21 | end 22 | 23 | function love.draw() 24 | local x, y = 20, 10 25 | local xf, yf = 20, 260 26 | love.graphics.clear( unpack(blue) ) 27 | love.graphics.setColor( unpack(black) ) 28 | love.graphics.rectangle("fill", xLimit + xf, 0, 2, love.graphics.getHeight()) 29 | 30 | love.graphics.setColor( 255, 0, 0, 90 ) 31 | love.graphics.rectangle("fill", 0, y2, love.graphics.getWidth(), 10) 32 | love.graphics.setColor( 150, 255, 150, 90 ) 33 | love.graphics.rectangle("fill", 0, y3, love.graphics.getWidth(), 10) 34 | 35 | love.graphics.setColor( unpack(white) ) -- Белый. Без искажения. 36 | love.graphics.print(coloredText, x, y) -- Нормальный вывод 37 | love.graphics.setColor( 255, 255, 255, 100 ) 38 | love.graphics.print(coloredText, x, y + 120) -- Подмешиваем цвет 39 | 40 | love.graphics.setColor( unpack(white) ) -- Белый. Без искажения. 41 | love.graphics.printf(coloredText, xf, yf, xLimit, "center") -- Форматируем вывод 42 | end 43 | 44 | function love.update(dt) 45 | xLimit = xLimit - dt * speed -- Двигаем лимит (ширину) вывода текста 46 | if xLimit < 200 then 47 | xLimit = love.graphics.getWidth() 48 | end 49 | 50 | y2 = y2 + speed * dt -- Полосы под первым текстом 51 | y3 = y3 - speed * dt 52 | if y2 > 100 then 53 | y2 = -10 54 | end 55 | if y3 < -10 then 56 | y3 = 100 57 | end 58 | 59 | red[3] = red[3] + dt * speed -- Меняем цвет red 60 | if red[3] > 255 then 61 | red[3] = 0 62 | end 63 | 64 | black[4] = black[4] + dt * speed -- Меняем прозрачность цвета black 65 | if black[4] > 255 then 66 | black[4] = 0 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /Fonts/main_1.lua: -------------------------------------------------------------------------------- 1 | -- Про Шрифты. УРОК 1 2 | 3 | -- The default font (Bitstream Vera Sans) 4 | -- Any font file supported by FreeType 2 5 | -- An image containing glyphs (ImageFont) 6 | 7 | function love.load() 8 | love.graphics.setDefaultFilter("nearest", "nearest") 9 | text = "ABCxyz123#! - Не ешь, подумай! Булочки хорошие." 10 | font1 = love.graphics.newFont( 20 ) 11 | font2 = love.graphics.newFont( "res/Bukhari_Script.ttf", 20 ) 12 | font2_80 = love.graphics.newFont( "res/Bukhari_Script.ttf", 80 ) 13 | font3 = love.graphics.newFont( "res/Certege.ttf", 20 ) 14 | font4 = love.graphics.newFont( "res/MIROSLN.ttf", 20 ) 15 | font5 = love.graphics.newImageFont("res/imagefont.png", 16 | " abcdefghijklmnopqrstuvwxyz" .. 17 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ0" .. 18 | "123456789.,!?-+/():;%&`'*#=[]\"", 0) 19 | end 20 | 21 | function love.draw() 22 | love.graphics.clear( 0, 0, 130 ) 23 | love.graphics.setColor( 255, 255, 255 ) 24 | love.graphics.setFont(font1) 25 | love.graphics.print(text, 20, 10) 26 | love.graphics.setFont(font2) 27 | love.graphics.print(text, 20, 40) 28 | -- love.graphics.setFont(font2_80) 29 | -- love.graphics.setColor( 255, 100, 100 ) 30 | -- love.graphics.print(text, -500, 60, 0.3) 31 | -- love.graphics.setFont(font3) 32 | -- love.graphics.print(text, 20, 70) 33 | -- love.graphics.setFont(font4) 34 | -- love.graphics.print(text, 20, 100) 35 | -- love.graphics.setFont(font5) 36 | -- love.graphics.print(text, 20, 130) 37 | end 38 | 39 | function love.update(dt) 40 | end -------------------------------------------------------------------------------- /Fonts/main_2.lua: -------------------------------------------------------------------------------- 1 | -- Про Шрифты. УРОК 2 2 | 3 | function love.load() 4 | love.graphics.setDefaultFilter("nearest", "nearest") 5 | text = "ABCxyz123#|{[\\ - Не ешь, подумай!\n Булочки хорошие." 6 | font = love.graphics.newFont( 20 ) 7 | font1 = love.graphics.newFont( 40 ) 8 | -- font1:setLineHeight(0.7) 9 | font2 = love.graphics.newFont( "res/Bukhari_Script.ttf", 40 ) 10 | font1:setFallbacks( font2 ) 11 | 12 | font1_base_line = font1:getBaseline() 13 | font2_base_line = font2:getBaseline() 14 | font1_ascent = font1:getAscent() 15 | font2_ascent = font2:getAscent() 16 | font1_descent = font1:getDescent() 17 | font2_descent = font2:getDescent() 18 | end 19 | 20 | function love.draw() 21 | local x, y1, y2 = 20, 10, 120 22 | 23 | love.graphics.clear( 0, 0, 130 ) 24 | love.graphics.setColor( 255, 0, 0 ) 25 | love.graphics.line(x, y1 + font1_base_line, font1:getWidth(text), y1 + font1_base_line) 26 | love.graphics.line(x, y2 + font2_base_line, 600, y2 + font2_base_line) 27 | love.graphics.setColor( 255, 150, 150 ) 28 | love.graphics.line(x, y1 + font1_base_line - font1_ascent, 600, y1 + font1_base_line - font1_ascent) 29 | love.graphics.line(x, y2 + font2_base_line - font2_ascent, 600, y2 + font2_base_line - font2_ascent) 30 | love.graphics.setColor( 150, 255, 150 ) 31 | love.graphics.line(x, y1 + font1_base_line - font1_descent, 600, y1 + font1_base_line - font1_descent) 32 | love.graphics.line(x, y2 + font2_base_line - font2_descent, 600, y2 + font2_base_line - font2_descent) 33 | 34 | love.graphics.setColor( 255, 255, 255 ) 35 | love.graphics.setFont(font1) -- Шрифт 1 36 | love.graphics.print(text, x, y1) 37 | 38 | love.graphics.setFont(font2) -- Рус шрифт 2 39 | love.graphics.print(text, x, y2) 40 | 41 | love.graphics.setFont(font) -- Просто инфо по шрифтам 42 | love.graphics.print( "font1 Base Line, Ascent, Descent:"..font1_base_line..","..font1_ascent..","..font1_descent, 20, y2 + 100) 43 | love.graphics.print( "font2 Base Line, Ascent, Descent:"..font2_base_line..","..font2_ascent..","..font2_descent, 20, y2 + 120) 44 | 45 | love.graphics.print( "font2 height:"..font2:getHeight( ), 20, y2 + 140) 46 | if font2:hasGlyphs( "ой, привеееет!" ) then 47 | love.graphics.print( "The font has the listed Glyphs", 20, y2 + 160) 48 | end 49 | local width, wrappedtext = font:getWrap( text, 160 ) 50 | love.graphics.print( "getWrap 160px width, wrappedtext:"..width..", "..#wrappedtext, 20, y2 + 180) 51 | love.graphics.print( "font2 width of 12345:"..font2:getWidth("12345"), 20, y2 + 200) 52 | end -------------------------------------------------------------------------------- /Fonts/main_3.lua: -------------------------------------------------------------------------------- 1 | -- Про Вывод Текста и Шрифты. УРОК 3 2 | function love.load() 3 | y2, y3 = 0, 50 4 | xLimit = 800 5 | speed = 40 6 | 7 | white = { 255, 255, 255 } 8 | red = { 255, 20, 20, 200 } 9 | green = { 0, 255, 20 } 10 | black = { 0, 0, 0, 255 } 11 | blue = { 0, 0, 130 } -- для фона экрана 12 | 13 | text1 = "ТЕКСТ ОДИН" 14 | text2 = "текст ДВА" 15 | textRed = "КРАСНЫЕ буквы" 16 | 17 | coloredText = { green, text1, black, text2, red, textRed } 18 | 19 | font = love.graphics.newFont( "res/Bukhari_Script.ttf", 40 ) 20 | love.graphics.setFont(font) -- Шрифт 21 | end 22 | 23 | function love.draw() 24 | local x, y = 20, 10 25 | local xf, yf = 20, 260 26 | love.graphics.clear( unpack(blue) ) 27 | love.graphics.setColor( unpack(black) ) 28 | love.graphics.rectangle("fill", xLimit + xf, 0, 2, love.graphics.getHeight()) 29 | 30 | love.graphics.setColor( 255, 0, 0, 90 ) 31 | love.graphics.rectangle("fill", 0, y2, love.graphics.getWidth(), 10) 32 | love.graphics.setColor( 150, 255, 150, 90 ) 33 | love.graphics.rectangle("fill", 0, y3, love.graphics.getWidth(), 10) 34 | 35 | love.graphics.setColor( unpack(white) ) -- Белый. Без искажения. 36 | love.graphics.print(coloredText, x, y) -- Нормальный вывод 37 | love.graphics.setColor( 255, 255, 255, 100 ) 38 | love.graphics.print(coloredText, x, y + 120) -- Подмешиваем цвет 39 | 40 | love.graphics.setColor( unpack(white) ) -- Белый. Без искажения. 41 | love.graphics.printf(coloredText, xf, yf, xLimit, "center") -- Форматируем вывод 42 | end 43 | 44 | function love.update(dt) 45 | xLimit = xLimit - dt * speed -- Двигаем лимит (ширину) вывода текста 46 | if xLimit < 200 then 47 | xLimit = love.graphics.getWidth() 48 | end 49 | 50 | y2 = y2 + speed * dt -- Полосы под первым текстом 51 | y3 = y3 - speed * dt 52 | if y2 > 100 then 53 | y2 = -10 54 | end 55 | if y3 < -10 then 56 | y3 = 100 57 | end 58 | 59 | red[3] = red[3] + dt * speed -- Меняем цвет red 60 | if red[3] > 255 then 61 | red[3] = 0 62 | end 63 | 64 | black[4] = black[4] + dt * speed -- Меняем прозрачность цвета black 65 | if black[4] > 255 then 66 | black[4] = 0 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /Fonts/res/Bukhari_Script.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Fonts/res/Bukhari_Script.ttf -------------------------------------------------------------------------------- /Fonts/res/Certege.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Fonts/res/Certege.ttf -------------------------------------------------------------------------------- /Fonts/res/MIROSLN.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Fonts/res/MIROSLN.ttf -------------------------------------------------------------------------------- /Fonts/res/imagefont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Fonts/res/imagefont.png -------------------------------------------------------------------------------- /Lua language/funct_sugar.lua: -------------------------------------------------------------------------------- 1 | -- Сахарок для вызова функции 2 | -- когда можно использовать . или : при вызове функции в таблице 3 | kitty = { says = "мя-мя", food = "кактусы", x = 2, 4 | foo = function() print(1) end } 5 | doge = { says = "woff", food = "crabs", x = 5} 6 | --kitty.foo() 7 | kitty.eat = function(self) 8 | print("ест",self.food) 9 | end 10 | 11 | function kitty:say(a) 12 | print("говорит", self.says, a) 13 | end 14 | kitty:eat() 15 | kitty:say(4) 16 | kitty.say(doge, 77) -------------------------------------------------------------------------------- /Lua language/if_statement.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Lua language/if_statement.lua -------------------------------------------------------------------------------- /Lua language/if_while_repeat.lua: -------------------------------------------------------------------------------- 1 | -- Управляющие конструкции if, while и repeat 2 | 3 | counter = 0 4 | 5 | repeat 6 | counter = counter + 1 7 | print("мы внутри цикла repeat until", counter) 8 | until counter > 5 9 | 10 | 11 | 12 | print("конец") 13 | -------------------------------------------------------------------------------- /Lua language/lesson 3.lua: -------------------------------------------------------------------------------- 1 | print("НАЧАЛО") 2 | 3 | print("КОНЕЦ") -------------------------------------------------------------------------------- /Lua language/math.lua: -------------------------------------------------------------------------------- 1 | -- Немножко математики в Lua 2 | math.randomseed( os.time() ) 3 | 4 | r = math.random(3,50) 5 | 6 | print(r) 7 | 8 | 9 | 10 | 11 | -- +%()^ 12 | -- round .5math.min sin deg rad pi -------------------------------------------------------------------------------- /Lua language/my_saturday.lua: -------------------------------------------------------------------------------- 1 | -- Как я проведу СУПЕР воскресенье 2 | print("Начало") 3 | local хорошая_погода = true 4 | local починили_комп = true 5 | if починили_комп then 6 | print("Завивисаем ВКонтакте") 7 | elseif хорошая_погода then 8 | print("Иду играть в футбол на улицу!") 9 | else 10 | print("Смотрим аниме по телику") 11 | end 12 | print("Делаем ДЗ") 13 | print("Конец") -------------------------------------------------------------------------------- /Lua language/random.lua: -------------------------------------------------------------------------------- 1 | -- СЛУЧАЙНЫЕ ЧИСЛА в Lua 2 | -- Математическая и системная библиотеки 3 | math.randomseed( os.time() ) 4 | local загаданоЧисло = math.random(100, 300) 5 | print("Загадано число 1:", загаданоЧисло) 6 | local загаданоЧисло = math.random(100, 300) 7 | print("Загадано число 2:", загаданоЧисло) 8 | local загаданоЧисло = math.random(100, 300) 9 | print("Загадано число 3:", загаданоЧисло) -------------------------------------------------------------------------------- /Lua language/vars.lua: -------------------------------------------------------------------------------- 1 | local myVar = 100 2 | 3 | a = 10 4 | do 5 | 6 | local b = 5 7 | print(b, a) 8 | end 9 | print(b, a) 10 | 11 | -- регистр переменных 12 | g = 12 13 | G = 50 14 | g = 13 15 | print(g, G) 16 | 17 | -- числа десятичные, восьмеричные и шестнадцатеричные 18 | h1 = 200 19 | h2 = 077 20 | h3 = 0x31 21 | print(h1, h2, h3) 22 | 23 | -- строки 24 | str1 = "hel'lo!" 25 | str2 = 'he"llo!' 26 | st3 = [["hello" 27 | 'hello!!!']] 28 | print(str1,str2, st3) 29 | -- сложные строки 30 | st4 = [===[ ]==]text2 31 | text2 32 | text3 ]===] 33 | print(st4) 34 | -- множественное присваивание 35 | a = 12 36 | b = a 37 | print(a, b) 38 | 39 | -- приведение типов 40 | --tostring() 41 | --tonumber() 42 | --s = io.read() 43 | --s = tonumber( s ) 44 | --s = s * 2 45 | --print(s) 46 | --io.read() 47 | 48 | s2 = "stroka1" 49 | s3 = tostring(true) 50 | print(s2..s3) -------------------------------------------------------------------------------- /Lua language/занятие 3.lua: -------------------------------------------------------------------------------- 1 | print("НАЧАЛО") 2 | 3 | 4 | print("КОНЕЦ") -------------------------------------------------------------------------------- /OOP/oop lesson 1/main.lua: -------------------------------------------------------------------------------- 1 | class = require "lib.middleclass" 2 | 3 | Mlekopit = class("Mlekopit") 4 | 5 | function Mlekopit:initialize(ima, eda) 6 | self.ima = ima 7 | self.eda = eda or "НЕПОЙМИЧТО" 8 | self.x, self.y = 0, 0 9 | self.nashelEdu = true 10 | end 11 | function Mlekopit:idi() 12 | print(self.ima.." идёт куда-то...") 13 | end 14 | function Mlekopit:golos() 15 | print(self.ima.." что-то пищит...") 16 | end 17 | function Mlekopit:naidiEdu() 18 | if self.nashelEdu then 19 | print(self.ima.." уже нашел "..self.eda..". Не будет искать новую.") 20 | else 21 | print("Ура, "..self.ima.." нашел "..self.eda.."...") 22 | self.nashelEdu = true 23 | end 24 | end 25 | function Mlekopit:est(eda) 26 | if eda then 27 | print(self.ima.." съел "..eda.."...") 28 | return 29 | end 30 | 31 | if self.nashelEdu then 32 | print(self.ima.." съел "..self.eda.."...") 33 | self.nashelEdu = false 34 | else 35 | print("У "..self.ima.." нет еды...") 36 | end 37 | end 38 | 39 | mlek1 = Mlekopit:new("Мышка", "сыр") 40 | mlek1:golos() 41 | mlek2 = Mlekopit:new("Белка", "огромный орех") 42 | mlek2:golos() 43 | mlek3 = Mlekopit:new("Медведь", "мёд") 44 | function mlek3:golos() 45 | print(self.ima.." рычит...") 46 | end 47 | mlek3:golos() 48 | mlek3:est() 49 | mlek3:naidiEdu() 50 | mlek3:est() 51 | mlek1:est("грибочек") 52 | mlek2:est() 53 | mlek2:idi() 54 | ------ 55 | Chelovek = class("Chelovek", Mlekopit) 56 | function Chelovek:golos() 57 | math.randomseed(os.time()) 58 | if math.random() <= 0.5 then 59 | print(self.ima.." сказал умную фразу") 60 | else 61 | print(self.ima.." попросил помочь с задачей дня...") 62 | end 63 | end 64 | function Chelovek:naidiEdu() 65 | if self.nashelEdu then 66 | print(self.ima.." не шевелится. Он уже имеет "..self.eda.." в холодильнике.") 67 | else 68 | print(self.ima.." купил в магазине "..self.eda..".") 69 | self.nashelEdu = true 70 | end 71 | end 72 | function Chelovek:pishiCod() 73 | print(self.ima.." ленится и не пишет код.") 74 | end 75 | yan = Chelovek:new("человек Ян") 76 | yan:golos() 77 | yan:est() 78 | yan:naidiEdu() 79 | yan:est() 80 | yan:pishiCod() 81 | mlek1.pishiCod = Chelovek.pishiCod 82 | mlek1:pishiCod() 83 | mlek1.pishiCod(mlek1) 84 | -------------------------------------------------------------------------------- /OOP/oop lesson 4/main.lua: -------------------------------------------------------------------------------- 1 | class = require "lib.middleclass" 2 | 3 | Unit = class("Unit") 4 | 5 | function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2) 6 | return x1 < x2+w2 and 7 | x2 < x1+w1 and 8 | y1 < y2+h2 and 9 | y2 < y1+h1 10 | end 11 | 12 | function CheckLinearCollision(y1,h1, y2,h2) 13 | return y1 < y2+h2 and 14 | y2 < y1+h1 15 | end 16 | 17 | function Unit:initialize(name, x, y) 18 | self.name = name 19 | self.x = x 20 | self.y = y 21 | self.r = love.math.random(10, 20) 22 | self.color = {love.math.random(1, 255), 23 | love.math.random(1, 255), 24 | love.math.random(1, 255), 50 25 | } 26 | end 27 | 28 | -- возвращ true если Unit на экране и не касается границ экрана 29 | function Unit:isOnScreen() 30 | if self.x - self.r < 0 31 | or self.x + self.r > love.graphics.getWidth() 32 | or self.y - self.r < 0 33 | or self.y + self.r > love.graphics.getHeight() 34 | then 35 | return false 36 | else 37 | return true 38 | end 39 | end 40 | -- ИИ 41 | function Unit:update(dt) 42 | local oldx, oldy = self.x, self.y 43 | local sx, sy = love.math.random(-100, 100) * dt, love.math.random(-100, 100) * dt 44 | self.x = self.x + sx 45 | self.y = self.y + sy 46 | if not self:isOnScreen() or self:collideWithAny() then 47 | self.x = oldx 48 | self.y = oldy 49 | elseif not self:isOnScreen() then 50 | self:fixCollidedXY() 51 | end 52 | end 53 | 54 | function Unit:draw() 55 | love.graphics.setColor(unpack(self.color)) 56 | love.graphics.circle("fill", self.x, self.y, self.r) 57 | love.graphics.setColor(255,255,255) 58 | love.graphics.print(self.name, self.x, self.y) 59 | love.graphics.print("x:"..math.floor(self.x)..",y:"..math.floor(self.y), 60 | self.x - self.r, self.y + 10) 61 | end 62 | 63 | UnitDrop = class("UnitDrop", Unit) 64 | function UnitDrop:initialize(name, x, y) 65 | Unit.initialize(self, name, x, y) 66 | self.color = {love.math.random(155, 255), 67 | 0, 68 | 0, 69 | 255 70 | } 71 | end 72 | -- ИИ 73 | function UnitDrop:update(dt) 74 | local oldx, oldy = self.x, self.y 75 | local sy 76 | if self.y < love.graphics.getHeight() - self.r * 2 then 77 | sy = 100 * dt 78 | self.y = self.y + sy 79 | if self:collideWithAny() then 80 | self.y = oldy 81 | end 82 | end 83 | end 84 | 85 | UnitPong = class("UnitPong", Unit) 86 | function UnitPong:initialize(name, x, y) 87 | Unit.initialize(self, name, x, y) 88 | self.color = {0, 89 | 0, 90 | love.math.random(155, 255), 91 | 255 92 | } 93 | if love.math.random() < 0.5 then 94 | self.speedx = 0 95 | self.speedy = 80 96 | else 97 | self.speedx = 80 98 | if love.math.random() < 0.5 then 99 | self.speedy = 0 100 | else 101 | self.speedy = 80 102 | end 103 | end 104 | end 105 | -- ИИ 106 | function UnitPong:update(dt) 107 | local oldx, oldy = self.x, self.y 108 | self.x = self.x + self.speedx * dt 109 | if not self:isOnScreen() or self:collideWithAny() then 110 | self.x = oldx 111 | self.speedx = -self.speedx 112 | end 113 | self.y = self.y + self.speedy * dt 114 | if not self:isOnScreen() or self:collideWithAny() then 115 | self.y = oldy 116 | self.speedy = -self.speedy 117 | end 118 | end 119 | 120 | Player = class("Player", Unit) 121 | function Player:initialize(name, x, y, keys) 122 | Unit.initialize(self, name, x, y) 123 | self.color = {0, 124 | love.math.random(155, 255), 125 | 0, 126 | 255 127 | } 128 | self.speed = 100 129 | self.keys = keys or {left = "a", right = "d", up = "w", down = "s"} 130 | end 131 | 132 | function Player:control(dt) 133 | local oldx, oldy = self.x, self.y 134 | local sx, sy = 0, 0 135 | if love.keyboard.isDown(self.keys.left) and 136 | self.x > 0 + self.r then 137 | sx = -self.speed * dt 138 | elseif love.keyboard.isDown(self.keys.right) and 139 | self.x < love.graphics.getWidth() - self.r then 140 | sx = self.speed * dt 141 | end 142 | if love.keyboard.isDown(self.keys.up) and 143 | self.y > 0 + self.r then 144 | sy = -self.speed * dt 145 | elseif love.keyboard.isDown(self.keys.down) and 146 | self.y < love.graphics.getHeight() - self.r then 147 | sy = self.speed * dt 148 | end 149 | self.x = self.x + sx 150 | self.y = self.y + sy 151 | if self:collideWithAny() then 152 | self.x = oldx 153 | self.y = oldy 154 | end 155 | end 156 | 157 | --проверка столкновения текущего объекта с другим other 158 | function Unit:collideWith(other) 159 | if self == other then 160 | return false 161 | end 162 | if math.sqrt((self.x - other.x)^2 + (self.y - other.y)^2) 163 | < self.r + other.r 164 | then 165 | return true 166 | else 167 | return false 168 | end 169 | end 170 | 171 | function Unit:collideWithAny() 172 | for i = 1, #units do 173 | if self:collideWith(units[i]) then 174 | return true 175 | end 176 | end 177 | return false 178 | end 179 | 180 | function Player:update(dt) 181 | self:control(dt) 182 | end 183 | 184 | function Unit:fixCollidedXY() 185 | while self:collideWithAny() do 186 | self.x = love.math.random(20,love.graphics.getWidth()-20) 187 | self.y = love.math.random(20,love.graphics.getHeight()-20) 188 | end 189 | end 190 | 191 | function love.load() 192 | units = {} 193 | for i = 1, 55 do 194 | units[#units + 1] = Unit:new("ball"..i, 195 | love.math.random(20,love.graphics.getWidth()-20), 196 | love.math.random(20,love.graphics.getHeight()-20)) 197 | end 198 | for i = 1, 30 do 199 | units[#units + 1] = UnitDrop:new("Drop"..i, 200 | love.math.random(20,love.graphics.getWidth()-20), 201 | love.math.random(20,love.graphics.getHeight()-20)) 202 | end 203 | units[#units + 1] = Player:new("IGROK", 204 | love.graphics.getWidth() / 2, 205 | love.graphics.getHeight() / 2) 206 | units[#units + 1] = Player:new("IGROK2", 207 | love.graphics.getWidth() / 2 + 100, 208 | love.graphics.getHeight() / 2, 209 | {left = "left", right = "right", up = "up", down = "down"}) 210 | for i = 1, 40 do 211 | units[#units + 1] = UnitPong:new("Pong"..i, 212 | love.math.random(20,love.graphics.getWidth()-20), 213 | love.math.random(20,love.graphics.getHeight()-20)) 214 | end 215 | for i = 1, #units do 216 | units[i]:fixCollidedXY() 217 | end 218 | end 219 | 220 | function love.draw() 221 | for i = 1, #units do 222 | units[i]:draw() 223 | end 224 | end 225 | 226 | function love.update(dt) 227 | for i = 1, #units do 228 | units[i]:update(dt) 229 | end 230 | if love.keyboard.isDown("escape") then 231 | love.event.quit() 232 | end 233 | end 234 | -------------------------------------------------------------------------------- /OOP/oop lessons 2-3/main.lua: -------------------------------------------------------------------------------- 1 | class = require "lib.middleclass" 2 | 3 | Unit = class("Unit") 4 | 5 | function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2) 6 | return x1 < x2+w2 and 7 | x2 < x1+w1 and 8 | y1 < y2+h2 and 9 | y2 < y1+h1 10 | end 11 | 12 | function CheckLinearCollision(y1,h1, y2,h2) 13 | return y1 < y2+h2 and 14 | y2 < y1+h1 15 | end 16 | 17 | function Unit:initialize(name, x, y) 18 | self.name = name 19 | self.x = x 20 | self.y = y 21 | self.r = love.math.random(10, 20) 22 | self.color = {love.math.random(1, 255), 23 | love.math.random(1, 255), 24 | love.math.random(1, 255), 50 25 | } 26 | end 27 | 28 | -- возвращ true если Unit на экране и не касается границ экрана 29 | function Unit:isOnScreen() 30 | if self.x - self.r < 0 31 | or self.x + self.r > love.graphics.getWidth() 32 | or self.y - self.r < 0 33 | or self.y + self.r > love.graphics.getHeight() 34 | then 35 | return false 36 | else 37 | return true 38 | end 39 | end 40 | -- ИИ 41 | function Unit:update(dt) 42 | self.x = self.x + love.math.random(-100, 100) * dt 43 | self.y = self.y + love.math.random(-100, 100) * dt 44 | end 45 | 46 | function Unit:draw() 47 | love.graphics.setColor(unpack(self.color)) 48 | love.graphics.circle("fill", self.x, self.y, self.r) 49 | love.graphics.setColor(255,255,255) 50 | love.graphics.print(self.name, self.x, self.y) 51 | love.graphics.print("x:"..math.floor(self.x)..",y:"..math.floor(self.y), 52 | self.x - self.r, self.y + 10) 53 | end 54 | 55 | UnitDrop = class("UnitDrop", Unit) 56 | function UnitDrop:initialize(name, x, y) 57 | Unit.initialize(self, name, x, y) 58 | self.color = {love.math.random(155, 255), 59 | 0, 60 | 0, 61 | 255 62 | } 63 | end 64 | -- ИИ 65 | function UnitDrop:update(dt) 66 | if self.y < love.graphics.getHeight() - self.r * 2 then 67 | self.y = self.y + 100 * dt 68 | end 69 | end 70 | 71 | UnitPong = class("UnitPong", Unit) 72 | function UnitPong:initialize(name, x, y) 73 | Unit.initialize(self, name, x, y) 74 | self.color = {0, 75 | 0, 76 | love.math.random(155, 255), 77 | 255 78 | } 79 | if love.math.random() < 0.5 then 80 | self.speedx = 0 81 | self.speedy = 80 82 | else 83 | self.speedx = 80 84 | if love.math.random() < 0.5 then 85 | self.speedy = 0 86 | else 87 | self.speedy = 80 88 | end 89 | end 90 | end 91 | -- ИИ 92 | function UnitPong:update(dt) 93 | local oldx, oldy = self.x, self.y 94 | self.x = self.x + self.speedx * dt 95 | if not self:isOnScreen() then 96 | self.x = oldx 97 | self.speedx = -self.speedx 98 | end 99 | self.y = self.y + self.speedy * dt 100 | if not self:isOnScreen() then 101 | self.y = oldy 102 | self.speedy = -self.speedy 103 | end 104 | end 105 | 106 | Player = class("Player", Unit) 107 | function Player:initialize(name, x, y, keys) 108 | Unit.initialize(self, name, x, y) 109 | self.color = {0, 110 | love.math.random(155, 255), 111 | 0, 112 | 255 113 | } 114 | self.speed = 100 115 | self.keys = keys or {left = "a", right = "d", up = "w", down = "s"} 116 | end 117 | 118 | function Player:control(dt) 119 | local oldx, oldy = self.x, self.y 120 | local sx, sy = 0, 0 121 | if love.keyboard.isDown(self.keys.left) and 122 | self.x > 0 + self.r then 123 | sx = -self.speed * dt 124 | elseif love.keyboard.isDown(self.keys.right) and 125 | self.x < love.graphics.getWidth() - self.r then 126 | sx = self.speed * dt 127 | end 128 | if love.keyboard.isDown(self.keys.up) and 129 | self.y > 0 + self.r then 130 | sy = -self.speed * dt 131 | elseif love.keyboard.isDown(self.keys.down) and 132 | self.y < love.graphics.getHeight() - self.r then 133 | sy = self.speed * dt 134 | end 135 | self.x = self.x + sx 136 | self.y = self.y + sy 137 | if self:collideWithAny() then 138 | self.x = oldx 139 | self.y = oldy 140 | end 141 | end 142 | 143 | --проверка столкновения текущего объекта с другим other 144 | function Player:collideWith(other) 145 | if self == other then 146 | return false 147 | end 148 | if math.sqrt((self.x - other.x)^2 + (self.y - other.y)^2) 149 | < self.r + other.r 150 | then 151 | return true 152 | else 153 | return false 154 | end 155 | end 156 | 157 | function Player:collideWithAny() 158 | for i = 1, #units do 159 | if self:collideWith(units[i]) then 160 | return true 161 | end 162 | end 163 | return false 164 | end 165 | 166 | function Player:update(dt) 167 | self:control(dt) 168 | end 169 | 170 | function love.load() 171 | units = {} 172 | for i = 1, 5 do 173 | units[#units + 1] = Unit:new("ball"..i, 174 | love.math.random(1,love.graphics.getWidth()), 175 | love.math.random(1,love.graphics.getHeight())) 176 | end 177 | for i = 1, 30 do 178 | units[#units + 1] = UnitDrop:new("Drop"..i, 179 | love.math.random(1,love.graphics.getWidth()), 180 | love.math.random(1,love.graphics.getHeight())) 181 | end 182 | units[#units + 1] = Player:new("IGROK", 183 | love.graphics.getWidth() / 2, 184 | love.graphics.getHeight() / 2) 185 | units[#units + 1] = Player:new("IGROK2", 186 | love.graphics.getWidth() / 2 + 100, 187 | love.graphics.getHeight() / 2, 188 | {left = "left", right = "right", up = "up", down = "down"}) 189 | for i = 1, 10 do 190 | units[#units + 1] = UnitPong:new("Drop"..i, 191 | love.math.random(1,love.graphics.getWidth()), 192 | love.math.random(1,love.graphics.getHeight())) 193 | end 194 | end 195 | 196 | function love.draw() 197 | for i = 1, #units do 198 | units[i]:draw() 199 | end 200 | end 201 | 202 | function love.update(dt) 203 | for i = 1, #units do 204 | units[i]:update(dt) 205 | end 206 | if love.keyboard.isDown("escape") then 207 | love.event.quit() 208 | end 209 | end 210 | -------------------------------------------------------------------------------- /OOP/oop middleclass/metamethods.lua: -------------------------------------------------------------------------------- 1 | local class = require 'middleclass' 2 | 3 | Point = class('Point') 4 | function Point:initialize(x,y) 5 | self.x = x 6 | self.y = y 7 | end 8 | function Point:__tostring() 9 | return 'Point: [' .. tostring(self.x) .. ', ' .. tostring(self.y) .. ']' 10 | end 11 | 12 | p1 = Point(100, 200) 13 | p2 = Point(35, -10) 14 | print(p1) 15 | print(p2) -------------------------------------------------------------------------------- /OOP/oop middleclass/middleclass.lua: -------------------------------------------------------------------------------- 1 | local middleclass = { 2 | _VERSION = 'middleclass v4.1.1', 3 | _DESCRIPTION = 'Object Orientation for Lua', 4 | _URL = 'https://github.com/kikito/middleclass', 5 | _LICENSE = [[ 6 | MIT LICENSE 7 | 8 | Copyright (c) 2011 Enrique García Cota 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a 11 | copy of this software and associated documentation files (the 12 | "Software"), to deal in the Software without restriction, including 13 | without limitation the rights to use, copy, modify, merge, publish, 14 | distribute, sublicense, and/or sell copies of the Software, and to 15 | permit persons to whom the Software is furnished to do so, subject to 16 | the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included 19 | in all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 25 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 26 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | ]] 29 | } 30 | 31 | local function _createIndexWrapper(aClass, f) 32 | if f == nil then 33 | return aClass.__instanceDict 34 | else 35 | return function(self, name) 36 | local value = aClass.__instanceDict[name] 37 | 38 | if value ~= nil then 39 | return value 40 | elseif type(f) == "function" then 41 | return (f(self, name)) 42 | else 43 | return f[name] 44 | end 45 | end 46 | end 47 | end 48 | 49 | local function _propagateInstanceMethod(aClass, name, f) 50 | f = name == "__index" and _createIndexWrapper(aClass, f) or f 51 | aClass.__instanceDict[name] = f 52 | 53 | for subclass in pairs(aClass.subclasses) do 54 | if rawget(subclass.__declaredMethods, name) == nil then 55 | _propagateInstanceMethod(subclass, name, f) 56 | end 57 | end 58 | end 59 | 60 | local function _declareInstanceMethod(aClass, name, f) 61 | aClass.__declaredMethods[name] = f 62 | 63 | if f == nil and aClass.super then 64 | f = aClass.super.__instanceDict[name] 65 | end 66 | 67 | _propagateInstanceMethod(aClass, name, f) 68 | end 69 | 70 | local function _tostring(self) return "class " .. self.name end 71 | local function _call(self, ...) return self:new(...) end 72 | 73 | local function _createClass(name, super) 74 | local dict = {} 75 | dict.__index = dict 76 | 77 | local aClass = { name = name, super = super, static = {}, 78 | __instanceDict = dict, __declaredMethods = {}, 79 | subclasses = setmetatable({}, {__mode='k'}) } 80 | 81 | if super then 82 | setmetatable(aClass.static, { 83 | __index = function(_,k) 84 | local result = rawget(dict,k) 85 | if result == nil then 86 | return super.static[k] 87 | end 88 | return result 89 | end 90 | }) 91 | else 92 | setmetatable(aClass.static, { __index = function(_,k) return rawget(dict,k) end }) 93 | end 94 | 95 | setmetatable(aClass, { __index = aClass.static, __tostring = _tostring, 96 | __call = _call, __newindex = _declareInstanceMethod }) 97 | 98 | return aClass 99 | end 100 | 101 | local function _includeMixin(aClass, mixin) 102 | assert(type(mixin) == 'table', "mixin must be a table") 103 | 104 | for name,method in pairs(mixin) do 105 | if name ~= "included" and name ~= "static" then aClass[name] = method end 106 | end 107 | 108 | for name,method in pairs(mixin.static or {}) do 109 | aClass.static[name] = method 110 | end 111 | 112 | if type(mixin.included)=="function" then mixin:included(aClass) end 113 | return aClass 114 | end 115 | 116 | local DefaultMixin = { 117 | __tostring = function(self) return "instance of " .. tostring(self.class) end, 118 | 119 | initialize = function(self, ...) end, 120 | 121 | isInstanceOf = function(self, aClass) 122 | return type(aClass) == 'table' 123 | and type(self) == 'table' 124 | and (self.class == aClass 125 | or type(self.class) == 'table' 126 | and type(self.class.isSubclassOf) == 'function' 127 | and self.class:isSubclassOf(aClass)) 128 | end, 129 | 130 | static = { 131 | allocate = function(self) 132 | assert(type(self) == 'table', "Make sure that you are using 'Class:allocate' instead of 'Class.allocate'") 133 | return setmetatable({ class = self }, self.__instanceDict) 134 | end, 135 | 136 | new = function(self, ...) 137 | assert(type(self) == 'table', "Make sure that you are using 'Class:new' instead of 'Class.new'") 138 | local instance = self:allocate() 139 | instance:initialize(...) 140 | return instance 141 | end, 142 | 143 | subclass = function(self, name) 144 | assert(type(self) == 'table', "Make sure that you are using 'Class:subclass' instead of 'Class.subclass'") 145 | assert(type(name) == "string", "You must provide a name(string) for your class") 146 | 147 | local subclass = _createClass(name, self) 148 | 149 | for methodName, f in pairs(self.__instanceDict) do 150 | _propagateInstanceMethod(subclass, methodName, f) 151 | end 152 | subclass.initialize = function(instance, ...) return self.initialize(instance, ...) end 153 | 154 | self.subclasses[subclass] = true 155 | self:subclassed(subclass) 156 | 157 | return subclass 158 | end, 159 | 160 | subclassed = function(self, other) end, 161 | 162 | isSubclassOf = function(self, other) 163 | return type(other) == 'table' and 164 | type(self.super) == 'table' and 165 | ( self.super == other or self.super:isSubclassOf(other) ) 166 | end, 167 | 168 | include = function(self, ...) 169 | assert(type(self) == 'table', "Make sure you that you are using 'Class:include' instead of 'Class.include'") 170 | for _,mixin in ipairs({...}) do _includeMixin(self, mixin) end 171 | return self 172 | end 173 | } 174 | } 175 | 176 | function middleclass.class(name, super) 177 | assert(type(name) == 'string', "A name (string) is needed for the new class") 178 | return super and super:subclass(name) or _includeMixin(_createClass(name), DefaultMixin) 179 | end 180 | 181 | setmetatable(middleclass, { __call = function(_, ...) return middleclass.class(...) end }) 182 | 183 | return middleclass 184 | -------------------------------------------------------------------------------- /OOP/oop middleclass/mixins1.lua: -------------------------------------------------------------------------------- 1 | local class = require 'middleclass' 2 | HasWings = { -- HasWings is a module, not a class. It can be "included" into classes 3 | fly = function(self) 4 | print('Бяк-бяк-бяк (машет крыльями) я ' .. self.class.name) 5 | end 6 | } 7 | 8 | Animal = class('Животное') 9 | 10 | Insect = class('Насекомое', Animal) -- or Animal:subclass('Insect') 11 | 12 | Worm = class('Червь', Insect) -- worms don't have wings 13 | 14 | Bee = class('Пчела', Insect) 15 | Bee:include(HasWings) --Bees have wings. This adds fly() to Bee 16 | 17 | Mammal = class('Млекопитающее', Animal) 18 | 19 | Fox = class('Лиса', Mammal) -- foxes don't have wings, but are mammals 20 | 21 | Bat = class('Летучая мышь', Mammal) 22 | Bat:include(HasWings) --Bats have wings, too. 23 | 24 | local bee = Bee() -- or Bee:new() 25 | local bat = Bat() -- or Bat:new() 26 | local fox = Fox() 27 | bee:fly() 28 | bat:fly() 29 | fox:fly() -------------------------------------------------------------------------------- /OOP/oop middleclass/mixins2included.lua: -------------------------------------------------------------------------------- 1 | local class = require 'middleclass' 2 | DrinksCoffee = {} 3 | 4 | -- This is another valid way of declaring functions on a mixin. 5 | -- Note that we are using the : operator, so there's an implicit self parameter 6 | function DrinksCoffee:drink(drinkTime) 7 | if(drinkTime~=self.class.coffeeTime) then 8 | print(self.name .. ': Сейчас не время пить кофе!') 9 | else 10 | print(self.name .. ': Ммм, обожаю пить кофе в ' .. drinkTime) 11 | end 12 | end 13 | 14 | -- the included method is invoked every time DrinksCoffee is included on a class 15 | -- notice that paramters can be passed around 16 | function DrinksCoffee:included(klass) 17 | print(klass.name .. ' пьёт кофе в ' .. klass.coffeeTime) 18 | end 19 | 20 | EnglishMan = class('Англичанин') 21 | EnglishMan.static.coffeeTime = 5 22 | EnglishMan:include(DrinksCoffee) 23 | function EnglishMan:initialize(name) self.name = name end 24 | 25 | Spaniard = class('Испанец') 26 | Spaniard.static.coffeeTime = 6 27 | Spaniard:include(DrinksCoffee) 28 | function Spaniard:initialize(name) self.name = name end 29 | 30 | tom = EnglishMan:new('Том') 31 | juan = Spaniard:new('Гуан') 32 | 33 | tom:drink(5) 34 | juan:drink(5) 35 | juan:drink(6) -------------------------------------------------------------------------------- /OOP/oop middleclass/quick look.lua: -------------------------------------------------------------------------------- 1 | local class = require 'middleclass' 2 | 3 | Person = class('Person') --this is the same as class('Person', Object) or Object:subclass('Person') 4 | function Person:initialize(name) 5 | self.name = name 6 | end 7 | function Person:speak() 8 | print('Привет, я ' .. self.name ..'.') 9 | end 10 | 11 | AgedPerson = class('AgedPerson', Person) -- or Person:subclass('AgedPerson') 12 | AgedPerson.static.ADULT_AGE = 18 --this is a class variable 13 | function AgedPerson:initialize(name, age) 14 | Person.initialize(self, name) -- this calls the parent's constructor (Person.initialize) on self 15 | self.age = age 16 | end 17 | function AgedPerson:speak() 18 | Person.speak(self) -- prints "Привет, я xx." 19 | if(self.age < AgedPerson.ADULT_AGE) then --accessing a class variable from an instance method 20 | print('Я несовершеннолетний.') 21 | else 22 | print('Я уже взрослый.') 23 | end 24 | end 25 | 26 | local p1 = AgedPerson:new('Гриша хулиган', 13) -- this is equivalent to AgedPerson('Гриша хулиган', 13) - the :new part is implicit 27 | local p2 = AgedPerson:new('Люк Скайуокер', 21) 28 | p1:speak() 29 | p2:speak() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lua-lessons-ru 2 | Исходные тексты видео курса "Уроки #Roblox, #Love2D и #Lua" 3 | 4 | https://www.youtube.com/channel/UCrwjc6vNx-QSEe00QsU1-xg 5 | 6 | Материалы для уроков: 7 | 8 | Самое свежее по Роблокс API https://developer.roblox.com/ 9 | 10 | Библиотека проверки столкновений bump от kikito https://github.com/kikito/bump.lua 11 | 12 | Библиотека anim8 от kikito https://github.com/kikito/anim8 13 | 14 | Библиотека easing tween от kikito https://github.com/kikito/tween.lua 15 | 16 | ООП для Lua от kikito https://github.com/kikito/middleclass 17 | 18 | Рекомендую: 19 | 20 | Бесплатный графический редактор Paint.Net https://www.getpaint.net/ 21 | 22 | Бесплатный редактор спрайтов и анимации GraphicsGALE https://graphicsgale.com/us/ 23 | 24 | Бесплатный редактор спрайтов и анимации https://www.aseprite.org/ 25 | 26 | Бесплатная IDE с отладчиком для разработки https://studio.zerobrane.com/ (автору можно задонейтить деньги, он молодец) 27 | 28 | Фреймворк Love2D можно скачать здесь https://love2d.org/ там же вы найдете главный форум с примерами и ответами на вопросы. 29 | 30 | Краткий API по функциям Love2D http://love2d-community.github.io/love-api/#callbacks 31 | -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/1min guide RunService.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/1min guide RunService.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/1min guide Trails and Beams.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/1min guide Trails and Beams.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/1min guide switch light button door.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/1min guide switch light button door.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/3lightsBaseplate.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/3lightsBaseplate.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/3lightsBaseplate2.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/3lightsBaseplate2.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/BindableEvents.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/BindableEvents.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/Lesson Roblox API spawn.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/Lesson Roblox API spawn.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/Place1with3Spawns.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/Place1with3Spawns.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/Tiny Question 1 2 parts touch Unanchored Baseplate.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/Tiny Question 1 2 parts touch Unanchored Baseplate.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/clickDet.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/clickDet.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/contectActionServics 3.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/contectActionServics 3.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/contectActionServics.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/contectActionServics.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/debris roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/debris roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/for loop pairs ipairs.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/for loop pairs ipairs.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/gameAAAstart.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/gameAAAstart.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/houseDaySunMoonVillage.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/houseDaySunMoonVillage.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/howTo Move Car.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/howTo Move Car.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/less6 soccer Baseplate.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/less6 soccer Baseplate.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 0 pathfinding moving between points.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 0 pathfinding moving between points.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 1 DataStore2 installation Roblox.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 1 DataStore2 installation Roblox.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 1 Roblox accessory.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 1 Roblox accessory.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 1 Roblox leaderboard.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 1 Roblox leaderboard.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 1 Roblox sound music.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 1 Roblox sound music.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 1 anti-exploit Roblox.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 1 anti-exploit Roblox.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 1 pathfinding.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 1 pathfinding.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 1-2 Roblox RemoteFunction.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 1-2 Roblox RemoteFunction.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 16 magnitude roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 16 magnitude roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 2 DataStore2 Roblox.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 2 DataStore2 Roblox.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 2 Roblox sound music.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 2 Roblox sound music.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 2 part flags remoteEvents.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 2 part flags remoteEvents.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 3 Roblox RemoteFunction.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 3 Roblox RemoteFunction.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 3 Roblox sound music.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 3 Roblox sound music.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 4 Roblox RemoteFunction on Client.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 4 Roblox RemoteFunction on Client.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 4 Roblox sound music.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 4 Roblox sound music.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 5 roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 5 roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 6 roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 6 roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 8 roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 8 roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson 9 roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson 9 roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson D1 efrect off.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson D1 efrect off.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson Donate Attach Part To Head roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson Donate Attach Part To Head roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson T3 Save player data.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson T3 Save player data.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson T4 Roblox Lua Libraries.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson T4 Roblox Lua Libraries.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson T6 Roblox DataTypes Enums.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson T6 Roblox DataTypes Enums.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson dialog.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson dialog.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson random stuff.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson random stuff.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson seat 1 Roblox.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson seat 1 Roblox.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson13 remoteFunc.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson13 remoteFunc.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lesson4 killblocks.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lesson4 killblocks.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/lsBaseplate.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/lsBaseplate.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/modules lesson.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/modules lesson.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/most rotate roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/most rotate roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/movingPanel.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/movingPanel.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/movingPlatform.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/movingPlatform.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/newLighting.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/newLighting.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/pyramPlace1.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/pyramPlace1.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/r3 Baseplate.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/r3 Baseplate.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/rays rays everywhere remoteEvent.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/rays rays everywhere remoteEvent.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/rotating fan under ceiling.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/rotating fan under ceiling.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/soccerBaseplate.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/soccerBaseplate.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/streetsLightVars Baseplate.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/streetsLightVars Baseplate.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/t1 lesson Baseplate.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/t1 lesson Baseplate.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/userinputservice mouse lessons 1-2.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/userinputservice mouse lessons 1-2.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/vid less tables Baseplate.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/vid less tables Baseplate.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/vlesson 2.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/vlesson 2.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/vlesson 4.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/vlesson 4.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/vlesson12.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/vlesson12.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/vlesson8 clone serverstorage Baseplate.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/vlesson8 clone serverstorage Baseplate.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2020 lessons/wedge hinge motor.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2020 lessons/wedge hinge motor.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2021 lessons/2021 1 начинающим Все виды кнопок и условия.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2021 lessons/2021 1 начинающим Все виды кнопок и условия.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2021 lessons/2021 Урок 1 Advanced Atributes.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2021 lessons/2021 Урок 1 Advanced Atributes.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2021 lessons/GetChildren IsA GetPartBoundsInRadius.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2021 lessons/GetChildren IsA GetPartBoundsInRadius.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2021 lessons/Делаем игру 1 Кролики Лисы и Капуста.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2021 lessons/Делаем игру 1 Кролики Лисы и Капуста.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2021 lessons/Делаем игру 1.5 Кролики Лисы и Капуста.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2021 lessons/Делаем игру 1.5 Кролики Лисы и Капуста.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2021 lessons/Делаем игру 2 Кролики Лисы и Капуста.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2021 lessons/Делаем игру 2 Кролики Лисы и Капуста.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2021 lessons/Делаем игру 2.1 Кролики Лисы и Капуста.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2021 lessons/Делаем игру 2.1 Кролики Лисы и Капуста.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2021 lessons/Потоки 1 функция SPAWN.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2021 lessons/Потоки 1 функция SPAWN.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/2021 lessons/Потоки 2 функция DELAY и генератор домов.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/2021 lessons/Потоки 2 функция DELAY и генератор домов.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/animation/1min guide Animate NPC.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/animation/1min guide Animate NPC.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/animation/1min guide Animate Player.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/animation/1min guide Animate Player.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/camera/camera 1.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/camera/camera 1.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/debugger/lesson T5 Roblox Lua Debugging.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/debugger/lesson T5 Roblox Lua Debugging.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/teams/teams 1 roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/teams/teams 1 roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/teams/teams 2 roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/teams/teams 2 roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/teams/teams 3 roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/teams/teams 3 roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/teams/teams 4 roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/teams/teams 4 roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/teams/teams roblox school 2020.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/teams/teams roblox school 2020.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/teleport/Lesson1 TeleportService 2nd place.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/teleport/Lesson1 TeleportService 2nd place.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/teleport/Lesson1 TeleportService.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/teleport/Lesson1 TeleportService.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/teleport/MainPlaceFromWhichWeTeleportToAnotherWith3Spawns.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/teleport/MainPlaceFromWhichWeTeleportToAnotherWith3Spawns.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/tools/Dispoisable Tool.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/tools/Dispoisable Tool.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/tools/idCardToolPassword 4stream.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/tools/idCardToolPassword 4stream.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/tools/idCardToolPassword.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/tools/idCardToolPassword.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/tools/tools Mouse click Jumper and Lighter.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/tools/tools Mouse click Jumper and Lighter.rbxl -------------------------------------------------------------------------------- /ROBLOX STUDIO/tools/tools test vl2.rbxl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/ROBLOX STUDIO/tools/tools test vl2.rbxl -------------------------------------------------------------------------------- /Sprites/sprites lesson 1/main.lua: -------------------------------------------------------------------------------- 1 | -- Про загрузку картинок и спрайты 2 | -- УРОК 1 3 | 4 | function love.load() 5 | spr = { 6 | love.graphics.newImage( "res/shipUp.png" ), 7 | love.graphics.newImage( "res/shipUpFire.png" ) 8 | } 9 | 10 | rotate = {} 11 | rotate[1] = 0 12 | rotate[2] = math.pi / 2 13 | rotate[3] = math.pi 14 | rotate[4] = -math.pi / 2 15 | 16 | x, y = 200, 100 17 | speed = 30 18 | speed2 = 10 19 | vpravo = false 20 | frame = 1 21 | slow = 0 22 | MYRG = 0.1 23 | rot = 1 24 | slowRot = 0 25 | MAX_ROT = 0.8 26 | end 27 | 28 | function love.draw() 29 | love.graphics.clear( 0, 0, 130 ) 30 | if vpravo then 31 | love.graphics.draw( spr[frame], x, y, rotate[rot] + math.pi / 2, nil, nil, 32, 32 ) 32 | else 33 | love.graphics.draw( spr[frame], x, y, rotate[rot], nil, nil, 32, 32 ) 34 | end 35 | end 36 | 37 | function love.update(dt) 38 | x = x + speed * dt 39 | y = y + speed2 * dt 40 | vpravo = love.mouse.isDown( 2 ) 41 | slow = slow + dt 42 | if slow > MYRG then 43 | slow = 0 44 | frame = frame + 1 45 | if frame > #spr then 46 | frame = 1 47 | end 48 | end 49 | 50 | slowRot = slowRot + dt 51 | if slowRot > MAX_ROT then 52 | slowRot = 0 53 | 54 | rot = rot + 1 55 | if rot > #rotate then 56 | rot = 1 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 1/res/shipUp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 1/res/shipUp.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 1/res/shipUpFire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 1/res/shipUpFire.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 1/res/spr1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 1/res/spr1.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 2/main.lua: -------------------------------------------------------------------------------- 1 | -- Про загрузку картинок и спрайты (дополнение) 2 | -- УРОК 3 3 | 4 | function love.load() 5 | spr = love.graphics.newImage( "res/spr0.png" ) 6 | 7 | spr1 = love.graphics.newImage( "res/spr1.png" ) 8 | quad1 = love.graphics.newQuad( 93, 96, 100, 98, spr1:getDimensions() ) 9 | 10 | font = love.graphics.newFont( 64 ) 11 | txtSpr = love.graphics.newText( font, "GAME OVER" ) 12 | x, y = 400, 300 13 | ugol = 0 14 | scale_x, scale_y = 2, 2 15 | origin_x, origin_y = 32, 32 16 | end 17 | 18 | function love.draw() 19 | love.graphics.clear( 50, 50, 50 ) -- Love2D 10.2 20 | love.graphics.setColor( 50, 50, 50, 127 ) -- Red, Green, Blue, Alpha 21 | love.graphics.draw( spr, x + 24, y + 24, ugol, scale_x, scale_y, origin_x, origin_y ) 22 | love.graphics.setColor( 255, 255, 255 ) -- Red, Green, Blue, Alpha 23 | love.graphics.draw( spr, x, y, ugol, scale_x, scale_y, origin_x, origin_y, -0.1, 0.3 ) 24 | love.graphics.draw( txtSpr, 0, 0 ) 25 | love.graphics.draw( spr1, quad1, 50, 70, 1) 26 | end 27 | 28 | function love.update(dt) 29 | 30 | end 31 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 2/res/shipUp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 2/res/shipUp.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 2/res/shipUpFire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 2/res/shipUpFire.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 2/res/spr0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 2/res/spr0.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 2/res/spr1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 2/res/spr1.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 3/lq.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | https://www.github.com/25a0/Quadtastic 3 | 4 | Copyright (c) 2017-2018 Moritz Neikes 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | ]] 24 | 25 | 26 | 27 | -- -------------------------------------------------------------------------- -- 28 | -- MORE DOCUMENTATION IS AVAILABLE ON https://github.com/25a0/Quadtastic -- 29 | -- -------------------------------------------------------------------------- -- 30 | 31 | local libquadtastic = {} 32 | 33 | -- Decides whether the given value is a valid quad. 34 | function libquadtastic.is_quad(quad) 35 | return type(quad) == "table" and quad.x and type(quad.x) == "number" and 36 | quad.y and type(quad.y) == "number" and 37 | quad.w and type(quad.w) == "number" and 38 | quad.h and type(quad.h) == "number" 39 | end 40 | 41 | function libquadtastic.get_metainfo(table) 42 | return table["_META"] or {} 43 | end 44 | 45 | -- Creates LOVE quads from the raw quads that are defined in the given table. 46 | -- width and height are the dimensions of the spritesheet for which the quads 47 | -- are defined. 48 | -- Returns a new table that is structured equally to the input table, but 49 | -- contains Quad objects instead of the raw quads. 50 | function libquadtastic.create_quads(table, width, height) 51 | local t = {} 52 | for k,v in pairs(table) do 53 | if libquadtastic.is_quad(v) then 54 | t[k] = love.graphics.newQuad(v.x, v.y, v.w, v.h, width, height) 55 | elseif type(v) == "table" then 56 | -- Recursively add the quads stored in this table 57 | t[k] = libquadtastic.create_quads(v, width, height) 58 | end 59 | end 60 | return t 61 | end 62 | 63 | -- Creates a color palette from the quads that are defined in the given table. 64 | -- Returns a new table which contains the RGBA value of the center of 65 | -- each defined quad in the input table. 66 | -- The defined colors are stored as a table, containing the R, G, B and A 67 | -- component of the color at index 1 through 4. Furthermore, each color is 68 | -- "callable", which makes it easier to change the alpha value on the fly. 69 | function libquadtastic.create_palette(table, image) 70 | 71 | local function create_palette(tab, imagedata) 72 | 73 | if libquadtastic.is_quad(tab) then 74 | -- Grab the pixel color of the quad's center 75 | local color = {imagedata:getPixel(tab.x + math.floor(tab.w/2), 76 | tab.y + math.floor(tab.h/2))} 77 | -- Make the table callable to easily modify the alpha value 78 | setmetatable(color, { 79 | __call = function(t, alpha) 80 | return {t[1], t[2], t[3], alpha or t[4]} 81 | end, 82 | }) 83 | return color 84 | 85 | elseif type(tab) == "table" then 86 | local palette = {} 87 | for k,v in pairs(tab) do 88 | -- Recursively add the quads stored in this table 89 | palette[k] = create_palette(v, imagedata) 90 | end 91 | return palette 92 | 93 | end 94 | end 95 | 96 | local imagedata 97 | 98 | if image:isCompressed() then 99 | error("Cannot currently handle compressed images") 100 | else 101 | imagedata = image:getData() 102 | end 103 | 104 | return create_palette(table, imagedata) 105 | end 106 | 107 | return libquadtastic -------------------------------------------------------------------------------- /Sprites/sprites lesson 3/main.lua: -------------------------------------------------------------------------------- 1 | -- Про загрузку картинок и спрайты (дополнение) 2 | -- УРОК 3 3 | 4 | function love.load() 5 | spr = love.graphics.newImage( "res/spr0.png" ) 6 | 7 | spr1 = love.graphics.newImage( "res/spr1.png" ) 8 | quad1 = love.graphics.newQuad( 93, 96, 100, 98, spr1:getDimensions() ) 9 | 10 | font = love.graphics.newFont( 64 ) 11 | txtSpr = love.graphics.newText( font, "GAME OVER" ) 12 | x, y = 400, 300 13 | ugol = 0 14 | scale_x, scale_y = 2, 2 15 | origin_x, origin_y = 32, 32 16 | end 17 | 18 | function love.draw() 19 | love.graphics.clear( 50, 50, 50 ) -- Love2D 10.2 20 | love.graphics.setColor( 50, 50, 50, 127 ) -- Red, Green, Blue, Alpha 21 | love.graphics.draw( spr, x + 24, y + 24, ugol, scale_x, scale_y, origin_x, origin_y ) 22 | love.graphics.setColor( 255, 255, 255 ) -- Red, Green, Blue, Alpha 23 | love.graphics.draw( spr, x, y, ugol, scale_x, scale_y, origin_x, origin_y, -0.1, 0.3 ) 24 | love.graphics.draw( txtSpr, 0, 0 ) 25 | love.graphics.draw( spr1, quad1, 50, 70, 1) 26 | end 27 | 28 | function love.update(dt) 29 | 30 | end 31 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 3/res/hero.lua: -------------------------------------------------------------------------------- 1 | return { 2 | _META = { 3 | image_path = "./spr3.png", 4 | version = "v0.6.5", 5 | }, 6 | vniz = { 7 | {x = 491, y = 406, w = 59, h = 69}, 8 | {x = 571, y = 406, w = 59, h = 69}, 9 | {x = 651, y = 405, w = 59, h = 70}, 10 | {x = 731, y = 406, w = 59, h = 70}, 11 | {x = 811, y = 406, w = 59, h = 69}, 12 | {x = 891, y = 405, w = 59, h = 70}, 13 | }, 14 | vpravo = { 15 | {x = 11, y = 6, w = 59, h = 68}, 16 | {x = 91, y = 4, w = 59, h = 70}, 17 | {x = 171, y = 5, w = 59, h = 70}, 18 | {x = 251, y = 5, w = 59, h = 69}, 19 | {x = 332, y = 6, w = 58, h = 68}, 20 | {x = 412, y = 3, w = 58, h = 71}, 21 | {x = 491, y = 4, w = 59, h = 70}, 22 | {x = 572, y = 4, w = 59, h = 70}, 23 | {x = 652, y = 5, w = 59, h = 70}, 24 | }, 25 | vverh = { 26 | {x = 14, y = 403, w = 52, h = 72}, 27 | {x = 94, y = 404, w = 52, h = 71}, 28 | {x = 174, y = 403, w = 52, h = 72}, 29 | {x = 254, y = 403, w = 52, h = 72}, 30 | {x = 334, y = 404, w = 52, h = 71}, 31 | {x = 414, y = 403, w = 52, h = 72}, 32 | }, 33 | } 34 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 3/res/shipUp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 3/res/shipUp.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 3/res/shipUpFire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 3/res/shipUpFire.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 3/res/spr0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 3/res/spr0.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 3/res/spr1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 3/res/spr1.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 3/res/spr3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 3/res/spr3.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/anim8/MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Enrique García Cota 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/anim8/README.md: -------------------------------------------------------------------------------- 1 | anim8 2 | ===== 3 | 4 | Animation library for [LÖVE](http://love2d.org). 5 | 6 | [![Build Status](https://travis-ci.org/kikito/anim8.png?branch=master)](https://travis-ci.org/kikito/anim8) 7 | [![Coverage Status](https://coveralls.io/repos/github/kikito/anim8/badge.svg?branch=master)](https://coveralls.io/github/kikito/anim8?branch=master) 8 | 9 | In order to build animations more easily, anim8 divides the process in two steps: first you create a *grid*, which 10 | is capable of creating *frames* (Quads) easily and quickly. Then you use the grid to create one or more *animations*. 11 | 12 | LÖVE compatibility 13 | ================== 14 | 15 | Since anim8 uses LÖVE's graphical functions, and they change from version to version, you must choose 16 | the version of anim8 which is compatible with your LÖVE. 17 | 18 | * The current version of anim8 is v2.1. It is compatible with LÖVE 0.9.x and 0.10.x 19 | * The last version of anim8 compatible with LÖVE 0.8.x was [anim8 v2.0](https://github.com/kikito/anim8/tree/v2.0.0). 20 | 21 | Example 22 | ======= 23 | 24 | ``` 25 | local anim8 = require 'anim8' 26 | 27 | local image, animation 28 | 29 | function love.load() 30 | image = love.graphics.newImage('path/to/image.png') 31 | local g = anim8.newGrid(32, 32, image:getWidth(), image:getHeight()) 32 | animation = anim8.newAnimation(g('1-8',1), 0.1) 33 | end 34 | 35 | function love.update(dt) 36 | animation:update(dt) 37 | end 38 | 39 | function love.draw() 40 | animation:draw(image, 100, 200) 41 | end 42 | ``` 43 | 44 | You can see a more elaborated example in the [demo branch](https://github.com/kikito/anim8/tree/demo). 45 | 46 | That demo transforms this spritesheet: 47 | 48 | ![1945](http://kikito.github.io/anim8/1945.png) 49 | 50 | Into several animated objects: 51 | 52 | ![1945](http://kikito.github.io/anim8/anim8-demo.gif) 53 | 54 | 55 | Explanation 56 | =========== 57 | 58 | Grids 59 | ----- 60 | 61 | Grids have only one purpose: To build groups of quads of the same size as easily as possible. In order to do this, they need to know only 2 things: the size of each quad and the size of the image they will be applied to. Each size is a width and a height, and those are the first 4 parameters of @anim8.newGrid@. 62 | 63 | Grids are just a convenient way of getting frames from a sprite. Frames are assumed to be distributed in rows and columns. Frame 1,1 is the one in the first row, first column. 64 | 65 | This is how you create a grid: 66 | 67 | `anim8.newGrid(frameWidth, frameHeight, imageWidth, imageHeight, left, top, border)`: 68 | 69 | * `frameWidth` and `frameHeight` are the dimensions of the animation *frames* - each of the individual "sub-images" that compose the animation. They are usually the same size as your character (so if the character is 70 | 32x32 pixels, `frameWidth` is 32 and so is `frameHeight`) 71 | * `imageWidth` and `imageHeight` are the dimensions of the image where all the frames are. In LÖVE, they can be obtained by doing `image:getWidth()` and `image:getHeight()`. 72 | * `left` and `top` are optional, and both default to 0. They are "the left and top coordinates of the point in the image where you want to put the origin of coordinates of the grid". If all the frames in your grid are 73 | the same size, and the first one's top-left corner is 0,0, you probably won't need to use `left` or `top`. 74 | * `border` is also an optional value, and it also defaults to zero. What `border` does is allowing you to define "gaps" between your frames in the image. For example, imagine that you have frames of 32x32, but they 75 | have a 1-px border around each frame. So the first frame is not at 0,0, but at 1,1 (because of the border), the second one is at 1,33 (for the extra border) etc. You can take this into account and "skip" these borders. 76 | 77 | To see this a bit more graphically, here are what those values mean for the grid which contains the "submarine" frames in the demo: 78 | 79 | ![explanation](http://kikito.github.io/anim8/anim8-explanation.png) 80 | 81 | Grids only have one important method: `Grid:getFrames(...)`. 82 | 83 | `Grid:getFrames` accepts an arbitrary number of parameters. They can be either numbers or strings. 84 | 85 | * Each two numbers are interpreted as quad coordinates in the format `(column, row)`. This way, `grid:getFrames(3,4)` will return the frame in column 3, row 4 of the grid. There can be more than just two: `grid:getFrames(1,1, 1,2, 1,3)` will return the frames in {1,1}, {1,2} and {1,3} respectively. 86 | * Using numbers for long rows or columns is tedious - so grids also accept strings indicating range plus a row/column index. Diferentiating rows and columns is based on the order in which the range and index are provided. A row can be fetch by calling `grid:getFrames('range', rowNumber)` and a column by calling `grid:getFrames(columnNumber, 'range')`. The previous column of 3 elements, for example, can be also expressed like this: `grid:getFrames(1,'1-3')`. Again, there can be more than one string-index pair (`grid:getFrames(1,'1-3', '2-4',3)`) 87 | * It's also possible to combine both formats. For example: `grid:getFrames(1,4, 1,'1-3')` will get the frame in {1,4} plus the frames 1 to 3 in column 1 88 | 89 | But you will probably never use getFrames directly. You can use a grid as if it was a function, and getFrames will be called. In other words, given a grid called `g`, this: 90 | 91 | g:getFrames('2-8',1, 1,2) 92 | 93 | Is equivalent to this: 94 | 95 | g('2-8',1, 1,2) 96 | 97 | This is very convenient to use in animations. 98 | 99 | Let's consider the submarine in the previous example. It has 7 frames, arranged horizontally. 100 | 101 | If you make its grid start on its first frame (using `left` and `top`), you can get its frames like this: 102 | 103 | -- frame, image, offsets, border 104 | local gs = anim8.newGrid(32,98, 1024,768, 366,102, 1) 105 | 106 | local frames = gs('1-7',1) 107 | 108 | However that way you will get a submarine which "emerges", then "suddenly disappears", and emerges again. To make it look more natural, you must add some animation frames "backwards", to give the illusion 109 | of "submersion". Here's the complete list: 110 | 111 | local frames = gs('1-7',1, '6-2',1) 112 | 113 | 114 | 115 | Animations 116 | ---------- 117 | 118 | Animations are groups of frames that are interchanged every now and then. 119 | 120 | `local animation = anim8.newAnimation(frames, durations, onLoop)`: 121 | 122 | * `frames` is an array of frames (Quads in LÖVE argot). You could provide your own quad array if you wanted to, but using a grid to get them is very convenient. 123 | * `durations` is a number or a table. When it's a number, it represents the duration of all frames in the animation. When it's a table, it can represent different durations for different frames. You can specify durations for all frames individually, like this: `{0.1, 0.5, 0.1}` or you can specify durations for ranges of frames: `{['3-5']=0.2}`. 124 | * `onLoop` is an optional parameter which can be a function or a string representing one of the animation methods. It does nothing by default. If specified, it will be called every time an animation "loops". It will have two parameters: the animation instance, and how many loops have been elapsed. The most usual value (apart from none) is the 125 | string 'pauseAtEnd'. It will make the animation loop once and then pause and stop on the last frame. 126 | 127 | Animations have the following methods: 128 | 129 | `animation:update(dt)` 130 | 131 | Use this inside `love.update(dt)` so that your animation changes frames according to the time that has passed. 132 | 133 | `animation:draw(image, x,y, angle, sx, sy, ox, oy, kx, ky)` 134 | 135 | Draws the current frame in the specified coordinates with the right angle, scale, offset & shearing. These parameters work exactly the same way as in [love.graphics.draw](https://love2d.org/wiki/love.graphics.draw). 136 | The only difference is that they are properly recalculated when the animation is flipped horizontally, vertically or both. See `getFrameInfo` below for more details. 137 | 138 | `animation:gotoFrame(frame)` 139 | 140 | Moves the animation to a given frame (frames start counting in 1). 141 | 142 | `animation:pause()` 143 | 144 | Stops the animation from updating (@animation:update(dt)@ will have no effect) 145 | 146 | `animation:resume()` 147 | 148 | Unpauses an animation 149 | 150 | `animation:clone()` 151 | 152 | Creates a new animation identical to the current one. The only difference is that its internal counter is reset to 0 (it's on the first frame). 153 | 154 | `animation:flipH()` 155 | 156 | Flips an animation horizontally (left goes to right and viceversa). This means that the frames are simply drawn differently, nothing more. 157 | 158 | Note that this method does not create a new animation. If you want to create a new one, use the `clone` method. 159 | 160 | This method returns the animation, so you can do things like `local a = anim8.newAnimation(g(1,'1-10'), 0.1):flipH()` or `local b = a:clone():flipV()`. 161 | 162 | `animation:flipV()` 163 | 164 | Flips an animation vertically. The same rules that apply to `flipH` also apply here. 165 | 166 | `animation:pauseAtEnd()` 167 | 168 | Moves the animation to its last frame and then pauses it. 169 | 170 | `animation:pauseAtStart()` 171 | 172 | Moves the animation to its first frame and then pauses it. 173 | 174 | `animation:getDimensions()` 175 | 176 | Returns the width and height of the current frame of the animation. This method assumes the frames passed to the animation are all quads (like the ones 177 | created by a grid). 178 | 179 | `animation:getFrameInfo(x,y, r, sx, sy, ox, oy, kx, ky)` 180 | 181 | This functions returns the parameters that would be passed to `love.graphics.draw` when drawing this animation: 182 | `frame, x, y, r, sx, sy, ox, oy, kx, ky`. 183 | 184 | * `frame` is the currently active frame for the animation (usually a quad produced by a grid) 185 | * `x,y` are the same coordinates passed as parameter to `getFrame` (there are no changes) 186 | * `r` is the same angle passed to `getFrame`, with no changes unless it is `nil`, in which case it becomes 0. 187 | * `sx,sy` are the scale values, with their sign changed if the animation is flipped vertically or horizontally 188 | * `ox,oy` are the offset values, with the width or height properly substracted if the animation is flipped. 0 is used as a initial value for these calculations if nil was passed. 189 | * `kx,ky` are the shearing factors, changed depending on the flip status. 190 | 191 | The `getFrame` method can be used when working with [spriteBatches](https://love2d.org/wiki/SpriteBatch). Here's how it can be used for adding & setting the corresponding quad in a spritebatch: 192 | 193 | ``` lua 194 | local id = spriteBatch:add(animation:getFrameInfo(x,y,r,sx,sy,ox,oy,kx,ky)) 195 | 196 | ... 197 | 198 | spriteBatch:set(id, animation:getFrameInfo(x,y,r,sx,sy,ox,oy,kx,ky)) 199 | ``` 200 | 201 | You can see an example of this in the [spritebatch-demo branch](https://github.com/kikito/anim8/tree/spritebatch-demo). 202 | 203 | 204 | Installation 205 | ============ 206 | 207 | Just copy the anim8.lua file wherever you want it. Then require it wherever you need it: 208 | 209 | local anim8 = require 'anim8' 210 | 211 | Please make sure that you read the license, too (for your convenience it's included at the beginning of the anim8.lua file). 212 | 213 | Specs 214 | ===== 215 | 216 | This project uses [busted](http://olivinelabs.com/busted/) for its specs. If you want to run the specs, you will have to install it first. Then just execute the following from the root folder: 217 | 218 | busted 219 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/anim8/anim8.lua: -------------------------------------------------------------------------------- 1 | local anim8 = { 2 | _VERSION = 'anim8 v2.3.1', 3 | _DESCRIPTION = 'An animation library for LÖVE', 4 | _URL = 'https://github.com/kikito/anim8', 5 | _LICENSE = [[ 6 | MIT LICENSE 7 | 8 | Copyright (c) 2011 Enrique García Cota 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a 11 | copy of this software and associated documentation files (the 12 | "Software"), to deal in the Software without restriction, including 13 | without limitation the rights to use, copy, modify, merge, publish, 14 | distribute, sublicense, and/or sell copies of the Software, and to 15 | permit persons to whom the Software is furnished to do so, subject to 16 | the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included 19 | in all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 25 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 26 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | ]] 29 | } 30 | 31 | local Grid = {} 32 | 33 | local _frames = {} 34 | 35 | local function assertPositiveInteger(value, name) 36 | if type(value) ~= 'number' then error(("%s should be a number, was %q"):format(name, tostring(value))) end 37 | if value < 1 then error(("%s should be a positive number, was %d"):format(name, value)) end 38 | if value ~= math.floor(value) then error(("%s should be an integer, was %d"):format(name, value)) end 39 | end 40 | 41 | local function createFrame(self, x, y) 42 | local fw, fh = self.frameWidth, self.frameHeight 43 | return love.graphics.newQuad( 44 | self.left + (x-1) * fw + x * self.border, 45 | self.top + (y-1) * fh + y * self.border, 46 | fw, 47 | fh, 48 | self.imageWidth, 49 | self.imageHeight 50 | ) 51 | end 52 | 53 | local function getGridKey(...) 54 | return table.concat( {...} ,'-' ) 55 | end 56 | 57 | local function getOrCreateFrame(self, x, y) 58 | if x < 1 or x > self.width or y < 1 or y > self.height then 59 | error(("There is no frame for x=%d, y=%d"):format(x, y)) 60 | end 61 | local key = self._key 62 | _frames[key] = _frames[key] or {} 63 | _frames[key][x] = _frames[key][x] or {} 64 | _frames[key][x][y] = _frames[key][x][y] or createFrame(self, x, y) 65 | return _frames[key][x][y] 66 | end 67 | 68 | local function parseInterval(str) 69 | if type(str) == "number" then return str,str,1 end 70 | str = str:gsub('%s', '') -- remove spaces 71 | local min, max = str:match("^(%d+)-(%d+)$") 72 | assert(min and max, ("Could not parse interval from %q"):format(str)) 73 | min, max = tonumber(min), tonumber(max) 74 | local step = min <= max and 1 or -1 75 | return min, max, step 76 | end 77 | 78 | function Grid:getFrames(...) 79 | local result, args = {}, {...} 80 | local minx, maxx, stepx, miny, maxy, stepy 81 | 82 | for i=1, #args, 2 do 83 | minx, maxx, stepx = parseInterval(args[i]) 84 | miny, maxy, stepy = parseInterval(args[i+1]) 85 | for y = miny, maxy, stepy do 86 | for x = minx, maxx, stepx do 87 | result[#result+1] = getOrCreateFrame(self,x,y) 88 | end 89 | end 90 | end 91 | 92 | return result 93 | end 94 | 95 | local Gridmt = { 96 | __index = Grid, 97 | __call = Grid.getFrames 98 | } 99 | 100 | local function newGrid(frameWidth, frameHeight, imageWidth, imageHeight, left, top, border) 101 | assertPositiveInteger(frameWidth, "frameWidth") 102 | assertPositiveInteger(frameHeight, "frameHeight") 103 | assertPositiveInteger(imageWidth, "imageWidth") 104 | assertPositiveInteger(imageHeight, "imageHeight") 105 | 106 | left = left or 0 107 | top = top or 0 108 | border = border or 0 109 | 110 | local key = getGridKey(frameWidth, frameHeight, imageWidth, imageHeight, left, top, border) 111 | 112 | local grid = setmetatable( 113 | { frameWidth = frameWidth, 114 | frameHeight = frameHeight, 115 | imageWidth = imageWidth, 116 | imageHeight = imageHeight, 117 | left = left, 118 | top = top, 119 | border = border, 120 | width = math.floor(imageWidth/frameWidth), 121 | height = math.floor(imageHeight/frameHeight), 122 | _key = key 123 | }, 124 | Gridmt 125 | ) 126 | return grid 127 | end 128 | 129 | ----------------------------------------------------------- 130 | 131 | local Animation = {} 132 | 133 | local function cloneArray(arr) 134 | local result = {} 135 | for i=1,#arr do result[i] = arr[i] end 136 | return result 137 | end 138 | 139 | local function parseDurations(durations, frameCount) 140 | local result = {} 141 | if type(durations) == 'number' then 142 | for i=1,frameCount do result[i] = durations end 143 | else 144 | local min, max, step 145 | for key,duration in pairs(durations) do 146 | assert(type(duration) == 'number', "The value [" .. tostring(duration) .. "] should be a number") 147 | min, max, step = parseInterval(key) 148 | for i = min,max,step do result[i] = duration end 149 | end 150 | end 151 | 152 | if #result < frameCount then 153 | error("The durations table has length of " .. tostring(#result) .. ", but it should be >= " .. tostring(frameCount)) 154 | end 155 | 156 | return result 157 | end 158 | 159 | local function parseIntervals(durations) 160 | local result, time = {0},0 161 | for i=1,#durations do 162 | time = time + durations[i] 163 | result[i+1] = time 164 | end 165 | return result, time 166 | end 167 | 168 | local Animationmt = { __index = Animation } 169 | local nop = function() end 170 | 171 | local function newAnimation(frames, durations, onLoop) 172 | local td = type(durations); 173 | if (td ~= 'number' or durations <= 0) and td ~= 'table' then 174 | error("durations must be a positive number. Was " .. tostring(durations) ) 175 | end 176 | onLoop = onLoop or nop 177 | durations = parseDurations(durations, #frames) 178 | local intervals, totalDuration = parseIntervals(durations) 179 | return setmetatable({ 180 | frames = cloneArray(frames), 181 | durations = durations, 182 | intervals = intervals, 183 | totalDuration = totalDuration, 184 | onLoop = onLoop, 185 | timer = 0, 186 | position = 1, 187 | status = "playing", 188 | flippedH = false, 189 | flippedV = false 190 | }, 191 | Animationmt 192 | ) 193 | end 194 | 195 | function Animation:clone() 196 | local newAnim = newAnimation(self.frames, self.durations, self.onLoop) 197 | newAnim.flippedH, newAnim.flippedV = self.flippedH, self.flippedV 198 | return newAnim 199 | end 200 | 201 | function Animation:flipH() 202 | self.flippedH = not self.flippedH 203 | return self 204 | end 205 | 206 | function Animation:flipV() 207 | self.flippedV = not self.flippedV 208 | return self 209 | end 210 | 211 | local function seekFrameIndex(intervals, timer) 212 | local high, low, i = #intervals-1, 1, 1 213 | 214 | while(low <= high) do 215 | i = math.floor((low + high) / 2) 216 | if timer >= intervals[i+1] then low = i + 1 217 | elseif timer < intervals[i] then high = i - 1 218 | else 219 | return i 220 | end 221 | end 222 | 223 | return i 224 | end 225 | 226 | function Animation:update(dt) 227 | if self.status ~= "playing" then return end 228 | 229 | self.timer = self.timer + dt 230 | local loops = math.floor(self.timer / self.totalDuration) 231 | if loops ~= 0 then 232 | self.timer = self.timer - self.totalDuration * loops 233 | local f = type(self.onLoop) == 'function' and self.onLoop or self[self.onLoop] 234 | f(self, loops) 235 | end 236 | 237 | self.position = seekFrameIndex(self.intervals, self.timer) 238 | end 239 | 240 | function Animation:pause() 241 | self.status = "paused" 242 | end 243 | 244 | function Animation:gotoFrame(position) 245 | self.position = position 246 | self.timer = self.intervals[self.position] 247 | end 248 | 249 | function Animation:pauseAtEnd() 250 | self.position = #self.frames 251 | self.timer = self.totalDuration 252 | self:pause() 253 | end 254 | 255 | function Animation:pauseAtStart() 256 | self.position = 1 257 | self.timer = 0 258 | self:pause() 259 | end 260 | 261 | function Animation:resume() 262 | self.status = "playing" 263 | end 264 | 265 | function Animation:draw(image, x, y, r, sx, sy, ox, oy, kx, ky) 266 | love.graphics.draw(image, self:getFrameInfo(x, y, r, sx, sy, ox, oy, kx, ky)) 267 | end 268 | 269 | function Animation:getFrameInfo(x, y, r, sx, sy, ox, oy, kx, ky) 270 | local frame = self.frames[self.position] 271 | if self.flippedH or self.flippedV then 272 | r,sx,sy,ox,oy,kx,ky = r or 0, sx or 1, sy or 1, ox or 0, oy or 0, kx or 0, ky or 0 273 | local _,_,w,h = frame:getViewport() 274 | 275 | if self.flippedH then 276 | sx = sx * -1 277 | ox = w - ox 278 | kx = kx * -1 279 | ky = ky * -1 280 | end 281 | 282 | if self.flippedV then 283 | sy = sy * -1 284 | oy = h - oy 285 | kx = kx * -1 286 | ky = ky * -1 287 | end 288 | end 289 | return frame, x, y, r, sx, sy, ox, oy, kx, ky 290 | end 291 | 292 | function Animation:getDimensions() 293 | local _,_,w,h = self.frames[self.position]:getViewport() 294 | return w,h 295 | end 296 | 297 | ----------------------------------------------------------- 298 | 299 | anim8.newGrid = newGrid 300 | anim8.newAnimation = newAnimation 301 | 302 | return anim8 303 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/main.lua: -------------------------------------------------------------------------------- 1 | -- Библиотека анимации anim8 by kikito 2 | -- УРОК 4 3 | 4 | local anim8 = require 'anim8.anim8' 5 | local image, g32, animation 6 | local x, y = 100, 100 7 | local flashScreen = false 8 | local ugol = 0 9 | 10 | function triggerFlashScreen() 11 | flashScreen = not flashScreen 12 | end 13 | 14 | function stoppppAniiiiim(anim, n) 15 | --if n > 5 then 16 | anim:pause() 17 | --flashScreen = not flashScreen 18 | --end 19 | end 20 | 21 | function krest(x, y) 22 | love.graphics.setColor(255,0,0) 23 | love.graphics.line(x - 10,y, x + 10, y) 24 | love.graphics.line(x,y - 10, x, y + 10) 25 | end 26 | 27 | function love.load() 28 | image = love.graphics.newImage("res/1945.png") 29 | g65 = anim8.newGrid(65, 65, image:getWidth(), image:getHeight(), 267,399, 1) 30 | g32 = anim8.newGrid(32, 32, image:getWidth(), image:getHeight(), 3,3, 1) 31 | SAMOLET_5 = anim8.newAnimation(g32("1-8", 2), 0.1 ) 32 | animation = anim8.newAnimation(g65("1-3", 1), 0.2 ) 33 | animation2 = anim8.newAnimation(g32("8-1", 3, "1-8", 3), 0.1, 'pauseAtEnd') 34 | animation3 = anim8.newAnimation(g32("1-8", 1), 0.2 ) 35 | animation2:gotoFrame(3) 36 | animation3:gotoFrame(6) 37 | --animation3:pauseAtEnd() 38 | end 39 | 40 | function love.draw() 41 | if flashScreen then 42 | love.graphics.clear(55,0,0) 43 | else 44 | love.graphics.clear(0,0,0) 45 | end 46 | krest(x, y) 47 | love.graphics.setColor(255,255,255) 48 | animation:draw(image, x, y, ugol, 1, 1, 32, 32) 49 | animation2:draw(image, 32, 100, 0, 2, 2) 50 | animation3:draw(image, 64, 200, 0, 4, 4) 51 | end 52 | 53 | function love.update(dt) 54 | if love.keyboard.isDown("right") then 55 | if ugol < math.pi / 2 then 56 | ugol = ugol + 10 * dt 57 | elseif ugol > math.pi / 2 then 58 | ugol = ugol - 10 * dt 59 | end 60 | x = x + 100 * dt 61 | end 62 | if love.keyboard.isDown("left") then 63 | if ugol > -math.pi / 2 then 64 | ugol = ugol - 10 * dt 65 | end 66 | x = x - 100 * dt 67 | end 68 | 69 | if love.keyboard.isDown("up") then 70 | if ugol < 0 then 71 | ugol = ugol + 10 * dt 72 | end 73 | if ugol > 0 then 74 | ugol = ugol - 10 * dt 75 | end 76 | y = y - 100 * dt 77 | end 78 | if love.keyboard.isDown("down") then 79 | if ugol > math.pi then 80 | ugol = ugol - 10 * dt 81 | end 82 | if ugol < math.pi then 83 | ugol = ugol + 10 * dt 84 | end 85 | y = y + 100 * dt 86 | end 87 | 88 | animation:update(dt) 89 | animation2:update(dt) 90 | animation3:update(dt) 91 | end 92 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/res/1945.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 4/res/1945.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/res/hero.lua: -------------------------------------------------------------------------------- 1 | return { 2 | _META = { 3 | image_path = "./spr3.png", 4 | version = "v0.6.5", 5 | }, 6 | vniz = { 7 | {x = 491, y = 406, w = 59, h = 69}, 8 | {x = 571, y = 406, w = 59, h = 69}, 9 | {x = 651, y = 405, w = 59, h = 70}, 10 | {x = 731, y = 406, w = 59, h = 70}, 11 | {x = 811, y = 406, w = 59, h = 69}, 12 | {x = 891, y = 405, w = 59, h = 70}, 13 | }, 14 | vpravo = { 15 | {x = 11, y = 6, w = 59, h = 68}, 16 | {x = 91, y = 4, w = 59, h = 70}, 17 | {x = 171, y = 5, w = 59, h = 70}, 18 | {x = 251, y = 5, w = 59, h = 69}, 19 | {x = 332, y = 6, w = 58, h = 68}, 20 | {x = 412, y = 3, w = 58, h = 71}, 21 | {x = 491, y = 4, w = 59, h = 70}, 22 | {x = 572, y = 4, w = 59, h = 70}, 23 | {x = 652, y = 5, w = 59, h = 70}, 24 | }, 25 | vverh = { 26 | {x = 14, y = 403, w = 52, h = 72}, 27 | {x = 94, y = 404, w = 52, h = 71}, 28 | {x = 174, y = 403, w = 52, h = 72}, 29 | {x = 254, y = 403, w = 52, h = 72}, 30 | {x = 334, y = 404, w = 52, h = 71}, 31 | {x = 414, y = 403, w = 52, h = 72}, 32 | }, 33 | } 34 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/res/shipUp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 4/res/shipUp.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/res/shipUpFire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 4/res/shipUpFire.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/res/spr0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 4/res/spr0.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/res/spr1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 4/res/spr1.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 4/res/spr3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 4/res/spr3.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 5 aseprite/lib/cron.lua: -------------------------------------------------------------------------------- 1 | local cron = { 2 | __VERSION = 'cron.lua 2.0.0', 3 | __DESCRIPTION = 'Time-related functions for lua', 4 | __URL = 'https://github.com/kikito/cron.lua', 5 | __LICENSE = [[ 6 | Copyright (c) 2011 Enrique García Cota 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a 9 | copy of this software and associated documentation files (the 10 | "Software"), to deal in the Software without restriction, including 11 | without limitation the rights to use, copy, modify, merge, publish, 12 | distribute, sublicense, and/or sell copies of the Software, and to 13 | permit persons to whom the Software is furnished to do so, subject to 14 | the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included 17 | in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | ]] 27 | } 28 | 29 | -- Private functions 30 | 31 | local function isCallable(callback) 32 | local tc = type(callback) 33 | if tc == 'function' then return true end 34 | if tc == 'table' then 35 | local mt = getmetatable(callback) 36 | return type(mt) == 'table' and type(mt.__call) == 'function' 37 | end 38 | return false 39 | end 40 | 41 | local function checkPositiveInteger(name, value) 42 | if type(value) ~= "number" or value < 0 then 43 | error(name .. " must be a positive number") 44 | end 45 | end 46 | 47 | local Clock = {} 48 | local Clock_mt = {__index = Clock} 49 | 50 | local function newClock(time, callback, update, ...) 51 | checkPositiveInteger('time', time) 52 | assert(isCallable(callback), "callback must be a function") 53 | 54 | return setmetatable({ 55 | time = time, 56 | callback = callback, 57 | args = {...}, 58 | running = 0, 59 | update = update 60 | }, Clock_mt) 61 | end 62 | 63 | local function updateAfterClock(self, dt) -- returns true if expired 64 | checkPositiveInteger('dt', dt) 65 | 66 | if self.running >= self.time then return true end 67 | 68 | self.running = self.running + dt 69 | 70 | if self.running >= self.time then 71 | self.callback(unpack(self.args)) 72 | return true 73 | end 74 | return false 75 | end 76 | 77 | local function updateEveryClock(self, dt) 78 | checkPositiveInteger('dt', dt) 79 | 80 | self.running = self.running + dt 81 | 82 | while self.running >= self.time do 83 | self.callback(unpack(self.args)) 84 | self.running = self.running - self.time 85 | end 86 | return false 87 | end 88 | 89 | function Clock:reset(running) 90 | running = running or 0 91 | checkPositiveInteger('running', running) 92 | 93 | self.running = running 94 | end 95 | 96 | 97 | function cron.after(time, callback, ...) 98 | return newClock(time, callback, updateAfterClock, ...) 99 | end 100 | 101 | function cron.every(time, callback, ...) 102 | return newClock(time, callback, updateEveryClock, ...) 103 | end 104 | 105 | return cron 106 | 107 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 5 aseprite/main.lua: -------------------------------------------------------------------------------- 1 | -- Библиотека 'peachy' by Josh Perry 2 | -- (парсинг и анимация из редактора спрайтов aseprite) 3 | -- УРОК 5 4 | local peachy = require("peachy") 5 | function love.load() 6 | spriteSheetDude = love.graphics.newImage("res/spr/dude.png") 7 | man = peachy.new("res/spr/dude.json", spriteSheetDude, "stand") 8 | x = 150 9 | man:onLoop (function() 10 | x = x + 1 11 | end) 12 | end 13 | function love.draw() 14 | man:draw( x, 50, 0, 2, 2) 15 | end 16 | function love.update(dt) 17 | man:update(dt) 18 | end 19 | function love.keypressed(key) 20 | if key == "space" then 21 | man:setTag("run") 22 | end 23 | if key == "1" then 24 | man:togglePlay () 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 5 aseprite/peachy.lua: -------------------------------------------------------------------------------- 1 | --- A parser/renderer for Aseprite animations in L?VE. 2 | -- @classmod peachy 3 | 4 | local peachy = { 5 | _VERSION = "1.0.0-alpha", 6 | _DESCRIPTION = "A parser/renderer for Aseprite animations in L?VE.", 7 | _URL = "https://github.com/josh-perry/peachy", 8 | _LICENSE = [[ 9 | MIT License 10 | 11 | Copyright (c) 2018 Josh Perry 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in all 21 | copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 | SOFTWARE. 30 | ]] 31 | } 32 | 33 | local PATH = select('1', ...):match(".+%.") or "" 34 | local json = require(PATH.."/lib/json") 35 | local cron = require(PATH.."/lib/cron") 36 | 37 | peachy.__index = peachy 38 | 39 | --- Creates a new Peachy animation object. 40 | -- 41 | -- If imageData isn't specified then Peachy will attempt to load it using the 42 | -- filename from the JSON data. 43 | -- 44 | -- If no initial tag is set then the object will be paused (i.e. not displayed) with no tag. 45 | -- The animation will start playing immediately once created. 46 | -- 47 | -- @usage 48 | -- -- Load the image ourselves and set animation tag to "Spin". 49 | -- -- Will start playing immediately. 50 | -- spinner = peachy.new("spinner.json", love.graphics.newImage("spinner.png"), "Spin") 51 | -- 52 | -- @tparam string dataFile a path to an Aseprite JSON file. It is also possible to pass a predecoded table, 53 | -- which is useful for performance when creating large amounts of the same animation. 54 | -- @tparam Image imageData a L?VE image to animate. 55 | -- @tparam string initialTag the name of the animation tag to use initially. 56 | -- @return the new Peachy object. 57 | function peachy.new(dataFile, imageData, initialTag) 58 | assert(dataFile ~= nil, "No JSON data!") 59 | 60 | local self = setmetatable({}, peachy) 61 | 62 | -- check if datafile is a lua table (i.e. pre decoded) 63 | if type(dataFile) == 'table' then 64 | self._jsonData = dataFile 65 | else 66 | -- Read the data 67 | self._jsonData = json.decode(love.filesystem.read(dataFile)) 68 | end 69 | 70 | -- Load the image 71 | self.image = imageData or love.graphics.newImage(self._jsonData.meta.image) 72 | 73 | self:_checkImageSize() 74 | 75 | self:_initializeFrames() 76 | self:_initializeTags() 77 | 78 | self.paused = true 79 | 80 | self.tag = nil 81 | self.tagName = nil 82 | self.direction = nil 83 | 84 | if initialTag then 85 | self:setTag(initialTag) 86 | self.paused = false 87 | end 88 | 89 | return self 90 | end 91 | 92 | --- Switch to a different animation tag. 93 | -- In the case that we're attempting to switch to the animation currently playing, 94 | -- nothing will happen. 95 | -- 96 | -- @tparam string tag the animation tag name to switch to. 97 | function peachy:setTag(tag) 98 | assert(tag, "No animation tag specified!") 99 | assert(self.frameTags[tag], "Tag "..tag.." not found in frametags!") 100 | 101 | if self.tag == self.frameTags[tag] then 102 | return 103 | end 104 | 105 | self.tagName = tag 106 | self.tag = self.frameTags[self.tagName] 107 | self.frameIndex = nil 108 | self.direction = self.tag.direction 109 | 110 | if self.direction == "pingpong" then 111 | self.direction = "forward" 112 | end 113 | 114 | self:nextFrame() 115 | end 116 | 117 | --- Jump to a particular frame index (1-based indexes) in the current animation. 118 | -- 119 | -- Errors if the frame is outside the tag's frame range. 120 | -- 121 | -- @usage 122 | -- -- Go to the 4th frame 123 | -- sound:setFrame(4) 124 | -- 125 | -- @tparam number frame the frame index to jump to. 126 | function peachy:setFrame(frame) 127 | if frame < 1 or frame > #self.tag.frames then 128 | error("Frame "..frame.." is out of range of tag '"..self.tagName.."' (1.."..#self.tag.frames..")") 129 | end 130 | 131 | self.frameIndex = frame 132 | 133 | self.frame = self.tag.frames[self.frameIndex] 134 | self.frameTimer = cron.after(self.frame.duration, self.nextFrame, self) 135 | end 136 | 137 | --- Draw the animation's current frame in a specified location. 138 | -- @tparam number x the x position. 139 | -- @tparam number y the y position. 140 | -- @tparam number rot the rotation to draw at. 141 | -- @tparam number sx the x scaling. 142 | -- @tparam number sy the y scaling. 143 | -- @tparam number ox the origin offset x. 144 | -- @tparam number oy the origin offset y. 145 | function peachy:draw(x, y, rot, sx, sy, ox, oy) 146 | if not self.frame then 147 | return 148 | end 149 | 150 | love.graphics.draw(self.image, self.frame.quad, x, y, rot or 0, sx or 1, sy or 1, ox or 0, oy or 0) 151 | end 152 | 153 | --- Update the animation. 154 | -- @tparam number dt frame delta. Should be called from love.update and given the dt. 155 | function peachy:update(dt) 156 | assert(dt, "No dt passed into update!") 157 | 158 | if self.paused then 159 | return 160 | end 161 | 162 | -- If we're trying to play an animation and it's nil or hasn't been set up 163 | -- properly then error 164 | assert(self.tag, "No animation tag has been set!") 165 | assert(self.frameTimer, "Frame timer hasn't been initialized!") 166 | 167 | -- Update timer in milliseconds since that's how Aseprite stores durations 168 | self.frameTimer:update(dt * 1000) 169 | end 170 | 171 | --- Move to the next frame. 172 | -- Internal: unless you want to skip frames, this generally will not ever 173 | -- need to be called manually. 174 | function peachy:nextFrame() 175 | local forward = self.direction == "forward" 176 | 177 | if forward then 178 | self.frameIndex = (self.frameIndex or 0) + 1 179 | else 180 | self.frameIndex = (self.frameIndex or #self.tag.frames + 1) - 1 181 | end 182 | 183 | -- Looping 184 | if forward and self.frameIndex > #self.tag.frames then 185 | if self.tag.direction == "pingpong" then 186 | self:_pingpongBounce() 187 | else 188 | self.frameIndex = 1 189 | end 190 | self:call_onLoop() 191 | elseif not forward and self.frameIndex < 1 then 192 | if self.tag.direction == "pingpong" then 193 | self:_pingpongBounce() 194 | else 195 | self.frameIndex = #self.tag.frames 196 | self:call_onLoop() 197 | end 198 | end 199 | 200 | -- Get next frame 201 | self.frame = self.tag.frames[self.frameIndex] 202 | 203 | self.frameTimer = cron.after(self.frame.duration, self.nextFrame, self) 204 | end 205 | 206 | --- Check for callbacks 207 | function peachy:call_onLoop() 208 | if self.callback_onLoop then self.callback_onLoop(unpack(self.args_onLoop)) end 209 | end 210 | 211 | --- Pauses the animation. 212 | function peachy:pause() 213 | self.paused = true 214 | end 215 | 216 | --- Unpauses the animation. 217 | function peachy:play() 218 | self.paused = false 219 | end 220 | 221 | --- Stops the animation (pause it then return to first frame or last if specified) 222 | function peachy:stop(onLast) 223 | local index = 1 224 | self.paused = true 225 | if onLast then index = #self.tag.frames end 226 | self:setFrame(index) 227 | end 228 | 229 | --- Adds a callback function that will be called when the animation loops 230 | function peachy:onLoop(fn, ...) 231 | self.callback_onLoop = fn 232 | self.args_onLoop = {...} 233 | end 234 | 235 | --- Toggle between playing/paused. 236 | function peachy:togglePlay() 237 | if self.paused then 238 | self:play() 239 | else 240 | self:pause() 241 | end 242 | end 243 | 244 | --- Provides width stored in the metadata of a current frame 245 | function peachy:getWidth() 246 | return self._jsonData.frames[self.frameIndex].frame.w 247 | end 248 | 249 | --- Provides height stored in the metadata of a current frame 250 | function peachy:getHeight() 251 | return self._jsonData.frames[self.frameIndex].frame.h 252 | end 253 | 254 | --- Internal: handles the ping-pong animation type. 255 | -- 256 | -- Should only be called when we actually want to bounce. 257 | -- Swaps the direction. 258 | function peachy:_pingpongBounce() 259 | -- We need to increment/decrement frame index by 2 because 260 | -- at this point we've already gone to the next frame 261 | if self.direction == "forward" then 262 | self.direction = "reverse" 263 | self.frameIndex = self.frameIndex - 2 264 | else 265 | self.direction = "forward" 266 | self.frameIndex = self.frameIndex + 2 267 | end 268 | end 269 | 270 | --- Internal: loads all of the frames 271 | -- 272 | -- Loads quads and frame duration data from the JSON. 273 | -- 274 | -- Called from peachy.new 275 | function peachy:_initializeFrames() 276 | assert(self._jsonData ~= nil, "No JSON data!") 277 | assert(self._jsonData.meta ~= nil, "No metadata in JSON!") 278 | assert(self._jsonData.frames ~= nil, "No frame data in JSON!") 279 | 280 | -- Initialize all the quads 281 | self.frames = {} 282 | for _, frameData in ipairs(self._jsonData.frames) do 283 | local frame = {} 284 | 285 | local fd = frameData.frame 286 | frame.quad = love.graphics.newQuad(fd.x, fd.y, fd.w, fd.h, self._jsonData.meta.size.w, self._jsonData.meta.size.h) 287 | frame.duration = frameData.duration 288 | 289 | table.insert(self.frames, frame) 290 | end 291 | end 292 | 293 | --- Internal: loads all of the animation tags 294 | -- 295 | -- Called from peachy.new 296 | function peachy:_initializeTags() 297 | assert(self._jsonData ~= nil, "No JSON data!") 298 | assert(self._jsonData.meta ~= nil, "No metadata in JSON!") 299 | assert(self._jsonData.meta.frameTags ~= nil, "No frame tags in JSON! Make sure you exported them in Aseprite!") 300 | 301 | self.frameTags = {} 302 | 303 | for _, frameTag in ipairs(self._jsonData.meta.frameTags) do 304 | local ft = {} 305 | ft.direction = frameTag.direction 306 | ft.frames = {} 307 | 308 | for frame = frameTag.from + 1, frameTag.to + 1 do 309 | table.insert(ft.frames, self.frames[frame]) 310 | end 311 | 312 | self.frameTags[frameTag.name] = ft 313 | end 314 | end 315 | 316 | --- Internal: checks that the loaded image size matches the metadata 317 | -- 318 | -- Called from peachy.new 319 | function peachy:_checkImageSize() 320 | local imageWidth, imageHeight = self._jsonData.meta.size.w, self._jsonData.meta.size.h 321 | assert(imageWidth == self.image:getWidth(), "Image width metadata doesn't match actual width of file") 322 | assert(imageHeight == self.image:getHeight(), "Image height metadata doesn't match actual height of file") 323 | end 324 | 325 | return peachy 326 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 5 aseprite/res/spr/astst.json: -------------------------------------------------------------------------------- 1 | { "frames": [ 2 | { 3 | "filename": "astst 0.aseprite", 4 | "frame": { "x": 0, "y": 0, "w": 32, "h": 32 }, 5 | "rotated": false, 6 | "trimmed": false, 7 | "spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 }, 8 | "sourceSize": { "w": 32, "h": 32 }, 9 | "duration": 100 10 | }, 11 | { 12 | "filename": "astst 1.aseprite", 13 | "frame": { "x": 32, "y": 0, "w": 32, "h": 32 }, 14 | "rotated": false, 15 | "trimmed": false, 16 | "spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 }, 17 | "sourceSize": { "w": 32, "h": 32 }, 18 | "duration": 100 19 | }, 20 | { 21 | "filename": "astst 2.aseprite", 22 | "frame": { "x": 64, "y": 0, "w": 32, "h": 32 }, 23 | "rotated": false, 24 | "trimmed": false, 25 | "spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 }, 26 | "sourceSize": { "w": 32, "h": 32 }, 27 | "duration": 100 28 | } 29 | ], 30 | "meta": { 31 | "app": "http://www.aseprite.org/", 32 | "version": "1.2.9-x64", 33 | "image": "B:\\Projects\\lua-lessons-ru\\Sprites\\sprites lesson 5 aseprite\\res\\spr\\astst.png", 34 | "format": "RGBA8888", 35 | "size": { "w": 96, "h": 32 }, 36 | "scale": "1", 37 | "frameTags": [ 38 | { "name": "wiggle", "from": 0, "to": 2, "direction": "forward" } 39 | ], 40 | "layers": [ 41 | { "name": "Layer 1", "opacity": 255, "blendMode": "normal" } 42 | ], 43 | "slices": [ 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 5 aseprite/res/spr/astst.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 5 aseprite/res/spr/astst.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 5 aseprite/res/spr/dude.json: -------------------------------------------------------------------------------- 1 | { "frames": [ 2 | { 3 | "filename": "dude 0.aseprite", 4 | "frame": { "x": 0, "y": 0, "w": 80, "h": 120 }, 5 | "rotated": false, 6 | "trimmed": false, 7 | "spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 120 }, 8 | "sourceSize": { "w": 80, "h": 120 }, 9 | "duration": 100 10 | }, 11 | { 12 | "filename": "dude 1.aseprite", 13 | "frame": { "x": 80, "y": 0, "w": 80, "h": 120 }, 14 | "rotated": false, 15 | "trimmed": false, 16 | "spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 120 }, 17 | "sourceSize": { "w": 80, "h": 120 }, 18 | "duration": 100 19 | }, 20 | { 21 | "filename": "dude 2.aseprite", 22 | "frame": { "x": 160, "y": 0, "w": 80, "h": 120 }, 23 | "rotated": false, 24 | "trimmed": false, 25 | "spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 120 }, 26 | "sourceSize": { "w": 80, "h": 120 }, 27 | "duration": 330 28 | } 29 | ], 30 | "meta": { 31 | "app": "http://www.aseprite.org/", 32 | "version": "1.2.9-x64", 33 | "image": "B:\\projects\\lua-lessons-ru\\Sprites\\sprites lesson 5 aseprite\\res\\spr\\dude.png", 34 | "format": "RGBA8888", 35 | "size": { "w": 240, "h": 120 }, 36 | "scale": "1", 37 | "frameTags": [ 38 | { "name": "stand", "from": 0, "to": 0, "direction": "forward" }, 39 | { "name": "run", "from": 1, "to": 2, "direction": "forward" } 40 | ], 41 | "layers": [ 42 | { "name": "Layer 1", "opacity": 255, "blendMode": "normal" } 43 | ], 44 | "slices": [ 45 | ] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Sprites/sprites lesson 5 aseprite/res/spr/dude.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 5 aseprite/res/spr/dude.png -------------------------------------------------------------------------------- /Sprites/sprites lesson 5 aseprite/source/astst.aseprite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 5 aseprite/source/astst.aseprite -------------------------------------------------------------------------------- /Sprites/sprites lesson 5 aseprite/source/dude.aseprite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/Sprites/sprites lesson 5 aseprite/source/dude.aseprite -------------------------------------------------------------------------------- /Tween/kikito tween/main.lua: -------------------------------------------------------------------------------- 1 | -- Библиотека tween by kikito 2 | local tween = require 'tween' 3 | 4 | function love.load() 5 | krug = {x = 20, y = 20, r1 = 10, r2 = 10, c = {255, 0, 255}} 6 | go = { x = 100, y = 100, 7 | sprite = love.graphics.newText(love.graphics.newFont(100), "GaMe OvEr!") } 8 | z = {} 9 | for i = 1, 20 do 10 | z[#z + 1] = { x = i * 40, y = 600 - 20, r = love.math.random(3, 7), 11 | c = {love.math.random(40, 100), 12 | love.math.random(140, 200), 13 | love.math.random(0, 255)}, 14 | 15 | } 16 | z[#z].tw = tween.new(love.math.random(1, 5), z[#z], 17 | { x = love.math.random(0, 800), 18 | y = love.math.random(0, 600), 19 | c = {255, 0, 0}, 20 | r = love.math.random(20, 40) 21 | }, 22 | "inOutBounce") 23 | end 24 | --local t = tween.new(duration, subject, target, [easing]) 25 | krugTweenY = tween.new(3, krug, { y = 600 - 20 }, "outBounce") 26 | krugTweenX = tween.new(5, krug, { x = 800 - 20, r1 = 3, 27 | c = {80, 255, 30} }, "outQuad") 28 | goTweenY = tween.new(1, go, { y = 240 }, "outElastic") 29 | end 30 | 31 | function love.draw() 32 | love.graphics.setColor(krug.c[1],krug.c[2],krug.c[3]) 33 | love.graphics.circle("fill", krug.x, krug.y, krug.r1, krug.r2) 34 | love.graphics.setColor(55,255,55) 35 | love.graphics.draw(go.sprite, go.x, go.y, 0.1) 36 | --love.graphics.setColor(255,255,255) 37 | for i = 1, #z do 38 | love.graphics.setColor(z[i].c[1],z[i].c[2],z[i].c[3]) 39 | love.graphics.circle("fill", z[i].x, z[i].y, z[i].r, 7) 40 | end 41 | end 42 | 43 | function love.update(dt) 44 | krugTweenX:update(dt) 45 | krugTweenY:update(dt) 46 | goTweenY:update(dt) 47 | for i = 1, #z do 48 | z[i].tw:update(dt) 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /love.filesystem/fs Lesson 1/conf.lua: -------------------------------------------------------------------------------- 1 | function love.conf(t) 2 | t.window.title = "love.FileSystem УРОК 1 - Уроки Lua & Love2D для маленьких гопников" -- The window title (string) 3 | t.window.width = 640 -- The window width (number) 4 | t.window.height = 320 -- The window height (number) 5 | t.console = true 6 | end -------------------------------------------------------------------------------- /love.filesystem/fs Lesson 1/main.lua: -------------------------------------------------------------------------------- 1 | -- файловая система в Love2D 2 | -- УРОК 1 пишем в файл, читаем из файла, как хранить данные на диске 3 | r = {} 4 | function love.load() 5 | if arg[#arg] == "-debug" then require("mobdebug").start() end 6 | end 7 | 8 | function addRect(x, y, w, h) 9 | r[#r + 1] = {x, y, w, h} 10 | print("added", x, y, w, h) 11 | end 12 | function drawRects() 13 | local p 14 | for i = 1, #r do 15 | p = r[i] 16 | love.graphics.rectangle("line", p[1], p[2], p[3], p[4] ) 17 | end 18 | end 19 | function saveRects() 20 | local t = "r = {" 21 | for i = 1, #r do 22 | p = r[i] 23 | t = t .. "{" .. p[1] .. "," .. p[2] .. "," .. p[3] .. "," .. p[4] .. "}," 24 | end 25 | t = t .. "}" 26 | local success = love.filesystem.write("rects.txt", t, #t ) 27 | end 28 | function clearRects() 29 | r = {} 30 | end 31 | function loadRects() 32 | --local contents, size = love.filesystem.read( "rects.txt" ) 33 | local chunk = love.filesystem.load ("rects.txt" ) 34 | --print(contents, size, #contents) 35 | chunk() 36 | end 37 | function love.draw() 38 | drawRects() 39 | end 40 | function love.update(dt) 41 | end 42 | function love.keypressed(key) 43 | if key == "s" then 44 | saveRects() 45 | end 46 | if key == "c" then 47 | clearRects() 48 | end 49 | if key == "l" then 50 | loadRects() 51 | end 52 | if key == "escape" then 53 | love.event.quit() 54 | end 55 | end 56 | 57 | local px, py 58 | function love.mousepressed( x, y, button, isTouch ) 59 | -- print("love.mousepressed", x, y, button, isTouch) 60 | px, py = x, y 61 | end 62 | function love.mousereleased( x, y, button, isTouch ) 63 | -- print(" love.mousereleased", x, y, button, isTouch) 64 | addRect(px, py, x - px, y - py) 65 | end 66 | -------------------------------------------------------------------------------- /love.filesystem/fs Lesson 2/conf.lua: -------------------------------------------------------------------------------- 1 | function love.conf(t) 2 | t.window.title = "love.FileSystem УРОК 2 - Уроки Lua & Love2D для маленьких гопников" -- The window title (string) 3 | t.window.width = 640 -- The window width (number) 4 | t.window.height = 320 -- The window height (number) 5 | t.console = false 6 | end -------------------------------------------------------------------------------- /love.filesystem/fs Lesson 2/lib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 rxi 2 | 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /love.filesystem/fs Lesson 2/lib/json.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- json.lua 3 | -- 4 | -- Copyright (c) 2018 rxi 5 | -- 6 | -- Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | -- this software and associated documentation files (the "Software"), to deal in 8 | -- the Software without restriction, including without limitation the rights to 9 | -- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | -- of the Software, and to permit persons to whom the Software is furnished to do 11 | -- so, subject to the following conditions: 12 | -- 13 | -- The above copyright notice and this permission notice shall be included in all 14 | -- copies or substantial portions of the Software. 15 | -- 16 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | -- SOFTWARE. 23 | -- 24 | 25 | local json = { _version = "0.1.1" } 26 | 27 | ------------------------------------------------------------------------------- 28 | -- Encode 29 | ------------------------------------------------------------------------------- 30 | 31 | local encode 32 | 33 | local escape_char_map = { 34 | [ "\\" ] = "\\\\", 35 | [ "\"" ] = "\\\"", 36 | [ "\b" ] = "\\b", 37 | [ "\f" ] = "\\f", 38 | [ "\n" ] = "\\n", 39 | [ "\r" ] = "\\r", 40 | [ "\t" ] = "\\t", 41 | } 42 | 43 | local escape_char_map_inv = { [ "\\/" ] = "/" } 44 | for k, v in pairs(escape_char_map) do 45 | escape_char_map_inv[v] = k 46 | end 47 | 48 | 49 | local function escape_char(c) 50 | return escape_char_map[c] or string.format("\\u%04x", c:byte()) 51 | end 52 | 53 | 54 | local function encode_nil(val) 55 | return "null" 56 | end 57 | 58 | 59 | local function encode_table(val, stack) 60 | local res = {} 61 | stack = stack or {} 62 | 63 | -- Circular reference? 64 | if stack[val] then error("circular reference") end 65 | 66 | stack[val] = true 67 | 68 | if val[1] ~= nil or next(val) == nil then 69 | -- Treat as array -- check keys are valid and it is not sparse 70 | local n = 0 71 | for k in pairs(val) do 72 | if type(k) ~= "number" then 73 | error("invalid table: mixed or invalid key types") 74 | end 75 | n = n + 1 76 | end 77 | if n ~= #val then 78 | error("invalid table: sparse array") 79 | end 80 | -- Encode 81 | for i, v in ipairs(val) do 82 | table.insert(res, encode(v, stack)) 83 | end 84 | stack[val] = nil 85 | return "[" .. table.concat(res, ",") .. "]" 86 | 87 | else 88 | -- Treat as an object 89 | for k, v in pairs(val) do 90 | if type(k) ~= "string" then 91 | error("invalid table: mixed or invalid key types") 92 | end 93 | table.insert(res, encode(k, stack) .. ":" .. encode(v, stack)) 94 | end 95 | stack[val] = nil 96 | return "{" .. table.concat(res, ",") .. "}" 97 | end 98 | end 99 | 100 | 101 | local function encode_string(val) 102 | return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"' 103 | end 104 | 105 | 106 | local function encode_number(val) 107 | -- Check for NaN, -inf and inf 108 | if val ~= val or val <= -math.huge or val >= math.huge then 109 | error("unexpected number value '" .. tostring(val) .. "'") 110 | end 111 | return string.format("%.14g", val) 112 | end 113 | 114 | 115 | local type_func_map = { 116 | [ "nil" ] = encode_nil, 117 | [ "table" ] = encode_table, 118 | [ "string" ] = encode_string, 119 | [ "number" ] = encode_number, 120 | [ "boolean" ] = tostring, 121 | } 122 | 123 | 124 | encode = function(val, stack) 125 | local t = type(val) 126 | local f = type_func_map[t] 127 | if f then 128 | return f(val, stack) 129 | end 130 | error("unexpected type '" .. t .. "'") 131 | end 132 | 133 | 134 | function json.encode(val) 135 | return ( encode(val) ) 136 | end 137 | 138 | 139 | ------------------------------------------------------------------------------- 140 | -- Decode 141 | ------------------------------------------------------------------------------- 142 | 143 | local parse 144 | 145 | local function create_set(...) 146 | local res = {} 147 | for i = 1, select("#", ...) do 148 | res[ select(i, ...) ] = true 149 | end 150 | return res 151 | end 152 | 153 | local space_chars = create_set(" ", "\t", "\r", "\n") 154 | local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",") 155 | local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u") 156 | local literals = create_set("true", "false", "null") 157 | 158 | local literal_map = { 159 | [ "true" ] = true, 160 | [ "false" ] = false, 161 | [ "null" ] = nil, 162 | } 163 | 164 | 165 | local function next_char(str, idx, set, negate) 166 | for i = idx, #str do 167 | if set[str:sub(i, i)] ~= negate then 168 | return i 169 | end 170 | end 171 | return #str + 1 172 | end 173 | 174 | 175 | local function decode_error(str, idx, msg) 176 | local line_count = 1 177 | local col_count = 1 178 | for i = 1, idx - 1 do 179 | col_count = col_count + 1 180 | if str:sub(i, i) == "\n" then 181 | line_count = line_count + 1 182 | col_count = 1 183 | end 184 | end 185 | error( string.format("%s at line %d col %d", msg, line_count, col_count) ) 186 | end 187 | 188 | 189 | local function codepoint_to_utf8(n) 190 | -- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa 191 | local f = math.floor 192 | if n <= 0x7f then 193 | return string.char(n) 194 | elseif n <= 0x7ff then 195 | return string.char(f(n / 64) + 192, n % 64 + 128) 196 | elseif n <= 0xffff then 197 | return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128) 198 | elseif n <= 0x10ffff then 199 | return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128, 200 | f(n % 4096 / 64) + 128, n % 64 + 128) 201 | end 202 | error( string.format("invalid unicode codepoint '%x'", n) ) 203 | end 204 | 205 | 206 | local function parse_unicode_escape(s) 207 | local n1 = tonumber( s:sub(3, 6), 16 ) 208 | local n2 = tonumber( s:sub(9, 12), 16 ) 209 | -- Surrogate pair? 210 | if n2 then 211 | return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000) 212 | else 213 | return codepoint_to_utf8(n1) 214 | end 215 | end 216 | 217 | 218 | local function parse_string(str, i) 219 | local has_unicode_escape = false 220 | local has_surrogate_escape = false 221 | local has_escape = false 222 | local last 223 | for j = i + 1, #str do 224 | local x = str:byte(j) 225 | 226 | if x < 32 then 227 | decode_error(str, j, "control character in string") 228 | end 229 | 230 | if last == 92 then -- "\\" (escape char) 231 | if x == 117 then -- "u" (unicode escape sequence) 232 | local hex = str:sub(j + 1, j + 5) 233 | if not hex:find("%x%x%x%x") then 234 | decode_error(str, j, "invalid unicode escape in string") 235 | end 236 | if hex:find("^[dD][89aAbB]") then 237 | has_surrogate_escape = true 238 | else 239 | has_unicode_escape = true 240 | end 241 | else 242 | local c = string.char(x) 243 | if not escape_chars[c] then 244 | decode_error(str, j, "invalid escape char '" .. c .. "' in string") 245 | end 246 | has_escape = true 247 | end 248 | last = nil 249 | 250 | elseif x == 34 then -- '"' (end of string) 251 | local s = str:sub(i + 1, j - 1) 252 | if has_surrogate_escape then 253 | s = s:gsub("\\u[dD][89aAbB]..\\u....", parse_unicode_escape) 254 | end 255 | if has_unicode_escape then 256 | s = s:gsub("\\u....", parse_unicode_escape) 257 | end 258 | if has_escape then 259 | s = s:gsub("\\.", escape_char_map_inv) 260 | end 261 | return s, j + 1 262 | 263 | else 264 | last = x 265 | end 266 | end 267 | decode_error(str, i, "expected closing quote for string") 268 | end 269 | 270 | 271 | local function parse_number(str, i) 272 | local x = next_char(str, i, delim_chars) 273 | local s = str:sub(i, x - 1) 274 | local n = tonumber(s) 275 | if not n then 276 | decode_error(str, i, "invalid number '" .. s .. "'") 277 | end 278 | return n, x 279 | end 280 | 281 | 282 | local function parse_literal(str, i) 283 | local x = next_char(str, i, delim_chars) 284 | local word = str:sub(i, x - 1) 285 | if not literals[word] then 286 | decode_error(str, i, "invalid literal '" .. word .. "'") 287 | end 288 | return literal_map[word], x 289 | end 290 | 291 | 292 | local function parse_array(str, i) 293 | local res = {} 294 | local n = 1 295 | i = i + 1 296 | while 1 do 297 | local x 298 | i = next_char(str, i, space_chars, true) 299 | -- Empty / end of array? 300 | if str:sub(i, i) == "]" then 301 | i = i + 1 302 | break 303 | end 304 | -- Read token 305 | x, i = parse(str, i) 306 | res[n] = x 307 | n = n + 1 308 | -- Next token 309 | i = next_char(str, i, space_chars, true) 310 | local chr = str:sub(i, i) 311 | i = i + 1 312 | if chr == "]" then break end 313 | if chr ~= "," then decode_error(str, i, "expected ']' or ','") end 314 | end 315 | return res, i 316 | end 317 | 318 | 319 | local function parse_object(str, i) 320 | local res = {} 321 | i = i + 1 322 | while 1 do 323 | local key, val 324 | i = next_char(str, i, space_chars, true) 325 | -- Empty / end of object? 326 | if str:sub(i, i) == "}" then 327 | i = i + 1 328 | break 329 | end 330 | -- Read key 331 | if str:sub(i, i) ~= '"' then 332 | decode_error(str, i, "expected string for key") 333 | end 334 | key, i = parse(str, i) 335 | -- Read ':' delimiter 336 | i = next_char(str, i, space_chars, true) 337 | if str:sub(i, i) ~= ":" then 338 | decode_error(str, i, "expected ':' after key") 339 | end 340 | i = next_char(str, i + 1, space_chars, true) 341 | -- Read value 342 | val, i = parse(str, i) 343 | -- Set 344 | res[key] = val 345 | -- Next token 346 | i = next_char(str, i, space_chars, true) 347 | local chr = str:sub(i, i) 348 | i = i + 1 349 | if chr == "}" then break end 350 | if chr ~= "," then decode_error(str, i, "expected '}' or ','") end 351 | end 352 | return res, i 353 | end 354 | 355 | 356 | local char_func_map = { 357 | [ '"' ] = parse_string, 358 | [ "0" ] = parse_number, 359 | [ "1" ] = parse_number, 360 | [ "2" ] = parse_number, 361 | [ "3" ] = parse_number, 362 | [ "4" ] = parse_number, 363 | [ "5" ] = parse_number, 364 | [ "6" ] = parse_number, 365 | [ "7" ] = parse_number, 366 | [ "8" ] = parse_number, 367 | [ "9" ] = parse_number, 368 | [ "-" ] = parse_number, 369 | [ "t" ] = parse_literal, 370 | [ "f" ] = parse_literal, 371 | [ "n" ] = parse_literal, 372 | [ "[" ] = parse_array, 373 | [ "{" ] = parse_object, 374 | } 375 | 376 | 377 | parse = function(str, idx) 378 | local chr = str:sub(idx, idx) 379 | local f = char_func_map[chr] 380 | if f then 381 | return f(str, idx) 382 | end 383 | decode_error(str, idx, "unexpected character '" .. chr .. "'") 384 | end 385 | 386 | 387 | function json.decode(str) 388 | if type(str) ~= "string" then 389 | error("expected argument of type string, got " .. type(str)) 390 | end 391 | local res, idx = parse(str, next_char(str, 1, space_chars, true)) 392 | idx = next_char(str, idx, space_chars, true) 393 | if idx <= #str then 394 | decode_error(str, idx, "trailing garbage") 395 | end 396 | return res 397 | end 398 | 399 | 400 | return json 401 | -------------------------------------------------------------------------------- /love.filesystem/fs Lesson 2/main.lua: -------------------------------------------------------------------------------- 1 | -- файловая система в Love2D 2 | -- УРОК 2 пишем в файл, читаем из файла, как хранить данные на диске 3 | json = require "lib.json" 4 | 5 | function love.load() 6 | if arg[#arg] == "-debug" then require("mobdebug").start() end 7 | 8 | test = { 9 | {name = "gob1", type = "goblin", x = 33, y =16, draw = "fff" }, 10 | {name = "gob2", type = "goblin", x = 23, y =100, draw = "fff" }, 11 | {name = "gob3", type = "goblin", x = 43, y =6, draw = "fff" }, 12 | } 13 | -- test = {key1 = 1, key2 = 33, key3 = "ffffff", key = "green"} 14 | 15 | local to_file = json.encode(test) 16 | love.filesystem.write( "saveGame.txt", to_file, #to_file ) 17 | 18 | local contents, size = love.filesystem.read( "saveGame.txt" ) 19 | print (contents) 20 | 21 | test2 = json.decode(contents) 22 | 23 | print(test2.name) 24 | 25 | end 26 | -------------------------------------------------------------------------------- /turtle/ch.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | print "Черепашка готова" 3 | 4 | пауза = wait 5 | вперед = move 6 | назад = function(n) move(-n) end 7 | направо = turn 8 | налево = function(n) turn(-n) end 9 | function переменная(name) 10 | _G[name] = 0 11 | end 12 | 13 | перо = pnsz 14 | цветRGB = function(r, g, b) 15 | pncl( colr( r,g,b )) 16 | end 17 | очистить_фон = wipe 18 | показать_черепашку = show 19 | спрятать_черепашку = hide 20 | место= posn 21 | 22 | function домой() 23 | posn(0, 0) 24 | налево(90) 25 | end 26 | 27 | function повтори(n, st) 28 | for i = 1, n do 29 | loadstring(st)() 30 | end 31 | end 32 | 33 | домой() -------------------------------------------------------------------------------- /turtle/ch_test1.lua: -------------------------------------------------------------------------------- 1 | require "ch" 2 | показать_черепашку() 3 | цветRGB(255, 0, 0) 4 | перо(5) 5 | переменная('п') 6 | п = п + 1 7 | вперед(100) 8 | налево(90) 9 | вперед(100) 10 | --очистить_фон() 11 | налево(90) 12 | вперед(100) 13 | 14 | цветRGB(0, 255, 0) 15 | домой() 16 | повтори(22, "вперед(12) направо(15)") 17 | пауза() -------------------------------------------------------------------------------- /turtle/dz/8dz kuncov.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | function kmove(x, y) 3 | move(x) 4 | turn(90) 5 | move(y) 6 | turn(90) 7 | move(x) 8 | turn(90) 9 | move(y) 10 | 11 | turn(90) 12 | move(x) 13 | end 14 | for i = 1, 5 do 15 | kmove(75, 5) 16 | turn(144) 17 | end 18 | 19 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz.lua: -------------------------------------------------------------------------------- 1 | 2 | require "turtle" 3 | show () 4 | jump(-100) 5 | for qp = 1, 4 do 6 | for fcb = 1, 4 do 7 | move (50) 8 | turn (90) 9 | move (50) 10 | turn (90) 11 | move (50) 12 | turn (90) 13 | move (50) 14 | turn (90) 15 | jump (50) 16 | end 17 | turn (90) 18 | move (50) 19 | turn (90) 20 | move (200) 21 | turn (180) 22 | end 23 | wait () -------------------------------------------------------------------------------- /turtle/dz/dz10_1_2_3.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | size (500,250);turn(-90);jump(-120) --Черепаху вниз поля 3 | function vetka (dlin) 4 | if dlin < 3 then 5 | return 6 | end 7 | if dlin < 10 then -- Если длина < 10 8 | pncl(colr(0,225,0)) -- Зеленые листочки 9 | elseif dlin < 70 then -- Если длина < 70 10 | pncl(colr(220,110,0)) -- Светло коричневый 11 | else 12 | pncl(colr(160,80,0)) 13 | end 14 | pnsz ( dlin / 15 ) -- ТОЛЩИНА. Разделим длину на 15 15 | 16 | move (dlin) -- рисуем ствол 17 | 18 | local ugol = 10 + rand(50) -- случайный угол от 10 до 50 19 | turn (ugol) -- поворот направо 20 | vetka(dlin * 0.6) -- правая ветвь 21 | turn (-ugol) -- повернем назад, как было 22 | 23 | ugol = 10 + rand(50) -- случайный угол от 10 до 50 24 | turn (-ugol) -- налево повернем 25 | vetka(dlin * 0.6) 26 | turn (ugol) -- повернемся назад, как было 27 | 28 | ugol = (rand(30)-15) -- случайный угол от -15 до 15 29 | turn (ugol) -- поворот для третьей ветки 30 | vetka(dlin * 0.6) -- третья ветка 31 | turn (-ugol) -- повернем назад, как было 32 | 33 | jump(-dlin) -- прыгнем назад, к корню 34 | end 35 | vetka(100) 36 | wait() 37 | -------------------------------------------------------------------------------- /turtle/dz/dz6_1.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | pnsz(3) -- толщина 3 3 | -- Забор 4 | for i = 1, 5 do -- 5 раз повторяем 5 | turn (-90) 6 | move (70) 7 | turn (90) 8 | move (10) 9 | turn (90) 10 | move (70) 11 | turn (90) 12 | move (10) 13 | turn (-180) 14 | jump (20) 15 | end 16 | -- Трава 17 | pncl( colr( 0, 255, 0) ) -- Зелёный цвет 18 | zero(140, 230) -- сместим начало координат 19 | for i = 1, 3 do -- три раза повторяем 20 | turn (-60) 21 | move (20) 22 | back (20) 23 | turn (-30) 24 | move (20) 25 | back (20) 26 | turn (-30) 27 | move (20) 28 | back (20) 29 | turn (-240) 30 | jump (30) 31 | end 32 | zero(30, 227) 33 | move(100) 34 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz6_2.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | pnsz (3) 3 | pncl( colr( 255, 0, 0) ) 4 | turn (-90) 5 | -- КРЕСТ 6 | for drop = 1, 4 do 7 | move (50) 8 | turn (-90) 9 | move (5) 10 | back (5) 11 | turn (180) 12 | move (5) 13 | back (5) 14 | turn (-90) 15 | back (50) 16 | turn (90) 17 | end 18 | wait () -------------------------------------------------------------------------------- /turtle/dz/dz6_3.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | hide() 3 | local черный = colr(0,0,0) 4 | local красный = colr(255,0,0) 5 | local зеленый = colr(0,255,0) 6 | local синий = colr(0,0, 255) 7 | local желтый = colr(255,255,0) 8 | fill( черный, 0, 0 ) -- закрасим всё черным из точки 0,0 9 | pncl( желтый ) -- выбираем красный цвет 10 | for i = 1, 400 do -- рисуем 100 звезд 11 | local x = rand(450) - 250 -- случайное число от 0 до 250 12 | local y = rand(450) - 250 -- случайное число от 0 до 250 13 | pixl( x, y ) 14 | end 15 | pncl( синий ) -- выбираем синий цвет 16 | oval(0, 0, 190, 170) -- рисуем окружность 17 | fill( желтый, 0, 0 ) 18 | fill( синий, 0, 0 ) 19 | pncl( зеленый ) -- выбираем желтый цвет 20 | rect(-30, 0, 60, 20, 20) 21 | text( "ЗЕМЛЯ", 0, -30+10, 3 ) 22 | 23 | fill( желтый, 0, 0 ) 24 | show() 25 | pnsz(2) 26 | pncl( желтый ) -- выбираем синий цвет 27 | jump(200) 28 | turn(-90) 29 | for i = 1, 360 do 30 | move(2) 31 | --turn(-1) 32 | jump(2) 33 | turn(-1) 34 | 35 | end 36 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz6_3a.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | local голубой = colr (0,191,255) 3 | local черный = colr (0,0,0) 4 | local желтый = colr (255,255,0) 5 | pncl(желтый) 6 | fill(черный) 7 | for i= 0, 100 do -- Звёзды 8 | pixl (rand (300),rand (300)) 9 | pixl (rand (-300),rand (300)) 10 | pixl (rand (300),rand (-300)) 11 | pixl (rand (-300),rand (-300)) 12 | end 13 | oval(0, 0, 180, 160, голубой, start, finish) 14 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz6_templ.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | local черный = colr(0,0,0) 3 | local красный = colr(255,0,0) 4 | local зеленый = colr(0,255,0) 5 | local синий = colr(0,0, 255) 6 | fill( черный, 0, 0 ) -- закрасим всё черным из точки 0,0 7 | pncl( красный ) -- выбираем красный цвет 8 | for i = 1, 100 do -- рисуем 100 звезд 9 | local x = rand(250) -- случайное число от 0 до 250 10 | local y = rand(250) -- случайное число от 0 до 250 11 | pixl( x, y ) 12 | end 13 | pncl( синий ) -- выбираем синий цвет 14 | oval(0, 0, 200) -- рисуем окружность (если в овале указать только 1 размер) 15 | pncl( зеленый ) -- выбираем желтый цвет 16 | rect(0, 0, 60, 20, 20) 17 | text( "ЗЕМЛЯ", 0, 10, 3 ) 18 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz7_1.lua: -------------------------------------------------------------------------------- 1 | require "turtle" -- 1я черепашка уже есть, черная 2 | trtl() -- ставим 2ю черепашку 3 | pncl(colr(255,0,0)) -- красный цвет 4 | turn(90) 5 | trtl() -- ставим 3ю черепашку 6 | pncl(colr(0,0,255))-- синий цвет 7 | turn(180) 8 | trtl() -- ставим 4ю черепашку 9 | pncl(colr(0,255,0))-- зеленый цвет 10 | pnsz(4) 11 | turn(270) 12 | pick() -- выбрали всех 13 | jump(75) 14 | turn(90) 15 | move(75) 16 | turn(90) 17 | move(75) 18 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz7_2.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | -- первая черная черепашка всегда есть 3 | -- добавим 359 оставшихся, каждую поворачивая на еще 1 градус 4 | for угол = 1, 359 do 5 | trtl() -- ставим еще 1 черепашку 6 | pncl( ranc() ) -- случайный цвет 7 | turn(угол) -- повернем на угол 8 | end 9 | pick() -- выберем всех черепах 10 | move(200) -- всем командуем ВПЕРЕД! 11 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz8 kornev.lua: -------------------------------------------------------------------------------- 1 | 2 | 3 | require "turtle" 4 | function kmove (длина) 5 | for i = 1, 6 do 6 | turn (144) 7 | move (длина) 8 | turn (-90) 9 | move (5) 10 | turn (-90) 11 | move (длина) 12 | turn (-90) 13 | move (5) 14 | turn (-90) 15 | jump (100) 16 | end 17 | end 18 | kmove (100) 19 | wait() 20 | -------------------------------------------------------------------------------- /turtle/dz/dz8 ulian.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | function kmove(x) 3 | turn(-90) 4 | move(5) 5 | turn(90) 6 | move(x) 7 | turn(90) 8 | move(5) 9 | turn(90) 10 | move(x) 11 | turn(-180) 12 | jump(x) 13 | end 14 | size(700,700) 15 | function zvezda(x, y) 16 | for i = 1, 5 do 17 | kmove(x) 18 | turn(144) 19 | end 20 | end 21 | for i =1, 360 do 22 | zvezda(200) 23 | end 24 | wait(100) -------------------------------------------------------------------------------- /turtle/dz/dz8 valeev.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | function kmove(x) 3 | turn(-90) 4 | move(5) 5 | turn(90) 6 | move(x) 7 | turn(90) 8 | move(5) 9 | turn(90) 10 | move(x) 11 | jump(-x) 12 | turn(180) 13 | end 14 | for i = 1, 5 do 15 | kmove(200) 16 | turn(144) 17 | end 18 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz8_1.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | function kmove(x) 3 | turn(-90) 4 | move(5) -- узкая сторона 5 шагов 5 | turn(90) 6 | move(x) 7 | turn(90) 8 | move(5) -- узкая сторона 5 шагов 9 | turn(90) 10 | move(x) 11 | jump(-x) -- прыгнем в начало 12 | turn(180) -- повернемся, как было 13 | end 14 | for i = 1, 5 do --пятиконечная звезда 15 | kmove(200) 16 | turn(144) 17 | end 18 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz9_1.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | size (1100,500) 3 | zero (0,250) 4 | 5 | function El () 6 | trtl (1).angle = -90 7 | pnsz(5) 8 | pncl(colr(150,75,0)) 9 | move (70) 10 | pncl(colr( 0,225,0)) 11 | turn (-150) 12 | move (50) 13 | turn (-120) 14 | move (50) 15 | turn (-120) 16 | move (50) 17 | turn (-150) 18 | jump (70) 19 | turn (-90) 20 | end 21 | function Z () 22 | pnsz(5) 23 | pncl(colr(0,0,0)) 24 | end 25 | 26 | -- 1 27 | jump (55) 28 | El () 29 | -- 2 30 | Z () 31 | turn (-45) 32 | move (75) 33 | El () 34 | -- 3 35 | Z () 36 | turn (-15) 37 | move (60) 38 | El () 39 | -- 4 40 | Z () 41 | turn (60) 42 | move (100) 43 | El () 44 | -- 5 45 | Z () 46 | turn (0) 47 | move (150) 48 | El () 49 | -- 6 50 | Z () 51 | turn (-45) 52 | move (60) 53 | El () 54 | -- 7 55 | Z () 56 | turn (60) 57 | move (80) 58 | El () 59 | -- 8 60 | Z () 61 | turn (0) 62 | move (100) 63 | El () 64 | -- 9 65 | Z () 66 | turn (15) 67 | move (50) 68 | El () 69 | -- 10 70 | Z () 71 | turn (-15) 72 | move (100) 73 | El () 74 | -- 11 75 | Z () 76 | turn (-25) 77 | move (60) 78 | El () 79 | -- 12 80 | Z () 81 | turn (-35) 82 | move (70) 83 | El () 84 | -- 13 85 | Z () 86 | turn (50) 87 | move (100) 88 | El () 89 | -- 14 90 | Z () 91 | turn (-20) 92 | move (55) 93 | El () 94 | -- 15 95 | Z () 96 | turn (0) 97 | move (100) 98 | El () 99 | 100 | wait() 101 | -------------------------------------------------------------------------------- /turtle/dz/dz9_2.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | show () 3 | posn (-180, 0) 4 | for i = 1, 8 do 5 | trtl(1).angle = 270 6 | move (55) 7 | turn (-140) 8 | move (35) 9 | trtl(1).angle = 0 10 | move (45) 11 | turn (-130) 12 | move (35) 13 | trtl(1).angle = 90 14 | jump (55) 15 | trtl(1).angle = 0 16 | rand (10) 17 | if rand(20)>5 then 18 | turn (7) 19 | else 20 | turn (-7) 21 | end 22 | move (50) 23 | end 24 | wait () -------------------------------------------------------------------------------- /turtle/dz/dz9_3.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | size (600,300) 3 | posn (-300,150) 4 | for i=1,10 do 5 | turn (45) 6 | turn (rand (-90)) 7 | move (50) 8 | local ug=trtl(1).angle 9 | turn (-ug) 10 | turn (-90) 11 | move (100) 12 | turn (130) 13 | move (30) 14 | turn (140) 15 | move (45) 16 | turn (140) 17 | move (30) 18 | turn (130) 19 | move (100) 20 | turn (-90) 21 | end 22 | wait () -------------------------------------------------------------------------------- /turtle/dz/dz_td1_1.lua: -------------------------------------------------------------------------------- 1 | -- квадрат 4мя черепашками 2 | require "turtle" 3 | 4 | for i = 1, 359 do 5 | 6 | trtl() 7 | pncl (ranc()) 8 | turn (i) 9 | 10 | end 11 | pick() 12 | move (179) 13 | 14 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz_td1_2.lua: -------------------------------------------------------------------------------- 1 | -- 360 лучей 2 | require "turtle" 3 | 4 | for i = 1, 359 do 5 | 6 | trtl() 7 | pncl (ranc()) 8 | turn (i) 9 | 10 | end 11 | pick() 12 | move (179) 13 | 14 | wait() -------------------------------------------------------------------------------- /turtle/dz/dz_td1_3.lua: -------------------------------------------------------------------------------- 1 | -- звезда 2 | require "turtle" 3 | zero (130, 200) 4 | 5 | function kmove (x) 6 | 7 | turn (-90) 8 | move (7) 9 | turn (90) 10 | move (x) 11 | turn (90) 12 | move (7) 13 | turn (90) 14 | move (x) 15 | move (-x) 16 | turn (180) 17 | 18 | end 19 | for i = 1, 5 do 20 | kmove (210) 21 | turn (144) 22 | end 23 | wait() -------------------------------------------------------------------------------- /turtle/lesson1.lua: -------------------------------------------------------------------------------- 1 | require "ch" 2 | show() 3 | pnsz(3) 4 | 5 | local ребро = 150 6 | pncl(ranc()) 7 | move(ребро) 8 | turn(90) 9 | pncl(ranc()) 10 | move(ребро) 11 | turn(90) 12 | pncl(ranc()) 13 | move(ребро) 14 | turn(90) 15 | pncl(ranc()) 16 | move(ребро) 17 | turn(90) 18 | pncl(ranc()) 19 | wait() -------------------------------------------------------------------------------- /turtle/lesson3for.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | local количество = 7 -- сколько всего деревьев рисовать 3 | local высота = 110 -- высота ствола 4 | local высота2 = 30 -- высота ребра квадрата для листвы 5 | local промежуток = 50 -- между стволами деревьев 6 | size(количество * промежуток +100, (высота + высота2 + высота2) ) 7 | zero(30, (высота + высота2 + высота2)) 8 | show() 9 | pnsz(3) 10 | for i = 1, количество do 11 | -- начало дерева 12 | turn(-90) 13 | pncl( colr( 255, 0, 0) ) 14 | move(высота) 15 | pncl( colr( 0, 255, 0) ) 16 | turn(-45) 17 | move(высота2) 18 | turn(90) 19 | move(высота2) 20 | turn(90) 21 | move(высота2) 22 | turn(90) 23 | move(высота2) 24 | turn(-45) 25 | jump(высота) 26 | turn(-90) 27 | jump(промежуток) 28 | -- конец дерева 29 | end 30 | back( (количество + 1) * промежуток) 31 | wait() -------------------------------------------------------------------------------- /turtle/lesson4.1.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | 3 | local красный = colr(255, 0, 0) 4 | pncl(красный) 5 | load("pic1.png", -200, -200) 6 | for i = 0, 225, 1 do 7 | pncl( ranc() ) 8 | line(0,0, rand(450) - 450/2, rand(-100)) 9 | -- rect( 0, -100, 100, 50 ) 10 | -- fill( ranc(), 50, -80 ) 11 | -- rect( 0, 0, 100, 50, 25 ) 12 | -- font(13) 13 | -- text("ПРИВЕТ!", rand(360), rand(450) - 450/2, rand(100)) 14 | -- crcl(0, 0, i, ranc(), 0, rand(360) ) 15 | -- oval(0, 0, i * 3, i * 2, ranc() ) 16 | 17 | wait(0.1) 18 | end 19 | 20 | 21 | --save("pic_out") 22 | wait() -------------------------------------------------------------------------------- /turtle/lesson4okruzh.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | show() 3 | pnsz(3) 4 | 5 | for i = 1, 360 do 6 | move(1) 7 | turn(1) 8 | end 9 | for i = 1, 360 do 10 | move(1) 11 | turn(-1) 12 | end 13 | 14 | wait() -------------------------------------------------------------------------------- /turtle/lesson4okruzh_while.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | show() 3 | pnsz(3) 4 | 5 | local s = 1 6 | while s <= 360 do 7 | move(1) 8 | turn(1) 9 | print( s ) 10 | s = s + 1 11 | end 12 | 13 | wait() -------------------------------------------------------------------------------- /turtle/lesson4spiral.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | show() 3 | pnsz(3) 4 | for i = 1, 100 do 5 | move(i) 6 | turn(29) 7 | end 8 | 9 | wait() -------------------------------------------------------------------------------- /turtle/lesson4zvezda.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | show() 3 | pnsz(3) 4 | local rebro = 10 5 | for i = 1, 5 do 6 | move(rebro) 7 | turn(144) 8 | end 9 | 10 | wait() -------------------------------------------------------------------------------- /turtle/lesson4zvezda_func.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | show() 3 | pnsz(3) 4 | 5 | function zvezda ( rebro ) 6 | for i = 1, 5 do 7 | move(rebro) 8 | turn(144) 9 | end 10 | end 11 | 12 | for i = 1, 121 do 13 | zvezda ( 100 ) 14 | turn(15) 15 | move (i) 16 | end 17 | save( " zvezda ") 18 | wait() -------------------------------------------------------------------------------- /turtle/lesson5.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | 3 | function kvad(x) 4 | for i = 1, 4 do 5 | move(x) 6 | turn(90) 7 | end 8 | end 9 | 10 | function punkt(n) 11 | for i = 1, n do 12 | jump(5) 13 | move(5) 14 | end 15 | end 16 | 17 | show() 18 | --1 19 | posn(100, 100) 20 | turn(180) 21 | move(100) 22 | 23 | trtl() --2 24 | --rant() 25 | pncl( colr(255,0,0) ) 26 | turn(-90) 27 | move(100) 28 | 29 | trtl() --3 30 | pncl( colr(0,255,0) ) 31 | move(100) 32 | 33 | rant() 34 | rant() 35 | rant() 36 | rant() 37 | rant() 38 | 39 | pick() 40 | posn(0, 0) 41 | kvad(30) 42 | punkt(15) 43 | kvad(40) 44 | wait() -------------------------------------------------------------------------------- /turtle/lesson5a.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | 3 | function kvad(x) 4 | for i = 1, 4 do 5 | move(x) 6 | turn(90) 7 | end 8 | end 9 | 10 | function punkt(n) 11 | for i = 1, n do 12 | pncl( ranc() ) 13 | jump(5) 14 | move(5) 15 | end 16 | end 17 | 18 | show() 19 | --1 20 | trtl() --2 21 | trtl() --3 22 | trtl() 23 | trtl() 24 | trtl() 25 | trtl() 26 | trtl() --8 27 | pick() 28 | pnsz(3) 29 | for i = 1, 8 do 30 | pick( i ) 31 | pncl( ranc() ) 32 | posn(-200, i * 40 - 200) 33 | end 34 | --pick() 35 | for i = 1, 4 do 36 | pick( i, i + 4 ) 37 | punkt(40) 38 | end 39 | --kvad(30) 40 | 41 | --kvad(40) 42 | wait() -------------------------------------------------------------------------------- /turtle/pic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/turtle/pic1.png -------------------------------------------------------------------------------- /turtle/pic_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D0NM/lua-lessons-ru/b5469f8797adef7e0e6b0e872e5c043a60b64962/turtle/pic_out.png -------------------------------------------------------------------------------- /turtle/tmplt.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | 3 | show() 4 | pnsz(2) 5 | --move(20) 6 | pncl( ranc() ) 7 | line(0,0, 50, 50) 8 | pixl(3,70) 9 | 10 | fill( ranc(), 100, 0 ) 11 | text("Привет", 0, 5, 5) 12 | 13 | wait() -------------------------------------------------------------------------------- /turtle/turtleKletka4x4.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | show() -- Показать черепашку 3 | size(900,900) -- Увеличили поле 4 | 5 | function РисуйКвадрат() 6 | for i = 1,4 do 7 | move(100) 8 | turn(90) 9 | end 10 | end 11 | 12 | for i=1, 4 do 13 | move(200) 14 | turn(90) 15 | for m = 1,4 do 16 | turn(90) 17 | РисуйКвадрат() 18 | end 19 | end 20 | wait() -------------------------------------------------------------------------------- /turtle/turtleKletka4x4_2.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | 3 | local g=colr (0,225,0) 4 | local blue=colr (0,0,225) 5 | local r=colr (225,0,0) 6 | local b=colr (0,0,0) 7 | 8 | pncl (g) 9 | for i= -225, 225 do 10 | fill (b) 11 | crcl (0,0,200,blue) 12 | end 13 | wait () -------------------------------------------------------------------------------- /turtle/z10.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | pnsz(2); posn(-150, -150) 3 | function kva (dlina) 4 | for i = 1, 4 do 5 | move(dlina) 6 | turn(90) 7 | end 8 | if dlina > 10 then 9 | move(dlina / 2) 10 | turn(45) 11 | kva( dlina * 0.7) 12 | end 13 | end 14 | kva(300) 15 | wait() 16 | -------------------------------------------------------------------------------- /turtle/z10_0.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | function kva (dlina) 3 | for i = 1, 4 do 4 | move(dlina) 5 | turn(90) 6 | end 7 | end 8 | kva(200) 9 | wait() -------------------------------------------------------------------------------- /turtle/z10_01prKv.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | function kva(dlina) 3 | for i = 1, 4 do 4 | move(dlina) 5 | turn(90) 6 | end 7 | kva(dlina - 10) 8 | end 9 | kva(200) 10 | wait() -------------------------------------------------------------------------------- /turtle/z10_02_1.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | function kva(dlina) 3 | if dlina < 10 then 4 | return 5 | end 6 | for i = 1, 4 do 7 | move(dlina) 8 | turn(90) 9 | end 10 | move(5); turn(90); move(5); turn(-90) 11 | kva(dlina - 10) 12 | end 13 | kva(200) 14 | wait() -------------------------------------------------------------------------------- /turtle/z10_02prKvOtst.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | function kva(dlina) 3 | for i = 1, 4 do 4 | move(dlina) 5 | turn(90) 6 | end 7 | move(5); turn(90); move(5); turn(-90) 8 | kva(dlina - 10) 9 | end 10 | kva(200) 11 | wait() -------------------------------------------------------------------------------- /turtle/z11_0.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | -- Выводим текст при клике мыши 3 | while true do 4 | if clck("ld") then 5 | print("ЛЕВАЯ") 6 | elseif clck("rd") then 7 | print("ПРАВАЯ") 8 | elseif clck("ru") then 9 | print("ПРАВАЯ отпущена") 10 | elseif clck("l2") then -- L2 11 | print("ЛЕВАЯ 2 РАЗА") 12 | end 13 | wait(0.1) 14 | end 15 | --wait() -------------------------------------------------------------------------------- /turtle/z11_1.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | -- Покажи координаты курсора 3 | -- там, где было нажатие клавиш мыши 4 | local x, y 5 | while true do 6 | x, y = clck("ld") 7 | if x then 8 | print("ЛЕВАЯ", x, y) 9 | end 10 | x, y = clck("rd") 11 | if x then 12 | print("ПРАВАЯ", x, y) 13 | end 14 | x, y = clck("l2") -- Left Double Click 15 | if x then 16 | print("ЛЕВАЯ 2х", x, y) 17 | end 18 | wait(0.1) 19 | end 20 | wait() -------------------------------------------------------------------------------- /turtle/z11_2.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | -- Узнай коды клавиш 3 | while true do 4 | local k = char() 5 | if k then 6 | print( k ) 7 | end 8 | wait(0.1) 9 | end 10 | wait() -------------------------------------------------------------------------------- /turtle/z11_3_.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | while true do 3 | move(1) 4 | local k = char() 5 | if k == КОД_КЛАВИШИ then 6 | --ЧТО-ТО ДЕЛАЙ ЧЕРЕПАХА 7 | end 8 | wait(0.1) 9 | end 10 | wait() -------------------------------------------------------------------------------- /turtle/z11_5.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | trtl() -- поставим на поле вторую черепаху 3 | pncl( colr(255,0,0) ) -- покрасим её в красный 4 | pnsz(2) -- толщина её пера 2 5 | for i = 1, 10000 do 6 | pick(2) -- выберем 2ю черепаху 7 | move(1) -- она рисует пунктир 8 | jump(3) 9 | pick(1) -- выберем 1ю черепаху 10 | move(2) -- она просто идет вперед 11 | 12 | k = char() 13 | if k == 314 then -- <-- 14 | turn(-5) 15 | elseif k == 316 then -- > 16 | turn(5) 17 | elseif k == 32 then 18 | local x, y = posn() 19 | pick(2) 20 | posn(x, y) 21 | trtl(2).angle = trtl(1).angle 22 | elseif k then 23 | print( k ) 24 | end 25 | wait(0.1) 26 | end 27 | 28 | wait() -------------------------------------------------------------------------------- /turtle/z11_6.lua: -------------------------------------------------------------------------------- 1 | require "turtle" 2 | trtl() -- поставим на поле вторую черепаху 3 | pncl( colr(255,0,0) ) -- покрасим её в красный 4 | pnsz(2) -- толщина её пера 2 5 | show() 6 | for i = 1, 10000 do 7 | pick(2) -- выберем 2ю черепаху 8 | move(1) -- она рисует пунктир 9 | jump(3) 10 | pick(1) -- выберем 1ю черепаху 11 | move(2) -- она просто идет вперед 12 | 13 | k = char() 14 | pick(1) 15 | if k == 314 then 16 | turn(-5) 17 | elseif k == 316 then 18 | turn(5) 19 | elseif k == 32 then 20 | local x, y = posn() 21 | pick(2) 22 | posn(x, y) 23 | trtl(2).angle = trtl(1).angle 24 | elseif k then 25 | print( k ) 26 | end 27 | -- Телепорт черепашек по клику мышки 28 | local x, y = clck("ld") -- left down 29 | if x then 30 | pick(1) 31 | posn(x, y) 32 | end 33 | x, y = clck("rd") --right down 34 | if x then 35 | pick(2) 36 | posn(x, y) 37 | end 38 | wait(0.1) 39 | end 40 | 41 | wait() -------------------------------------------------------------------------------- /turtle/z8_1.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | 3 | function zig() 4 | move(100) 5 | turn(-170) 6 | move(100) 7 | turn(170) 8 | end 9 | 10 | zig() 11 | zig() 12 | zig() 13 | zig() 14 | wait() -------------------------------------------------------------------------------- /turtle/z8_2.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | pnsz(2) 3 | function zig(x) 4 | move(x) 5 | turn(-170) 6 | move(x) 7 | turn(170) 8 | end 9 | 10 | zig(100) 11 | zig(100) 12 | zig(100) 13 | wait() -------------------------------------------------------------------------------- /turtle/z8_2a.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | 3 | function zig(x) 4 | move(x) 5 | turn(-170) 6 | move(x) 7 | turn(170) 8 | end 9 | 10 | for i = 10, 50 do 11 | zig(i) 12 | end 13 | wait() -------------------------------------------------------------------------------- /turtle/z8_3.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | 3 | function zigmove(z) 4 | if z < 10 then 5 | move(z) 6 | return 7 | end 8 | zigmove(z / 3) 9 | turn(90) 10 | zigmove(z / 6) 11 | turn(-90) 12 | zigmove(z / 3) 13 | turn(-90) 14 | zigmove(z / 6) 15 | turn(90) 16 | zigmove(z / 3) 17 | end 18 | 19 | function treug(x) 20 | zigmove(x) 21 | turn(-120) 22 | zigmove(x) 23 | turn(-120) 24 | zigmove(x) 25 | turn(-120) 26 | end 27 | 28 | treug(200) 29 | 30 | wait() -------------------------------------------------------------------------------- /turtle/z8_3fract_tree.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | size(700,700) 3 | hide() 4 | 5 | function branch(x) 6 | if x < 1 then 7 | return 8 | end 9 | pnsz(x) 10 | move( x * 10 ) 11 | 12 | local u1 = math.random(30, 60) 13 | turn(-u1) 14 | branch(x - 1) 15 | turn(u1) 16 | 17 | local u1 = math.random(30, 60) 18 | turn(u1) 19 | branch(x - 1) 20 | turn(-u1) 21 | 22 | jump( -x * 10) 23 | end 24 | 25 | turn(-90) 26 | jump(-100) 27 | 28 | for i = 1, 40 do 29 | --posn(math.random(-600, 600), math.random(-700, 400)) 30 | rant() 31 | end 32 | pick() 33 | branch(5+ rand(3)) 34 | 35 | wait() -------------------------------------------------------------------------------- /turtle/z8_3simple_fract_tree.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | size(700,700) 3 | --hide() 4 | 5 | function ВЕТВИ(x) 6 | move( x ) 7 | turn( 45 ) 8 | move( x ) 9 | jump( -x ) 10 | turn( -45 ) 11 | 12 | turn( -45 ) 13 | move( x ) 14 | jump( -x ) 15 | turn( 45 ) 16 | 17 | jump( -x ) 18 | end 19 | 20 | turn(-90) 21 | jump(-100) 22 | 23 | ВЕТВИ(50) 24 | 25 | wait() -------------------------------------------------------------------------------- /turtle/z9_0.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | shag = 5 3 | for i = 1, 2500 do 4 | move(shag) 5 | 6 | if rand(10) < 5 then 7 | turn(15) 8 | else 9 | turn(-15) 10 | end 11 | 12 | local x,y = posn() 13 | if x > 250 then 14 | posn(-250, y) 15 | end 16 | if x < -250 then 17 | posn(250, y) 18 | end 19 | if y > 250 then 20 | posn(x, -250) 21 | end 22 | if y < -250 then 23 | posn(x, 250) 24 | end 25 | 26 | wait(0.01) 27 | end 28 | wait() -------------------------------------------------------------------------------- /turtle/z9_1.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | shag = 5 3 | for i = 1, 2500 do 4 | move(shag) 5 | 6 | if rand(10) < 5 then 7 | turn(15) 8 | else 9 | turn(-15) 10 | end 11 | 12 | local x,y = posn() 13 | if x > 250 or x < -250 14 | or y > 250 or y < -250 15 | then 16 | rant(1) 17 | posn(0, 0) 18 | end 19 | -- wait(0.01) 20 | end 21 | wait() -------------------------------------------------------------------------------- /turtle/z9_2.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | shag = 5 3 | for i = 1, 2500 do 4 | move(shag) 5 | 6 | if rand(10) < 5 then 7 | turn(15) 8 | else 9 | turn(-15) 10 | end 11 | print ( trtl(1).angle ) 12 | trtl(1).angle = -90 13 | 14 | 15 | local x,y = posn() 16 | if x > 250 or x < -250 17 | or y > 250 or y < -250 18 | then 19 | rant(1) 20 | posn(0, 0) 21 | end 22 | wait(0.01) 23 | end 24 | wait() -------------------------------------------------------------------------------- /turtle/z9_3.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | shag = 5 3 | rant(1) 4 | for i = 1, 2500 do 5 | move(shag) 6 | local x,y = posn() 7 | if x > 250 then 8 | trtl(1).angle = 180 9 | end 10 | if x < -250 then 11 | trtl(1).angle = 0 12 | end 13 | if y > 250 then 14 | trtl(1).angle = 270 15 | end 16 | if y < -250 then 17 | trtl(1).angle = 90 18 | end 19 | turn(1) 20 | wait(0.01) 21 | end 22 | wait() -------------------------------------------------------------------------------- /turtle/z9_4.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | for i = 1, 2500 do 3 | move(5) 4 | local x,y = posn() 5 | if x > 250 then 6 | trtl(1).angle = 180 7 | -- posn(0,0) 8 | end 9 | wait(0.01) 10 | end 11 | wait() -------------------------------------------------------------------------------- /turtle/z9___vl.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | zero(0,0) -- начало координат левый верхний угол 3 | turn(55) 4 | for i = 1, 10000 do 5 | move(5) 6 | if rand(6) < 3 then 7 | turn(3) 8 | else 9 | turn(-3) 10 | end 11 | local x, y = posn() 12 | print(x, y) 13 | if x > 450 then 14 | posn( 0, y ) 15 | end 16 | if x < 0 then 17 | posn( 450, y ) 18 | end 19 | if y > 450 then 20 | posn( x, 0 ) 21 | end 22 | if y < 0 then 23 | posn( x, 450 ) 24 | end 25 | wait(0.01) 26 | end 27 | wait() 28 | -------------------------------------------------------------------------------- /turtle/z9_posn.lua: -------------------------------------------------------------------------------- 1 | require"turtle" 2 | --zero(0,0) -- начало координат левый верхний угол 3 | rant(1) 4 | trtl(1).angle = 45 5 | function p() 6 | print("Х,У", posn()) 7 | print("угол", trtl(1).angle) 8 | end 9 | 10 | for i = 1, 4 do 11 | p() 12 | move(100) 13 | turn(90) 14 | end 15 | wait() 16 | --------------------------------------------------------------------------------