Remember the vector graphics star wars game from the 80’s?
I am trying to simulate the stars from that.
Very choppy, slow and needs work.
Any feedback on how to smooth it or even redo it would be great.
-- stars
function setup()
displayMode(FULLSCREEN)
createstars()
checkagain = false
end
function createstars()
stars = {}
for i = 1,125 do
--rx = math.random(1,1200)
-- ry= math.random(1,800)
s= Star(true)
--u = { x=rx, y=ry}
table.insert(stars,s)
end
for i = 1,50 do
--rx = math.random(1,1200)
-- ry= math.random(1,800)
s= Star(false)
--u = { x=rx, y=ry}
table.insert(stars,s)
end
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(0, 0, 0, 255)
for a,b in pairs(stars) do
b:draw()
end
movestars()
end
function movestars()
for b,s in pairs(stars) do
s:move()
end
end
And.
Star = class()
function Star:init(init)
-- you can accept and set parameters here
self.mx = 500
self.my = 400
if init == true then
self.x = math.random(self.mx-10,self.mx+10)
self.y = math.random(self.my-10,self.my+10)
else
self.x = math.random(1,1200)
self.y = math.random(1,1200)
end
self.xspeed = math.random(1,10)
self.yspeed = math.random(1,10)
self.size = math.random(1,3)
self.maxsize =6
end
function Star:draw()
-- Codea does not automatically call this method
strokeWidth(self.size)
-- stroke(math.random(1,255),math.random(1,255), math.random(1,255))
line(self.x,self.y,self.x,self.y)
end
function Star:touched(touch)
-- Codea does not automatically call this method
end
function Star:move()
if self.x <= self.mx and self.y <= self.my then
self.x = self.x - self.xspeed
self.y = self.y - self.yspeed
end
if self.x <= self.mx and self.y >= self.my then
self.x = self.x - self.xspeed
self.y = self.y + self.yspeed
end
if self.x >= self.mx and self.y >= self.my then
self.x = self.x + self.xspeed
self.y = self.y + self.yspeed
end
if self.x >= self.mx and self.y <= self.my then
self.x = self.x + self.xspeed
self.y = self.y - self.yspeed
end
if self.x <= 0 or self.y <= 0 then
self:init(true)
return
else
if self.y >= 1000 or self.x >= 1000 then
self:init(true)
return
end
end
if math.random(1,12) == 5 then
if self.size + 1 <= self.maxsize then
self.size = self.size + 1
return
end
end
if self.yspeed + self.xspeed > 15 then
if math.random(1,5) == 5 then
if self.size + 1 <= self.maxsize then
self.size = self.size + 1
return
end
end
end
end