Skip to content

Commit

Permalink
Merge pull request #51 from fallingleaflun/master
Browse files Browse the repository at this point in the history
Add "D" and change to 15 red balls in snooker mode
  • Loading branch information
tailuge authored May 5, 2024
2 parents 1eed901 + 54ca49d commit 4a60859
Show file tree
Hide file tree
Showing 8 changed files with 1,252 additions and 9 deletions.
Binary file added dist/models/d-cloth-hires.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/models/d-snooker.bin
Binary file not shown.
Binary file added dist/models/d-snooker.blend
Binary file not shown.
1,215 changes: 1,215 additions & 0 deletions dist/models/d-snooker.gltf

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion src/controller/placeball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,26 @@ export class PlaceBall extends ControllerBase {
case "ArrowRight":
this.moveTo(0, -input.t * this.placescale)
break
// use cursor movement for placing cueball
case "movementXUp":
this.moveTo(0, -input.t * this.placescale * 2)
break

case "movementYUp":
this.moveTo(-input.t * this.placescale * 2, 0)
break
// use IJKL for placing cueball
case "KeyI":
this.moveTo(0, input.t * this.placescale)
break
case "KeyK":
this.moveTo(0, -input.t * this.placescale)
break
case "KeyJ":
this.moveTo(-input.t * this.placescale, 0)
break
case "KeyL":
this.moveTo(input.t * this.placescale, 0)
break
case "SpaceUp":
return this.placed()
default:
Expand Down
21 changes: 16 additions & 5 deletions src/controller/rules/snooker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class Snooker implements Rules {
score = 0
rulename = "snooker"

static readonly tablemodel = "models/snooker.min.gltf"
// add "D" in snooker model
static readonly tablemodel = "models/d-snooker.gltf"

readonly container: Container

Expand Down Expand Up @@ -221,10 +222,20 @@ export class Snooker implements Rules {

placeBall(target?: Vector3): Vector3 {
if (target) {
// constrain to "D" in the future
const max = new Vector3(Rack.baulk, Rack.sixth)
const min = new Vector3(Rack.baulk - Rack.sixth, -Rack.sixth)
return target.clamp(min, max)
// constrain to "D"
const centre = new Vector3(Rack.baulk, 0, 0)
const radius = Rack.sixth
const distance = target.distanceTo(centre)
if (target.x >= Rack.baulk) {
target.x = Rack.baulk
}
if (distance > radius) {
const direction = target.clone().sub(centre).normalize()
return centre.add(direction.multiplyScalar(radius))
}
else {
return target;
}
}
return new Vector3(Rack.baulk, -Rack.sixth / 2.6, 0)
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/rack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ export class Rack {
balls.push(new Ball(Rack.jitter(colours[4]), 0xffaacc))
balls.push(new Ball(Rack.jitter(colours[5]), 0x010101))

const triangle = Rack.trianglePositions().slice(0, 6)
// change to 15 red balls
const triangle = Rack.trianglePositions().slice(0, 15)
triangle.forEach((p) => {
balls.push(new Ball(Rack.jitter(p.add(Rack.down)), 0xee0000))
})
Expand Down
4 changes: 2 additions & 2 deletions test/rules/snooker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ describe("Snooker", () => {
container.processEvents()
}

it("Snooker has 6 colours and 6 reds", (done) => {
expect(table.balls).to.be.length(13)
it("Snooker has 6 colours and 15 reds", (done) => {
expect(table.balls).to.be.length(22)
done()
})

Expand Down

0 comments on commit 4a60859

Please sign in to comment.