Error in my Space Invaders

Hello! I was making a “Space Invaders” game. I was making the code tween all the invaders downwards when I ran into an error. I don’t understand what the problem is. Please help.
Here’s the code that I use for lowering the invaders:

function lowerInvaders()
    for i,a in ipairs(invaders) do
        tween(0.5,a,{position.y = a.position.y - 20}) -- Error: "}" expected near "="

Oh woops, sorry! I haven’t used tween in while. I should have done it like this:

tween(0.5,a.position,{y = a.position.y - 20})

@Kolosso - don’t use tweens for this.

Just write


No tween?

The error (apart from the fact you didn’t need tweens) was that you were using tweens incorrectly. Look at the Animation demo project or my post here.

RT*M ! :wink:

Alright, so now I’m moving on to making the player’s ship. So I made a bullet class, and each bulllet has a static physics body for their hitbox. The invaders also have static physics bodies for their hitboxes. I’m trying to make it so that if a bullet hits an invader, both the invader and the bullet will be destroyed, and removed from their table (bullets and invaders are the two tables). Not sure how to do that though.

function collide(contact)
    if contact.state == BEGAN then
        if contact.bodyA == "invader" and contact.bodyB == "bullet" or contact.bodyB == "invader" and contact.bodyA == "bullet" then

I wrote this, to detect the collisions, but I don’t know what to write next.

The easiest way to handle physics collisions is to index the parent class for the body by the body itself.


bodies[self.body] = self

Then, give the classes a collide method, and in the global collide function, you can write:

bodies[contact.bodyA]:collide(contact.bodyB, contact)
bodies[contact.bodyB]:collide(contact.bodyA, contact)

@Kolosso - it seems to me that you’re learning how to make your game by asking questions each time you get stuck, and while we don’t mind helping fix problems, we’d like you to try to find answers in the many tutorials, sample code, ebooks etc available to you, because we don’t have time to provide one to one tuition.

For example (and this is only one resource), I’ve written an ebook on Codea, which covers physics and collisions, at this link.

So please take the time and trouble to do some reading before asking questions.