Can someone help me for my shooter game?

Why can’t I shoot with this code (so with the code you should be able to shoot because maybe that sounds strange) btw: the code is for a shooter game.


function setup()
    x = 10
    a = true
    
end

function draw()
    
    background(128)
    -- Monster-Klasse definieren
shootX = x


    sprite(asset.builtin.Planet_Cute.Character_Boy,x, 500)
    if a then
    x = x + 5
        b = false 
        tween.delay(1, function()
            a = false
            b = true
           a = false 
        end)
        
     
    end
    
    if b then
        x = x - 5
        a = false
        tween.delay(1, function()
            b = false
        a = true  
        end)
    end
    
    
    
    if shoot then
        sprite(asset.builtin.UI.Blue_Button_05, shootX, 500)
        sprite.x = sprite.x + 5
    end
end

function touched(t)
    if t.state == ENDED then
        shoot = true
    end
end

sprite.x is undefined. Change that to a valid variable name.

@dave1707 No. Because that wouldn’t work either because actually I wanted that when you click that you shoot a small ball for my shooter game, I’ve made such a similar game before and it worked but you couldn’t move a character because in my actual shooter game you can move

Here’s a simple example. Tap screen to shoot.

viewer.mode=FULLSCREEN

function setup()
    x,y=0,HEIGHT*.8
    speed=3
    sTab={}
    dist=40
end

function draw()    
    background(224, 205, 178)
    if hit then
        sprite(asset.builtin.Tyrian_Remastered.Explosion_Ball,x,y,90)
    else
        x=x+speed
        if x<0 or x>WIDTH then
            speed=-speed       
        end
        sprite(asset.builtin.Planet_Cute.Character_Boy,x,y)
        for a,b in pairs(sTab) do
            sprite(asset.builtin.Tyrian_Remastered.Twisted, WIDTH/2, b)
            sTab[a]=sTab[a]+10
            if sTab[a]>y-dist and sTab[a]<y+dist and x>WIDTH/2-dist and x<WIDTH/2+dist then
                hit=true
                speed=0
            end
            if sTab[a]>HEIGHT then
                table.remove(sTab,a)
            end                   
        end
    end
end  
      
function touched(t)
    if t.state == ENDED then
        table.insert(sTab,1)
        
    end
end

@dave1707 Oh, the code is good but actually I wanted you to be able to move a character and the ball appears at the character (but I forgot to write that to them) and here is the code to move again:


function setup()
    Charaktere = {
        asset.builtin.Planet_Cute.Character_Boy
    }
    x = 10
    y = 10
    
    time = os.date("*t")
stunde = time.hour
minute = time.min
end

function draw()
    background(0)
    sprite(asset.builtin.Planet_Cute.Character_Boy, y, x)
    
    
    sprite(asset.builtin.Blocks.Cactus_Inside, 200, 250, 250, 400)
    sprite(asset.builtin.UI.Blue_Button_07, 200, 420)
    sprite(asset.builtin.UI.Blue_Button_07, 300, 250)
    sprite(asset.builtin.UI.Blue_Button_07, 100, 250)
    sprite(asset.builtin.UI.Blue_Button_07, 200, 100)
end
function touched(t)
if t.state == MOVING then        
        if t.x >= 200-120 and t.x <= 200+120 and 
            t.y >= 420-49 and t.y <= 420+49 then   
            x = x + 5
            
        end 
        end     
        
     if t.state == MOVING then        
        if t.x >= 200-120 and t.x <= 200+120 and 
            t.y >= 100-49 and t.y <= 100+49 then   
            x = x - 5
            
        end 
    end 
    
    if t.state == MOVING then        
        if t.x >= 300-120 and t.x <= 300+120 and 
            t.y >= 250-49 and t.y <= 250+49 then   
            y = y + 5
            
        end 
    end 
    
    if t.state == MOVING then        
        if t.x >= 100-120 and t.x <= 100+120 and 
            t.y >= 250-49 and t.y <= 250+49 then   
            y = y - 5
            
        end 
    end 
    
    
    if t.state == BEGAN then        
        if t.x >= 200-120 and t.x <= 200+120 and 
            t.y >= 420-49 and t.y <= 420+49 then   
            x = x + 5
            
        end 
        end     
        
     if t.state == BEGAN then        
        if t.x >= 200-120 and t.x <= 200+120 and 
            t.y >= 100-49 and t.y <= 100+49 then   
            x = x - 5
            
        end 
    end 
    
    if t.state == BEGAN then        
        if t.x >= 300-120 and t.x <= 300+120 and 
            t.y >= 250-49 and t.y <= 250+49 then   
            y = y + 5
            
        end 
    end 
    
    if t.state == BEGAN then        
        if t.x >= 100-120 and t.x <= 100+120 and 
            t.y >= 250-49 and t.y <= 250+49 then   
            y = y - 5
            
        end 
    end 
