Memodifikasi game

 Laporan memodifikasi flappy bird

Di

S

U

S

U

N

Oleh

Annis Atikah

Xll RPL

SMK NEGERI 1SIABU


TAHUN PELAJARAN

2024/2025


  • TUJUAN
    • Supaya siswa dapat mengetahui kode program dari aplikasi game dan dapat mengubah warna"nya
    • ALAT DAN BAHAN
    • Chromebook
    • Aplikasi Visual Studio Code
    • ANALISA DATA
    • Aplikasi game tetris menggunakan kode program dari HTML
    • LANGKAH-LANGKAH KERJA
    • Menghidupkan Chromebook
    • Membuka aplikasi Google Chrome
    • Mencari kodingan aplikasi game tetristetris
    Codingan :
    <!DOCTYPE html>
    <html>
        <head>  </head>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, viewport-fit=cover">
        <meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/DLgXf1zr/styles.css">
        <link rel="manifest" href="https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/DLgXf1zr/manifest.json">
        <style>@media screen and (min-aspect-ratio: 1280/720) {    #application-canvas.fill-mode-KEEP_ASPECT {        width: auto;        height: 100%;        margin: 0 auto;    }}</style>
        <title>Flappy annis Bird</title>
        <script src="https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/DLgXf1zr/playcanvas-stable.min.js"></script>
        <script>
            ASSET_PREFIX = "https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/DLgXf1zr/";
            SCRIPT_PREFIX = "https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/DLgXf1zr/";
            SCENE_PATH = "404993.json";
            CONTEXT_OPTIONS = {
                'antialias': true,
                'alpha': false,
                'preserveDrawingBuffer': false,
                'preferWebGl2': true,
                'powerPreference': "default"
            };
            SCRIPTS = [ 37175323, 21399876, 4554207, 4554213, 4554214, 4554217, 4554270, 4554271, 4554273, 4554276, 4554279, 20754603, 20755574, 37175329, 37186400 ];
            CONFIG_FILENAME = "https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/DLgXf1zr/config.json";
            INPUT_SETTINGS = {
                useKeyboard: true,
                useMouse: true,
                useGamepads: false,
                useTouch: true
            };
            pc.script.legacy = false;
            PRELOAD_MODULES = [
            ];
        </script>
    <style type="text/css">body {
        background-color: #f884db;
    }
    #application-splash-wrapper {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        background-color: #a428f7;
    }
    #application-splash {
        position: absolute;
        top: calc(50% - 28px);
        width: 264px;
        left: calc(50% - 132px);
    }
    #application-splash img {
        width: 100%;
    }
    #progress-bar-container {
        margin: 20px auto 0 auto;
        height: 2px;
        width: 100%;
        background-color: #73ff00;
    }
    #progress-bar {
        width: 0%;
        height: 100%;
        background-color: rgb(240, 24, 114);
    }
    @media (max-width: 480px) {
        #application-splash {
            width: 170px;
            left: calc(50% - 85px);
        }
    }</style><script src="https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/DLgXf1zr/__game-scripts.js"></script></head>
    <body>
        <script src="https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/DLgXf1zr/__start__.js">
            
        </script><canvas id="application-canvas" tabindex="0" width="990" height="733" style="width: 990px; height: 733px;" class="fill-mode-FILL_WINDOW"></canvas>
        <script src="https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/DLgXf1zr/__loading__.js">

        </script>


    </body>
    </html>
    <STYLE>
        * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
    }
    .background {
    height: 100vh;
    width: 100vw;
    background: url('images/background-img.png') no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }
    .bird {
    height: 100px;
    width: 130px;
    position: fixed;
    top: 40vh;
    left: 30vw;
    z-index: 100;
    }
    .pipe_sprite {
    position: fixed;
    top: 40vh;
    left: 100vw;
    height: 70vh;
    width: 6vw;
    background:radial-gradient(lightgreen 50%, green);
    border: 5px solid black;
    }
    .message {
    position: absolute;
    z-index: 10;
    color: black;
    top: 30%;
    left: 50%;
    font-size: 4em;
    transform: translate(-50%, -50%);
    text-align: center;
    }
    .messageStyle{
    background: white;
    padding: 30px;
    box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
    border-radius: 5%;
    }
    .score {
    position: fixed;
    z-index: 10;
    height: 10vh;
    font-size: 10vh;
    font-weight: 100;
    color: white;
    -webkit-text-stroke-width: 2px;
        -webkit-text-stroke-color: black;
    top: 0;
    left: 0;
    margin: 10px;
    font-family: Arial, Helvetica, sans-serif;
    }
    .score_val {
    color: gold;
    font-weight: bold;
    }
    @MEDIAN only screen and (max-width: 1080px) {
        .message{
    font-size: 50px;
    top: 50%;
    white-space: nowrap;
    }
    .score{
    font-size: 8vh;
    }
    .bird{
    width: 120px;
    height: 90px;
    }
    .pipe_sprite{
    width: 14vw;
    }
    }
    </STYLE>
    <SCRIPT>
        let move_speed = 3, grativy = 0.5;
    let bird = document.querySelector('.bird');
    let img = document.getElementById('bird-1');
    let sound_point = new Audio('sounds effect/point.mp3');
    let sound_die = new Audio('sounds effect/die.mp3');

    // getting bird element properties
    let bird_props = bird.getBoundingClientRect();

    // This method returns DOMReact -> top, right, bottom, left, x, y, width and height
    let background = document.querySelector('.background').getBoundingClientRect();

    let score_val = document.querySelector('.score_val');
    let message = document.querySelector('.message');
    let score_title = document.querySelector('.score_title');

    let game_state = 'Start';
    img.style.display = 'none';
    message.classList.add('messageStyle');

    document.addEventListener('keydown', (e) => {
        
        if(e.key == 'Enter' && game_state != 'Play'){
            document.querySelectorAll('.pipe_sprite').forEach((e) => {
                e.remove();
            });
            img.style.display = 'block';
            bird.style.top = '40vh';
            game_state = 'Play';
            message.innerHTML = '';
            score_title.innerHTML = 'Score : ';
            score_val.innerHTML = '0';
            message.classList.remove('messageStyle');
            play();
        }
    });

    function play(){
        function move(){
            if(game_state != 'Play') return;

            let pipe_sprite = document.querySelectorAll('.pipe_sprite');
            pipe_sprite.forEach((element) => {
                let pipe_sprite_props = element.getBoundingClientRect();
                bird_props = bird.getBoundingClientRect();

                if(pipe_sprite_props.right <= 0){
                    element.remove();
                }else{
                    if(bird_props.left < pipe_sprite_props.left + pipe_sprite_props.width && bird_props.left + bird_props.width > pipe_sprite_props.left && bird_props.top < pipe_sprite_props.top + pipe_sprite_props.height && bird_props.top + bird_props.height > pipe_sprite_props.top){
                        game_state = 'End';
                        message.innerHTML = 'Game Over'.fontcolor('red') + '<br>Press Enter To Restart';
                        message.classList.add('messageStyle');
                        img.style.display = 'none';
                        sound_die.play();
                        return;
                    }else{
                        if(pipe_sprite_props.right < bird_props.left && pipe_sprite_props.right + move_speed >= bird_props.left && element.increase_score == '1'){
                            score_val.innerHTML =+ score_val.innerHTML + 1;
                            sound_point.play();
                        }
                        element.style.left = pipe_sprite_props.left - move_speed + 'px';
                    }
                }
            });
            requestAnimationFrame(move);
        }
        requestAnimationFrame(move);

        let bird_dy = 0;
        function apply_gravity(){
            if(game_state != 'Play') return;
            bird_dy = bird_dy + grativy;
            document.addEventListener('keydown', (e) => {
                if(e.key == 'ArrowUp' || e.key == ' '){
                    img.src = 'images/Bird-2.png';
                    bird_dy = -7.6;
                }
            });

            document.addEventListener('keyup', (e) => {
                if(e.key == 'ArrowUp' || e.key == ' '){
                    img.src = 'images/Bird.png';
                }
            });

            if(bird_props.top <= 0 || bird_props.bottom >= background.bottom){
                game_state = 'End';
                message.style.left = '28vw';
                window.location.reload();
                message.classList.remove('messageStyle');
                return;
            }
            bird.style.top = bird_props.top + bird_dy + 'px';
            bird_props = bird.getBoundingClientRect();
            requestAnimationFrame(apply_gravity);
        }
        requestAnimationFrame(apply_gravity);

        let pipe_seperation = 0;

        let pipe_gap = 35;

        function create_pipe(){
            if(game_state != 'Play') return;

            if(pipe_seperation > 115){
                pipe_seperation = 0;

                let pipe_posi = Math.floor(Math.random() * 43) + 8;
                let pipe_sprite_inv = document.createElement('div');
                pipe_sprite_inv.className = 'pipe_sprite';
                pipe_sprite_inv.style.top = pipe_posi - 70 + 'vh';
                pipe_sprite_inv.style.left = '100vw';

                document.body.appendChild(pipe_sprite_inv);
                let pipe_sprite = document.createElement('div');
                pipe_sprite.className = 'pipe_sprite';
                pipe_sprite.style.top = pipe_posi + pipe_gap + 'vh';
                pipe_sprite.style.left = '100vw';
                pipe_sprite.increase_score = '1';

                document.body.appendChild(pipe_sprite);
            }
            pipe_seperation++;
            requestAnimationFrame(create_pipe);
        }
        requestAnimationFrame(create_pipe);
    }
    </SCRIPT>
    Hasilnya :


    Hasilnya tetap sama 

    Komentar

    Postingan populer dari blog ini

    Membuat jam digital dengan arduino R3

    Manajemen dan pengembangan usaha

    Bab 3 pelajaran Pemrograman Berorientasi Objek Kls XII RPL