haha guess who forgot to push

This commit is contained in:
UndeadMaelys 2022-01-18 00:53:03 +01:00
parent a333bcc9b7
commit 9b6e9cf339
25 changed files with 439 additions and 181 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 B

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 184 B

BIN
assets/projectileCard5.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

BIN
assets/projectileCard6.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

BIN
assets/projectileCard7.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

BIN
assets/projectileCard8.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

107
main.lua
View File

@ -3,107 +3,30 @@ function love.load()
love.graphics.setColor(1,1,1) love.graphics.setColor(1,1,1)
love.keyboard.setKeyRepeat(true) love.keyboard.setKeyRepeat(true)
love.graphics.setDefaultFilter("nearest") -- good pixel love.graphics.setDefaultFilter("nearest") -- good pixel
window_width = 600 windowWidth = 600
window_height = 600 windowHeight = 600
t = 0 currentMenu = 1
TimeDone = false MenuInit(currentMenu)
BackgroundColor = {0,0,0}
BackgroundTimer = 0
BackgroundPeriod = 0.1
EnemyTimer = 0
EnemyPeriod = 0.8
You = Player:New(1/2*window_width,4/5*window_height)
end end
function love.update(dt) function love.update(dt)
current_dt = dt current_dt = dt
if doStageStep == true then
You:Input() stageStep()
for _, obj in pairs(List.Simulate) do
obj:Step()
end end
if currentMenu ~= nil
for _, bullet in pairs(List.FriendlyBullet) do and currentMenu > 0 then
for _, enemy in pairs(List.Enemy) do MenuStep(currentMenu)
if bullet:CollisionWith(enemy) then
if bullet.hits > 0 then
enemy:Damage(bullet.damage)
bullet.hits = bullet.hits - 1
if bullet.hits <= 0 then
bullet:Kill()
end end
end end
end
end
end
for _, bullet in pairs(List.EnemyBullet) do
if bullet:CollisionWith(You) then
if bullet.hits > 0 then
You:Damage(bullet.damage)
bullet.hits = bullet.hits - 1
if bullet.hits <= 0 then
bullet:Kill()
end
end
end
end
if TimeDone == false then
t = t + dt
EnemyTimer = EnemyTimer + dt
BackgroundTimer = BackgroundTimer + dt
end
if EnemyTimer >= 0 then --EnemyPeriod then
--EnemyTimer = EnemyTimer - EnemyPeriod
EnemyTimer = -1000000000000
for i=1, 1 do
local rand = 1 --math.random(10)
if rand == 1 then
local rand_x = math.random(-100,100)
local rand_y = math.random(-100,100)
local x = Shooter:New(1/2*window_width,1/5*window_height)
else
local rand_x = math.random(-10,10)
local rand_y = math.random(-10,10)
local x = Fang:New(window_width/2+rand_x,window_height/2+rand_y)
end
end
end
end
function love.keypressed(key)
end
function love.draw() function love.draw()
love.graphics.setColor(BackgroundColor) if doStageDraw == true then
love.graphics.rectangle("fill",0,0,window_width,window_height) stageDraw()
love.graphics.setColor(1,1,1)
You:Draw()
for _, obj in pairs(List.Simulate) do
obj:Draw()
end end
for _, enemy in pairs(List.Enemy) do if currentMenu ~= nil
if enemy.show_health == true then enemy:DrawHealth() end and currentMenu > 0 then
MenuDisplay(currentMenu)
end end
local width = You.max_health*3 love.graphics.print(love.timer.getFPS(), 10, windowHeight-20)
local height = 20
love.graphics.setColor(1,1,1)
love.graphics.rectangle("fill",20,10,width, height)
love.graphics.setColor(0,1,0)
love.graphics.rectangle("fill",20+1,10+1,You.health/You.max_health*(width)-2, height-2)
love.graphics.setColor(1,1,1)
love.graphics.line(0,1/5*window_height,window_height,1/5*window_height)
love.graphics.rectangle("line",0,0,window_width,window_height)
-- overlay
--love.graphics.print(t, 10, 10)
love.graphics.print(BackgroundTimer, window_width-100, 10)
love.graphics.print(BackgroundPeriod, window_width-100, 20)
love.graphics.print(#List.Simulate, window_width-100, window_height-10)
love.graphics.print(love.timer.getFPS(), 10, window_height-20)
end end

View File

@ -1,5 +1,8 @@
require "scripts/math" require "scripts/math"
require "scripts/lists" require "scripts/lists"
require "scripts/score"
require "scripts/animations" require "scripts/animations"
require "scripts/attack_patterns" require "scripts/attack_patterns"
require "scripts/entity" require "scripts/entity"
require "scripts/stage"
require "scripts/menus"

View File

@ -29,6 +29,11 @@ Animation = {
path = "assets/projectileBlueRocket", path = "assets/projectileBlueRocket",
frames = 1, frames = 1,
speed = 1 speed = 1
},
projectileCard = {
path = "assets/projectileCard",
frames = 8,
speed = 1/24
} }
} }

