First version

This commit is contained in:
2022-04-11 18:34:26 +03:00
committed by GitHub
parent d68a4f0da7
commit 37e6bd6a28
32 changed files with 824 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
-----Отрисовка Бонусов-----
function game.bonus.draw()
for i,v in ipairs(bonus) do
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(v.texture, v.x-25, v.y-25)
end
end
+11
View File
@@ -0,0 +1,11 @@
function game.bonus.load()
bonus = {}
bonus.texture = {}
bonus.types = 5
bonus.textures = {}
bonus.textures.lvlUp = love.graphics.newImage("textures/bonus/lvlUp.png")
bonus.textures.laser = love.graphics.newImage("textures/bonus/laser.png")
bonus.textures.plasma = love.graphics.newImage("textures/bonus/plasma.png")
bonus.textures.health = love.graphics.newImage("textures/bonus/health.png")
bonus.textures.life = love.graphics.newImage("textures/bonus/life.png")
end
+85
View File
@@ -0,0 +1,85 @@
-----Создание Бонусов-----
function game.bonus.create(enemyX, enemyY, type)
local locBonus = {}
locBonus.type = type
locBonus.x = enemyX
locBonus.y = enemyY
locBonus.width = 50
locBonus.height = 50
locBonus.angle = 0
if type == 1 then
locBonus.texture = bonus.textures.lvlUp
elseif type == 2 then
locBonus.texture = bonus.textures.laser
elseif type == 3 then
locBonus.texture = bonus.textures.plasma
elseif type == 4 then
locBonus.texture = bonus.textures.health
elseif type == 5 then
locBonus.texture = bonus.textures.life
end
table.insert(bonus, locBonus)
end
-----Удаление Бонусов-----
function game.bonus.delete(deletedBonuses)
for i,v in ipairs(deletedBonuses) do
table.remove(bonus, v)
end
end
-----Обновление Бонусов-----
function game.bonus.update(dt)
local deletedBonuses = {}
--Перебор Бонусов--
for i,v in ipairs(bonus) do
--Обновление Координат--
v.x = v.x - dt * 250
v.y = v.y + dt * 500 * math.cos(v.angle)
v.angle = v.angle + 0.05
--Удаление Бонусов Когда Они Уходят Далеко за Экран--
if v.x < -100 then
table.insert(deletedBonuses, i)
end
if CheckCollision(v.x, v.y, v.width, v.height, player.x, player.y, player.width, player.height) then
if v.type == 1 then
player.levelUp = true
player.score = player.score + 200
elseif v.type == 2 then
player.weapon.type.new = "laser"
player.weapon.changed = true
player.score = player.score + 100
elseif v.type == 3 then
player.weapon.type.new = "plasma"
player.weapon.changed = true
player.score = player.score + 100
elseif v.type == 4 then
if player.health.current + 100 < player.health.max then
player.health.current = player.health.current + 100
else
player.health.current = player.health.max
end
player.score = player.score + 50
elseif v.type == 5 then
if player.lifes.current < player.lifes.max then
player.lifes.current = player.lifes.current + 1
end
player.score = player.score + 250
end
table.insert(deletedBonuses, i)
end
end
game.bonus.delete(deletedBonuses)
end
+20
View File
@@ -0,0 +1,20 @@
-----Отрисовка Врагов-----
function game.enemy.draw()
for i,v in ipairs(enemy) do
if v.type == 1 then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(v.texture.ship, v.x, v.y, v.angle, -1, 1)
elseif v.type == 2 then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(v.texture.ship, v.x, v.y, v.angle, -1, 1)
end
end
end
function game.enemy.shot.draw()
for i,v in ipairs(enemy.shot) do
love.graphics.setColor(255, 100, 0, 255)
love.graphics.draw(v.texture, v.x, v.y, v.angle, 1, 1)
end
end
+47
View File
@@ -0,0 +1,47 @@
function game.enemy.load()
enemy = {}
enemy.shot = {}
--Тип Врага №1--
enemy.type1 = {}
enemy.type1.texture = {}
enemy.type1.texture.ship = love.graphics.newImage("textures/enemy/1/ship.png")
enemy.type1.texture.shot = love.graphics.newImage("textures/enemy/1/shot.png")
enemy.type1.shot = {}
enemy.type1.shot.height = {}
enemy.type1.shot.damage = 100
enemy.type1.shot.speed = 1000
enemy.type1.width = 100
enemy.type1.height = 50
enemy.type1.health = 250
enemy.type1.x = 1500
enemy.type1.y = 360
enemy.type1.speed = {current = 0, max = 2500}
enemy.type1.acceleration = 500
enemy.massEnemyIndex = 0
--Тип Врага №1--
enemy.type2 = {}
enemy.type2.texture = {}
enemy.type2.texture.ship = love.graphics.newImage("textures/enemy/2/ship.png")
enemy.type2.texture.shot = love.graphics.newImage("textures/enemy/2/shot.png")
enemy.type2.shot = {}
enemy.type2.shot.height = {}
enemy.type2.shot.damage = 150
enemy.type2.shot.speed = 500
enemy.type2.width = 100
enemy.type2.height = 50
enemy.type2.health = 250
enemy.type2.x = 1500
enemy.type2.y = 360
enemy.type2.speed = {current = 0, max = 1000}
enemy.type2.acceleration = 250
enemy.massEnemyIndex = 0
test = {}
test.angle1 = {x = 0, y = 0}
test.angle2 = {x = 0, y = 0}
test.angle3 = {x = 0, y = 0}
test.angle4 = {x = 0, y = 0}
end
+263
View File
@@ -0,0 +1,263 @@
-----Создание Врагов-----
function game.enemy.create(dt)
if enemy.count == nil then
enemy.count = enemyOnStart
end
if enemy.left > 0 then
if enemy.count <= 0 and current.enemies < 5 then
enemy.massEnemyIndex = enemy.massEnemyIndex+1
enemy.type = level.lvl1.enemy[enemy.massEnemyIndex]
local locEnemy = {}
locEnemy.texture = {}
locEnemy.speed = {}
locEnemy.shot = {}
if enemy.type == 1 then
locEnemy.sideSpeed = 0
locEnemy.angle = math.random(math.pi - 0.5, math.pi + 0.5)
locEnemy.reload = 0
locEnemy.type = 1
locEnemy.width = enemy.type1.width
locEnemy.height = enemy.type1.height
locEnemy.health = enemy.type1.health
locEnemy.x = enemy.type1.x
locEnemy.y = enemy.type1.y
locEnemy.realX = locEnemy.x + locEnemy.width / 2
locEnemy.realY = locEnemy.y + locEnemy.height / 2
locEnemy.speed.current = enemy.type1.speed.current
locEnemy.speed.max = enemy.type1.speed.max
locEnemy.shot.damage = enemy.type1.shot.damage
locEnemy.shot.speed = enemy.type1.shot.speed
locEnemy.acceleration = enemy.type1.acceleration
locEnemy.texture.ship = enemy.type1.texture.ship
locEnemy.texture.shot = enemy.type1.texture.shot
enemy.massEnemyIndex = enemy.massEnemyIndex+1
enemy.delay = 250
table.insert(enemy, locEnemy)
elseif enemy.type == 2 then
locEnemy.sideSpeed = 0
locEnemy.angle = math.random(math.pi - 0.5, math.pi + 0.5)
locEnemy.reload = 0
locEnemy.type = 2
locEnemy.width = enemy.type2.width
locEnemy.height = enemy.type2.height
locEnemy.health = enemy.type2.health + 100
locEnemy.x = enemy.type2.x
locEnemy.y = enemy.type2.y
locEnemy.realX = locEnemy.x + locEnemy.width / 2
locEnemy.realY = locEnemy.y + locEnemy.height / 2
locEnemy.speed.current = enemy.type2.speed.current
locEnemy.speed.max = enemy.type2.speed.max
locEnemy.shot.damage = enemy.type2.shot.damage
locEnemy.shot.speed = enemy.type2.shot.speed
locEnemy.acceleration = enemy.type2.acceleration
locEnemy.texture.ship = enemy.type2.texture.ship
locEnemy.texture.shot = enemy.type2.texture.shot
enemy.massEnemyIndex = enemy.massEnemyIndex+1
enemy.delay = 250
table.insert(enemy, locEnemy)
end
current.enemies = current.enemies + 1
enemy.count = enemy.delay
enemy.left = enemy.left - 1
else
enemy.count = enemy.count - 100 * dt
end
else
current.levelCompleted = true
current.level = current.level + 1
current.levelChanged = true
end
end
-----Удаление Врагов-----
function game.enemy.delete(deletedEnemies)
for i,v in ipairs(deletedEnemies) do
table.remove(enemy, v)
current.enemies = current.enemies - 1
end
end
-----Обновление Врагов-----
function game.enemy.update(dt)
local deletedEnemies = {}
local deletedPlayerShots = {}
--Перебор Врагов--
for i,v in ipairs(enemy) do
--Разгон--
if v.speed.current < v.speed.max and v.speed.current > -v.speed.max then
if DistanceMeasurement(player.x, player.y, player.width, player.height, v.x, v.y, v.width, v.height) > 500 then
v.speed.current = v.speed.current + v.acceleration * dt
else
if v.speed.current > 0 then
v.speed.current = v.speed.current - v.acceleration * dt * (v.speed.current / 100 + 0.1)
else
v.speed.current = v.speed.current - v.acceleration * dt
end
end
end
if v.realY > player.realY then
v.sideSpeed = v.sideSpeed + dt * 75
else
v.sideSpeed = v.sideSpeed - dt * 75
end
--Обновление Координат--
v.x = v.x + v.speed.current * dt * math.cos(v.angle)
v.y = v.y + v.speed.current * dt * math.sin(v.angle)
v.x = v.x + v.sideSpeed * dt * math.cos(v.angle+math.pi/2)
v.y = v.y + v.sideSpeed * dt * math.sin(v.angle+math.pi/2)
--Расчет Углов--
test.angle1 = {x = v.x, y = v.y}
test.angle2 = {x = v.x + v.width * math.cos(v.angle+math.pi), y = v.y + v.width * math.sin(v.angle+math.pi) }
test.angle3 = {x = test.angle2.x + v.height * math.sin(v.angle+math.pi), y = test.angle2.y - v.height * math.cos(v.angle+math.pi) }
test.angle4 = {x = v.x + v.height * math.sin(v.angle+math.pi), y = v.y - v.height * math.cos(v.angle+math.pi) }
--Расчет Реальных Координат--
v.realX = (test.angle1.x + test.angle3.x) / 2
v.realY = (test.angle1.y + test.angle3.y) / 2
--Поворот--
if directionCheckUp7(v.realX, v.realY, v.angle, player.realX, player.realY) then
v.angle = v.angle - dt
else
v.angle = v.angle + dt
end
--Удаление Врагов Когда Их ХП Падает Ниже Нуля--
if v.health <= 0 then
table.insert(deletedEnemies, i)
player.score = player.score + 500
local bonusCreate = math.random(1, 10)
if bonusCreate == 1 then
game.bonus.create(v.x, v.y, math.random(1, bonus.types) )
end
end
--Удаление Врагов Когда Они Уходят Далеко за Экран--
if v.x < -1000 or v.x > 2280 or v.y < -1000 or v.y > 1720 then
table.insert(deletedEnemies, i)
end
--Перебор Снарядов и Проверка на Попадания--
for ii,vv in ipairs(player.shot) do
if hitCheck(v.x, v.y, v.width, v.height, v.angle, vv.x, vv.y, vv.size.width, vv.size.height) then
v.health = v.health - math.random(vv.damage*0.5, vv.damage*2)
v.angle = v.angle + math.random(-1, 1) * player.weapon.projectile.kick
v.speed.current = v.speed.current - player.weapon.projectile.kick * 10
table.insert(deletedPlayerShots, ii)
end
end
game.player.shot.delete(deletedPlayerShots)
--Стрельба--
if v.reload < 0 then
game.enemy.shot.create(v)
v.reload = 10
else
v.reload = v.reload - dt*5
end
end
game.enemy.delete(deletedEnemies)
end
function directionCheckUp7(enemyX, enemyY, enemyA, playerX, playerY)
local y = (playerX - enemyX) * math.tan(enemyA) + enemyY
if y < playerY then
return true
else
return false
end
end
function hitCheck(enemyX, enemyY, enemyW, enemyH, enemyA, shotX, shotY, shotW, shotH)
-- 1 2
-- 4 3
local max = {x = math.max(test.angle1.x, test.angle2.x, test.angle3.x, test.angle4.x), y = math.max(test.angle1.y, test.angle2.y, test.angle3.y, test.angle4.y)}
local min = {x = math.min(test.angle1.x, test.angle2.x, test.angle3.x, test.angle4.x), y = math.min(test.angle1.y, test.angle2.y, test.angle3.y, test.angle4.y)}
local shell = {x = shotX + shotW / 2, y = shotY + shotH / 2}
if ( (shell.y > min.y) and (shell.y < max.y) and (shell.x > min.x) and (shell.x < max.x) ) then
return true
else
return false
end
end
function game.enemy.shot.create(v)
local shot = {}
shot.x = v.realX
shot.y = v.realY
shot.angle = v.angle
shot.speed = v.shot.damage
shot.damage = v.shot.speed
shot.size = {}
shot.size.width = 15
shot.size.height = 15
shot.texture = v.texture.shot
table.insert(enemy.shot, shot)
end
function game.enemy.shot.update(dt)
local deletedEnemyShots = {}
for i,v in ipairs(enemy.shot) do
v.x = v.x + v.speed * dt * math.cos(v.angle)
v.y = v.y + v.speed * dt * math.sin(v.angle)
if v.x < 0 or v.y > 720 or v.y < 0 or v.x > 1280 then
table.insert(deletedEnemyShots, i)
end
if CheckCollision(v.x, v.y, v.size.width, v.size.height, player.x, player.y, player.width, player.height) then
if not current.godmode then
player.health.current = player.health.current - v.damage
end
table.insert(deletedEnemyShots, i)
end
end
game.enemy.shot.delete(deletedEnemyShots)
end
function game.enemy.shot.delete(deletedEnemyShots)
for i,v in ipairs(deletedEnemyShots) do
table.remove(enemy.shot, v)
end
end
function game.enemy.reset()
while current.enemies ~= 0 do
table.remove(enemy, i)
current.enemies = current.enemies - 1
end
end
+100
View File
@@ -0,0 +1,100 @@
function game.interface()
--HP--
game.player.health()
game.player.score()
--Перегрев--
game.player.heat()
--Пауза--
if current.pause then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.drawq(menu.texture.buttons, menu.texture.interface.pause, 490, 260)
end
game.menu()
end
-----Отрисовка Меню в Игре-----
function game.menu()
if player.dead then
menu.selection()
menu.enter()
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(menu.texture.dead, 50, 50)
love.graphics.setColor(255, 255, 255, 255)
if current.button == buttonRestart then
love.graphics.drawq(menu.texture.buttons, menu.texture.button.restart.pressed, 200, 500)
else
love.graphics.drawq(menu.texture.buttons, menu.texture.button.restart.unpressed, 200, 500)
end
if current.button == buttonMenu then
love.graphics.drawq(menu.texture.buttons, menu.texture.button.menu.pressed, 900, 500)
else
love.graphics.drawq(menu.texture.buttons, menu.texture.button.menu.unpressed, 900, 500)
end
end
end
-----Отрисовка HP Игрока-----
function game.player.health()
local health = {x = 50, y = 50, multiplier = 0.5} --координаты левого верхнего угла полоски здоровья и множитель зависимости от HP
if not player.dead then
--Красное--
love.graphics.setColor(255, 0, 0, 100)
love.graphics.rectangle("fill", health.x + player.health.current * health.multiplier, health.y, (player.health.max - player.health.current) * health.multiplier, 25)
--Зеленое--
love.graphics.setColor(0, 255, 0, 100)
love.graphics.rectangle("fill", health.x, health.y, player.health.current * health.multiplier, 25)
if current.godmode then
love.graphics.setColor(255, 100, 0, 200)
love.graphics.print("Godmode", health.x+175, health.y, 0, 2.5, 2.5, 0, 0)
end
else
love.graphics.setColor(255, 0, 0, 100)
love.graphics.rectangle("fill", health.x, health.y, player.health.max * health.multiplier, 25)
end
end
-----Отрисовка Перегрева Оружия-----
function game.player.heat()
local heat = {x = 50, y = 80, multiplier = 5} --координаты левого верхнего угла полоски перегрева и множитель зависимости от перегрева
if player.weapon.heat.current >= 0 then
--Серое--
love.graphics.setColor(100, 100, 100, 100)
love.graphics.rectangle("fill", heat.x + player.weapon.heat.current * heat.multiplier, heat.y, (player.weapon.heat.max - player.weapon.heat.current) * heat.multiplier, 10)
--Оранжевое--
love.graphics.setColor(220, 100, 0, 100)
love.graphics.rectangle("fill", heat.x, heat.y, player.weapon.heat.current * heat.multiplier, 10)
else
love.graphics.setColor(100, 100, 100, 100)
love.graphics.rectangle("fill", heat.x, heat.y, player.weapon.heat.max * heat.multiplier, 10)
end
end
-----Очки и Жизни-----
function game.player.score()
local score = {x = 50, y = 100}
local life = {x = 50, y = 150}
love.graphics.setColor(255, 255, 255, 100)
love.graphics.print(player.score, score.x, score.y, 0, 2.5, 2.5, 0, 0)
for i = 0, player.lifes.current-1 do
love.graphics.draw(menu.texture.live, life.x + life.x * i /2, life.y)
end
end
+119
View File
@@ -0,0 +1,119 @@
-----КОНСТАНТЫ-----
enemyOnStart = 1
-----Массивы Функций-----
game = {} --массив с функциями по работе с экраном игры
game.enemy = {} --массив с функциями по работе с врагами
game.enemy.shot = {} --массив с функциями по работе с выстрелами игрока
game.player = {} --массив с функциями по работе с игроком
game.player.weapon = {} --массив с функциями по работе с оружием игрока
game.player.shot = {} --массив с функциями по работе с выстрелами игрока
game.test = {} --массив с функциями для тестирования
game.bonus = {}
game.background = {}
game.level = {}
-----ОТРИСОВКА ИГРЫ-----
function game.draw()
game.background.draw()
--Игрок--
game.player.draw()
game.player.shot.draw()
--Враги--
game.enemy.draw()
game.enemy.shot.draw()
--Бонусы--
game.bonus.draw()
--Интерфейс--
game.interface()
--Тестирование--
game.test.draw()
end
-----ОБНОВЛЕНИЕ ИГРЫ-----
function game.update(dt)
game.background.update(dt)
game.level.update()
game.player.weapon.update()
game.player.dead()
game.player.control(dt)
game.player.shot.update(dt)
game.player.levelUpdate()
enemy.type = 1
game.enemy.create(dt)
game.enemy.update(dt)
game.enemy.shot.update(dt)
game.bonus.update(dt)
end
function DistanceMeasurement(box1x, box1y, box1w, box1h, box2x, box2y, box2w, box2h)
local x1 = box1x + box1w/2
local y1 = box1y + box1h/2
local x2 = box2x + box2w/2
local y2 = box2y + box2h/2
local dist = ( (x1 - x2)^2 + (y1 - y2)^2 )^0.5
return dist
end
function CheckCollision(box1x, box1y, box1w, box1h, box2x, box2y, box2w, box2h)
if box1x > box2x + box2w - 1 or -- box1 на правой стороне box2?
box1y > box2y + box2h - 1 or -- box1 под box2?
box2x > box1x + box1w - 1 or -- box2 на правой стороне box1?
box2y > box1y + box1h - 1 -- box2 под box1?
then
return false -- Нет коллизии!!
else
return true -- Есть контакт!
end
end
function game.background.load()
background1 = {}
background1.texture = love.graphics.newImage("textures/background.png")
background1.x = 0
background1.y = 0
background2 = {}
background2.texture = love.graphics.newImage("textures/background.png")
background2.x = 2560
background2.y = 0
end
function game.background.update(dt)
background1.x = background1.x - dt * 500
if background1.x < -2560 then
background1.x = 1280
end
background2.x = background2.x - dt * 500
if background2.x < -2560 then
background2.x = 1280
end
end
function game.background.draw()
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(background1.texture, background1.x, background1.y)
love.graphics.draw(background2.texture, background2.x, background2.y)
end