Block slicer

I will get the code for block slicer in a bit…

What’s block slicer? Is it like Icebreaker?

No…

More like fruit ninja

Any more info?

Is there any purpose to this discussion if you don’t describe the game at all or supply any code?

Got the code:

displayMode(FULLSCREEN)

function setup()    
    bf={}
    fru={}
    touches = {}
    timer=0.1
    fs=9
    score=0
    lf={}
    rf={}
end


function touched(touch)
    if touch.state == ENDED then

        touches[touch.id] = nil
    else

        touches[touch.id] = touch
    end
end

function draw()

physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
    timer = timer + DeltaTime
     background(68, 53, 30, 255)
sprite("Cargo Bot:Background Fade",WIDTH/2,HEIGHT/2)
    for k,touch in pairs(touches) do

        math.randomseed(touch.id)

        fill(0, 161, 255, 255)
        sprite("Small World:Sword")
    

        ellipse(touch.x, touch.y,30)
        table.insert(bf,{x=touch.x,y=touch.y,t=300,s=7})
                for i,f in pairs(fru) do 
                    if math.abs(f.x-touch.x)<40 and math.abs(f.y-touch.y)<40 then
                        score = score +1
                        local r=physics.body(CIRCLE,f.size/3)
                        r.x=f.x+100
                        r.y=f.y
                        r.linearVelocity=vec2(math.random(50,100))
                        r.type=DYNAMIC
                        r.s=f.size
                        r.angle=math.deg(math.atan2(CurrentTouch.y-f.y,CurrentTouch.x-f.x))
                        table.insert(rf,r)
                                  local l=physics.body(CIRCLE,f.size/3)
                        l.x=f.x-100
                        l.y=f.y
                        l.linearVelocity=vec2(math.random(-100,-50))
                        l.type=DYNAMIC
                        l.s=f.size
                        l.angle=math.deg(math.atan2(CurrentTouch.y-f.y,CurrentTouch.x-f.x))-90
                        table.insert(lf,l)
                        table.remove(fru,i)

                    end
                    end

    for i,b in pairs(bf)  do 
        sprite("Platformer Art:Water",b.x,b.y,b.s)
        strokeWidth(1)
        stroke(255, 0, 0, 255)
        b.t = b.t -40
        if b.t<=0 then
            table.remove(bf,i)
        end
        end
        end

        if timer>0 then
         local   size=math.random(30,60)
       local fruit=physics.body(CIRCLE,size/2)
    fruit.size=size
    fruit.x=math.random(100,WIDTH-100)
    fruit.y=-10
    fruit.restitution=.9
    fruit.type=DYNAMIC
    fruit.linearVelocity=vec2(math.random(-100,100),math.random(600,700))
    fruit.angle=math.random(90)
    table.insert(fru,fruit)
            timer=math.random(-4,-1)
end
for i,f in pairs(fru) do 
    pushMatrix()
    translate(f.x,f.y)
    rotate(f.angle)
    sprite("Platformer Art:Block Brick",0,0,f.size,f.size)
    popMatrix()

    if 
    f.y<-100 then
        table.remove(fru,i)
        end
        end
pushStyle()
            text("Score:"..score,50,HEIGHT-50)  
            popStyle()    



    for j,r in pairs(rf) do 

        pushMatrix()
        translate(r.x,r.y)
        rotate(r.angle)
        sprite("Small World:Treasure",0,0,r.s/2)
        if r.y<0
    then table.remove(rf,j)
    end
    popMatrix()

        end


    for j,r in pairs(lf) do 

        pushMatrix()
        translate(r.x,r.y)
        rotate(r.angle)
        sprite("Space Art:Red Explosion",0,0,r.s/2)
        popMatrix()



     if r.y<0
    then table.remove(lf,j)
    end
        end

    end

So, just copy the code. I hope none of my art is in there

This is a great game and is fun to play well done. =D> =D>

Two changes though.
Put:

physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))

In setup() rather than draw() since you only need to define them once(this stops the program crashing my iPad due to lack of memory.

And when drawing the background with

sprite("Cargo Bot:Background Fade",WIDTH/2,HEIGHT/2)

Add a forth parameter as the width of the image to fill the entire screen:

sprite("Cargo Bot:Background Fade",WIDTH/2,HEIGHT/2,WIDTH)

@Coder just putting physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT)) in setup won’t work, you need to define it with a global variable to keep it in memory otherwise garbage collector comes along and eats it right up and your physics body is gone. This is what I learnt when first approaching physics, so that may be why he thought to put it in draw function.

Ok sorry i should have checked that.

Don’t apologize, not criticising just sharing knowledge learnt from the same mistakes.

@Luatee, @Coder - you shouldn’t create new edges 60 times a second in draw, you only need to do it once in setup. To avoid them being collected by garbage, simply assign them to a global variable, eg

e1=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))

As long as your edge is referred to by a variable, it is safe from garbage collection

EDIT - sorry, Luatee, I see you already said that, my mistake

@Ignatz Also, @Coder pointed out that the edges were made in draw instead of setup.

The user and all related content has been deleted.

~X(