Orb-Bits
  • MarkMark February 17

    An update of the little game I put together for Zoyt's competition. Now with scoring, new system designs, minor tweaks, and even more obnoxious sounds.

  • MarkMark February 17
    Ship = class()
    
    function Ship:init(r, d)
        self.radius = r
        self.deg = d
        self.planet = 0
        self.landed = false
        self.x = 0
        self.y = 0
        self.dd = 100 / r * -1
        self.fire = false
        self.exploded = false
        self.exptimer = 1
        self.fuel = 1000
    end
    
    function Ship:land(p)
        self.radius = p.radius + p.size / 2
        self.deg = p.deg + 2
        self.landed = true
    end
        
    function Ship:draw()
        local r, tx, ty, i
        -- the further from the center, the slower it goes
        self.deg = self.deg + self.dd
        if self.deg > 360 then
            self.deg = self.deg - 360
        end
        r = math.rad(self.deg)
        tx = (self.radius * scale) * math.cos(r) + WIDTH / 2
        ty = (self.radius * scale) * math.sin(r) + HEIGHT / 2
        self.x = tx
        self.y = ty
        stroke(235, 235, 234, 255)
        pushMatrix()
        translate(self.x, self.y)
        rotate(self.deg - 90)
        if not self.exploded then
            line(0, 0, 5, 15)
            line(5, 15, 10, 0)
            line(10, 0, 0, 0)
            if self.fire then
                sound(SOUND_SHOOT, 29097)
                stroke(223, 148, 161, 255)
                line(2, 0, 5, -5)
                line(8, 0, 5, -5)
                line(5, 0, 5, -11)
                self.radius = self.radius + 1
                self.dd = 100 / self.radius * -1
                self.landed = false
            else
                if self.landed == false then
                    self.radius = self.radius - 100 / self.radius
                    if self.radius < 0 then
                        self.radius = 0
                    end
                    self.dd = 100 / self.radius * -1
                end
            end
        else
            if self.exptimer < 100 then
                self.exptimer = self.exptimer + 1
                line(self.exptimer, 0, self.exptimer, 0)
                line(0, self.exptimer, 0, self.exptimer)
                line(-self.exptimer, -self.exptimer, 
                self.exptimer, self.exptimer)
                line(-self.exptimer, self.exptimer, 
                self.exptimer, -self.exptimer)
            end
        end
        popMatrix()
        pushMatrix()
        translate(WIDTH - 50, 0)
        local y
        y = (HEIGHT - 100) / 1000
        stroke(0, 216, 255, 255)
        if self.fuel < 200 then
            stroke(255, 26, 0, 255)
        end
        
        strokeWidth(2)
        line(20, 50, 20, 50 + y * self.fuel)
        fontSize(14)
        fill(0, 250, 255, 255)
        text("Fuel", 20, 40)
        
        popMatrix()
    end
    
  • MarkMark February 17
    Orbiter = class()
    
    function Orbiter:init(r, d, s)
        -- set initial location
        self.radius = r
        self.deg = d
        self.size = s
        self.x = 0
        self.y = 0
        self.dd = 100 / r * -1
        self.clr = color(255, 255, 255, 255)
        self.tagged = false
        self.scale = 1
    end
    
    function Orbiter:draw()
        local r, x, y
        noFill()
        stroke(self.clr)
        strokeWidth(2)
        -- the further from the center, the slower it goes
        self.deg = self.deg + self.dd
        if self.deg > 360 then
            self.deg = self.deg - 360
        end
        r = math.rad(self.deg)
        self.x = (self.radius * scale) * math.cos(r) + WIDTH / 2
        self.y = (self.radius * scale) * math.sin(r) + HEIGHT / 2
        pushMatrix()
        translate(self.x, self.y)
        rotate(self.deg - 90)
        ellipse(0, 0, self.size)
        x = self.size / 2
        if self.tagged then
            line(-x, 0, x, 0)
            line(0, -x, 0, x)
        end
        popMatrix()
    end
        
     function Orbiter:land(x, y)
        if math.abs(self.x - x) < self.size / 2 + 10 and
        math.abs(self.y - y) < self.size / 2 + 10 then
            return true
        else
            return false
        end
        
    end
    
  • MarkMark February 17

    I created a blank file and named it Misc just because I needed to pull out this one function to make the Main file fit into a single comment. You can put this function into a file, or toss it back in main following setup.

    function newSystem()
        local i
        fadetimer = 255
        if system == 1 then
            planets = {}
            rocks = {}
            planets[1] = Orbiter(75, 0, 20)
            planets[1].clr = color(222, 222, 222, 255)
            planets[2] = Orbiter(150, 0, 30)
            planets[2].clr = color(231, 230, 84, 255)
            planets[3] = Orbiter(220, 0, 30)
            planets[3].clr = color(134, 196, 224, 255)
            for i = 1, 36 do
                rocks[i] = Orbiter(320, i * 10, 6)
                rocks[i].clr = color(255, 0, 14, 255)
                rocks[i].tagged = true
            end
            ship = Ship(planets[1].radius, 0)
            ship.fuel = 600
        elseif system == 2 then
            planets = {}
            rocks = {}
            planets[1] = Orbiter(80, 0, 22)
            planets[1].clr = color(166, 255, 0, 255)
            planets[2] = Orbiter(150, 0, 35)
            planets[2].clr = color(0, 237, 255, 255)
            planets[3] = Orbiter(322, 0, 40)
            planets[3].clr = color(255, 0, 222, 255)
            for i = 1, 36 do
                rocks[i] = Orbiter(200 + i * 10, i * 10, 6)
                rocks[i].clr = color(255, 0, 14, 255)
                rocks[i].tagged = true
            end
            ship = Ship(planets[2].radius, 0)
            ship.fuel = 500
        elseif system == 3 then
            planets = {}
            rocks = {}
            planets[1] = Orbiter(80, 0, 22)
            planets[1].clr = color(255, 0, 75, 255)
            planets[2] = Orbiter(80, 90, 22)
            planets[2].clr = color(0, 237, 255, 255)
            planets[3] = Orbiter(80, 180, 22)
            planets[3].clr = color(255, 0, 222, 255)
            planets[4] = Orbiter(80, 270, 22)
            planets[4].clr = color(103, 133, 29, 255)
            for i = 1, 12 do
                rocks[i] = Orbiter(150, i * 30, 6)
                rocks[i].clr = color(255, 0, 14, 255)
                rocks[i].tagged = true
            end
            planets[5] = Orbiter(220, 0, 44)
            planets[5].clr = color(103, 133, 29, 255)
            for i = 1, 12 do
                rocks[i + 12] = Orbiter(300, i * 30, 6)
                rocks[i + 12].clr = color(255, 0, 14, 255)
                rocks[i + 12].tagged = true
            end
            planets[6] = Orbiter(350, 0, 36)
            planets[6].clr = color(206, 0, 255, 255)
            ship = Ship(planets[1].radius, 0)
            ship.fuel = 800
        elseif system == 4 then
            planets = {}
            rocks = {}
            planets[1] = Orbiter(100, 0, 22)
            planets[1].clr = color(227, 229, 223, 255)
            planets[2] = Orbiter(150, 0, 35)
            planets[2].clr = color(0, 237, 255, 255)
            planets[3] = Orbiter(290, 0, 20)
            planets[3].clr = color(255, 0, 222, 255)
            planets[4] = Orbiter(340, 0, 20)
            planets[4].clr = color(0, 255, 2, 255)
            for i = 1, 36 do
                rocks[i] = Orbiter(200 + math.random(50), i * 10, 6)
                rocks[i].clr = color(255, 0, 14, 255)
                rocks[i].tagged = true
            end
            ship = Ship(planets[4].radius, 0)
            ship.fuel = 400
        elseif system == 5 then
            planets = {}
            rocks = {}
            planets[1] = Orbiter(35, 0, 15)
            planets[1].clr = color(224, 226, 221, 255)
            planets[2] = Orbiter(75, 0, 25)
            planets[2].clr = color(180, 225, 90, 255)
            planets[3] = Orbiter(125, 0, 25)
            planets[3].clr = color(0, 236, 255, 255)
            planets[4] = Orbiter(200, 0, 20)
            planets[4].clr = color(255, 145, 0, 255)
            for i = 1, 36 do
                rocks[i] = Orbiter(260 + math.random(35), i * 10, 6)
                rocks[i].clr = color(255, 0, 14, 255)
                rocks[i].tagged = true
            end
            planets[5] = Orbiter(340, 0, 50)
            planets[5].clr = color(176, 0, 255, 255)
            ship = Ship(planets[4].radius, 0)
            ship.fuel = 600
        else
            -- random system
            numplanets = math.random(5) + 1
            planets = {}
            for i = 1, numplanets do
                planets[i] = Orbiter(i *  75, math.random(360), 
                math.random(25) + 10)
                planets[i].clr = color(155 + math.random(100), 
                155 + math.random(100), 155 + math.random(100), 255)
            end
            rocks = {}
            --ring 1
            numrocks = math.random(30) + 1
            for i = 1, numrocks do
                rocks[i] = Orbiter( 190 + math.random(30), 
                math.random(360), 6)
                rocks[i].clr = color(255, 0, 14, 255)
                rocks[i].tagged = true
            end
            ship = Ship(planets[numplanets].radius, 
            planets[numplanets].deg)
            ship.fuel = 600
        end
    end
    
  • MarkMark February 17

    And here's Main.


    -- Orb-Bits -- ======================= -- Version 1.1 -- Mark Sumner -- ======================= function setup()     displayMode(FULLSCREEN)     x = 100     y = 100     system = 1     scale = 1     deg = 270     ship = Ship(111,111)     score = 0     newSystem()     soundtimer = 0     fadetimer = 255     gameon = true     bestscore = readLocalData("high")     if bestscore == nil then bestscore = 0 end end function draw()     local i     background(0, 0, 0)     noSmooth()     stroke(246, 255, 0, 255)     pushMatrix()     translate(WIDTH/2, HEIGHT/2)     i = math.random(10) + 15     line(-i, 0, i, 0)     line(0, -i, 0, i)     line(-i, -i, i, i)     line(-i, i, i, -i)     popMatrix()     font("Copperplate-Bold")     fontSize(48)     if fadetimer > 0 then         fill(179, 160, 160, fadetimer)         text("System "..system, WIDTH / 2, HEIGHT / 2+50)     end     fill(116, 206, 226, 255)     fontSize(24)     text(score, 100, HEIGHT-24)     text(bestscore, WIDTH - 100, HEIGHT-24)     alltagged = true     for i, p in ipairs(planets) do         p:draw()         if ship.fire == false and p:land(ship.x, ship.y) then             if not p.tagged then                  score = score + system * 100                 sound(SOUND_HIT, 19317)             end             ship:land(p)             p.tagged = true             if ElapsedTime > soundtimer + 1 then                 sound(SOUND_BLIT, p.radius)                 soundtimer = ElapsedTime             end         end         if not p.tagged then             alltagged = false         end     end     for i, r in ipairs(rocks) do         r:draw()         if r:land(ship.x, ship.y) and not ship.exploded then             sound(SOUND_EXPLODE, 27961)             ship.exploded = true             ship.exptimer = 1         end     end     if CurrentTouch.state == BEGAN or CurrentTouch.state == MOVING then         if gameon then             if not ship.exploded then                 if ship.fuel > 0 then                     ship.fire = true                     ship.fuel = ship.fuel - 1                 end             end         else             if score > bestscore then                 saveLocalData("high", score)                 bestscore = score             end             gameon = true             ship = Ship(1000,1)             scale = 1             system = 1             score = 0             newSystem()         end     else         ship.fire = false     end     ship:draw()     if alltagged then         scale = scale + 0.1         if scale > 8 then             system = system + 1             score = score + ship.fuel             newSystem()         end     else         if scale > 1 then             scale = scale - 0.1         end     end     if ship.radius < 10 then         if scale > 0 then             sound(DATA, "ZgJAQgBFETsPLjNnGVWbO2JQWT8Y"..             "mL++QwA4ZEF+PxYvbRph")             scale = scale - 0.1         else             gameon = false         end     end     if ship.exploded and ship.exptimer > 20 then         gameon = false     end     if not gameon then         font("Copperplate-Bold")         fill(252, 252, 252, 255)         fontSize(48)         text("Game Over", WIDTH / 2, HEIGHT / 2 - 50)     end      fadetimer = fadetimer - 1      end
  • Juanjo56Juanjo56 February 17

    Only I want to do a comment It is on something that already and I dress in several code: where you put: bestscore = readlocaldata ("high") if bestscore == nil then bestscore = 0 end meiby to be simply: bestscore = readlocaldata("high",0)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with OpenID Sign In with Google

Sign In Apply for Membership

In this Discussion

Tagged