Skip to content

Commit

Permalink
Merge pull request #249 from omenking/66-garbage-preview-thumbs
Browse files Browse the repository at this point in the history
#66 garbage thumbs
  • Loading branch information
omenking authored Jan 1, 2018
2 parents 6e34b71 + 20fcccf commit 37d87a0
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 101 deletions.
1 change: 1 addition & 0 deletions app/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
,{"type": "image" , "name": "playfield_wall1" }
,{"type": "image" , "name": "bauble_times" }
,{"type": "image" , "name": "font" }
,{"type": "spritesheet" , "name": "garbage_thumb" , "options": {"x": 48 , "y": 32, "frames": 4}}
,{"type": "spritesheet" , "name": "ints_small" , "options": {"x": 16 , "y": 16, "frames": 18}}
,{"type": "spritesheet" , "name": "ints_large" , "options": {"x": 16 , "y": 24, "frames": 18}}
,{"type": "spritesheet" , "name": "playfield_cursor" , "options": {"x": 76 , "y": 44, "frames": 2}}
Expand Down
Binary file added app/assets/images/garbage_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions src/renderer/components/garbage_preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import ComponentGarbageThumb from 'components/garbage_thumb'
import ComponentPlayfield from 'components/playfield'

export default class ComponentGarbagePreview {
public playfield : ComponentPlayfield
public thumbs : Array<ComponentGarbageThumb>
public x : number
public y : number

constructor(){
this.thumbs = [
new ComponentGarbageThumb(0),
new ComponentGarbageThumb(1),
new ComponentGarbageThumb(2),
new ComponentGarbageThumb(3)
]
}

create(playfield : ComponentPlayfield, x: number, y : number){
this.playfield = playfield
this.x = x
this.y = y
this.thumbs[0].create(this)
this.thumbs[1].create(this)
this.thumbs[2].create(this)
this.thumbs[3].create(this)
}

update(){
this.thumbs[0].update()
this.thumbs[1].update()
this.thumbs[2].update()
this.thumbs[3].update()
}

render(){
this.thumbs[0].render()
this.thumbs[1].render()
this.thumbs[2].render()
this.thumbs[3].render()
}

get_index(kind : string, val : number){
this.thumbs[0].kind = kind
this.thumbs[0].size = val
return 0
}

fly_pos(pos){
return {
x: this.thumbs[0].x,
y: this.thumbs[0].y
}
}
}
85 changes: 83 additions & 2 deletions src/renderer/components/garbage_thumb.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,90 @@
import game from 'core/game'
import ComponentGarbagePreview from 'components/garbage_preview'
import ComponentParticleClear from 'components/particle_clear'
import {
CHAIN,
COMBO
} from 'core/data';

export default class ComponentGarbageThumb {
private _size
private _kind
private preview : ComponentGarbagePreview
private sprite : Phaser.Sprite
public size : number
public kind : string
private pos : number
public x : number
public y : number
public visible : boolean
public particles : Array<ComponentParticleClear>

constructor(pos : number){
this.pos = pos
this.particles = [
new ComponentParticleClear(0),
new ComponentParticleClear(1),
new ComponentParticleClear(2),
new ComponentParticleClear(3)
]
}

get absolute_center_x(){
return this.x + this.sprite.width / 2
}

get absolute_center_y(){
return this.y + this.sprite.height / 2
}

create(preview){
this.preview = preview
this.sprite = game.add.sprite(0,0,'garbage_thumb',0)
this.y = this.preview.y
this.x = this.preview.x + (this.pos * this.sprite.width)
this.sprite.visible = false
this.visible = false
this.sprite.x = this.x
this.sprite.y = this.y
this.particles[0].create(this,this.preview.playfield.pi)
this.particles[1].create(this,this.preview.playfield.pi)
this.particles[2].create(this,this.preview.playfield.pi)
this.particles[3].create(this,this.preview.playfield.pi)
}

pop_in(){
this.particles[0].set_counter()
this.particles[1].set_counter()
this.particles[2].set_counter()
this.particles[3].set_counter()
this.visible = true
}

update(){
this.particles[0].update()
this.particles[1].update()
this.particles[2].update()
this.particles[3].update()
}

get frame(){
if (this.kind === COMBO){
if (this.size === 4) {
return 0
} else if (this.size === 5) {
return 1
} else if (this.size === 6) {
return 2
}
} else if (this.kind === CHAIN) {
return 3
}
}

render(){
this.particles[0].render()
this.particles[1].render()
this.particles[2].render()
this.particles[3].render()
this.sprite.visible = this.visible
this.sprite.frame = this.frame
}
}
35 changes: 26 additions & 9 deletions src/renderer/components/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import {
TIME_SWAP,
TIME_CLEAR,
TIME_POP,
TIME_FALL
TIME_FALL,
COMBO,
CHAIN
} from 'core/data';

