I make a game with lua/LÖVE and i use the middleclass library for OOP, but i have a problem, my game is a space shooter game with a base class "entity" a subclass "player" and "meteor" (enemy that fall from the top of the screen with a random x coordinate) but i don't know how to make the random spawn system for the meteor (a random x coordinate).
Entity = class('Entity')
function Entity:initialize(x, y, width, height, image)
self.x = x
self.y = y
self.width = width
self.height = height
self.image = image
end
function Entity:draw()
love.graphics.draw(self.image, self.x, self.y)
end
meteor.lua = http://ift.tt/2s3Dkpb gameState.lua = http://ift.tt/2sD1iVi
(the game file)
Everytimes that i launch the game, the x coordinate of the meteor object is the same, i want to spawn one meteor with a random x coordinate every 2 seconds, but i don't know how to do that. I think that i've made something wrong but i don't know. :/
After that i would like also to delete the object when it is outside of the screen. I know how to do that without oop but with oop i'm stuck...
Thanks you in advance !
Aucun commentaire:
Enregistrer un commentaire