Generating playable objects

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.
User avatar
eliasaif
Prole
Posts: 25
Joined: Sat May 02, 2009 4:04 pm
Location: Sweden

Generating playable objects

Post by eliasaif »

I'm trying to make a game where you first have a playable object, then if you press a button, a new playable object will be generated and the first object won't be playable anymore. Does anyone know how to do this generation?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Generating playable objects

Post by bartbes »

I have a very (very, very) bad implementation of this in netris. Basically I set an 'active' flag. But.. your question, what do you mean by "generation"?
User avatar
eliasaif
Prole
Posts: 25
Joined: Sat May 02, 2009 4:04 pm
Location: Sweden

Re: Generating playable objects

Post by eliasaif »

Ok, what I mean with generation is that a new object (body) will be made when pushing a button.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Generating playable objects

Post by bartbes »

Okay, but that depends on the object you're trying to create. I had a few possibilities and just used math.random to decide which one to create.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Generating playable objects

Post by Robin »

eliasaif wrote:I'm trying to make a game where you first have a playable object, then if you press a button, a new playable object will be generated and the first object won't be playable anymore. Does anyone know how to do this generation?
What exactly is your question?

How to generate the object? Exactly the same way you create all other objects.
How to have a different playable object? Bartbes answered that one already.
Help us help you: attach a .love.
User avatar
eliasaif
Prole
Posts: 25
Joined: Sat May 02, 2009 4:04 pm
Location: Sweden

Re: Generating playable objects

Post by eliasaif »

The question is how I can make new objects by pressing a button. I'm pretty new to this.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Generating playable objects

Post by Robin »

eliasaif wrote:The question is how I can make new objects by pressing a button. I'm pretty new to this.
Alright. Well, there are a number of ways to do that, most of which involve tables. Do you have any code written for this game?

An example:
If you have "class" PlayerObject, and in load(), you called

Code: Select all

player = PlayerObject:new()
then, in keypressed(), you could do something like:

Code: Select all

oldplayer = player
player = PlayerObject:new()
But how you can do it greatly depends on the rest of the code.
Help us help you: attach a .love.
User avatar
eliasaif
Prole
Posts: 25
Joined: Sat May 02, 2009 4:04 pm
Location: Sweden

Re: Generating playable objects

Post by eliasaif »

Ok, i attached the code.
Attachments
game.love
(8.37 KiB) Downloaded 110 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Generating playable objects

Post by Robin »

I made an example how it could be done. If you want to be able to make multiple new player objects, you might want to put the old player objects in a table, instead of this:
Attachments
main.lua
(2.83 KiB) Downloaded 121 times
Help us help you: attach a .love.
User avatar
eliasaif
Prole
Posts: 25
Joined: Sat May 02, 2009 4:04 pm
Location: Sweden

Re: Generating playable objects

Post by eliasaif »

That's exactly what I meant! But how do I get the old objects to still have an image?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 63 guests