Howdy, Stranger!

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

Run Multiple Tabs?

edited November 5 in Questions Posts: 15

I’m trying to make it so if you touch a (button) that says easy , on the main tab, you’ll start the flappy bird example on a different tab, idk how or where to put the code for that. I guess my code is to long to post on here...

Comments

  • dave1707dave1707 Mod
    Posts: 7,155

    @CodeLearnerMike There’s an example somewhere on this forum where someone wrote a program where you could run the different example programs from a menu. I don’t remember who wrote it or how long ago it was. Is that what you’re after.

  • edited November 5 Posts: 58

    --# Main -- Screen function setup() currentScreen = Screen1() end function draw() background(0,0,0) currentScreen:draw() end function touched(touch) currentScreen:touched(touch) end --# Screen1 Screen1 = class() function Screen1:init() font("Futura-CondensedExtraBold") fontSize(22) textMode(CENTER) end function Screen1:draw() background(185, 81, 81, 255) text("Screen 1 tape Screen", WIDTH/2, HEIGHT/2) end function Screen1:touched(touch) if touch.tapCount==1 then currentScreen = Screen2() end end --# Screen2 Screen2 = class() function Screen2:init() font("AmericanTypewriter-Bold") fontSize(22) textMode(CENTER) end function Screen2:draw() background(100, 41, 106, 255) text("Screen 2 double tap Screen", WIDTH/2, HEIGHT/2) end function Screen2:touched(touch) if touch.tapCount == 2 then currentScreen = Screen1() end end
  • edited November 5 Posts: 1,014

    @CodeLearnerMike - might have got the wrong idea about what you are wanting to achieve, but - I thought you wanted to run separate programs by selecting options - so an easy mode, a harder mode and !!$#&!!! I'll never be able to do that !!!

    If so try looking under the first Craft demo (Learn Craft) where John has set several demo programs (each with their own setup) and run them from the Main.lua which is the last tab.

  • @dave1707 that may be a good place to start,seems everyone has a different way of doing things though lol , I wish all commands that work in lua were highlighted, like how function is purple. @Diablo76 it works by itself, but when I copy and paste the bubble example (cause it’s simple) code into screen2 I loose sceeen1s menu ,I tried getting the menu on screen1 to work but couldn’t ... @Bri_G well by programs I mean different code from different tabs,so let’s say we have a main tab with code for a button that says Start ,and when touched it loads a second tab let’s say called screen2,and on screen2 it loads the most important code, the game itself.

  • dave1707dave1707 Mod
    Posts: 7,155

    @CodeLearnerMike Look at the code I have in this link. See if you might be able to use something like it. When you go into the different sites, press Done in the upper left of the screen to return back to the program.

    https://codea.io/talk/discussion/8785/setting-up-a-game
    
  • @dave1707 Thanks that code is simple to understand, however could you edit it to allow for one of the buttons when touched to load a different tab with let’s say the bubble example, instead of main? I tried myself but just end up either getting errors,blank screen,etc.
    I defiantly appreciate all your guys help.

  • dave1707dave1707 Mod
    Posts: 7,155

    @CodeLearnerMike Here’s an example to run Bubbles from a menu. Just to let you know, the Bubbles code here was modified to work with a menu, so you can’t just run any example code using this. As I said above, there’s an example somewhere in this forum that might let you run any example from a menu. I just haven’t found it yet. Copy this code then long press Add New Project to create this code into tabs.

    --# Main
    
    displayMode(FULLSCREEN)
    
    function setup()
        rectMode(CENTER)
        emitter = Bubbles(0, 0)
    end
    
    function draw()
        if bubb then
            background(40, 40, 50)
            fill(255)
            text("Drag your finger to make bubbles", WIDTH/2, HEIGHT - 60)
            fill(255,0,0)
            text("Tap here to return to the menu.",WIDTH/2,HEIGHT-30)
            emitter:update()
            emitter:draw()
        else
            background(255, 154, 0, 255)
            fill(0)
            rect(WIDTH/2-10,HEIGHT/2-10,200,100)
            fill(255)
            rect(WIDTH/2,HEIGHT/2,200,100)
            fill(0)
            text("Tap here to start Bubbles",WIDTH/2,HEIGHT/2)        
        end
    end
    
    function touched(t)
        if t.state==BEGAN then
            if not bubb then
                if t.x>WIDTH/2-100 and t.x<WIDTH/2+100 and
                        t.y>HEIGHT/2-50 and t.y<HEIGHT/2+50 then
                    bubb=true
                end
            elseif bubb and t.y>HEIGHT-70 then
                bubb=false
            end
        elseif t.state==MOVING and bubb then
            emitter.x = t.x
            emitter.y = t.y
            emitter:emit()
        end
    end
    
    --# Bubble
    
    Bubbles = class()
    
    function Bubbles:init(x, y)
        self.x = x
        self.y = y
        self.bubbles = {}
        self.maxbubbles = 100
        self.bubblecount = 0
    end
    
    function Bubbles:emit()
        if self.bubblecount < self.maxbubbles then
            local dir = vec2(0,1):rotate(math.random() - 0.5) * math.random(1,6)
            local size = math.random(10, 50)
            local life = math.random(30, 60)
            local bubble = {pos = vec2(self.x, self.y), 
                            dir = dir, 
                            size = size, 
                            life = life}
            table.insert(self.bubbles, bubble)
            self.bubblecount = self.bubblecount + 1
        end
    end
    
    function Bubbles:update()
        for k,v in pairs(self.bubbles) do
            v.pos = v.pos + v.dir
            v.life = v.life - 1
            if v.life == 0 then
                self.bubbles[k] = nil
                self.bubblecount = self.bubblecount - 1
            end
        end
    end
    
    function Bubbles:draw()
        pushStyle()
        ellipseMode(CENTER)
        stroke(255)
        strokeWidth(4)
        fill(153, 197, 210, 100)
        for k,v in pairs(self.bubbles) do
            ellipse(v.pos.x, v.pos.y, v.size)
        end
        popStyle()
    end
    
Sign In or Register to comment.