function love.load ()
rectangle1 = { x = math.random (0,750) , y = 400, breite = 50 , hoehe = 75}
rectangle2 = { x =math.random (0,750) , y = 200, breite = 100, hoehe = 50}
rectangle3 = { x = math.random (0,750) , y = 10 , breite = 75 , hoehe = 88 }
rectangle4 = { x = math.random (0,750) , y = 522 , breite = 64 , hoehe = 46 }
rectangle5 = { x = math.random (0,750) , y = 300 , breite = 64 , hoehe = 46 }
rectangle6 = { x = math.random (0,750) , y = 355 , breite = 64 , hoehe = 46 }
rectangleList = { rectangle1 ,rectangle2, rectangle3 , rectangle4,rectangle5,rectangle6}
end
function love.draw()
drawRectangleOne()
drawRectangleTwo()
drawRectangleThree()
drawRectangleFour()
drawRectangleFive()
drawRectangleSix()
end
function drawRectangleOne()
love.graphics.setColor(0,255,0)
for index,meinRechteck in ipairs (rectangleList) do
love.graphics.rectangle("fill",rectangle1.x,rectangle1.y,rectangle1.breite,rectangle1.hoehe)
end
end
function drawRectangleTwo()
love.graphics.setColor(0,255,0)
for index,meinRechteck in ipairs (rectangleList) do
love.graphics.rectangle("fill",rectangle2.x,rectangle2.y,rectangle2.breite,rectangle2.hoehe)
end
end
function drawRectangleThree()
love.graphics.setColor(0,255,0)
for index,meinRechteck in ipairs (rectangleList) do
love.graphics.rectangle("fill",rectangle3.x,rectangle3.y,rectangle3.breite,rectangle3.hoehe)
end
end
function drawRectangleFour()
love.graphics.setColor(0,255,0)
for index,meinRechteck in ipairs (rectangleList) do
love.graphics.rectangle("fill",rectangle4.x,rectangle4.y,rectangle4.breite,rectangle4.hoehe)
end
end
function drawRectangleFive()
love.graphics.setColor(0,255,0)
for index,meinRechteck in ipairs (rectangleList) do
love.graphics.rectangle("fill",rectangle5.x,rectangle5.y,rectangle5.breite,rectangle5.hoehe)
end
end
function drawRectangleSix()
love.graphics.setColor(0,255,0)
for index,meinRechteck in ipairs (rectangleList) do
love.graphics.rectangle("fill",rectangle6.x,rectangle6.y,rectangle6.breite,rectangle6.hoehe)
end
end
function love.mousepressed(x, y, button)
if button == "l" then
for i, v in ipairs(rectangleList ) do
if v.x <= rectangle1.x and rectangle1.x <= v.x and v.y <= rectangle1.y and rectangle1.y <= v.y and
v.x <= rectangle2.x and rectangle.x <= v.x and v.y <= rectangle2.y and rectangle2.y <= v.y and
v.x <= rectangle3.x and rectangle3.x <= v.x and v.y <= rectangle3.y and rectangle3.y <= v.y and
v.x <= rechteck4.x and rectangle4.x <= v.x and v.y <= rectangle4.y and rectangle4.y <= v.y and
v.x <= rechteck5.x and rectangle5.x <= v.x and v.y <= rectangle5.y and rectangle5.y <= v.y and
v.x <= rechteck6.x and rectangle6.x <= v.x and v.y <= rectangle6.y and rectangle6.y <= v.y
then
table.remove(rectangleListe,i)
end
end
end
end
function love.update(dt)
for index,meinRechteck in ipairs (rectangleList) do
rectangle1.y = rectangle1.y + math.random(-3,3)
rectangle1.x = rectangle1.x + math.random(-3,3)
rectangle2.y = rectangle2.y + math.random(-3,3)
rectangle2.x = rectangle2.x + math.random(-3,3)
rectangle3.y = rectangle3.y + math.random(-3,3)
rectangle3.x = rectangle3.x + math.random(-3,3)
rectangle4.y = rectangle4.y + math.random(-3,3)
rectangle4.x = rectangle4.x + math.random(-3,3)
rectangle5.y = rectangle5.y + math.random(-3,3)
rectangle5.x = rectangle5.x + math.random(-3,3)
rectangle6.y = rectangle6.y + math.random(-3,3)
rectangle6.x = rectangle6.x + math.random(-3,3)
end
end
CAN YOU HELP ME PLEASE ?? It does not work!!!
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: CAN YOU HELP ME PLEASE ?? It does not work!!!
You made some typos, and have completely missed the point of tables and loops. That's not terrible or something, it just mean you have something to learn. I'm going to fix some things, and hope you'll understand it. If you have questions, please ask them.
p.s. you can write your code between
Code: Select all
function love.load ()
rectangle1 = { x = math.random (0,750) , y = 400, breite = 50 , hoehe = 75}
rectangle2 = { x =math.random (0,750) , y = 200, breite = 100, hoehe = 50}
rectangle3 = { x = math.random (0,750) , y = 10 , breite = 75 , hoehe = 88 }
rectangle4 = { x = math.random (0,750) , y = 522 , breite = 64 , hoehe = 46 }
rectangle5 = { x = math.random (0,750) , y = 300 , breite = 64 , hoehe = 46 }
rectangle6 = { x = math.random (0,750) , y = 355 , breite = 64 , hoehe = 46 }
rectangleList = { rectangle1 ,rectangle2, rectangle3 , rectangle4,rectangle5,rectangle6}
end
function love.draw()
for i, rectangle in ipairs(rectangleList) do
drawRectangle(rectangle)
end
end
function drawRectangleOne(rectangle)
love.graphics.setColor(0,255,0)
love.graphics.rectangle("fill",rectangle.x,rectangle.y,rectangle.breite,rectangle.hoehe)
end
function love.mousepressed(x, y, button)
if button == "l" then
-- I removed this part, because I couldn't figure out what you wanted to do here
end
end
function love.update(dt)
for index,rectangle in ipairs (rectangleList) do
rectangle.y = rectangle.y + math.random(-3,3)
rectangle.x = rectangle.x + math.random(-3,3)
end
end
Code: Select all
and [ /code].
Also, I haven't tested this. Sorry.
Help us help you: attach a .love.
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: CAN YOU HELP ME PLEASE ?? It does not work!!!
Second, I'm going to give you the same tip I posted for someone else in another thread, but it's a lot of text so here's a link:
http://love2d.org/forums/viewtopic.php? ... 312#p91312
Your use of rectangle1, rectangle2, rectangle3, ..., rectangle6 and a separate rectangleList is kind of a wasteful way of doing things. Instead follow my tip in the link above. You will not have to code as much.
Also, yes, please use the
http://love2d.org/forums/viewtopic.php? ... 312#p91312
Your use of rectangle1, rectangle2, rectangle3, ..., rectangle6 and a separate rectangleList is kind of a wasteful way of doing things. Instead follow my tip in the link above. You will not have to code as much.
Also, yes, please use the
Code: Select all
tags.
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests