Flappy Cow — различия между версиями

Материал из Department of Theoretical and Applied Mechanics
Перейти к: навигация, поиск
(top)
 
(не показано 6 промежуточных версий этого же участника)
Строка 1: Строка 1:
 +
==Описание==
 +
 
Реализация и визуализация аналога игры “Flappy Bird” - “Flappy Cow”
 
Реализация и визуализация аналога игры “Flappy Bird” - “Flappy Cow”
  
Исполнители: Мальцева О.Н., Клочко Д.А.
+
Исполнители: [[Мальцева_Олеся|Мальцева О.Н.]], [[Клочко_Дарья|Клочко Д.А.]].
 +
 
 +
Группа 13632/1 Кафедра Теоретической механики
 +
 
 +
Текст курсового проекта: [[http://mech.spbstu.ru/File:%D0%9A%D1%83%D1%80%D1%81%D0%BE%D0%B2%D0%BE%D0%B9_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82_%D0%9C%D0%B0%D0%BB%D1%8C%D1%86%D0%B5%D0%B2%D0%B0_%D0%9A%D0%BB%D0%BE%D1%87%D0%BA%D0%BE.docx]]
 +
==Основные правила==
 +
 
 +
1.Управление производится клавишами вверх и вниз
  
Группа 13632/2 Кафедра Теоретической механики
+
2.“Коровка” не должна касаться травинок
 +
 
 +
3.Счёт ведётся с начала игры, вне зависимости от того, пройдет ли "корова" "травинку".
  
 
==Визуализация==
 
==Визуализация==
  
 
{{#widget:Iframe |url=http://tm.spbstu.ru/htmlets/MalcevaON/title.html |width=600|height=700 |border=0 }}
 
{{#widget:Iframe |url=http://tm.spbstu.ru/htmlets/MalcevaON/title.html |width=600|height=700 |border=0 }}
 +
 +
==Код программы==
 +
<div class="mw-collapsible mw-collapsed">
 +
window.addEventListener("load", main, false);
 +
function main() {
 +
var ctx = canvas.getContext('2d');
 +
var bird = new Image();
 +
var bg = new Image();
 +
var fg = new Image();
 +
var pipeUp = new Image();
 +
var pipeBottom = new Image();
 +
var score = 0;
 +
bird.src = 'img/korova.png';
 +
bg.src = 'img/nebo.jpg'
 +
fg.src = 'img/flappy_bird_fg.png';
 +
pipeUp.src = 'img/flappy_bird_pipeUp.png';
 +
pipeBottom.src = 'img/flappy_bird_pipeBottom.png';
 +
var gap = 70;
 +
var gravitation = 1;
 +
var Posx = 10;
 +
var Posy = 150;
 +
//нажатие
 +
document.addEventListener("keydown", moveUp);
 +
function moveUp(){
 +
  gravitation = -7;
 +
}
 +
var pipe = [];
 +
pipe[0] = {
 +
  x : canvas.width,
 +
  y : 0
 +
}
 +
function draw(){
 +
ctx.clearRect(0,0, 288,512);
 +
    ctx.drawImage(bg, -bg.width/2-90, 0);
 +
    for (var i = 0; i < pipe.length; i++){
 +
        ctx.drawImage(pipeUp, pipe[i].x, pipe[i].y);
 +
        ctx.drawImage(pipeBottom, pipe[i].x, pipe[i].y + pipeUp.height + gap);
 +
      pipe[i].x--;
 +
      if (pipe[i].x == 125){
 +
        pipe.push({
 +
          x: canvas.width,
 +
          y: Math.floor(Math.random() * pipeUp.height) - pipeUp.height
 +
        });
 +
      }
 +
      if (Posx + bird.width >= pipe[i].x
 +
        && Posx <= pipe[i].x + pipeUp.width
 +
        && (Posy <= pipe[i].y + pipeUp.height
 +
        || Posy + bird.height >= pipe[i].y + pipeUp.height + gap)
 +
        || Posy + bird.height >= canvas.height - fg.height){
 +
          location.reload();
 +
        }
 +
    }
 +
    ctx.drawImage(fg, 0, canvas.height - fg.height);
 +
    ctx.drawImage(bird, Posx, Posy);
 +
    Posy += gravitation;
 +
    if (gravitation != 1){
 +
      gravitation += 1;
 +
    }
 +
          score++; some_name.innerHTML = score;
 +
    console.log(pipe);
 +
    requestAnimationFrame(draw);
 +
}
 +
pipeBottom.onload = draw;
 +
}

Текущая версия на 10:53, 29 мая 2019

Описание[править]

Реализация и визуализация аналога игры “Flappy Bird” - “Flappy Cow”

Исполнители: Мальцева О.Н., Клочко Д.А..

Группа 13632/1 Кафедра Теоретической механики

Текст курсового проекта: [[1]]

Основные правила[править]

1.Управление производится клавишами вверх и вниз

2.“Коровка” не должна касаться травинок

3.Счёт ведётся с начала игры, вне зависимости от того, пройдет ли "корова" "травинку".

Визуализация[править]

Код программы[править]

window.addEventListener("load", main, false);
function main() {
var ctx = canvas.getContext('2d');
var bird = new Image();
var bg = new Image();
var fg = new Image();
var pipeUp = new Image();
var pipeBottom = new Image();
var score = 0;
bird.src = 'img/korova.png';
bg.src = 'img/nebo.jpg'
fg.src = 'img/flappy_bird_fg.png';
pipeUp.src = 'img/flappy_bird_pipeUp.png'; 
pipeBottom.src = 'img/flappy_bird_pipeBottom.png'; 
var gap = 70;
var gravitation = 1;
var Posx = 10;
var Posy = 150;
//нажатие
document.addEventListener("keydown", moveUp);
function moveUp(){
  gravitation = -7;
}
var pipe = [];
pipe[0] = {
 x : canvas.width,
 y : 0
}
function draw(){
	ctx.clearRect(0,0, 288,512);
    ctx.drawImage(bg, -bg.width/2-90, 0);
    for (var i = 0; i < pipe.length; i++){
       ctx.drawImage(pipeUp, pipe[i].x, pipe[i].y);
       ctx.drawImage(pipeBottom, pipe[i].x, pipe[i].y + pipeUp.height + gap);
      pipe[i].x--;
      if (pipe[i].x == 125){
        pipe.push({
          x: canvas.width,
          y: Math.floor(Math.random() * pipeUp.height) - pipeUp.height
        });
      }
      if (Posx + bird.width >= pipe[i].x
        && Posx <= pipe[i].x + pipeUp.width
        && (Posy <= pipe[i].y + pipeUp.height
        || Posy + bird.height >= pipe[i].y + pipeUp.height + gap)
        || Posy + bird.height >= canvas.height - fg.height){
          location.reload();
        }
    }
    ctx.drawImage(fg, 0, canvas.height - fg.height);
    ctx.drawImage(bird, Posx, Posy);
    Posy += gravitation;
    if (gravitation != 1){
      gravitation += 1;
    }
         score++; some_name.innerHTML = score;
    console.log(pipe);
    requestAnimationFrame(draw);
}
pipeBottom.onload = draw;
}