Created
October 5, 2012 18:17
-
-
Save Synvox/3841463 to your computer and use it in GitHub Desktop.
Snow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --# Main | |
| -- Snow | |
| function setup() | |
| displayMode(FULLSCREEN) | |
| instances={} | |
| currentIndex=0 | |
| table.insert(instances,SnowMaker(0,1)) | |
| end | |
| function draw() | |
| background(31, 68, 104, 255) | |
| strokeWidth(5) | |
| fill(255, 255, 255, 255) | |
| rect(0,0,WIDTH,50) | |
| sprite("Small World:Tree Cone",500,50) | |
| sprite("Small World:House White",550,50) | |
| for i,obj in ipairs(instances) do | |
| currentIndex = i | |
| obj:draw() | |
| end | |
| end | |
| --# SnowMaker | |
| SnowMaker = class() | |
| function SnowMaker:init(delay,amount) | |
| self.delay=delay | |
| self.counter=0 | |
| self.amount=amount | |
| end | |
| function SnowMaker:draw() | |
| self.counter = self.counter + 1 | |
| if self.counter > self.delay then | |
| self.counter = 0 | |
| for i=1,self.amount do | |
| local x=math.random(0,WIDTH) | |
| local y=HEIGHT | |
| newSnow=SnowFlake(x,y) | |
| table.insert(instances,newSnow) | |
| end | |
| end | |
| end | |
| --# SnowFlake | |
| SnowFlake = class() | |
| function SnowFlake:init(x,y) | |
| self.x=x | |
| self.y=y | |
| self.yspeed=-math.random(5,6) | |
| self.size=math.random(4,5) | |
| end | |
| function SnowFlake:draw() | |
| self.y = self.y + self.yspeed | |
| self.x = self.x + math.random(-1,1) + Gravity.x*4 | |
| if self.x<0 then | |
| self.x = self.x + WIDTH | |
| end | |
| if self.x>WIDTH then | |
| self.x = self.x - WIDTH | |
| end | |
| if self.y<0 then | |
| table.remove(instances,currentIndex) | |
| end | |
| noStroke() | |
| fill(255, 255, 255, 255) | |
| ellipse(self.x,self.y,self.size,self.size) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment