View difference between Paste ID: 1epXjywW and Uy25X7j3
SHOW: | | - or go back to the newest paste.
1
 ~~
2
function setup()
3
    supportedOrientations(ANY)
4
    balles = {}
5
    x = 0
6
    oi = 1
7
    max = 150
8
    maxer = 0
9
    maxGreat = 5
10
    star = {}
11
    be = false
12
    displayMode(FULLSCREEN)
13
    supportedOrientations(PORTRAIT)
14
   
15
    time_start=ElapsedTime
16
    frames = 0
17
    FPS = 60
18
19
    wall1 = physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
20
    wall2 = physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
21
    wall3 = physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
22
    wall4 = physics.body(EDGE,vec2(WIDTH,HEIGHT),vec2(0,HEIGHT))
23
    wall1.type = STATIC
24
    wall2.type = STATIC
25
    wall3.type = STATIC
26
    wall4.type = STATIC
27
    wall1.restitution = .5
28
    wall2.restitution = .5
29
    wall3.restitution = .5
30
    wall4.restitution = .5
31
32
    ~~
33
    if be then
34
    for i=1, 78 do
35
     table.insert(star, i, physics.body(CIRCLE, math.random(1,5)))
36
    star[i].x = math.random(0, WIDTH)
37
    star[i].y = math.random(0, HEIGHT)
38
    star[i].type = STATIC
39
    end
40
 end
41
~~ finishes the check if stars are gonna be rendered or not(and its loop)
42
end
43
44
45
~~
46
47
~~
48
function touched(touch)
49
50
    ~~
51
    if touch.state == ENDED then
52
    else
53
54
       ~~
55
        if x<max then
56
        table.insert(balles, x, physics.body(POLYGON,vec2(touch.x-10, touch.y+10),
57
                                                     vec2(touch.x-10, touch.y-10),
58
                                                     vec2(touch.x+10, touch.y-10),
59
                                                     vec2(touch.x+10, touch.y+10)))
60
        
61
        balles[x].type = DYNAMIC
62
        x = x + 1
63
        else
64
            if maxer < maxGreat then
65
            table.insert(balles, x, physics.body(CIRCLE, math.random(25,40)))
66
            maxer = maxer + 1
67
            balles[x].x = touch.x
68
            balles[x].y = touch.y
69
            balles[x].type = DYNAMIC
70
            balles[x].density = balles[x].radius
71
            end
72
        ~~ --finishes the check of max particules 
73
            end
74
     ~~finishes check for touch
75
        end
76
~~ final end
77
end
78
79
    -- This function gets called once every frame
80
function draw()
81
    physics.gravity(Gravity)
82
    background(0, 0, 0, 10)
83
    strokeWidth(3)
84
    stroke(255, 255, 255, 255)
85
    
86
    sprite("Documents:stars",WIDTH/2,HEIGHT/2)
87
    debugText()
88
89
90
    ~~
91
    for k, ball in pairs(balles) do
92
     fill(math.random(0,255),math.random(0,255), math.random(0,255), math.random(0,255))
93
    
94
    end
95
    ~~
96
    
97
    ~~
98
    for a, stars in pairs(star) do
99
       strokeWidth(.5)
100
        fill(math.random(0,255),math.random(0,255), math.random(0,255), math.random(0,255))
101
         ellipse(stars.x, stars.y, stars.radius*2)
102
      end
103
    ~~
104
105
    FPS = frames / ( ElapsedTime - time_start)
106
    frames=frames+1
107
108
end
109
110
    function debugText()
111
        fill(255)
112
        font("Georgia-Italic")
113
        textSize(5)
114
        textMode(CORNER)
115
        
116
        text("Particles alive: ", 10, 1000)
117
        text("Little particules: "..x.. "/" ..max, 10, 980)
118
        text("Big particules: "..maxer.. "/" ..maxGreat, 10, 960)
119
        text("FPS: " ..FPS, WIDTH-60, 1000)
120
        end