Howdy, Stranger!

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

Codea fruits vs blades Vr:1

edited November 2013 in Code Sharing Posts: 6

Hello every body it's my game
It's Vr :1 I am going to do more update as soon as possible
Here is a video :

And here code:

displayMode(FULLSCREEN)
function setup()
    bf={}
    fru={}
    touches = {}
    timer=0
    fs=0
    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(255, 255, 255, 255)
sprite("Documents:bg",WIDTH/2,HEIGHT/2)
    for k,touch in pairs(touches) do

        math.randomseed(touch.id)

        fill(255, 0, 0, 255)

        ellipse(touch.x, touch.y,20)
        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+10
                        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-10
                        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("Cargo Bot:Crate Goal Red",b.x,b.y,b.s)
        strokeWidth(1)
        stroke(0, 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(60,100)
       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("Documents:wm",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("Documents:rf",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("Documents:lf",0,0,r.s/2)
        popMatrix()



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

    end

Comments

  • edited November 2013 Posts: 547

    @matinMN nice, but I'dd watch out with the copyright on the textures and name, call it differently and change the pictures and there's no problem at all

    also, put 3 ~ on the line before and after the code to format it nicely

  • Yea I will change the background and also the name

  • IgnatzIgnatz Mod
    Posts: 5,396

    I fixed the formatting.

    Your app looks exactly like Cut the Fruit. No problem as long as you don't try to sell it!

  • Here is anew Vr:2.1

    also problem how can I use just half of a photo please help. Me

  • IgnatzIgnatz Mod
    Posts: 5,396

    Use a picture editing program to cut the picture in half and make a new picture

  • Also, if you wanna keep try to the 'fruit ninja' type of game, you shouldn't use physics bodies

    I can think of 2 reasons why not to use them

    1) Once you'dd go with powerups and get 'frenzy' then they would slow the game down
    2) They shouldn't be supposed to bounce off on collission with eachother

  • edited December 2013 Posts: 1,976

    I would create another image, sprite the image you want to cut in half in it, but half way down so it gets cut off, and sprite that. Example/function:

    -- Image Slice
    
    function setup()
        myImage = readImage("Platformer Art:Mushroom")
        imageTop, imageBottom = sliceImage(myImage)
    end
    
    function sliceImage(theImage)
        local topHalf = image(theImage.width, theImage.height)
        local bottomHalf = image(theImage.width, theImage.height)
        setContext(topHalf)
        sprite(theImage, theImage.width / 2, theImage.height / 4)
        setContext(bottomHalf)
        sprite(theImage, theImage.width / 2, theImage.height * 1.25)
        setContext()
        return topHalf, bottomHalf
    end
    
    function draw()
        background(255)
        sprite(myImage, 100, 100)
        sprite(imageTop, 200, 100)
        sprite(imageBottom, 300, 100)
    end
    

    Should work with any sprite

    @Ignatz I thought you'd go with a code approach...

  • What SkyTheCoder gives is a great start, if you wanna go more complex and make it so that you can cut it in any way you'dd like, that's possible as well, but that requires some more thinking and math, but it should't slow the program to much down

    But the example above creates the images in setup, which saves memory for later

  • Posts: 437

    Hey, I like the project, to add a similar line fx you can use something like this:

            local l = nil
            for k,p in ipairs(self.fingerLastPos) do
                if l then
                    local a = math.fmod(k,11)
                    strokeWidth(a)
                    stroke(233-(a*11), 166-k-2)
                    line(p.x,p.y, l.x, l.y)
                end
                l = p
           end
    

    where self.fingerLastPos are a table with last vec2 touch positions.
    Regards

  • Posts: 1,595

    You could also put blendmode Additive in before the line draw call to make it look a more like the knife slash, depends on the stroke colour though as to how it's affected..

Sign In or Register to comment.