end

The touched function could be cut down to this. Is the character going to be able to shoot and if so in which direction.

function touched(t)
    if t.state == BEGAN or t.state==MOVING then        
        if t.x >= 200-120 and t.x <= 200+120 and 
        t.y >= 420-49 and t.y <= 420+49 then   
            x = x + 5            
        elseif t.x >= 200-120 and t.x <= 200+120 and 
        t.y >= 100-49 and t.y <= 100+49 then   
            x = x - 5            
        elseif t.x >= 300-120 and t.x <= 300+120 and 
        t.y >= 250-49 and t.y <= 250+49 then   
            y = y + 5           
        elseif t.x >= 100-120 and t.x <= 100+120 and 
        t.y >= 250-49 and t.y <= 250+49 then   
            y = y - 5            
        end 
    end    
end

Here’s an example that allows the character to move around and shoot. Tap near the top of screen to shoot.

viewer.mode=FULLSCREEN    

function setup()
    tab={}
    x,y = WIDTH/2,60
end

function draw()
    background(0)
    sprite(asset.builtin.Planet_Cute.Character_Boy,x,y)    
    sprite(asset.builtin.Blocks.Cactus_Inside, 200, 250, 250, 400)
    sprite(asset.builtin.UI.Blue_Button_07, 200, 420)
    sprite(asset.builtin.UI.Blue_Button_07, 300, 250)
    sprite(asset.builtin.UI.Blue_Button_07, 100, 250)
    sprite(asset.builtin.UI.Blue_Button_07, 200, 100)
    shooting() 
end

function shooting()
    if shoot then
        shoot=false
        if #tab<5 then  -- only allow 5 bullets at a time
            table.insert(tab,vec2(x,y)) -- position of player for bullet
        end
    end
    for a,b in pairs(tab) do    -- show and increment bullet
        sprite(asset.builtin.Tyrian_Remastered.Evil_Spike,tab[a].x,tab[a].y)
        tab[a].y=tab[a].y+5
    end
    for a,b in pairs(tab) do        -- remove bullet when off screen at top
        if tab[a].y>HEIGHT then
            table.remove(tab,a)
        end
    end
end

function touched(t)
    if t.state==BEGAN and t.y>HEIGHT-200 then   -- shoot
        shoot=true
    end
    if t.state == BEGAN or t.state==MOVING then        
        if t.x >= 200-120 and t.x <= 200+120 and 
        t.y >= 420-49 and t.y <= 420+49 then   
            y = y + 5            
        elseif t.x >= 200-120 and t.x <= 200+120 and 
        t.y >= 100-49 and t.y <= 100+49 then   
            y = y - 5            
        elseif t.x >= 300-120 and t.x <= 300+120 and 
        t.y >= 250-49 and t.y <= 250+49 then   
            x = x + 5           
        elseif t.x >= 100-120 and t.x <= 100+120 and 
        t.y >= 250-49 and t.y <= 250+49 then   
            x = x - 5            
        end 
    end    
end

@dave1707 @Killer.Jo - nice to see you making progress, hope you can follow @dave1707 s code, it is a nice little demo.

Couldn’t resist playing with it (don’t get much time to nowadays) but added a few mods to hopefully make it a little mores interesting and to make it easier to read/understand. By adding a joypad creation function and naming the variables so it is more obvious. Hope that helps.


-- DS1707Shooter with mods

viewer.mode=FULLSCREEN_NO_BUTTONS
function setup()
    --
    init()
end

function draw()
    --
    background(0)
    sprite(pad,padPos.x, padPos.y)
    sprite(ship,x,y,120,160) 
    shooting() 
end

function shooting()
    offset = 20
    if shoot then
        shoot=false
        if #tab<5 then  -- only allow 5 bullets at a time
            table.insert(tab,vec2(x,y+offset)) -- position of player for bullet
        end
    end
    for a,b in pairs(tab) do    -- show and increment bullet
        sprite(asset.builtin.Tyrian_Remastered.Bullet_Simple_B, tab[a].x, tab[a].y+offset)
        tab[a].y=tab[a].y+5
    end
    for a,b in pairs(tab) do        -- remove bullet when off screen at top
        if tab[a].y+offset>HEIGHT then
            table.remove(tab,a)
        end
    end
