User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







lua:codea:stargenerator:star.lua
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)
        self.size = math.random(1,3)
    else
        self.x = math.random(1,1200)
        self.y = math.random(1,1200)
        self.size = math.random(1,6)
    end
    self.xspeed = math.random(1,10)
    self.yspeed = math.random(1,10)
 
    self.maxsize =6
    self.sc1 = math.random(1,255)
    self.sc2 = math.random(1,255)
    self.sc3 = math.random(1,255)
 
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))
    stroke(self.sc1,self.sc2,self.sc3)
    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
advertising
lua/codea/stargenerator/star.lua.txt · Last modified: 2013/01/24 04:05 by Wayne Michael

Impressum Datenschutz