Code: Select all
screen = {}
screen.w, screen.h = love.graphics.getDimensions()
quad = love.graphics.newQuad( 0, 0, screen.w, screen.h, screen.w, screen.h)
function newgame()
terrorist={life=30}
gun={bullets=7,damage=2,time=0,delay=0.5}
blood={}
time=0
sniper_count=0
win=nil
lose=nil
sniper=nil
blood_img = love.image.newImageData("img/blood.png")
blood.w, blood.h = blood_img:getWidth(), blood_img:getHeight()
go=nil
tri = love.image.newImageData("img/tr.png")
terrorist.w, terrorist.h = tri:getWidth(), tri:getHeight()
tr = love.graphics.newImage(tri)
terrorist.x, terrorist.y = screen.w/2-terrorist.w/2, screen.h/2-terrorist.h/2
end
function love.load()
newgame()
cursor = love.graphics.newImage("img/cursor.png")
map = love.graphics.newImage("img/map.png")
gun_img = love.graphics.newImage("img/gun.png")
sniper_img = love.graphics.newImage("img/sniper.png")
sniperdrop = love.graphics.newImage("img/sniperdrop.png")
sniperm = love.graphics.newImage("img/sniperm.png")
hshot = love.audio.newSource("audio/hshot.mp3")
shot_gun = love.audio.newSource("audio/gun.wav")
shot_sniper = love.audio.newSource("audio/sniper.wav")
shot = shot_gun
fail = love.audio.newSource("audio/fail.wav")
swap = love.audio.newSource("audio/swap.wav")
add = love.audio.newSource("audio/add.wav")
sub = love.audio.newSource("audio/sub.wav")
die = love.audio.newSource("audio/die.wav")
go1 = love.audio.newSource("audio/go.wav")
love.mouse.setVisible(false)
end
function love.update(dt)
time = time + dt
if math.floor(time)>=10 or (sniper and gun.bullets<=0) then lose=true end
end
function love.mousereleased( x, y, button, istouch )
if win or lose then love.load() end
if button==1 and gun.time+gun.delay<time then
isshot=true
gun.time=time
if gun.bullets>0 then
shot:stop() shot:play()
else
fail:stop() fail:play()
end
elseif button==2 and sniper then
if sniper_count==1 then
sub:stop();sub:play()
sniper_count=0
elseif sniper_count==0 then
add:stop();add:play()
sniper_count=sniper_count+1
end
end
end
function enemy(x,y)
if win or lose then return false end
if gun.bullets>0 and isshot and (x>terrorist.x and x<terrorist.x+terrorist.w) and (y>terrorist.y and y<terrorist.y+terrorist.h-5) then
if y<terrorist.y+15 and sniper_count>0 then hshot:play() win=true end
for tr_i=1, blood.h-1 do
for tr_j=1, blood.w-1 do
tr_r,tr_g,tr_b,tr_a = blood_img:getPixel(tr_j,tr_i)
if ((x-terrorist.x)+tr_j)<(terrorist.w)+25 and ((y-terrorist.y)+tr_i)<(terrorist.h) then
if tr_a>200 and ((x-terrorist.x)+tr_j)-25>0 and ((y-terrorist.y)+tr_i)-25>0 then
tr_red,tr_green,tr_blue,tr_alpha = tri:getPixel((x-terrorist.x)+tr_j-25,(y-terrorist.y)+tr_i-25)
if tr_alpha>0 then tri:setPixel(((x-terrorist.x)+tr_j)-25,((y-terrorist.y)+tr_i)-25, tr_r,tr_g,tr_b,tr_a) end
end
end
end
end
tr = love.graphics.newImage(tri)
terrorist.life=terrorist.life-gun.damage
if terrorist.life<=0 then
die:play()
win=true
end
end
love.graphics.draw(tr,terrorist.x,terrorist.y)
end
function getgun(x,y,w,h)
if sniper then return false end
local xs , ys =terrorist.x+terrorist.w+10, terrorist.y+terrorist.h-10
if isshot and (x>xs and x<xs+w) and (y>ys and y<ys+h) then
sniper=true
gun_img=sniper_img
gun={bullets=5,damage=10,time=0,delay=1.5}
shot = shot_sniper
swap:play()
end
love.graphics.draw(sniperdrop, xs, ys)
end
function love.draw()
if not go then go1:play() go=true end
x, y = love.mouse.getPosition()
if sniper_count>0 then love.graphics.push() love.graphics.translate(100-x-100,100-y-100) love.graphics.scale(2,2) end
love.graphics.draw(map, quad)
enemy(x,y)
getgun(x,y,sniperdrop:getWidth(),sniperdrop:getHeight())
if sniper_count==0 then
love.graphics.draw(cursor, x-cursor:getWidth()/2, y-cursor:getHeight()/2)
love.graphics.draw(gun_img, x+gun_img:getWidth()/2, screen.h-gun_img:getHeight())
else
love.graphics.pop()
love.graphics.draw(sniperm,x-sniperm:getWidth()/2,y-sniperm:getHeight()/2)
end
love.graphics.setColor(0,0,0,100)
love.graphics.rectangle("fill", 0, 0, screen.w, 75)
love.graphics.setColor(255,255,255,255)
if not win and not lose then
love.graphics.print("Bullets: "..gun.bullets.." eHP: "..(math.floor((terrorist.life/30)*100)).."% "..string.format("%02i",(10-time)), 10,10,0,3)
elseif win then
love.graphics.print("You Win", 10,10,0,3)
elseif lose then
love.graphics.print("You Lose", 10,10,0,3)
end
if isshot and gun.bullets>0 then gun.bullets=gun.bullets-1 end
isshot=nil
end