end

function touched(t)
    if t.state ~= ENDED then
        if t.x >= padPos.x-40 and t.x <= padPos.x+40 then   -- shoot
            if t.y >= padPos.y-40 and t.y <= padPos.y+40 then
                shoot=true
            end
        end
    end
    if t.state == BEGAN or t.state==MOVING then        
        if t.x >= padLeft.x-40 and t.x <= padLeft.x+40 and 
        t.y >= padLeft.y-40 and t.y <= padLeft.y+40 then   
            x = x - 5            
        elseif t.x >= padRight.x-40 and t.x <= padRight.x+40 and 
        t.y >= padRight.y-40 and t.y <= padRight.y+40 then   
            x = x + 5            
        elseif t.x >= padUp.x-40 and t.x <= padUp.x+40 and 
        t.y >= padUp.y-40 and t.y <= padUp.y+40 then   
            y = y + 5           
        elseif t.x >= padDown.x-40 and t.x <= padDown.x+40 and 
        t.y >= padDown.y-40 and t.y <= padDown.y+40 then   
            y = y - 5            
        end 
    end    
end

function init()
    --
    tab={}
    x,y = WIDTH/2,60
    ship = asset.builtin.Tyrian_Remastered.Ship_B
    pad = image(248,248)
    padPos = vec2(128,136)
    padLeft = vec2(40,124)
    padRight = vec2(208,124)
    padUp = vec2(124, 208)
    padDown = vec2(124, 40)
    padFire = vec2(124, 124)
    makePad()
end

function makePad()
    --
    setContext(pad)
    textMode(CENTER)
    font("AmericanTypewriter-Bold")
    fontSize(32)
    ellipseMode(CENTER)
    fill(193, 196, 216)
    stroke(58, 67, 134)
    ellipse(124,124,200,200)
    fill(107, 211, 103)
    stroke(38, 74, 36)
    strokeWidth(8)
    ellipse(padLeft.x, padLeft.y,80,80)
    ellipse(padRight.x, padRight.y,80,80)
    ellipse(padDown.x, padDown.y,80,80)
    ellipse(padUp.x, padUp.y,80,80)
    fill(34, 105, 39)
    text("L",padLeft.x, padLeft.y)
    text("R",padRight.x, padRight.y)
    text("D",padDown.x, padDown.y)
    text("U",padUp.x, padUp.y)
    fill(255)
    stroke(184, 33, 24)
    ellipse(padFire.x, padFire.y,80,80)
    fill(251, 25, 12)
    text("F", padPos.x-4, padPos.y-12)
    setContext()
end

P.s. to simplify this you could save the joypad image from within Codea and remove that function call, just be careful as you would lose the links to the touch positions especially if you scale the joypad png you saved.

Progress may be slow now but it will get much faster with each step you take in learning.

If you want a joystick type control, replace the touched function with the code below. Use one finger to move the ship and do a double tap with another finger to shoot.

function touched(t)
    if t.state==BEGAN and t.tapCount==2 then
        shoot=true
    end
    if t.state==CHANGED then
        x=x+t.deltaX*2
        y=y+t.deltaY*2
    end
end

Ok, actually I wanted you to shoot to the left, but I’ve already arranged that myself. But could you still help me with the sprite called “guard” attacking the “player” (so the sprite guard should throw off the player with a sprite) and if the sprite hits something should happen (so first in the “chat” should be “test”) That could be a bit too much to ask but would be nice :+1:

Are you after something like this.


viewer.mode=FULLSCREEN
function setup()
    --
    init()
    tab1={}
    set()
    explode=false
end

function draw()
    --
    background(255, 185, 0)
    sprite(pad,padPos.x, padPos.y)
    sprite(ship,x,y,120,160) 
    shooting() 
    attack()
    hit()
end

function set()
    for z=1,10 do
        table.insert(tab1,vec2(math.random(WIDTH),HEIGHT+math.random(400)))
    end
end

function attack()
    for z=#tab1,1,-1 do
        sprite(asset.builtin.Tyrian_Remastered.Evil_Spike,tab1[z].x,tab1[z].y)
        tab1[z].y=tab1[z].y-math.random(0,3)
        if tab1[z].y<-5 then
            table.remove(tab1,z)
            table.insert(tab1,vec2(math.random(WIDTH),HEIGHT+math.random(200)))
        end
    end
