Commit a9007751 by Иван Кубота

pickup display count

parent fc10d164
...@@ -189,10 +189,10 @@ var h = 1024; ...@@ -189,10 +189,10 @@ var h = 1024;
var onResize = function () { var onResize = function () {
w = c1.width = window.innerWidth; w = c1.width = window.innerWidth;
h = c1.height = window.innerHeight; h = c1.height = window.innerHeight;
ctx.imageSmoothingEnabled = false;
}; };
/*document.addEventListener('resize', onResize); window.addEventListener('resize', onResize);
setTimeout(onResize, 1);*/ setTimeout(onResize, 1);
var Camera = { var Camera = {
position: [w/2, h/2], position: [w/2, h/2],
scale: 8, scale: 8,
...@@ -361,7 +361,7 @@ GameObject.prototype = { ...@@ -361,7 +361,7 @@ GameObject.prototype = {
var saying = this.saying; var saying = this.saying;
var currentChar = (+new Date() - saying.start)/1000 / (saying.duration/saying.length); var currentChar = (+new Date() - saying.start)/1000 / (saying.duration/saying.length);
saying.currentChar = Math.floor(currentChar); saying.currentChar = Math.floor(currentChar);
saying.currentChar = Math.min(Math.max(0, saying.currentChar), saying.length+4); saying.currentChar = Math.min(Math.max(0, saying.currentChar), saying.length+16);
var part = saying.sentence.substr(0, saying.currentChar); var part = saying.sentence.substr(0, saying.currentChar);
...@@ -373,6 +373,8 @@ GameObject.prototype = { ...@@ -373,6 +373,8 @@ GameObject.prototype = {
var symbolWidth = 2, symbolHeight = 5; var symbolWidth = 2, symbolHeight = 5;
if(place[0] === -1){ if(place[0] === -1){
var sx = ( this.position[ 0 ]+position[0] - ( saying.maxLength ) * symbolWidth ) * Camera.scale; var sx = ( this.position[ 0 ]+position[0] - ( saying.maxLength ) * symbolWidth ) * Camera.scale;
}else if(place[0] === 0){
var sx = ( this.position[ 0 ]+position[0] - ( saying.maxLength ) * symbolWidth/2 ) * Camera.scale;
} }
if(place[1] === -1){ if(place[1] === -1){
var sy = ( this.position[ 1 ]+position[1] - saying.rowsCount * symbolHeight ) * Camera.scale; var sy = ( this.position[ 1 ]+position[1] - saying.rowsCount * symbolHeight ) * Camera.scale;
...@@ -415,7 +417,7 @@ GameObject.prototype = { ...@@ -415,7 +417,7 @@ GameObject.prototype = {
currentCol++; currentCol++;
} }
if(this.saying.currentChar >= this.saying.length+4){ if(this.saying.currentChar >= this.saying.length+16){
if(saying.actions){ if(saying.actions){
if(this.actions){ if(this.actions){
saying.actions.forEach(act=>{ saying.actions.forEach(act=>{
......
...@@ -7,6 +7,32 @@ ...@@ -7,6 +7,32 @@
padding: 0; padding: 0;
overflow: hidden; overflow: hidden;
} }
#tinCans .img {
background: url('sprites/bbbbbeaaaans.png');
background-size: cover;
width: 64px;
height: 64px;
}
#tinCans .count {
font-family: monospace;
font-size: 32px;
position: absolute;
left: 43px;
top: 23px;
}
#tinCans {
visibility: hidden;
position: fixed;
top: 0;
left: 0;
z-index: 2;
display: flex;
flex-direction: row;
color: #fff;
}
#tinCans.visible {
visibility: visible;
}
</style> </style>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
...@@ -17,6 +43,10 @@ ...@@ -17,6 +43,10 @@
</head> </head>
<body> <body>
<canvas id="c1" width="1600" height="1024"></canvas> <canvas id="c1" width="1600" height="1024"></canvas>
<div id="tinCans">
<div class="img"></div>
<div class="count">x<span>0</span></div>
</div>
<script src="lib/gameEngine.js"></script> <script src="lib/gameEngine.js"></script>
<script src="object/Player.js"></script> <script src="object/Player.js"></script>
......
...@@ -58,7 +58,7 @@ class NPC extends GameObject { ...@@ -58,7 +58,7 @@ class NPC extends GameObject {
draw(dt, tfs){ draw(dt, tfs){
this.render(); this.render();
this.sayRender({ this.sayRender({
place: [-1, -1], place: [0, -1],
position: [0, 10], position: [0, 10],
background: '#c7cddd', background: '#c7cddd',
border: '#d28d5c', border: '#d28d5c',
......
var tinEl = document.getElementById('tinCans');
// Класс игрока // Класс игрока
class Player extends GameObject { class Player extends GameObject {
init(){ init(){
...@@ -113,8 +114,20 @@ class Player extends GameObject { ...@@ -113,8 +114,20 @@ class Player extends GameObject {
} }
} }
draw(){ draw(ctx){
this.render(); this.render();
if(this.tinCans !== this.lastTinCans){
if(this.lastTinCans !== void 0){
if( this.tinCans > this.lastTinCans ){
zzfx( ...[ 1.72, , 1975, .02, .07, .11, 2, .39, -0.2, 2.4, 400, .08, , , , , .02, .59, .04 ] );
}else{
zzfx(...[1.68,,695,.06,.19,.18,2,1.32,-9.6,,-248,.04,.01,,16,.2,.01,.55,.16,.32]);
}
}
this.lastTinCans = this.tinCans;
tinEl.classList.toggle('visible', this.tinCans>0);
tinEl.querySelector('span').innerText = this.tinCans;
}
//this.debug(); //this.debug();
} }
die(){ die(){
......
...@@ -6,6 +6,7 @@ class Trash extends GameObject { ...@@ -6,6 +6,7 @@ class Trash extends GameObject {
step(dt, tfs){ step(dt, tfs){
if(this.collide(Player) && this.visible){ if(this.collide(Player) && this.visible){
this.getItem( Player ).tinCans += 1; this.getItem( Player ).tinCans += 1;
console.log('Tin cans = ', this.getItem( Player ).tinCans ) console.log('Tin cans = ', this.getItem( Player ).tinCans )
this.visible = false; this.visible = false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment