-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Berlevog/19-jump
карта и первые наброски физики для прыжков
- Loading branch information
Showing
16 changed files
with
719 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"plugins": ["@babel/plugin-proposal-async-generator-functions", "@babel/plugin-transform-runtime"], | ||
"presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ResourceImage } from "../pages/Game/Resources"; | ||
import { DisplayObject, Engine, Sprite } from "./Engine"; | ||
|
||
class Cloud extends Sprite { | ||
public deleted: boolean = false; | ||
private sprite: ResourceImage; | ||
private interval: NodeJS.Timer; | ||
|
||
constructor(size: number, speed: number = 1) { | ||
super(); | ||
this.sprite = new ResourceImage("images/cloud.png"); | ||
this.size = { width: 24, height: 24 }; | ||
this.position = { x: 800, y: Math.floor(Math.random() * 80 + 5) }; | ||
this.interval = setInterval(() => { | ||
this.positionX = Math.floor(this.positionX - speed); | ||
}, 100); | ||
} | ||
|
||
render(renderer: Engine.IRenderer) { | ||
const { canvas, context } = renderer; | ||
context.save(); | ||
// context.scale(-1, 1); | ||
context.drawImage(this.sprite.img, this.positionX, this.positionY, this.size.width, this.size.height); | ||
context.restore(); | ||
} | ||
} | ||
|
||
export default class Clouds extends DisplayObject { | ||
private clouds: Cloud[]; | ||
private interval: NodeJS.Timer; | ||
|
||
constructor() { | ||
super(); | ||
this.clouds = [new Cloud(3)]; | ||
this.interval = setInterval(() => { | ||
this.clouds = this.clouds.filter((cloud) => !cloud.deleted); | ||
this.clouds.push(new Cloud(Math.floor(Math.random() * 3 + 1), Math.floor(Math.random() * 5 + 1))); | ||
}, 10000); | ||
} | ||
|
||
getClouds(): Cloud[] { | ||
return this.clouds; | ||
} | ||
|
||
render(renderer: Engine.IRenderer) { | ||
this.clouds.forEach((cloud) => { | ||
if (cloud.positionY < 0) { | ||
cloud.deleted = true; | ||
} | ||
cloud.render(renderer); | ||
}); | ||
} | ||
|
||
destroy() { | ||
clearInterval(this.interval); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { distanceTo, getAABBColision, isAABBColision, linearEquation, Rect } from "./Engine"; | ||
|
||
describe("AABB Collision detection works well", () => { | ||
it("Return false if no collision detected", () => { | ||
expect(isAABBColision(new Rect(0, 0, 100, 100), new Rect(101, 101, 100, 100))).toBeFalsy(); | ||
expect(isAABBColision(new Rect(100, 100, 20, 20), new Rect(0, 0, 20, 20))).toBeFalsy(); | ||
expect(isAABBColision(new Rect(0, 100, 100, 100), new Rect(0, 0, 100, 100))).toBeFalsy(); | ||
}); | ||
|
||
it("Return true when collision detected", () => { | ||
expect(isAABBColision(new Rect(0, 0, 100, 100), new Rect(50, 50, 100, 100))).toBeTruthy(); | ||
expect(isAABBColision(new Rect(50, 50, 100, 100), new Rect(0, 0, 100, 100))).toBeTruthy(); | ||
expect(isAABBColision(new Rect(0, 100, 100, 100), new Rect(0, 50, 100, 100))).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe("AABB Collision returns right colision side", () => { | ||
it("Should return right", () => { | ||
expect(getAABBColision(new Rect(0, 0, 100, 100), new Rect(80, 0, 100, 100))?.right).toBeTruthy(); | ||
}); | ||
it("Should return left", () => { | ||
expect(getAABBColision(new Rect(80, 0, 100, 100), new Rect(0, 0, 100, 100))?.left).toBeTruthy(); | ||
}); | ||
it("Should return top", () => { | ||
expect(getAABBColision(new Rect(0, 0, 100, 100), new Rect(0, 80, 100, 100))?.top).toBeTruthy(); | ||
}); | ||
it("Should return bottom", () => { | ||
expect(getAABBColision(new Rect(0, 80, 100, 100), new Rect(0, 0, 100, 100))?.bottom).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it("Should return null if no collision", () => { | ||
expect(getAABBColision(new Rect(0, 0, 100, 100), new Rect(100, 100, 100, 100))).toBe(null); | ||
}); | ||
|
||
it("Должен посчитать растояние между двумя точками", () => { | ||
expect(distanceTo({ x: 0, y: 0 }, { x: 0, y: 100 })).toBe(100); | ||
expect(Math.floor(distanceTo({ x: 25, y: 25 }, { x: 100, y: 100 }))).toBe(106); | ||
}); | ||
it("Должен вычислить линейную функцию по двум точкам и вернуть Y от X", () => { | ||
expect(linearEquation({ x: 10, y: 10 }, { x: 20, y: 20 }, 15)).toBe(15); | ||
expect(linearEquation({ x: 0, y: 0 }, { x: 20, y: 20 }, 15)).toBe(15); | ||
expect(linearEquation({ x: 0, y: 0 }, { x: 10, y: 20 }, 10)).toBe(20); | ||
expect(linearEquation({ x: 0, y: 0 }, { x: 10, y: 20 }, 5)).toBe(10); | ||
}); |
Oops, something went wrong.