end

function hit()
    for z=#tab1,1,-1 do
        if tab1[z].x>x-40 and tab1[z].x<x+40 and tab1[z].y>y-40 and tab1[z].y<y+40 then
            table.remove(tab1,z)
            explode=true
        end
    end
    if explode then
        sprite(asset.builtin.Tyrian_Remastered.Explosion_Huge,x,y,200)
    end
end

function shooting()
    offset = 20
    if shoot then
        shoot=false
        if #tab<5 then  -- only allow 5 bullets at a time
            table.insert(tab,vec2(x,y+offset)) -- position of player for bullet
        end
    end
    for a,b in pairs(tab) do    -- show and increment bullet
        sprite(asset.builtin.Tyrian_Remastered.Bullet_Simple_B, tab[a].x, tab[a].y+offset)
        tab[a].y=tab[a].y+5
    end
    for a,b in pairs(tab) do        -- remove bullet when off screen at top
        if tab[a].y+offset>HEIGHT then
            table.remove(tab,a)
        end
    end
end

function touched(t)
    if t.state ~= ENDED then
        if t.x >= padPos.x-40 and t.x <= padPos.x+40 then   -- shoot
            if t.y >= padPos.y-40 and t.y <= padPos.y+40 then
                shoot=true
            end
        end
    end
    if t.state == BEGAN or t.state==MOVING then        
        if t.x >= padLeft.x-40 and t.x <= padLeft.x+40 and 
        t.y >= padLeft.y-40 and t.y <= padLeft.y+40 then   
            x = x - 5            
        elseif t.x >= padRight.x-40 and t.x <= padRight.x+40 and 
        t.y >= padRight.y-40 and t.y <= padRight.y+40 then   
            x = x + 5            
        elseif t.x >= padUp.x-40 and t.x <= padUp.x+40 and 
        t.y >= padUp.y-40 and t.y <= padUp.y+40 then   
            y = y + 5           
        elseif t.x >= padDown.x-40 and t.x <= padDown.x+40 and 
        t.y >= padDown.y-40 and t.y <= padDown.y+40 then   
            y = y - 5            
        end 
    end    
end

function init()
    --
    tab={}
    x,y = WIDTH/2,60
    ship = asset.builtin.Tyrian_Remastered.Ship_B
    pad = image(248,248)
    padPos = vec2(128,136)
    padLeft = vec2(40,124)
    padRight = vec2(208,124)
    padUp = vec2(124, 208)
    padDown = vec2(124, 40)
    padFire = vec2(124, 124)
    makePad()
end

function makePad()
    --
    setContext(pad)
    textMode(CENTER)
    font("AmericanTypewriter-Bold")
    fontSize(32)
    ellipseMode(CENTER)
    fill(193, 196, 216)
    stroke(58, 67, 134)
    ellipse(124,124,200,200)
    fill(107, 211, 103)
    stroke(38, 74, 36)
    strokeWidth(8)
    ellipse(padLeft.x, padLeft.y,80,80)
    ellipse(padRight.x, padRight.y,80,80)
    ellipse(padDown.x, padDown.y,80,80)
    ellipse(padUp.x, padUp.y,80,80)
    fill(34, 105, 39)
    text("L",padLeft.x, padLeft.y)
    text("R",padRight.x, padRight.y)
    text("D",padDown.x, padDown.y)
    text("U",padUp.x, padUp.y)
    fill(255)
    stroke(184, 33, 24)
    ellipse(padFire.x, padFire.y,80,80)
    fill(251, 25, 12)
    text("F", padPos.x-4, padPos.y-12)
    setContext()
end

Ohh, I forgot to add something again, my mistake :man_facepalming:, because I’m starting to feel sorry that I always want something from them. Because actually I wanted that with THIS code that the other player (the opponent and the sprite is called “Waist”) attacks you and that if you are hit that you then lost and if you shoot the “Waist” YOURSELF you win

the code:


if Training001 then
        
        ing()
            
            
           tween.delay(0.5, function()
       nicht = true 
            sprite(asset.documents.Nachladen, 150, 715, 100)
    end) 
              
        end 
    end 
    
    
    function shooting()
    shootX = shootX + 30
    nicht = false
    shootY = y
   
        
end
 

Since I don’t know what you really want, here’s something. Slide your finger on the screen to move the ship, double tap to shoot. There isn’t any code for hits.

viewer.mode=FULLSCREEN

