Creating buildings once and forever, how?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Boniard
Prole
Posts: 3
Joined: Mon Dec 26, 2011 10:29 am

Creating buildings once and forever, how?

Post by Boniard »

Hi everyone. I'm new and pretty much stupid Lover, so, i got a little problem, which i can't solve by myself. Also, i'm russian and that mean i now nothing about how to chat on english, so please, be kind to me:)

The problem is - i'm trying to create a "construction mode" state for my game, where you can place a building (gnome shelter) wherever you want, looking on how it will look when it's done with the help of kind of pre-building look. Well, how it usually can be found on any strategy games. So, i got a pre-building look - there is a shelter levitating along X-asis with the mouse moving around, but when i'm clicking left mouse button, which is supposed to mean that i choose a place to construct and building must be placed, building is, regarding to the ways i code, neither disappearing or continuing to follow the mouse, like it was no mouse click. I'd like to know about the ways you would create such a system, because no matter how hard i try, it's not working.

Subject: http://zalil.ru/32376028
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Creating buildings once and forever, how?

Post by Robin »

You could do it basically two ways:
  1. Keep a list of buildings. When you click, a copy of the building is appended to the list.
  2. Keep a grid of buildings. When you click, insert a copy of the building in its current position.
Help us help you: attach a .love.
Boniard
Prole
Posts: 3
Joined: Mon Dec 26, 2011 10:29 am

Re: Creating buildings once and forever, how?

Post by Boniard »

Can you, please, show an example?) I think i don't get it.

How can i make building not to disappear, when "constructionMode = false"? I see it's disappearing because of "constructionMode == true" condition, which is not true, when construction mode is off and building supposed to be constructed.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Creating buildings once and forever, how?

Post by Robin »

Ah, I see the problem. You only draw one building.
Instead of:

Code: Select all

if build == true then
love.graphics.draw(constructions[constructionsNum], mouseX, 357)
end
do:

Code: Select all

for i, building in ipairs(constructions)
    love.graphics.draw(building, mouseX, 357)
end
Help us help you: attach a .love.
Boniard
Prole
Posts: 3
Joined: Mon Dec 26, 2011 10:29 am

Re: Creating buildings once and forever, how?

Post by Boniard »

I did it!
http://zalil.ru/32379426 - fresh Main.lua with the decision
There is still some spare unuseful picture coming up in construction mode, but that's not critical and will be solved eventually:)

Anyway, thanks a lot, Robin)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 4 guests