Discord
Login
Community
DARK THEME

Objekt anklicken

Ich bin dabei ein Kartenspiel zu programmieren, allerdings kann man die Karten nicht anklicken. Ich nutze Microscript2.0 und ich bitte um Hilfe. Danke im voraus🙂.

Sie müssen das Problem genau spezifizieren, Code freigeben, der Ihrer Meinung nach für das Problem relevant ist, oder das Projekt selbst freigeben. Und bitte schreiben Sie auf Englisch.

Sie können jederzeit einfach die Sprite-Kollisionsbibliothek verwenden.

What is the sprite collision library?And how do I import them?

This is the code so far:

init = function() end

update = function() end

draw = function() karten = ["Blitz", "Tsunami", "Feuersturm"] karte1 = random.nextInt(karten) karte2 = random.nextInt(karten) karte3 = random.nextInt(karten) screen.drawMap( "map", 0, 0, 300, 200 ) screen.drawSprite( "karte1", -70, -55, 60, 90 ) screen.drawSprite( "karte2", 0, -50, 60, 90 ) screen.drawSprite( "karte3", 70, -55, 60, 90 ) screen.drawSprite( "karte4", -70, 55, 60, 90 ) screen.drawSprite( "karte5", 0, 50, 60, 90 ) screen.drawSprite( "karte6", 70, 55, 60, 90 ) if touch.touching then print(karte1) if touch.touching then print('Du hast ', karte1, ' gespielt') end end end

There are errors in your code here is what I think you will need:

init = function()
    //needs to be in init othervise it will glich or choose random every tick
    //if you need to run it multtiple times i'd suggest you to make this a function
    //that you can reuse
    karten = {"Blitz", "Tsunami", "Feuersturm"}
    karte1 = karten.choose()
    karte2 = karten.choose()
    karte3 = karten.choose()
end

update = function()
    if checkMouseHover(-70, -55, 60, 90) and (mouse.press or touch.press) then
        print(karte1)
    elsif checkMouseHover(0, -50, 60, 90) and (mouse.press or touch.press) then
        print(karte2)
    end
end

draw = function()
    screen.clear()// you need this in order to refreash screen
    //you can set a color by doing screen.clear('rgb(255,255,255)') or screen.clear('#ffffff') for example this is white
    screen.drawMap("map", 0, 0, 300, 200)// idk for what do u use this
    screen.drawSprite("karte1", -70, -55, 60, 90)
    screen.drawSprite("karte2", 0, -50, 60, 90)
    screen.drawSprite("karte3", 70, -55, 60, 90)
  //screen.drawSprite("karte4", -70, 55, 60, 90) we didn't choose at random card for this
  //screen.drawSprite("karte5", 0, 50, 60, 90)
  //screen.drawSprite("karte6", 70, 55, 60, 90)

end

List.choose = function()
  local index = random.nextInt(this.length)
  return this[index]
end

// checks to see if the mouse is touching/hovering over a rectangle
// works witth touch as well
checkMouseHover = function(x, y, width, height)
  local hover = true
  if mouse.x < (x - width/2) then hover = false end
  if mouse.x > (x + width/2) then hover = false end
  if mouse.y < (y - height/2) then hover = false end
  if mouse.y > (y + height/2) then hover = false end
  return hover
end

I don't have access to project to testt this so let me know if it works correctly...
Pro tip for posting: just copy/paste code inside ``` to make it readable. and don't worry about post lenght.

Thanks for the code. There are some problems e.g. the cards all show the same thing and only card1 and card2 can be clicked on. The fact that the maps are no longer updated as the game progresses is also a problem. Would it be ok if I invited you to the project?

Yeah, sure no problem..
I don't know what is problem with map I need to see it...
Only 2 cards are clickable because i made code that way just to give you example...
There are same cards because random can choose same nuumber multiple times...
But invite me and I'll see what can I do.

Thanks

sorry i wrote your name wrong i think it's correct now (that's why it took so long )

i have already made the third card clickable but i don't know how to continue

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community