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

pickup display count

parent fc10d164
......@@ -189,10 +189,10 @@ var h = 1024;
var onResize = function () {
w = c1.width = window.innerWidth;
h = c1.height = window.innerHeight;
ctx.imageSmoothingEnabled = false;
};
/*document.addEventListener('resize', onResize);
setTimeout(onResize, 1);*/
window.addEventListener('resize', onResize);
setTimeout(onResize, 1);
var Camera = {
position: [w/2, h/2],
scale: 8,
......@@ -361,7 +361,7 @@ GameObject.prototype = {
var saying = this.saying;
var currentChar = (+new Date() - saying.start)/1000 / (saying.duration/saying.length);
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);
......@@ -373,6 +373,8 @@ GameObject.prototype = {
var symbolWidth = 2, symbolHeight = 5;
if(place[0] === -1){
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){
var sy = ( this.position[ 1 ]+position[1] - saying.rowsCount * symbolHeight ) * Camera.scale;
......@@ -415,7 +417,7 @@ GameObject.prototype = {
currentCol++;
}
if(this.saying.currentChar >= this.saying.length+4){
if(this.saying.currentChar >= this.saying.length+16){
if(saying.actions){
if(this.actions){
saying.actions.forEach(act=>{
......
......@@ -7,6 +7,32 @@
padding: 0;
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>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
......@@ -17,6 +43,10 @@
</head>
<body>
<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="object/Player.js"></script>
......
......@@ -58,7 +58,7 @@ class NPC extends GameObject {
draw(dt, tfs){
this.render();
this.sayRender({
place: [-1, -1],
place: [0, -1],
position: [0, 10],
background: '#c7cddd',
border: '#d28d5c',
......
var tinEl = document.getElementById('tinCans');
// Класс игрока
class Player extends GameObject {
init(){
......@@ -113,8 +114,20 @@ class Player extends GameObject {
}
}
draw(){
draw(ctx){
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();
}
die(){
......
......@@ -6,6 +6,7 @@ class Trash extends GameObject {
step(dt, tfs){
if(this.collide(Player) && this.visible){
this.getItem( Player ).tinCans += 1;
console.log('Tin cans = ', this.getItem( Player ).tinCans )
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