function setup()
    tab={}
    tab1={}
    x,y = WIDTH/2,60
    ax,ay=WIDTH/2,HEIGHT
end

function draw()
    background(255, 185, 0)
    sprite(asset.builtin.Tyrian_Remastered.Ship_B, x, y, 100, 100) 
    shooting() 
    sprite(asset.builtin.Tyrian_Remastered.Energy_Orb_2, ax, ay)
    attack()
end

function shooting()
    offset = 20
    if shoot then
        shoot=false
        if #tab<5 then  -- only allow 5 bullets at a time
            table.insert(tab,vec2(x,y+offset)) -- position of player for bullet
        end
    end
    for a,b in pairs(tab) do    -- show and increment bullet
        sprite(asset.builtin.Tyrian_Remastered.Fire_Rock, tab[a].x, tab[a].y+offset)
        tab[a].y=tab[a].y+5
    end
    for a,b in pairs(tab) do        -- remove bullet when off screen at top
        if tab[a].y+offset>HEIGHT then
            table.remove(tab,a)
        end
    end
end

function attack()
    speed=4
    v1=vec2(ax-x,ay-y)
    v1=v1:normalize()
    ax=ax-v1.x*speed
    ay=ay-v1.y*speed
end

function touched(t)
    if t.state==BEGAN and t.tapCount==2 then
        shoot=true
    end
    if t.state==CHANGED then
        x=x+t.deltaX*2
        y=y+t.deltaY*2
    end
end

Oh, there was a mistake. Here is my correct question: Could you create a player and an opponent. The player can shoot down the opponent. The opponent should also shoot the player. But he should shoot like an AI. But I don’t expect much. And the player should also be able to shoot in the game. I don’t know anything about collision, so they should rather take over the collision. If the player is hit by the opponent, there should be “lost” in the middle. But if the opponent is hit by the player, there should be “Won” in the middle. It is supposed to be a small code, but it is fine. You probably don’t understand that, but that’s because I 1. I am German and therefore use a translator to talk to them and 2. I can explain things very badly

Try this. Slide your finger to move, double tap to shoot or restart.

viewer.mode=FULLSCREEN

function setup()
    vel=1
    shipBullet={}
    orbBullet={}
    hit=false
    msg=""
    shipX,shipY=WIDTH/2,60
    orbX,orbY=WIDTH/2,HEIGHT-50
end

function draw()
    background(255, 185, 0)
    if not hit then 
        shipMove()
        orbMove()
        shipShooting()
        orbShooting()
        orbHit()
        shipHit()
        text("Double tap to shoot",WIDTH/2,80)
    else
        fontSize(100)
        fill(255,0,0)
        text(msg,WIDTH/2,HEIGHT/2)
        fontSize(40)
        fill(255)
        text("Double tap to restart",WIDTH/2,HEIGHT/2-80)
    end
end

function shipMove()
    sprite(asset.builtin.Tyrian_Remastered.Ship_B, shipX, shipY, 100, 100) 
end

function orbMove()
    orbX=orbX+vel
    if orbX>WIDTH or orbX<0 then
        vel=-vel
    end
    sprite(asset.builtin.Tyrian_Remastered.Energy_Orb_2, orbX, orbY,50)
end

function shipShooting()
    offset = 20
    if shoot then
        shoot=false
        if #shipBullet<5 then  -- only allow 5 bullets at a time
            table.insert(shipBullet,vec2(shipX,shipY+offset))
        end
    end
    for a,b in pairs(shipBullet) do    -- show and increment bullet
        sprite(asset.builtin.Tyrian_Remastered.Energy_Orb_1, shipBullet[a].x, shipBullet[a].y+offset)
        shipBullet[a].y=shipBullet[a].y+5
    end
    for a,b in pairs(shipBullet) do
        if shipBullet[a].y+offset>HEIGHT then
            table.remove(shipBullet,a)
        end
    end
end

function orbShooting()
    if #orbBullet<1 then    -- change to 2 for 2 bullets
        table.insert(orbBullet,vec2(orbX,orbY)) 
    end
    for a,b in pairs(orbBullet) do    -- show and increment bullet
        sprite(asset.builtin.Tyrian_Remastered.Mine_Spiked_Huge, orbBullet[a].x, orbBullet[a].y)
        orbBullet[a].y=orbBullet[a].y-5
        attack()
    end
    for a,b in pairs(orbBullet) do
        if orbBullet[a].y<0 then
            table.remove(orbBullet,a)
        end
    end
end

