Şimdi Ara

2D Arayüzlü basit bir oyun yapmak istiyorum.

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir (1 Mobil) - 1 Masaüstü1 Mobil
5 sn
4
Cevap
0
Favori
171
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Merhaba, 2d arayüzlü resimlerde görüldüğü gibi o tarz bir oyun yapmak istiyorum. yazılım bilgim sıfır. sizden istediğim sadece hangi oyun motorunu hangi dili kullanmam gerekiyor. unity gibi 3d oyun tabanlı motorlarda uğraşmak saçma kaçar gibi geldi. hangi oyun motoru ve dili öğrenmem gerektiğini söylerseniz o konu üzerine udmyden kurs alacağım ve araştıracağım. şimdiden teşekkür ederim. (YAPMAK İSTEDİĞİM ÖRNEK OYUN; Ticarion, ticarium, Ticaret Simülatörü)




    < Bu mesaj bu kişi tarafından değiştirildi ahmetzkal -- 8 Şubat 2025; 11:15:1 >



    _____________________________
  • Löve + Lua + İngilizvce

    _____________________________
  • Önce yazılıma herhangi bir yerden giriş yap. Oralara çok var.

    Al bir başlangıç. Bunu not defterine kopyala "xxxx.html" olarak kaydet, kaydederken alttan ANSI seçiliyse UTF8'i seç.




    <!DOCTYPE html>

    <html>

    <head>

     <title>Basic Tetris HTML Game</title>

     <meta charset="UTF-8">

     <style>

      html, body {

       height: 100%;

       margin: 0;

      }

      body {

       background: black;

       display: flex;

       align-items: center;

       justify-content: center;

      }

      canvas {

       border: 1px solid white;

       display: block;

      }

     </style>

    </head>

    <body>

    <canvas id="game" width="320" height="640"></canvas>

    <script>

    // Tetris İşlevleri


    function getRandomInt(min, max) {

     min = Math.ceil(min);

     max = Math.floor(max);

     return Math.floor(Math.random() * (max - min + 1)) + min;

    }


    function generateSequence() {

     const sequence = ['I', 'J', 'L', 'O', 'S', 'T', 'Z'];

     while (sequence.length) {

      const rand = getRandomInt(0, sequence.length - 1);

      const name = sequence.splice(rand, 1)[0];

      tetrominoSequence.push(name);

     }

    }


    function getNextTetromino() {

     if (tetrominoSequence.length === 0) {

      generateSequence();

     }

     const name = tetrominoSequence.pop();

     const matrix = tetrominos[name];

     // Oyun alanında ortalamak için hesaplama

     const col = playfield[0].length / 2 - Math.ceil(matrix[0].length / 2);

     const row = name === 'I' ? -1 : -2;

     return { name: name, matrix: matrix, row: row, col: col };

    }


    function rotate(matrix) {

     const N = matrix.length - 1;

     return matrix.map((row, i) =>

      row.map((val, j) => matrix[N - j][i])

     );

    }


    function isValidMove(matrix, cellRow, cellCol) {

     for (let row = 0; row < matrix.length; row++) {

      for (let col = 0; col < matrix[row].length; col++) {

       if (

        matrix[row][col] &&

        (

         cellCol + col < 0 ||

         cellCol + col >= playfield[0].length ||

         cellRow + row >= playfield.length ||

         playfield[cellRow + row][cellCol + col]

        )

       ) {

        return false;

       }

      }

     }

     return true;

    }


    function placeTetromino() {

     // Aktif tetrominoyu playfield'e yerleştir

     for (let row = 0; row < tetromino.matrix.length; row++) {

      for (let col = 0; col < tetromino.matrix[row].length; col++) {

       if (tetromino.matrix[row][col]) {

        if (tetromino.row + row < 0) {

         return showGameOver();

        }

        playfield[tetromino.row + row][tetromino.col + col] = tetromino.name;

       }

      }

     }


     // Dolu satırları temizle ve puan ekle

     for (let row = playfield.length - 1; row >= 0;) {

      if (playfield[row].every(cell => !!cell)) {

       for (let r = row; r >= 0; r--) {

        for (let c = 0; c < playfield[r].length; c++) {

         playfield[r][c] = playfield[r - 1][c];

        }

       }

       score += 100;

      } else {

       row--;

      }

     }


     // Aktif tetromino yerine, nextTetromino'yu kullan; ardından yeni nextTetromino al

     tetromino = nextTetromino;

     nextTetromino = getNextTetromino();

    }


    function showGameOver() {

     cancelAnimationFrame(rAF);

     gameOver = true;

     context.fillStyle = 'black';

     context.globalAlpha = 0.75;

     context.fillRect(0, canvas.height / 2 - 30, canvas.width, 60);

     context.globalAlpha = 1;

     context.fillStyle = 'white';

     context.font = '36px monospace';

     context.textAlign = 'center';

     context.textBaseline = 'middle';

     context.fillText('Oyun Bitti!', canvas.width / 2, canvas.height / 2);

     context.fillText('Skor: ' + score, canvas.width / 2, canvas.height / 2 + 30);

     context.fillText('Yeniden Oyna F5', canvas.width / 2, canvas.height / 2 + 60);

    }


    // Canvas ve Oyun Parametreleri

    const canvas = document.getElementById('game');

    const context = canvas.getContext('2d');

    const grid = 32;

    const tetrominoSequence = [];


    // Playfield (satır: -2'den 19'a, kolon: 0'dan 9'a kadar)

    const playfield = [];

    for (let row = -2; row < 20; row++) {

     playfield[row] = [];

     for (let col = 0; col < 10; col++) {

      playfield[row][col] = 0;

     }

    }


    const tetrominos = {

     'I': [

      [0, 0, 0, 0],

      [1, 1, 1, 1],

      [0, 0, 0, 0],

      [0, 0, 0, 0]

     ],

     'J': [

      [1, 0, 0],

      [1, 1, 1],

      [0, 0, 0]

     ],

     'L': [

      [0, 0, 1],

      [1, 1, 1],

      [0, 0, 0]

     ],

     'O': [

      [1, 1],

      [1, 1]

     ],

     'S': [

      [0, 1, 1],

      [1, 1, 0],

      [0, 0, 0]

     ],

     'Z': [

      [1, 1, 0],

      [0, 1, 1],

      [0, 0, 0]

     ],

     'T': [

      [0, 1, 0],

      [1, 1, 1],

      [0, 0, 0]

     ]

    };


    const colors = {

     'I': 'cyan',

     'O': 'yellow',

     'T': 'purple',

     'S': 'green',

     'Z': 'red',

     'J': 'blue',

     'L': 'darkorange'

    };


    // Başlangıç değerleri

    let count = 0;

    let score = 0;

    let tetromino = getNextTetromino();

    let nextTetromino = getNextTetromino();

    let rAF = null;

    let gameOver = false;

    let dropSpeed = 35;

    const minDropSpeed = 5;

    let lastScoreCheckpoint = 0;


    // Ön izlemeyi ana canvas üzerine çiziyoruz

    function drawPreview() {

     // Preview alanı için parametreler (4x4 blokluk alan, küçük ölçek)

     const previewBlocks = 4;

     const blockSize = 16; // Küçük blok boyutu

     const previewX = canvas.width - previewBlocks * blockSize - 10; // Sağ üst köşede, 10px kenar boşluğu

     const previewY = 10;

      

     // Ön izleme alanı arka planını çiz (isteğe bağlı)

     context.fillStyle = "rgba(0, 0, 0, 0.5)";

     context.fillRect(previewX - 5, previewY - 5, previewBlocks * blockSize + 10, previewBlocks * blockSize + 10);

      

     // Sıradaki tetrominoyu, döndürülmemiş sabit haliyle çiziyoruz

     context.fillStyle = colors[nextTetromino.name];

     for (let row = 0; row < nextTetromino.matrix.length; row++) {

      for (let col = 0; col < nextTetromino.matrix[row].length; col++) {

       if (nextTetromino.matrix[row][col]) {

        context.fillRect(previewX + col * blockSize, previewY + row * blockSize, blockSize - 1, blockSize - 1);

       }

      }

     }

    }


    function loop() {

     rAF = requestAnimationFrame(loop);

     context.clearRect(0, 0, canvas.width, canvas.height);

      

     // Hız artışı (puan bazlı)

     if (score >= lastScoreCheckpoint + 100 && dropSpeed > minDropSpeed) {

      dropSpeed -= 2;

      lastScoreCheckpoint = score;

     }

      

     // Oyun alanındaki mevcut blokları çiz

     for (let row = 0; row < 20; row++) {

      for (let col = 0; col < 10; col++) {

       if (playfield[row][col]) {

        const name = playfield[row][col];

        context.fillStyle = colors[name];

        context.fillRect(col * grid, row * grid, grid - 1, grid - 1);

       }

      }

     }

      

     // Aktif tetrominoyu hareket ettir ve çiz

     if (tetromino) {

      if (++count > dropSpeed) {

       tetromino.row++;

       count = 0;

       if (!isValidMove(tetromino.matrix, tetromino.row, tetromino.col)) {

        tetromino.row--;

        placeTetromino();

       }

      }

      context.fillStyle = colors[tetromino.name];

      for (let row = 0; row < tetromino.matrix.length; row++) {

       for (let col = 0; col < tetromino.matrix[row].length; col++) {

        if (tetromino.matrix[row][col]) {

         context.fillRect((tetromino.col + col) * grid, (tetromino.row + row) * grid, grid - 1, grid - 1);

        }

       }

      }

     }

      

     // Ön izleme alanını çiz (oyun canvası içinde, sağ üst köşede)

     drawPreview();

      

     // Skoru oyun alanının sol üstünde göster

     context.fillStyle = 'white';

     context.font = '18px monospace';

     context.textAlign = 'left';

     context.textBaseline = 'top';

     context.fillText('Puan: ' + score, 10, 10);

    }


    loop();


    // Klavye kontrolleri

    document.addEventListener('keydown', function(e) {

     if (gameOver) return;

      

     if (e.which === 37 || e.which === 39) {

      const col = e.which === 37 ? tetromino.col - 1 : tetromino.col + 1;

      if (isValidMove(tetromino.matrix, tetromino.row, col)) {

       tetromino.col = col;

      }

     }

      

     if (e.which === 38) {

      const matrix = rotate(tetromino.matrix);

      if (isValidMove(matrix, tetromino.row, tetromino.col)) {

       tetromino.matrix = matrix;

      }

     }

      

     if (e.which === 40) {

      const row = tetromino.row + 1;

      if (!isValidMove(tetromino.matrix, row, tetromino.col)) {

       tetromino.row = row - 1;

       placeTetromino();

       return;

      }

      tetromino.row = row;

     }

    });

    </script>

    </body>

    </html>




    < Bu mesaj bu kişi tarafından değiştirildi woxow -- 15 Şubat 2025; 22:10:57 >
    _____________________________




  • Yapay Zeka’dan İlgili Konular
    Daha Fazla Göster
    
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.