Code: Select all
function love.load()
player = {x = 200,y = 200,Speed = 400, width = 30, height = 50}
enemy = {x = 150,y = 150, speed = 1000}
points = {{x = 400,y = 555}}
pointscounter = 0
end
function love.draw()
love.graphics.setColor(144,255,71)
[b]Here[/b] for i, v in pairs(player) do
love.graphics.rectangle("fill",v.x,v.y,v.width,v.height)
end
love.graphics.setColor(245, 58, 252)
for i , v in pairs(points) do
love.graphics.rectangle("fill",v.x,v.y,10,10)
end
love.graphics.setColor(144,255,71)
love.graphics.setColor(255,255,255)
love.graphics.print(pointscounter,0,0,0,1.5,1.5)
if pointscounter == 50 then
love.graphics.setColor(255,255,255)
love.graphics.print("You Win", 350, 300,0,1.5,1.5)
end
love.graphics.setColor(255,0,0)
love.graphics.rectangle("fill",enemy.x,enemy.y,15,15)
end
function love.update( dt )
if love.keyboard.isDown("d") and player.x + player.width < 800 then
player.x = player.x + player.Speed * dt
end
if love.keyboard.isDown("a") and player.x > 0 then
player.x = player.x - player.Speed * dt
end
if love.keyboard.isDown("w") and player.y > 0 then
player.y = player.y - player.Speed * dt
end
if love.keyboard.isDown("s") and player.y + player.height < 600 then
player.y = player.y + player.Speed * dt
end
dx = (player.x - enemy.x) * (enemy.speed * dt)
dy = (player.y - enemy.y) * (enemy.speed * dt)
enemy.x = enemy.x + (dx * dt)
enemy.y = enemy.y + (dy * dt)
[b]here[/b] for i,v in pairs(player) do
if CheckCollision(enemy.x,enemy.y,enemy.width,enemy.height,v.x,v.y,v.width,v.height) then
print("Got Hit")
end
end
for i,v in pairs(points) do
if CheckCollision(player.x,player.y,player.width,player.height,v.x,v.y,10,10) then
pointscounter = pointscounter + 1
v.delete = true
local newpoint = {x = math.random(690), y = math.random(490)}
table.insert(points,newpoint)
end
end
for x = #points,1,-1 do
if points[x].delete then
table.remove(points, x)
end
end
end
function love.keypressed ( key )
if key == "escape" then
love.event.quit()
end
end
-- not mine
function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
return x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1
end
[code/]
[b]It Keeps givin me the error[/b] [i]attempt to index field "v" (a number value)[i/]
[b]for some reason[/b]