View File

@ -30,9 +30,9 @@ AttackPattern.FixatedWeb = function(entity,t,a,b,c)
hits = 1, hits = 1,
moveSpeed = 4, moveSpeed = 4,
moveSpeedIncrease = 0.001, moveSpeedIncrease = 0.001,
moveHorizontalIncrease = 0.001, moveHorizontalIncrease = 0.00125,
moveSpeedLimits = { min = 2, max = 4}, moveSpeedLimits = { min = 2, max = 4},
animation = Animation.projectileGreen, animation = Animation.projectileCard,
hostile = true, hostile = true,
maximumTurnRate = 0.05 maximumTurnRate = 0.05
} }
@ -41,9 +41,9 @@ AttackPattern.FixatedWeb = function(entity,t,a,b,c)
hits = 1, hits = 1,
moveSpeed = 4, moveSpeed = 4,
moveSpeedIncrease = 0.001, moveSpeedIncrease = 0.001,
moveHorizontalIncrease = -0.001, moveHorizontalIncrease = -0.00125,
moveSpeedLimits = { min = 2, max = 4}, moveSpeedLimits = { min = 2, max = 4},
animation = Animation.projectileGreen, animation = Animation.projectileCard,
hostile = true, hostile = true,
maximumTurnRate = 0.05 maximumTurnRate = 0.05
} }
@ -67,7 +67,6 @@ AttackPattern.FixatedWeb = function(entity,t,a,b,c)
math.rad(a *-math.cos( 5 )) + math.rad(90) + math.rad(40), math.rad(a *-math.cos( 5 )) + math.rad(90) + math.rad(40),
b b
) )
Projectile:New( Projectile:New(
entity.pos.x, entity.pos.x,
entity.pos.y, entity.pos.y,
@ -169,7 +168,7 @@ AttackPattern.DrowningBarrage = function(entity,t,a,b,c)
Projectile:New( Projectile:New(
entity.pos.x, entity.pos.x,
entity.pos.y, entity.pos.y,
math.rad(b *math.cos(t)) + GetAngle( math.rad(b *math.cos(t)) + GetAngleFromVector(
target_x - entity.pos.x, target_x - entity.pos.x,
target_y - entity.pos.y), target_y - entity.pos.y),
BulletData BulletData
@ -195,7 +194,7 @@ AttackPattern.ShotAtPlayerDouble = function(entity)
Projectile:New( Projectile:New(
entity.pos.x, entity.pos.x,
entity.pos.y, entity.pos.y,
math.rad(-10)*i + GetAngle( math.rad(-10)*i + GetAngleFromVector(
target_x - entity.pos.x, target_x - entity.pos.x,
target_y - entity.pos.y), target_y - entity.pos.y),
BulletData BulletData
@ -221,7 +220,7 @@ AttackPattern.ShotAtPlayerTriple = function(entity,t,a)
Projectile:New( Projectile:New(
entity.pos.x, entity.pos.x,
entity.pos.y, entity.pos.y,
math.rad(-15)*i + GetAngle( math.rad(-15)*i + GetAngleFromVector(
target_x - entity.pos.x, target_x - entity.pos.x,
target_y - entity.pos.y), target_y - entity.pos.y),
BulletData BulletData

View File

@ -22,16 +22,18 @@ function Projectile:New(x,y,angle,data)
o.moveHorizontal = 0 o.moveHorizontal = 0
o.moveVertical = 0 o.moveVertical = 0
-- lists -- lists
o:AddList(List.Simulate) o:AddList("Simulate")
local friendly = data.friendly or false local friendly = data.friendly or false
local hostile = data.hostile or false local hostile = data.hostile or false
if friendly == true then if friendly == true then
o:AddList(List.FriendlyBullet) o:AddList("FriendlyBullet")
end end
if hostile == true then if hostile == true then
o:AddList(List.EnemyBullet) o:AddList("HostileBullet")
o.grazeTimer = 0
o.Grazed = false
end end
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -55,6 +57,7 @@ function Projectile:Step()
You.pos.y You.pos.y
) )
-- bends towards the player? owo
self.pos.x = self.pos.x + move_x + self.maximumTurnRate * math.cos(self.angle) self.pos.x = self.pos.x + move_x + self.maximumTurnRate * math.cos(self.angle)
self.pos.y = self.pos.y + move_y + self.maximumTurnRate * math.sin(self.angle) self.pos.y = self.pos.y + move_y + self.maximumTurnRate * math.sin(self.angle)
@ -63,18 +66,18 @@ function Projectile:Step()
self.pos.y + move_y self.pos.y + move_y
) )
-- bends towards the player? owo
if self.pos.x < 0 or self.pos.x > window_width -- if out of s screen, kill.
or self.pos.y < 0 or self.pos.y > window_height then if self.pos.x < 0 or self.pos.x > windowWidth
self:RemoveList(List.Simulate) or self.pos.y < 0 or self.pos.y > windowHeight then
self:RemoveList(List.CollidesEnemies) self:RemoveList("Simulate")
self:RemoveList("EnemyBullet")
self:RemoveList("FriendlyBullet")
end end
end end
function Projectile:Draw() function Projectile:Draw()
self.animation:Animate() self.animation:Animate()
love.graphics.line(self.pos.x, self.pos.y, self.pos.x + 10*self.vel.x, self.pos.y + 10*self.vel.y)
self.animation:Draw( self.animation:Draw(
self.pos.x, self.pos.x,
self.pos.y, self.pos.y,
@ -82,6 +85,7 @@ function Projectile:Draw()
self.draw_scale, self.draw_scale,
self.draw_scale self.draw_scale
) )
love.graphics.line(self.pos.x, self.pos.y, self.pos.x + 50*self.vel.x, self.pos.y + 50*self.vel.y)
--[[love.graphics.draw( --[[love.graphics.draw(
self.sprite, self.sprite,
self.pos.x, self.pos.x,

View File

@ -15,8 +15,8 @@ function Fang:New(x,y)
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
o:AddList(List.Simulate) o:AddList("Simulate")
o:AddList(List.Enemy) o:AddList("Enemy")
return o return o
end end

View File

@ -18,8 +18,8 @@ function Shooter:New(x,y)
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
o:AddList(List.Simulate) o:AddList("Simulate")
o:AddList(List.Enemy) o:AddList("Enemy")
o:ChangePattern(AttackPattern.DrowningBarrage) o:ChangePattern(AttackPattern.DrowningBarrage)
return o return o

View File

@ -50,7 +50,7 @@ function Player:New(x,y)
o.max_health = 100 o.max_health = 100
o.health = 100 o.health = 100
-- lists -- lists
o:AddList(List.Simulate) o:AddList("Simulate")
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -93,8 +93,8 @@ function Player:Input()
end end
-- Actually moving the player -- Actually moving the player
self.pos.x = math.min(math.max(self.pos.x + self.vel.x,self.hitbox),window_width - self.hitbox) self.pos.x = math.min(math.max(self.pos.x + self.vel.x,self.hitbox),windowWidth - self.hitbox)
self.pos.y = math.min(math.max(self.pos.y + self.vel.y,self.hitbox),window_height - self.hitbox) self.pos.y = math.min(math.max(self.pos.y + self.vel.y,self.hitbox),windowHeight - self.hitbox)
-- Get Ready to shoot if triggered -- Get Ready to shoot if triggered
if self.shotTimer > 0 then self.shotTimer = self.shotTimer - current_dt end if self.shotTimer > 0 then self.shotTimer = self.shotTimer - current_dt end
@ -103,7 +103,7 @@ function Player:Input()
-- Shoot if ready and triggered -- Shoot if ready and triggered
if love.mouse.isDown(1) and self.shotTimer == 0 then if love.mouse.isDown(1) and self.shotTimer == 0 then
local x, y = love.mouse.getPosition() local x, y = love.mouse.getPosition()
Projectile:New(self.pos.x,self.pos.y,GetAngle(x - self.pos.x, y - self.pos.y), self.GunType[self.current_gun]) Projectile:New(self.pos.x,self.pos.y,GetAngleFromVector(x - self.pos.x, y - self.pos.y), self.GunType[self.current_gun])
self.shotTimer = self.GunType[self.current_gun].shotCooldown self.shotTimer = self.GunType[self.current_gun].shotCooldown
end end
end end
@ -120,7 +120,7 @@ function Player:Draw()
love.graphics.circle("line", x, y, self.hitbox/2) love.graphics.circle("line", x, y, self.hitbox/2)
-- Draw Gun Name -- Draw Gun Name
love.graphics.print("Current Gun: "..self.GunType[self.current_gun].name, 10, 35) --love.graphics.print("Current Gun: "..self.GunType[self.current_gun].name, 10, 35)
-- Draw Self -- Draw Self
if self.sprite ~= nil then if self.sprite ~= nil then

View File

@ -45,89 +45,52 @@ function Entity:DrawHealth()
end end
function Entity:AddList(list) function Entity:AddList( target)
table.insert(list,self) if List[target] == nil then List[target] = {} end
table.insert(List[target],self)
self.id[target] = #List[target]
end
if list == List.Simulate then function Entity:RemoveList(target)
self.id.Simulate = #list if self.id[target] ~= nil then
elseif list == List.Enemy then for _, e in pairs(List[target]) do
self.id.Enemy = #list if e.id[target] > self.id[target] then
elseif list == List.EnemyBullet then e.id[target] = e.id[target] - 1
self.id.EnemyBullet = #list end
elseif list == List.FriendlyBullet then end
self.id.FriendlyBullet = #list table.remove(List[target],self.id[target])
end end
end end
function Entity:CollisionWith(obj) function Entity:DistanceWith(obj, distance)
if math.sqrt((obj.pos.x-self.pos.x)^2 + (obj.pos.y-self.pos.y)^2) < obj.hitbox + self.hitbox then if math.sqrt((obj.pos.x-self.pos.x)^2 + (obj.pos.y-self.pos.y)^2) < distance then
return true return true
else else
return false return false
end end
end end
function Entity:RemoveList(list) function Entity:Kill()
if list == List.Simulate then for target, _ in pairs(self.id) do
for _, e in pairs(list) do self:RemoveList(target)
if e.id.Simulate > self.id.Simulate then
e.id.Simulate = e.id.Simulate - 1
end
end
table.remove(list,self.id.Simulate)
elseif list == List.Enemy then
for _, e in pairs(list) do
if e.id.Enemy > self.id.Enemy then
e.id.Enemy = e.id.Enemy - 1
end
end
table.remove(list,self.id.Enemy)
elseif list == List.EnemyBullet then
for _, e in pairs(list) do
if e.id.EnemyBullet > self.id.EnemyBullet then
e.id.EnemyBullet = e.id.EnemyBullet - 1
end
end
table.remove(list,self.id.EnemyBullet)
elseif list == List.FriendlyBullet then
for _, e in pairs(list) do
if e.id.FriendlyBullet > self.id.FriendlyBullet then
e.id.FriendlyBullet = e.id.FriendlyBullet - 1
end
end
table.remove(list,self.id.FriendlyBullet)
end end
self = nil
end end
function Entity:AngleTowards(x,y) function Entity:AngleTowards(x,y)
target_x = x - self.pos.x target_x = x - self.pos.x
target_y = y - self.pos.y target_y = y - self.pos.y
self.angle = GetAngle(target_x,target_y) self.angle = GetAngleFromVector(target_x,target_y)
end end
function Entity:Kill()
if self.id.Simulate ~= nil then
self:RemoveList(List.Simulate)
end
if self.id.Enemy ~= nil then
self:RemoveList(List.Enemy)
end
if self.id.EnemyBullet ~= nil then
self:RemoveList(List.EnemyBullet)
end
if self.id.FriendlyBullet ~= nil then
self:RemoveList(List.FriendlyBullet)
end
self = nil
end
function Entity:MoveTowards(x,y,speed) function Entity:MoveTowards(x,y,speed)
target_x = x - self.pos.x target_x = x - self.pos.x
target_y = y - self.pos.y target_y = y - self.pos.y
local angle = GetAngle(target_x,target_y) local angle = GetAngleFromVector(target_x,target_y)
if speed ~= 0 then if speed ~= 0 then
if target_x ~= 0 then if target_x ~= 0 then

View File

@ -1,12 +1,60 @@
List = {} List = {}
-- list to simulate things (draw, step, move) -- Gameplay lists
List.Simulate = {} List.Simulate = {}
-- collide lists
List.Enemy = {} List.Enemy = {}
List.EnemyBullet = {} List.EnemyBullet = {}
List.FriendlyBullet = {} List.FriendlyBullet = {}
-- Animations -- Animations
List.AnimationContainers = {} List.AnimationContainers = {}
-- UI Elements
List.UIElement = {}
--[[
function AddToList(self, target) -- object where to store id, string name.
table.insert(List[target],self)
self.id[target] = #list
end
function RemoveFromList(self, list)
end
for _, value in pairs(self.id) do
RemoveFromList(self,value)
--[[function Entity:RemoveList(list)
if list == List.Simulate then
for _, e in pairs(list) do
if e.id.Simulate > self.id.Simulate then
e.id.Simulate = e.id.Simulate - 1
end
end
table.remove(list,self.id.Simulate)
elseif list == List.Enemy then
for _, e in pairs(list) do
if e.id.Enemy > self.id.Enemy then
e.id.Enemy = e.id.Enemy - 1
end
end
table.remove(list,self.id.Enemy)
elseif list == List.EnemyBullet then
for _, e in pairs(list) do
if e.id.EnemyBullet > self.id.EnemyBullet then
e.id.EnemyBullet = e.id.EnemyBullet - 1
end
end
table.remove(list,self.id.EnemyBullet)
elseif list == List.FriendlyBullet then
for _, e in pairs(list) do
if e.id.FriendlyBullet > self.id.FriendlyBullet then
e.id.FriendlyBullet = e.id.FriendlyBullet - 1
end
end
table.remove(list,self.id.FriendlyBullet)
end
end
]]

View File

@ -1,4 +1,4 @@
function GetAngle(x,y) function GetAngleFromVector(x,y)
local reduce = 0 local reduce = 0
if x < 0 then if x < 0 then
reduce = math.rad(180) reduce = math.rad(180)

82
scripts/menus.lua Normal file
View File

@ -0,0 +1,82 @@
require "scripts/ui/button"
function MenuStep(menu)
-- first get mouse
local mouse_x, mouse_y = love.mouse.getPosition()
for _, element in pairs(List.UIElement) do
if element.type == "Button" then
element:checkMouse(mouse_x, mouse_y)
end
end
if menu == 1 then
if M_game_start:getVariable() == true then
MenuExit(menu,0)
stageStart()
elseif M_exit:getVariable() == true then
love.event.quit()
end
else
end
end
function MenuExit(from,to)
for _, element in pairs(List.UIElement) do
element = nil
end
List.UIElement = {}
if from == 1 then
M_game_start = nil
M_exit = nil
end
currentMenu = to or 0
end
function MenuDisplay(menu)
for _, element in pairs(List.UIElement) do
element:Draw()
end
if menu == 1 then
love.graphics.print(tostring(M_exit[1]), windowWidth-100, windowHeight-10)
else
end
end
function MenuInit(menu)
-- main menu
if menu == 1 then
-- elements
M_game_start = interfaceButton:New(
windowWidth/2,
2/10*windowHeight,
windowWidth/6,
windowWidth/12,
{false,true},
1,
{
text = "Press here to start",
color = {0,0,0.5},
color2 = {1,1,1},
alpha = 1,
scale = 1,
scale_x = 1,
scale_y = 1
})
M_exit = interfaceButton:New(
windowWidth/2,
500,
windowWidth/6,
windowWidth/12,
{false,true},
1,
{
color = {1,0,0.5},
color2 = {1,1,1},
alpha = 1,
scale = 1,
scale_x = 1,
scale_y = 1
})
end
end

7
scripts/score.lua Normal file
View File

@ -0,0 +1,7 @@
function AddScore()
if Score-ScoreShown > 150 then
ScoreShown = ScoreShown + 150 --math.floor(1/5 * (Score - ScoreShown))
else
ScoreShown = math.floor(Score)
end
end

118
scripts/stage.lua Normal file
View File

@ -0,0 +1,118 @@
function stageStart()
doStageStep = true
doStageDraw = true
EnemyTimer = 0
EnemyPeriod = 0.8
Score = 0
ScoreShown = 0
t = 0
You = Player:New(1/2*windowWidth,4/5*windowHeight)
end
function stageStep()
-- [PLAYER STEP]
You:Input()
-- [WORLD STEP]
-- first, simulate basic interaction
for _, obj in pairs(List.Simulate) do
obj:Step()
end
-- develop extra interactions:
-- 1. friendly bullets
for _, bullet in pairs(List.FriendlyBullet) do
for _, enemy in pairs(List.Enemy) do
if bullet:DistanceWith(enemy, enemy.hitbox + bullet.hitbox) then
if bullet.hits > 0 then
enemy:Damage(bullet.damage)
Score = Score +bullet.damage
bullet.hits = bullet.hits - 1
if bullet.hits <= 0 then
bullet:Kill()
end
end
end
end
end
-- 2. ememy bullets
for _, bullet in pairs(List.EnemyBullet) do
if bullet:DistanceWith(You, You.hitbox + bullet.hitbox) then
if bullet.hits > 0 then
--You:Damage(bullet.damage)
bullet.hits = bullet.hits - 1
if bullet.hits <= 0 then
bullet:Kill()
end
end
else
if bullet:DistanceWith(You, 200) then
bullet.grazeTimer = bullet.grazeTimer + 1
if bullet.grazeTimer > 30
and bullet.Grazed ~= true then
--Score = Score +3
bullet.Grazed = true
end
else
bullet.grazeTimer = 0
end
end
end
for _, bullet in pairs(List.EnemyBullet) do
if love.keyboard.isDown("lshift") then
bullet:Kill()
end
end
-- [POST WORLD STEP]
-- update shown score
AddScore()
-- if game is not paused
t = t + current_dt
EnemyTimer = EnemyTimer + current_dt
if EnemyTimer >= 0 then --EnemyPeriod then
--EnemyTimer = EnemyTimer - EnemyPeriod
EnemyTimer = -1000000000000
for i=1, 1 do
local rand = 1 --math.random(10)
if rand == 1 then
local rand_x = math.random(-100,100)
local rand_y = math.random(-100,100)
local x = Shooter:New(1/2*windowWidth,1/5*windowHeight)
else
local rand_x = math.random(-10,10)
local rand_y = math.random(-10,10)
local x = Fang:New(windowWidth/2+rand_x,windowHeight/2+rand_y)
end
end
end
end
function stageDraw()
--[GAME WORLD]
-- draw background (unimplemented)
-- draw objects
for _, obj in pairs(List.Simulate) do
obj:Draw()
end
--[HEADS UP DISPLAY (HUD)]
-- show enemies healthbars
for _, enemy in pairs(List.Enemy) do
if enemy.show_health == true then enemy:DrawHealth() end
end
-- show recollection zone
love.graphics.line(0,1/5*windowHeight,windowHeight,1/5*windowHeight)
-- show game area
love.graphics.rectangle("line",0,0,windowWidth,windowHeight)
-- show score
love.graphics.print(ScoreShown, 10, 60)
--[DEBUGGING]
love.graphics.print(#List.Simulate, windowWidth-100, windowHeight-10)
end

106
scripts/ui/button.lua Normal file
View File

@ -0,0 +1,106 @@
interfaceButton = {type = "Button"}
-- centered buttons
function interfaceButton:New(x,y,w,h,table_values,value,style)
o = {}
o.pos = {
x = x,
y = y
}
o.size = {
w = w,
h = h
}
o.values = table_values or {false,true}
o.value = value or 1
o.target_variable = o.values[o.value]
o.clicked = false
o.style = {
text = style.text or nil,
color = style.color or {1,1,1},
color2 = style.color2 or {0,0,0},
--color3 = style.color3 or style.color2 or {0,0,0},
alpha = style.alpha or 1,
scale = style.scale or 1,
scale_x = style.scale_x or 1,
scale_y = style.scale_y or 1,
scale_proportion = 1
}
o.style.unselected = {
scale_proportion = o.style.scale_proportion
}
o.style.selected = {
scale_proportion = 1.5
}
AddElement(o)
setmetatable(o, self)
self.__index = self
return o
end
function interfaceButton:getVariable()
return self.target_variable
end
function AddElement(self)
table.insert(List.UIElement,self)
self.id = #List.UIElement
end
function interfaceButton:checkMouse(mouse_x, mouse_y)
if self.clicked == false
and mouse_x < self.pos.x + self.size.w/2
and mouse_x > self.pos.x - self.size.w/2
and mouse_y < self.pos.y + self.size.h/2
and mouse_y > self.pos.y - self.size.h/2 then
o.style.scale_proportion = o.style.selected.scale_proportion
if love.mouse.isDown(1) then
self.clicked = true
self.value = self.value + 1
if self.value > #self.values then
self.value = 1
end
self.target_variable = self.values[self.value]
end
else
o.style.scale_proportion = o.style.unselected.scale_proportion
self.clicked = false
end
end
function interfaceButton:Draw()
local c1, c2, c3, a = love.graphics.getColor()
love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha)
love.graphics.rectangle(
"fill",
self.pos.x-(self.size.w/2)*self.style.scale_x*self.style.scale_proportion,
self.pos.y-(self.size.h/2)*self.style.scale_y*self.style.scale_proportion,
self.size.w *self.style.scale_x*self.style.scale_proportion,
self.size.h *self.style.scale_y*self.style.scale_proportion)
love.graphics.setColor(self.style.color2[1],self.style.color2[2],self.style.color2[3],self.style.alpha)
love.graphics.rectangle(
"line",
self.pos.x-(self.size.w/2)*self.style.scale_x*self.style.scale_proportion,
self.pos.y-(self.size.h/2)*self.style.scale_y*self.style.scale_proportion,
self.size.w *self.style.scale_x*self.style.scale_proportion,
self.size.h *self.style.scale_y*self.style.scale_proportion)
if self.style.text ~= nil then
love.graphics.print(self.style.text,self.pos.x,self.pos.y)
else
love.graphics.print(tostring(self.target_variable),self.pos.x,self.pos.y)
end
love.graphics.setColor(c1,c2,c3,a)
end