Framework/code for entities?

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
dbltnk
Prole
Posts: 21
Joined: Thu Dec 10, 2009 8:23 pm

Framework/code for entities?

Post by dbltnk »

Disclaimer: I'm new to coding, LUA, LÖVE and this forum. So please don't hurt me if this is common knowledge around here. =D

I've been looking for a framework that provides me with a way of creating enemies (entities). I've found two, ËNVY (http://love2d.org/forum/viewtopic.php?f=5&t=172) and Greenshell (http://code.google.com/p/greenshell/). Both promise to do the thins I need.

But - and here comes the problem - there is no working download link to ËNVY anywhere to be found and Greenshell seems to have released no code yet. If anyone you has one of those frameworks around on your computer: could you please upload them to this board?

Thanks in advance.

Alex
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Framework/code for entities?

Post by Robin »

Here you go.
envy_001.love
Phase 14
(508.87 KiB) Downloaded 146 times
One note though: I think it wouldn't be too hard to write your own entity code, and you'd learn a lot from it as an extra benefit. ;)
Help us help you: attach a .love.
User avatar
dbltnk
Prole
Posts: 21
Joined: Thu Dec 10, 2009 8:23 pm

Re: Framework/code for entities?

Post by dbltnk »

Thanks for the file, Robin. You were right, it's better for the to build my own code first. Not only because the learning curve is smoother then but also because ËNVY has no documentation (I know of ) and so I wasn't able to find out which parts i needed. =D

Anyways, I've got a bit close on my goal of having multiple enemies attack the castle in my prototype called "Bollwerk". I was able to spawn quite a lot of enemies using tables (learned that bit from the Lovalanche demo). My current problem is that I see no way to make my enemies move again - as they did when I only had of of 'em.

Would any of you care to take a look and give me some input on where I messed up? The code is hopefully understandable, I commented everything.

http://dl.dropbox.com/u/893169/Bollwerk.love

Alex
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Framework/code for entities?

Post by Robin »

A note: I haven't tested it, because I'd have to download LÖVE 0.5.0, and I'm too lazy for that. ;)

I see you are using love.physics. That's alright, but it is best used in sidescroller/Mario type of games. (So 2D, down is bottom of screen, etc.) Especially since you are setting the position of the enemies themselves: it's awkward. Also, love.physics has severe bugs in 0.5.0, so you might want to do either of:
  1. Forgetting about love.physics, and handle collisions yourself.
  2. Upgrade to 0.6.0, which means you have to rewrite a lot of code.
Or both. :P

If you want to keep using love.physics, here's what you should know:
The Body which is associated with an enemy has (among others, of course) these four functions:

Code: Select all

getX()
setX()
getY()
setY()
Which, in your loop, comes down to:

Code: Select all

v.b:getX()
v.b:setX()
v.b:getY()
v.b:setY()
For performance and simplicity, I recommend the following:

Code: Select all

	for i,v in ipairs(enemies) do
		local x = v.b:getX()
		local y = v.b:getY()
		if x <= 250 and y <= 250 then
			(rest of your old code here)
		end

		v.b:setX(x)
		v.b:setY(y)
	end
Help us help you: attach a .love.
User avatar
dbltnk
Prole
Posts: 21
Joined: Thu Dec 10, 2009 8:23 pm

Re: Framework/code for entities?

Post by dbltnk »

Hey Robin,

thanks to your input, the game is coming together rapidly. Now my enemies are spawning randomly outside the playfield, attacking the castle and damaging it. What I want to do now is freeze/stop the game's timer when HP are down to zero. For that I'm changing the state of the game from "playing" to "lost".

I've tried to call

Code: Select all

if state == "lost" then love.update.stop()
end
in function update (dt) but this only crashes the game (which is also a way to stop the game but not really what I'm looking for *g*).

Is there a bettwer way to stop the timer? There's nothing in the documentation for that.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Framework/code for entities?

Post by Robin »

Functions don't have a stop attribute in Lua. ;)

I'm not sure what your are trying to achieve here. Do you want to:
  • Quit the game immediately?
  • Stop some sort of timer? (If so: what timer are you referring to?)
  • Stop the game, and proceed to a main menu or something like that?
Help us help you: attach a .love.
User avatar
dbltnk
Prole
Posts: 21
Joined: Thu Dec 10, 2009 8:23 pm

Re: Framework/code for entities?

Post by dbltnk »

What I want to do is stop the game from moving sprites or playing music while I'm showing the player a "you lose" screen where he can either restart or quit it. So far I've just put a blanket over the game which is still running in the background but that just seems wrong to me. =D

PS: Is there a way to delete/kill/remove sprites from the scene?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Framework/code for entities?

Post by bartbes »

Well, if state is a global you can add this to the start of the update function:

Code: Select all

if state == "lost" then return end
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Framework/code for entities?

Post by Robin »

dbltnk wrote:PS: Is there a way to delete/kill/remove sprites from the scene?
LÖVE has no concept of "scenes". If you want to not show a certain sprite, just don't draw it:

Code: Select all

function draw()
    if state == "lost" then
        love.graphics.draw(20, 20, "Haha, you lose!")
    else
        love.graphics.draw(20, 20, "You haven't lost (yet).")
    end
end
Help us help you: attach a .love.
User avatar
dbltnk
Prole
Posts: 21
Joined: Thu Dec 10, 2009 8:23 pm

Re: Framework/code for entities?

Post by dbltnk »

@bartbes
Thanks, that worked for what I wanted.

@Robin
There's a tutorial game that does what I want to do, destruction.love: I need to remove a entity from the game. Now I just need to find out how this works. =D
Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests