The code in enemy is:
Code: Select all
enemy = {}
enemy.timer = 0
enemy.timerLim = math.random(2,3)
enemy.amount = math.random(1,5)
enemy.side = math.random(1,3)
function enemy.generate(dt)
enemy.timer = enemy.timer + dt
if enemy.timer > enemy.timerLim then
for i=1,enemy.amount do
if enemy.side == 1 then --left
enemy.spawn(100,150)
end
if enemy.side == 2 then --right
enemy.spawn(3500,1500)
end
if enemy.side == 3 then --middle
enemy.spawn(2000,1500)
end
enemy.side = math.random(1,4)
end
enemy.amount = math.random(1,5)
enemy.timerLim = math.random(3,5)
enemy.timer = 0
end
end
enemyImage = love.graphics.newImage("Enemy.png")
enemy.speed = 1000
enemy.width = 1
enemy.height = 1
enemy.friction = 7.5
function enemy.spawn(x,y)
table.insert(enemy, {x = x, y = y, xvel = 0, yvel = 0, health = 5,width = enemy.width,height = enemy.height})
end
function enemy.draw()
for i,v in ipairs(enemy) do
love.graphics.draw(enemyImage, v.x, v.y, enemy.width,enemy.height)
end
end
function enemy.physics(dt)
for i,v in ipairs(enemy) do
v.x = v.x + v.xvel * dt
v.y = v.y + v.yvel * dt
v.xvel = v.xvel * (1 - math.min(dt*enemy.friction, 1))
v.yvel = v.yvel * (1 - math.min(dt*enemy.friction, 1))
end
end
function enemy.AI(dt)
for i,v in ipairs(enemy) do
if player.x + player.width / 2 < v.x + v.width / 2 then
if v.xvel > -enemy.speed then
v.xvel = v.xvel - enemy.speed * dt
end
end
if player.x + player.width / 2 > v.x + v.width / 2 then
if v.xvel < enemy.speed then
v.xvel = v.xvel + enemy.speed * dt
end
end
end
end
function enemy.bullet_collide()
for i,v in ipairs(enemy) do
for ia,va in ipairs(bullet) do
if va.x + va.width > v.x and
va.x < v.x + v.width and
va.y + va.height > v.y and
va.y < v.y + v.height then
table.remove(enemy, i)
table.remove(bullet, ia)
end
end
end
function enemy.player_collide()
for i,v in ipairs(enemy) do
for ia, va in ipairs(player) do
if va.x + va.width > v.x and
va.x < v.x + v.width and
va.y + va.height > v.y and
va.y < v.y + v.height then
va.health = va.health -25
end
end
end
end
function DRAW_ENEMY()
end
function UPDATE_ENEMY(dt)
end
end
Code: Select all
local sdping = love.sound.newSoundData("Bullet.mp3")
function playSound(sd)
love.audio.newSource(sd, "static"):play()
end
player = {}
player.health = 100
player.x = 0
player.y = 1500
pic = love.graphics.newImage("flappy.png")
player.xvel = 0
player.y_velocity = 1500
player.width = 1
player.height = 1
player.speed = 300
player.friction = 3.5
jump_height = -300
gravity = -400
health = player.health
background = {}
background2 = love.graphics.newImage("background.png")
floor = {}
floor.x = 0
floor.y = 1580
floorPic = love.graphics.newImage("floor.png")
function player_draw()
love.graphics.draw(background2, 0, 0)
love.graphics.draw(pic, player.x, player.y)
love.graphics.draw(floorPic, floor.x, floor.y)
end
function player_control(dt)
player.x = player.x + player.xvel
player.xvel = player.xvel * (1 - math.min(dt*player.friction, 1))
if love.keyboard.isDown("d") then
player.x = player.x + (player.speed * dt)
end
if love.keyboard.isDown('a') then
player.x = player.x - (player.speed * dt)
end
if player.y_velocity ~= 0 then
player.y = player.y + player.y_velocity * dt
player.y_velocity = player.y_velocity - gravity * dt
if player.y > 1500 then
player.y_velocity = 1500
player.y = 1500
end
end
end
function love.keypressed(key)
if key == " " then
if player.y_velocity == 1500 then
player.y_velocity = jump_height
end
end
end
function player.shoot(key)
if key == 'up' then
bullet.spawn(player.x + player.width /2 - bullet.width / 2,player.y - bullet.height,'up')
end
if key == 'down' then
bullet.spawn(player.x + player.width /2 - bullet.width / 2,player.y + bullet.height,'down')
end
if key == 'left' then
bullet.spawn(player.x - bullet.width,player.y + player.height / 2 - bullet.height /2, 'left')
end
if key == 'right' then
bullet.spawn(player.x + player.width,player.y + player.height / 2 - bullet.height /2, 'right')
end
end
function player.death()
if player.health < 1 then
player.x = 0
end
end