function attack()    
    speed=6
    if orbBullet[1].y>shipY then
        v1=vec2(orbBullet[1].x-shipX,orbBullet[1].y-shipY)
        v1=v1:normalize()
    end
    orbBullet[1].x=orbBullet[1].x-v1.x*speed
    orbBullet[1].y=orbBullet[1].y-v1.y
end

function shipHit()
    for a,b in pairs(orbBullet) do
        if orbBullet[a].x>shipX-30 and orbBullet[a].x<shipX+30 and orbBullet[a].y>shipY-30 and orbBullet[a].y<shipY+30 then
            msg="You lose"
            hit=true
        end
    end   
end

function orbHit()
    for a,b in pairs(shipBullet) do
        if shipBullet[a].x>orbX-30 and shipBullet[a].x<orbX+30 and shipBullet[a].y>orbY-30 and shipBullet[a].y<orbY+30 then
            msg="You win"
            hit=true
        end
    end   
end

function touched(t)
    if t.state==BEGAN and t.tapCount==2 then
        shoot=true
        if hit then
            viewer.restart()
        end
    end
    if t.state==CHANGED then
        shipX=shipX+t.deltaX*2
        shipY=shipY+t.deltaY*2
    end
end

Could you give me a small example of collision in codea? Because then I think I could start programming my game and it will be good! I just want a player, because you can’t move. So just a sprite, but it moves by itself to the left and to the right. And yet another sprite that moves to the right and to the left. If sprite2 bounces against sprite1, the console should say “Test (Lost)”. Then I would be really happy!!! Because then I think I could really start! Thanks again.

Edit: And the code was what I expected (so super good)

Here’s a simple collision example using Codea physics. If you don’t want to use physics, then just compare the position of the 2 objects. If they’re close enough then they hit. In the above code, orbHit and shipHit do collision based on how close the two objects are to each other.


viewer.mode=STANDARD

function setup() 
    fill(255)
    
    c1 = physics.body(CIRCLE,50)
    c1.type=DYNAMIC
    c1.x=300
    c1.y=HEIGHT
    c1.restitution=.8
    
    c2 = physics.body(CIRCLE,50)
    c2.type=STATIC
    c2.x=300
    c2.y=100
    c2.restitution=.8
end

function collide(contact)
    if contact.state == BEGAN then
        print("collide")
    end
end

function draw()
    background(30, 30, 30, 25)   
    ellipse(c1.x,c1.y,100,100)    
    ellipse(c2.x,c2.y,100,100)
end

Can you explain the function setup() to me?

Maybe I’ll be a little stupid now, but how can I use collision code in my code? So here is the code and please read on below:


if Training001 then
        background(77)  
        
        sprite(asset.builtin.Planet_Cute.Character_Boy, x,y)
        sprite(asset.builtin.Tyrian_Remastered.Brown_Capsule_1, x,y)
        
        sprite(asset.builtin.Planet_Cute.Character_Horn_Girl, WachenX, WachenY)
        sprite(asset.builtin.Tyrian_Remastered.Blades, WachenX, WachenY) 
           tween.delay(0.5, function()
       nicht = true 
            sprite(asset.documents.Nachladen, 150, 715, 100)
    end) 
              
        end 

Assuming the sprite (Brown Capsule 1) from the sprite (Character.boy) touches the sprite (Character.Horn.girl). Could I make something happen? And if the sprite (Brown Capsule 1) is touched by the sprite (character. Horn.girl), something should also happen, is that possible?

Here’s some simple collision code. Unless you use Codea physics to exactly outline each sprite and use physics collide, this is the easiest way to do collision. It’s not a true collision, just checking if the x,y values are close to each other. Slide you finger to move the boy sprite.

type or viewer.mode=STANDARD

function setup() 
    fill(255,0,0)
    fontSize(50)
    bx,by,gx,gy=WIDTH/2,100,WIDTH/2,HEIGHT/2    
end

function draw()
    background(234, 166, 76, 25)   
    sprite(asset.builtin.Planet_Cute.Character_Boy,bx,by) 
    sprite(asset.builtin.Planet_Cute.Character_Horn_Girl, gx, gy)
    checkCollide() 
end

function touched(t)
    if t.state==CHANGED then
        bx=bx+t.deltaX
        by=by+t.deltaY
    end
end

function checkCollide()
    dist=75
    if bx>gx-dist and bx<gx+dist and by>gy-dist and by<gy+dist then
        text("collide",WIDTH/2,HEIGHT/2)
    end
end code here