/**
Expand Down Expand Up @@ -101,6 +103,19 @@ export default class ComponentPanel {

get should_hang() { let under = this.under; return under === blank ? false : under.state === STATIC && under.kind === null; }

get absolute_center_x(){
let x = this.playfield.layer_block.x
x += (this.x * UNIT)
x += (UNIT / 2)
return x
}
get absolute_center_y(){
let y = this.playfield.layer_block.y
y += (this.y * UNIT)
y += (UNIT / 2)
return y
}

/** */
constructor() {
this.bauble = new ComponentBauble()
Expand Down Expand Up @@ -198,10 +213,10 @@ export default class ComponentPanel {

this.garbage.create(this,this.playfield)
this.bauble.create(this)
this.particles[0].create(this)
this.particles[1].create(this)
this.particles[2].create(this)
this.particles[3].create(this)
this.particles[0].create(this,this.playfield.pi)
this.particles[1].create(this,this.playfield.pi)
this.particles[2].create(this,this.playfield.pi)
this.particles[3].create(this,this.playfield.pi)
}

hang_enter() { this.counter = 10 }
Expand Down Expand Up @@ -343,10 +358,9 @@ export default class ComponentPanel {
*/
set_particle_garbage(){
if (!this.playfield.stage.flag_garbage) { return }
if (!this.first_pop) { return }
if (this.chain >= 2 || this.clear_len >= 4) {
this.bauble.particle_garbage.set_counter()
}
if (!this.first_pop) { return }
if (!this.sending_payload) { return }
this.bauble.particle_garbage.set_counter(COMBO,this.clear_len)
}

/*
Expand Down Expand Up @@ -583,6 +597,9 @@ export default class ComponentPanel {
})
}

get sending_payload(){
return this.chain >= 2 || this.clear_len >= 4
}
/*
* if this is the first panel to have popped in a chain
*/
Expand Down
32 changes: 12 additions & 20 deletions src/renderer/components/particle_clear.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import game from 'core/game'
import ComponentPanel from 'components/panel'
import {
FRAME_CLEAR_PARTICLE,
ANIM_CLEAR_PARTICLE_MOVE,
Expand All @@ -8,19 +7,21 @@ import {
} from 'core/data'

export default class ComponentPanelClear {
private panel : ComponentPanel
private sprite : Phaser.Sprite
private x : number
private y : number
private corner : number
public counter : number
public anchor : any
private pi : number

constructor(corner : number){
this.corner = corner
}

create(panel){
this.panel = panel
create(anchor,pi){
this.anchor = anchor
this.pi = pi
this.sprite = game.add.sprite(0, 0, 'particle_clear', 0)
this.sprite.visible = false
this.sprite.anchor.setTo(0.5)
Expand Down Expand Up @@ -56,10 +57,10 @@ export default class ComponentPanelClear {
}

load(data){
this.x = data[0]
this.y = data[1]
this.corner = data[2]
this.counter = data[3]
this.x = data[0]
this.y = data[1]
this.corner = data[2]
this.counter = data[3]
}

update(){
Expand All @@ -68,22 +69,13 @@ export default class ComponentPanelClear {
}

get frame(){
const i = this.playfield.pi
return (i * 8) + FRAME_CLEAR_PARTICLE[this.index]
}

get playfield(){
return this.panel.playfield
return (this.pi * 8) + FRAME_CLEAR_PARTICLE[this.index]
}

render(){
let offset = 6
let x = this.playfield.layer_block.x
let y = this.playfield.layer_block.y
x += (this.panel.x * UNIT)
y += (this.panel.y * UNIT)
x += (UNIT / 2)
y += (UNIT / 2)
let x = this.anchor.absolute_center_x
let y = this.anchor.absolute_center_y
if (this.corner === 0){ // top left
x -= ANIM_CLEAR_PARTICLE_MOVE[this.index] + offset
y -= ANIM_CLEAR_PARTICLE_MOVE[this.index] + offset
Expand Down
Loading

0 comments on commit 37d87a0

Please sign in to comment.