Howdy, Stranger!

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

Help getting started

Hi I’m new and just trying to learn how to use Codea. I’d like to make like a top down rts style game. The first thing I’d like to create maps similar to the terrain example but without voxels. I thought maybe I would use craft.model.plane to create maps, but I can’t figure out much on how to use it. Maybe someone could point me in the right direction. (Also I can’t seem to find a way to search this site for specific posts)

Comments

  • dave1707dave1707 Mod
    Posts: 9,977

    @boberto To search the forum, enter what you want to search for in the box to the left of the magnifying glass at the upper right, above New Discussion.

  • SimeonSimeon Admin Mod
    Posts: 5,778

    There is a search field in the top right on desktop (and iPad). On iPhone you may have to tap the "aA" button and choose "Request Desktop Website" to get the search field

    @John may be able to point you in the right direction with Craft-based-maps. Otherwise you could build your model and render it using the 2D rendering (lines, sprites, shapes) to get a sense of how the gameplay should work before attempting to render it in 3D or isometric with Craft

  • Posts: 2,689
    @boberto - the only way I have been able to build terrain maps is with the mesh system. But I'm sure, in the recent conversations on expanding Craft, @John made some reference into a Craft mesh which is accessible but gave no details. I'd search through those recent posts to start with and hope @John posts some details.
  • JohnJohn Admin Mod
    Posts: 762

    @Bri_G the Craft equivalent of mesh is craft.model, which has a pretty similar API to the original one. You just use it with entities instead drawing it directly. The World Generator project is an advanced example of this, but you could make a simpler flat one with pretty similar techniques

  • Posts: 2,689
    @John - thanks for the update, I'll look into that - pulled out a few old projects recently that could apply it. Thanks again.
  • dave1707dave1707 Mod
    edited December 2021 Posts: 9,977

    @boberto Is this something you might be able to use or to start with. Move your finger on the screen to move in the direction you want to go.

    viewer.mode=FULLSCREEN
    
    function setup()
        bx,bz,sx,vel,dir=0,0,0,0,0    
        scene = craft.scene()      
        ground=scene:entity()
        ground.model = craft.model.cube(vec3(1000,1,1000))
        ground.position=vec3(0,-2,0)
        ground.material = craft.material(asset.builtin.Materials.Standard)
        ground.material.map = readImage(asset.builtin.Surfaces.Desert_Cliff_Color)
        ground.material.offsetRepeat=vec4(0,0,10,10)    
        cam = scene:entity()
        cam:add(craft.camera, 60, .1, 1000, false)
    
        for z=1,100 do
            local t=scene:entity()
            t.model = craft.model(asset.builtin.Nature.naturePack_052_obj)
            t.position=vec3(math.random(-400,400),-2,math.random(-400,400))
            local t=scene:entity()
            t.model = craft.model(asset.builtin.Nature.naturePack_061_obj)
            t.position=vec3(math.random(-400,400),-2,math.random(-400,400))
        end
    end
    
    function update(dt)
        scene:update(dt)
        cam.eulerAngles = vec3(0,180+dir,0)
        bx=bx-vel*math.sin(math.rad(dir))
        bz=bz-vel*math.cos(math.rad(dir))
        cam.position=vec3(bx,0,bz)
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()    
        dir=dir-sx/5
        joyStick()
    end
    
    function joyStick()
        if show then
            d=vec2(cx,cy):dist(vec2(x,y))
            if d<50 then
                px,py=x,y
            else
                px=(x-cx)*60/d+cx
                py=(y-cy)*60/d+cy
            end
            d1=vec2(px,py):dist(vec2(cx,cy))
            sx=(px-cx)/(d1/4+.01)
            vel=((py-cy)/(d1/4+.01))/20
        end
    end
    
    function touched(t)
        if t.state==BEGAN then
            cx,cy=t.x,t.y
            x,y=cx,cy
            show=true
        elseif t.state==MOVING then
            x,y=t.x,t.y
        elseif t.state==ENDED then
            show=false
            vel=0
            sx=0
        end
    end
    
Sign In or Register to comment.