Commit 4887f606 by Иван Кубота

initial

parents
node_modules/*
package-lock.json
\ No newline at end of file
This diff is collapsed. Click to expand it.
Game({
transparent: '#171c39',
background: '#171c39',
file: '1.ldtk',
objects: {
Zone,
Player,
Key,
NPC
},
loaded: function() {
},
step: function(dt, tfs) {
physic(Levels["Game"], dt, tfs)
},
draw: function(dt, tfs) {
clear();
//if(Math.floor(tfs%2>1)){
render( Levels[ "Game" ] );
//}else{
// render( Levels[ "Dialog" ] );
//}
}
});
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed. Click to expand it.
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body, html {
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Game v3.0</title>
<script src="lib/engine.all.js"></script>
<script src="lib/ldtk.js"></script>
</head>
<body>
<canvas id="c1" width="1600" height="1024"></canvas>
<script src="lib/gameEngine.js"></script>
<script src="object/Player.js"></script>
<script src="object/Key.js"></script>
<script src="object/NPC.js"></script>
<script src="object/Zone.js"></script>
<script src="js/main.js"></script>
</body>
</html>
\ No newline at end of file
class Key extends GameObject {
step(dt, tfs){
if(this.collide(Player)){
var hole = this.getItem( Zone, { Name: 'Hole' } );
this.startTime = tfs;
hole.animate( 'hideWall', function( progress ){
if(progress === 0){
zzfx(...[1.11,,854,.02,.03,.2,,1.7,,,-131,.06,.01,,,,,.41,.01,.15]);
}
hole.opacity = 1 - progress;
if( hole.opacity < 0.1 ){
hole.visible = false;
}
}, 2 );
}
}
init() {
this.position[1]+=1;
}
draw(){
this.render();
this.debug();
}
}
\ No newline at end of file
class NPC extends GameObject {
step(dt, tfs){
if(this.collide(Player)){
if(!this.saying){
if(this.sentance < this.Dialog.length){
this.say( this.Dialog[ this.sentance ] );
this.sentance++;
}
}
}else{
this.wobble = Math.sin( tfs * 4 ) * 1;
this.wobble2 = Math.sin( tfs * 3+5 ) * 3;
this.position[ 1 ] = this.originalY + 1 + this.wobble | 0;
this.position[ 0 ] = this.originalX + ( this.wobble2 | 0 );
}
}
init() {
if(this.Dialog)
this.sentance = 0;
this.wobble = 0;
this.originalX = this.position[0];
this.originalY = this.position[1];
this.actions = {
openPassage: function() {
var passage = this.getItem(Zone, {Name: 'RocksPassage'});
passage.animate( 'hideThis', function( progress ){
passage.opacity = 1 - progress;
if( passage.opacity < 0.1 ){
passage.visible = false;
}
}, 2 );
}
}
//this.position[1]+=1;
}
draw(dt, tfs){
this.render();
this.sayRender({
place: [-1, -1],
position: [0, 10],
background: '#c7cddd',
border: '#d28d5c',
color: '#7e0404',
padding: [2, 1],
offset: [0, 4]
});
//this.debug();
}
}
\ No newline at end of file
// Класс игрока
class Player extends GameObject {
init(){
this.extendSprite();
this.position[1]++;
this.collisionOffset = [5,8,5,9];
this.xSpeed = 24
this.jumpSpeed = 32
this.onGround = true;
this.yAcceleration = 0;
this.G = 0.98;
//this.DEBUG = true;
this.loadAnimation('stay', {
path: 'sprites/playerStay.png',
size: [32, 64],
frames: 2,
duration: 1
});
this.loadAnimation('walk', {
path: 'sprites/playerWalk.png',
size: [32, 64],
frames: 4,
duration: 1
});
this.loadAnimation('jump', {
path: 'sprites/playerJump.png',
size: [32, 64],
frames: 3,
manual: true,
duration: 1
});
}
step(dt, tfs){
var futureX = this.position[0];
if(Keys.Right){
futureX += dt*this.xSpeed*(Math.sin(tfs*4*3.14)/6+1);
this.tile.f = 0;
this.setAnimation('walk');
}
if(Keys.Left){
futureX -= dt*this.xSpeed*(Math.sin(tfs*4*3.14)/6+1);
this.tile.f = 1;
this.setAnimation('walk');
}
if(!Keys.Left && !Keys.Right){
this.setAnimation('stay');
}
if(!this.wouldCollide([futureX, this.position[1]], ['Level', 'Patches'])){
this.position[0] = futureX;
}
if(Keys.Up){
if(this.onGround){
zzfx(...[1.99,,782,,.22,0,,1.77,,-24,,,,,,,.23]);
//zzfx(...[1.11,,466,.08,,.12,2,1.56,-7.1,,-357,.05,-0.01,,,,.01,.73]); // Random 216 - Mutation 2
this.yAcceleration = this.jumpSpeed;
this.onGround = false;
}
}
this.yAcceleration -= this.G;
while(true){
var futureY = this.position[ 1 ] - this.yAcceleration * dt;
if( !this.wouldCollide( [ this.position[ 0 ], futureY ], [ 'Level', 'Patches' ] ) ){
this.position[ 1 ] = futureY;
this.onGround = false;
var jumpFrame = 1;
if( this.yAcceleration > 10 ){
jumpFrame = 0;
}else if( this.yAcceleration < -8 ){
jumpFrame = 2;
}
this.setAnimation( 'jump', jumpFrame );
break;
}else{
this.yAcceleration *= 0.9;
if(Math.abs(this.yAcceleration)<0.2){
this.onGround = true;
break;
}
}
}
if(this.onGround){
this.yAcceleration = 0;
}
if(Keys.Down){
this.position[1]++;
}
this.updateAnimation(dt);
//this
//this.tile.srcRect[0] = 32*((tfs*4%4)|0);
//this.position[1]+=Math.sin(dt)
Camera.position[0] = this.position[0]+this.width/2;
Camera.position[1] = this.position[1]-this.height/3;
}
onFrameChange(name, frame){
if(name === 'walk'){
if(frame % 2 === 1){
zzfx( ...[ 1.04, , 213, .01, , .02, 1, 2.79, , , , , , .1, , , , .77, .01 ] ); // Blip 155
}
}else if(name === 'jump'){
}
}
draw(){
this.render();
//this.debug();
}
die(){
zzfx(...[,,435,.01,.01,.09,2,1.1,-3.2,,,,,,,,,.87,.1]);
}
}
\ No newline at end of file
// Зона вырезает кусок слоя уровня и даёт возможность показывать и скрывать выбранные участки геометрии уровня
class Zone extends GameObject {
init() {
this.tiles = this.extractTiles();
}
step(dt){
//this.opacity = Math.sin(+new Date()/1000)/2+0.5;
this.terraform(this.tiles, this.visible);
}
draw() {
this.renderTiles(this.tiles);
}
}
\ No newline at end of file
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