From 2da53b81ef33616ea511bdbdbee2ab2557754a5b Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Fri, 4 Nov 2016 15:33:19 +0100 Subject: [PATCH] Add button up --- assets/sprite/button.png | Bin 0 -> 7188 bytes assets/sprite/heart.png | Bin 0 -> 2931 bytes main.lua | 36 ++++++++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 assets/sprite/button.png create mode 100644 assets/sprite/heart.png diff --git a/assets/sprite/button.png b/assets/sprite/button.png new file mode 100644 index 0000000000000000000000000000000000000000..7de212c9188df4fe504a42c9138bfafbac0ab822 GIT binary patch literal 7188 zcma)gWmH^Cx9x6d(l`VsNSZ*f-~kf6Y24id3BfIBaA|@|a3^?x;10nF?gR+hNN|UP zJKR3wy>GmC@2~r#_N-d9#;&Tl*I0Aa4pUW@!NY!r4FCY1oUEie3j0yb6!Qt{*%j=E zg90oESv_X}!0-CEf%@!!m;wN{ij{w^&h3rB(|!G6+cd8(^|KLUeREXqiXl$X}808>1Pg z!8kfSQYm@-c?tfW4g)}TEGg==r}yro_~oOc{89Dz@7Z_TpFF(NS`_3J%l^aA1pPvR ziBQ+2WAzdMPMYn1{b9yLM_2}|jJZ7?iQUU&zXTBGa&e9TU?j=Fp*dJ1)`tlIlG*;O zmEu%qzbM!`o>2e7Sono=_klkU&d}WnCxm00BB-4{u#|p*GY5}U(y)Hu`~#!m?NGA} zj(5Q4=+yd&FXBLOV~m;ki@C)g3oPD`No-6v9}4;yu1g<0F%O zrY_uR(PY`_znyBIiA3_}Z2c~=B$$sDmFVN@*rtHI?zZLP=ayC6umj@++?iE4NT-O)q%wic7sEWX~kuA6?K(oWq&}a8F-)0W4*yb4^-=9dJ+Fa zp_Z}f>2){7M;`7FU0F8zX`*OiPC~CxiS9QHL}3yj~|#fwW)>(B(OnW^#`qItaq)yUZ+~8J2Ak{_y}|SextUhQhPq{(3!MpLq zEQLp0D=$rb@kfs4Q@&_@cv()pdWBlZ4`SZWX#yhw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Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0001Z8!wS)?Z7}D7Tym0O2`K%)u4Ab&l63)lbv002ovPDHLkV1liDb=d#_ literal 0 HcmV?d00001 diff --git a/main.lua b/main.lua index 216cc0d..772a26f 100644 --- a/main.lua +++ b/main.lua @@ -71,6 +71,21 @@ function love.load() love.graphics.newQuad(explosion.frame_width * 9, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()), love.graphics.newQuad(explosion.frame_width * 10, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()) } + + -- Button + control_up, control_right, control_left, control_quit = false, false, false, false + button = {} + button.img = love.graphics.newImage('assets/sprite/button.png') + button.num_frames = 2 + button.frame_width = button.img:getWidth() / button.num_frames + button.frame_height = button.img:getHeight() + button.frames = { + love.graphics.newQuad(button.frame_width * 0, 0, button.frame_width, button.frame_height, button.img:getWidth(), button.img:getHeight()), + love.graphics.newQuad(button.frame_width * 1, 0, button.frame_width, button.frame_height, button.img:getWidth(), button.img:getHeight()) + } + button_up = {} + button_up.x = window.width - button.img:getWidth() + button_up.y = level.y + (camera.height / 4) + -camera.y -- Generates initial asteroids asteroids_collision = 40 asteroids_collision_polygon = 8 @@ -123,7 +138,7 @@ function love.update(dt) fire.pos_frame = 1 end -- Controls - local control_up, control_right, control_left, control_quit = false, false, false, false + control_up, control_right, control_left, control_quit = false, false, false, false -- Keyboard if love.keyboard.isDown('escape') or love.keyboard.isDown('q') then control_quit = true @@ -140,16 +155,9 @@ function love.update(dt) if love.mouse.isDown(1) then local x, y = love.mouse.getPosition() -- Up - if x > width / 3 and x < width - (width / 3) and y < height / 3 then + if x > button_up.x and x < button_up.x + button.img:getWidth() and y > button_up.y + camera.y and y < button_up.y + button.img:getHeight() + camera.y then control_up = true end - -- Left - if x < width / 3 then - control_left = true - elseif x > width - (width / 3) then - -- Right - control_right = true - end end -- Ship move if control_up then @@ -270,6 +278,14 @@ function love.draw() if explosion.active then love.graphics.draw(explosion.img, explosion.frames[explosion.pos_frame], ship.body:getX(), ship.body:getY() + ship.img:getHeight() / 2) end + -- Controls + -- Up + button_up.y = level.y + (camera.height / 4) + -camera.y + local button_frame_up = button.frames[1] + if control_up then + button_frame_up = button.frames[2] + end + love.graphics.draw(button.img, button_frame_up, button_up.x, button_up.y) -- Texts if not play and not win then -- Game over love.graphics.print(text_restart.text, (camera.width / 2) - (text_restart.size / 2), -camera.y + (camera.height / 2)) @@ -277,7 +293,7 @@ function love.draw() if not play and win then -- Win love.graphics.print(text_good, (camera.width / 2) - (text_good.size / 2), -camera.y + (camera.height / 2)) end - love.graphics.print('Level ' .. level.num, level.x, level.y + -camera.y) + love.graphics.print('Level ' .. level.num, level.x, level.y + -camera.y) -- Score end --------------------------------- Functions