tembok update

This commit is contained in:
JERRY F 2025-11-26 18:44:19 +07:00
parent 0e7035e018
commit 7e654bfe9c
23 changed files with 65 additions and 177 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 605 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 415 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 491 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 488 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 486 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 574 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 314 B

View File

@ -1,60 +0,0 @@
<?php
session_start();
include "koneksi.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Halaman: Daftar</title>
</head>
<body>
<?php
if(isset($_POST['username'])) {
$nama = $_POST['nama'];
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = mysqli_query($koneksi, "INSERT INTO users(nama, username, password) value('$nama', '$username', '$password')");
if($query) {
echo '<script>alert("Selamat, anda berhasil mandaftarkan acc anda!")</script>';
} else {
echo '<script>alert("Maaf, pendaftaraan acc mu gagal")</script>';
}
}
?>
<form action="" method="post">
<table align="center">
<tr>
<td colspan="2" align="center">
<h3>Pendaftaran User</h3>
</td>
</tr>
<tr>
<td>Nama</td>
<td><input type="text" name="nama"></td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td></td>
<td>
<button type="submit">Daftarkan acc</button>
<a href="login.php">Login</a>
</td>
</tr>
</table>
</form>
</body>
</html>

View File

@ -1,26 +0,0 @@
<?php
// buat inisialisasi session
session_start();
// mengecek apakah ada session user yang aktif, jika tidak arahkan ke login.php
if(!isset($_SESSION['users'])) {
header('location:login.php'); // arahkan ke login.php
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Halaman ke-1</title>
</head>
<body style='text-align:center'>
<h1>Halaman ke-1</h1>
<a href="index.php">Home</a>
<a href="logout.php">Logout</a>
<hr>
<h3>Selamat datang, <?php echo $_SESSION['users']['nama'] ?></h3>
Halaman ini akan tampil setelah user login.
</body>
</html>

View File

@ -1,4 +0,0 @@
<?php
$koneksi = mysqli_connect("localhost", "root", "", "game") or die ('database tidak terhubung');
?>

View File

@ -1,58 +0,0 @@
<?php
session_start();
include "koneksi.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Halaman: Login</title>
</head>
<body>
<?php
if(isset($_POST['username'])) {
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = mysqli_query($koneksi, "SELECT * FROM users where username='$username' and password='$password'");
if(mysqli_num_rows($query) > 0) {
$data = mysqli_fetch_array($query);
$_SESSION['users'] = $data;
echo '<script>alert("Selamat datang, '.$data['nama'].'"); location.href="index.php";</script>';
} else {
echo '<script>alert("Username atau Password tidak sesuai");</script>';
}
}
?>
<form action="" method="post">
<table align="center">
<tr>
<td colspan="2" align="center">
<h3>Login User</h3>
</td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td></td>
<td>
<button type="submit">Masuk</button>
<a href="daftar.php">Daftar</a>
</td>
</tr>
</table>
</form>
</body>
</html>

View File

@ -1,9 +0,0 @@
<?php
session_start();
session_destroy();
// header('location:login.php');
?>
<script type="text/javascript">
alert('Selamat anda berhasil Logout.');
location.href = "login.php"
</script>

View File

@ -80,9 +80,7 @@
<canvas width="800" height="800" id="game"></canvas>
<div id="gameover" class="gameover"></div>
<div>
<div class="text">
Controls: <br />Movement: W A S D <br /><br />
</div>
<div class="text">Controls: <br />Movement: W A S D <br /><br /></div>
<div id="text" class="text"></div>
</div>
</div>
@ -105,21 +103,33 @@
//generate gambar external
var KepalaUlarImage = new Image();
KepalaUlarImage.src = "image/KepalaVertikalAtas.png"; // kepala ular
KepalaUlarImage.src = "image/KepalaHorizontalKanan.png";
var KepalAtas = new Image();
KepalAtas.src = "image/KepalaVertikalAtas.png";
var KepalaBawah = new Image();
KepalaBawah.src = "image/KepalaVertikalBawah.png";
var KepalaKiri = new Image();
KepalaKiri.src = "image/KepalaHorizontalKiri.png";
var KepalaKanan = new Image();
KepalaKanan.src = "image/KepalaHorizontalKanan.png";
// ↑ kepala ular
var BadanUlarImage = new Image();
BadanUlarImage.src = "image/BadanVertikal.png"; // badan ular awal
BadanUlarImage.src = "image/BadanVertikal.png";
// ↑ badan ular
var ApelImage = new Image();
ApelImage.src = "image/ApelLayer.png"; // Apel
var TembokImage = new Image();
TembokImage.src = "image/Tembok.png"; // Tembok Batagor
//D:\PROYEK UAS\Game ULAR\gambar\Tembok.png
//D:\PROYEK UAS\Game ULAR\gambar\Tembok.png
//set posisi ular dan Apel
var Ular = { x: 400, y: 400, dx: grid, dy: 0, cells: [], maxCells: 4 };
var Apel = { x: 0, y: 0 };
var Tembok = [];
UpdateScore(-1);
UpdateScore(0);
RandomizeApel();
RandomSpawnWall();
@ -143,8 +153,10 @@
Ular.maxCells = 4;
Ular.dx = grid;
Ular.dy = 0;
Tembok = [];
RandomizeApel();
UpdateScore(-1);
UpdateScore(0);
RandomSpawnWall();
}
} else {
InputKeyboard();
@ -183,13 +195,20 @@
if (TembokX === Apel.x && TembokY === Apel.y) {
kosong = false;
}
for (var i = 0; i < Tembok.length; i++) {
if (Tembok[i].x === TembokX && Tembok[i].y === TembokY) {
kosong = false;
break;
}
}
} while (kosong === false);
Tembok.push({x:TembokX, y:TembokY})
Tembok.push({ x: TembokX, y: TembokY });
}
//nambah tembok tiap score +10
//nambah tembok tiap score kelipatan ... berapa enaknya ya? 😁
function PenambahanTembok() {
if (score > 0 && score % 10 === 0 && Tembok.length < (score/10)) {
if (Tembok.length < Math.floor(score / 2)) {
RandomSpawnWall();
}
}
@ -206,7 +225,7 @@
"<br>Speed: " +
speed;
PenambahanTembok();
PenambahanTembok();
}
//gameover countdown
@ -224,10 +243,36 @@
function IntiGame() {
//buat gambarnya bisa keluar
content.drawImage(ApelImage, Apel.x, Apel.y, grid, grid);
Tembok.forEach(function(bata) {
Tembok.forEach(function (bata) {
content.drawImage(TembokImage, bata.x, bata.y, grid, grid);
})
});
Ular.cells.forEach(function (cell, index) {
if (index === 0) {
// Logika Pemilihan Gambar Kepala Ular
var posisiKepalaImage;
if (Ular.dx === grid) {
// KANAN
posisiKepalaImage = KepalaKanan;
} else if (Ular.dx === -grid) {
// KIRI
posisiKepalaImage = KepalaKiri;
} else if (Ular.dy === -grid) {
// ATAS
posisiKepalaImage = KepalAtas;
} else if (Ular.dy === grid) {
// BAWAH
posisiKepalaImage = KepalaBawah;
} else {
// Default, misalnya saat game baru mulai (dx=grid, dy=0, atau default awal)
posisiKepalaImage = KepalaKanan;
}
content.drawImage(posisiKepalaImage, cell.x, cell.y, grid, grid);
} else {
content.drawImage(BadanUlarImage, cell.x, cell.y, grid, grid);
}
});
//bagian generate ular
Ular.cells.forEach(function (cell, index) {
@ -246,10 +291,10 @@
//tabrak tembok = mati
if (index === 0) {
Tembok.forEach(function(bata) {
if (cell.x === wall.x && cell.y === wall.y) {
GameOver();
}
Tembok.forEach(function (bata) {
if (cell.x === bata.x && cell.y === bata.y) {
GameOver();
}
});
}