|
| 1 | +local isDebug=arg[#arg] == "-debug" |
| 2 | +if isDebug then require("mobdebug").start() end |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +local is_fullscreen=true |
| 7 | +w=nil |
| 8 | +h=nil |
| 9 | +rnd=love.math.random |
| 10 | +draw=love.graphics.draw |
| 11 | + |
| 12 | +local entities={} |
| 13 | + |
| 14 | +stars = {} |
| 15 | +stars2 = {} |
| 16 | +local max_stars = 100 |
| 17 | +local stars_r |
| 18 | +local stars_g |
| 19 | +local stars_b |
| 20 | + |
| 21 | +local stars2_r |
| 22 | +local stars2_g |
| 23 | +local stars2_b |
| 24 | + |
| 25 | + |
| 26 | +local stars_refresh=function() |
| 27 | + for i=1, max_stars do |
| 28 | + local x = rnd(w) |
| 29 | + local y = rnd(h) |
| 30 | + stars[i] = {x, y} |
| 31 | + |
| 32 | + x = rnd(w) |
| 33 | + y = rnd(h) |
| 34 | + stars2[i] = {x, y} |
| 35 | + end |
| 36 | + |
| 37 | + stars_r=rnd() |
| 38 | + stars_g=rnd() |
| 39 | + stars_b=rnd() |
| 40 | + |
| 41 | + stars2_r=rnd() |
| 42 | + stars2_g=rnd() |
| 43 | + stars2_b=rnd() |
| 44 | +end |
| 45 | + |
| 46 | + |
| 47 | +local stars_demo=function() |
| 48 | + if rnd()<0.02 then |
| 49 | + stars_refresh() |
| 50 | + end |
| 51 | + |
| 52 | + love.graphics.setColor(stars_r,stars_g,stars_b) |
| 53 | + love.graphics.points(stars) |
| 54 | + |
| 55 | + love.graphics.setColor(stars2_r,stars2_g,stars2_b) |
| 56 | + love.graphics.points(stars2) |
| 57 | +end |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +local update_size=function() |
| 62 | + w = love.graphics.getWidth() |
| 63 | + h = love.graphics.getHeight() |
| 64 | +end |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +local lines_demo_1=function() |
| 70 | + local x1=rnd(w) |
| 71 | + local x2=rnd(w) |
| 72 | + |
| 73 | + local y1=rnd(h) |
| 74 | + local y2=rnd(h) |
| 75 | + love.graphics.line(x1,y1,x2,y2) |
| 76 | +end |
| 77 | + |
| 78 | + |
| 79 | +local lines_demo_2=function() |
| 80 | + local x1=rnd(w) |
| 81 | + local x2=rnd(w) |
| 82 | + local x3=rnd(w) |
| 83 | + |
| 84 | + local y1=rnd(h) |
| 85 | + local y2=rnd(h) |
| 86 | + local y3=rnd(h) |
| 87 | + love.graphics.line(x1,y1,x2,y2) |
| 88 | + love.graphics.line(x2,y2,x3,y3) |
| 89 | +end |
| 90 | + |
| 91 | +local lines_demo_3=function() |
| 92 | + local x1=rnd(w) |
| 93 | + local x2=rnd(w) |
| 94 | + local y1=rnd(h) |
| 95 | + |
| 96 | + love.graphics.setColor( 1,0, 0, 1 ) |
| 97 | + love.graphics.line(x1,y1,x2,y1) |
| 98 | +end |
| 99 | + |
| 100 | +local lines_demo_4=function() |
| 101 | + local x1=rnd(w) |
| 102 | + local y2=rnd(w) |
| 103 | + local y1=rnd(h) |
| 104 | + |
| 105 | + love.graphics.setColor( 0,1, 1, 1 ) |
| 106 | + love.graphics.line(x1,y1,x1,y2) |
| 107 | +end |
| 108 | + |
| 109 | +local lines_demo_5=function() |
| 110 | + local x1=rnd(w) |
| 111 | + local x2=rnd(w) |
| 112 | + local x3=rnd(w) |
| 113 | + local x4=rnd(w) |
| 114 | + |
| 115 | + local y1=rnd(h) |
| 116 | + local y2=rnd(h) |
| 117 | + local y3=rnd(h) |
| 118 | + local y4=rnd(h) |
| 119 | + |
| 120 | + love.graphics.setColor( rnd(),rnd(), rnd(), 1 ) |
| 121 | + |
| 122 | + love.graphics.line(x1,y1,x2,y2) |
| 123 | + love.graphics.line(x2,y2,x3,y3) |
| 124 | + love.graphics.line(x3,y3,x4,y4) |
| 125 | +end |
| 126 | + |
| 127 | + |
| 128 | +local lines_demo_6=function() |
| 129 | + local x1=rnd(w) |
| 130 | + local y2=rnd(w) |
| 131 | + local y1=rnd(h) |
| 132 | + |
| 133 | + love.graphics.setColor( 0,1, 1, 1 ) |
| 134 | + love.graphics.line(x1,y1,x1,y2) |
| 135 | +end |
| 136 | + |
| 137 | + |
| 138 | +--- |
| 139 | + |
| 140 | +rnd2=function() |
| 141 | + return rnd()-0.5 |
| 142 | +end |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | +local lines7={} |
| 147 | + |
| 148 | + |
| 149 | +local init_lines_7=function() |
| 150 | + --x1,y1,x2,y2,r,g,b |
| 151 | + local new_line=function() |
| 152 | + return {rnd(w),rnd(h),rnd(w),rnd(h),rnd(),rnd(),rnd()} |
| 153 | + end |
| 154 | + |
| 155 | + lines7[1]=new_line() |
| 156 | + lines7[2]=new_line() |
| 157 | + lines7[3]=new_line() |
| 158 | +end |
| 159 | + |
| 160 | + |
| 161 | +local lines_demo_7=function() |
| 162 | + for k,line in pairs(lines7) do |
| 163 | + line[1]=line[1]+rnd2() |
| 164 | + line[2]=line[2]+rnd2() |
| 165 | + line[3]=line[3]+rnd2() |
| 166 | + line[4]=line[4]+rnd2() |
| 167 | + |
| 168 | + love.graphics.setColor(line[5],line[6],line[7], 1 ) |
| 169 | + love.graphics.line(line[1],line[2],line[3],line[4]) |
| 170 | + end |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | +end |
| 175 | + |
| 176 | + |
| 177 | +--- |
| 178 | +love.keypressed=function(key) |
| 179 | + if key=="escape" then |
| 180 | + is_fullscreen=not is_fullscreen |
| 181 | + love.window.setFullscreen(is_fullscreen, "desktop") |
| 182 | + update_size() |
| 183 | + end |
| 184 | +end |
| 185 | + |
| 186 | + |
| 187 | +love.update=function() |
| 188 | + player.update() |
| 189 | +end |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | +local bg |
| 195 | +local bg_y=-3000 |
| 196 | +bg_draw=function() |
| 197 | + bg_y=bg_y+1 |
| 198 | + draw(bg,0,bg_y) |
| 199 | +end |
| 200 | + |
| 201 | + |
| 202 | +love.draw=function() |
| 203 | + love.graphics.setColor( 1,1, 1, 1 ) |
| 204 | + |
| 205 | + -- out of style |
| 206 | + --bg_draw() |
| 207 | + lines_demo_1() |
| 208 | + lines_demo_2() |
| 209 | + lines_demo_3() |
| 210 | + lines_demo_4() |
| 211 | + lines_demo_5() |
| 212 | + lines_demo_6() |
| 213 | + lines_demo_7() |
| 214 | + stars_demo() |
| 215 | + -- love.graphics.polygon('line', 0, 0, 200, 400, 200, 100, 100,100, 90,70) |
| 216 | + player.draw() |
| 217 | + |
| 218 | +end |
| 219 | + |
| 220 | + |
| 221 | +love.load=function() |
| 222 | + player=require("player") |
| 223 | + |
| 224 | + stars_refresh() |
| 225 | + |
| 226 | + love.window.setFullscreen(is_fullscreen, "desktop") |
| 227 | + |
| 228 | + update_size() |
| 229 | + init_lines_7() |
| 230 | + -- bg=love.graphics.newImage("res/bg1.png") |
| 231 | +end |
0 commit comments