Skip to content

Commit

Permalink
Working on buster
Browse files Browse the repository at this point in the history
  • Loading branch information
YamanSD committed May 16, 2024
1 parent 81b1d2f commit c6fbef3
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 42 deletions.
Binary file modified assets/images/x_3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
142 changes: 108 additions & 34 deletions js/Game/Sprites/BusterShot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,142 @@
*/

class BusterShot extends Sprite {
constructor(x, y, left, power, onUpdate, hitBoxBrush) {
/**
* @param x {number}
* @param y {number}
* @param left {boolean}
* @param power {number}
* @param enemies {Sprite[]}
* @param scale {number}
*/
constructor(x, y, left, power, enemies, scale) {
super(
{},
[x, y],
onUpdate,
() => {
const speed = 10 + 3 * power;
this.x += left ? -speed : speed;

if (
this.x > 2 * this.game.cameraRX
|| this.rx < this.game.cameraX / 2
) {
this.game.removeSprite(this);
}

for (const enemy of enemies) {
const col = this.colliding(enemy);

if (col) {
enemy.damage(power * 5);
}
}

this.moveCurrentAnimation();
},
undefined,
undefined,
undefined,
undefined,
undefined,
hitBoxBrush
scale
);

this.currentAnimation = this.createAnimation(
0,
389,
15,
5,
1,
5,
15,
8,
1,
0,
3
);
if (power <= 1) {
this.currentAnimation = this.createAnimation(
0,
388,
15,
5,
1,
5,
15,
8,
1,
0,
3
);

this.hitBox = this.convertHitBoxes([
{
x,
y,
width: 15,
height: 8
}
]);
} else if (power < 3) {
this.currentAnimation = this.createAnimation(
0,
390,
43,
3,
1,
3,
26,
18,
1,
0,
3
);

this.hitBox = this.convertHitBoxes([
{
x,
y,
width: 26,
height: 18
}
]);
} else {
this.currentAnimation = this.createAnimation(
0,
310,
73,
3,
1,
3,
61,
30,
1,
0,
3
);

this.hitBox = this.convertHitBoxes([
{
x,
y,
width: 61,
height: 30
}
]);
}

this.flip = left;
}

get defaultHitBox() {
return this.convertHitBoxes([
{
x: this.x,
y: this.y,
width: this.width,
height: this.height
}
]);
return [];
}

get desc() {
return undefined;
}

draw(context) {
this.drawCurrentAnimation(this.x, this.y, context, 2);
}

get height() {
return this.getAnimation(this.currentAnimation).singleHeight;
this.drawCurrentAnimation(this.x, this.y, context);
}

get type() {
return "projectile";
}

get width() {
return this.getAnimation(this.currentAnimation).singleWidth;
}

/**
* @returns {string[]} sprite sheets.
*/
static get sheets() {
return ['x_0.png'];
return ['x_3.gif'];
}

/**
Expand Down
65 changes: 57 additions & 8 deletions js/Game/Sprites/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class Player extends Sprite {
dashDuration: 50, // In ticks
jumpForce: 10,
gravity: 15,
power: 1, // Power of the shot
initDashDuration: 50, // In ticks
tempAnimation: undefined
},
Expand Down Expand Up @@ -163,6 +164,12 @@ class Player extends Sprite {

// If not active do not take commands
if (this.states.get(PlayerControlsState) === PlayerControlsState.active) {
switch (this.states.get(PlayerAttackState)) {
case PlayerAttackState.charging:
this.power++;
break;
}

switch (this.states.get(PlayerDisplacementState)) {
case PlayerDisplacementState.move:
this.move();
Expand Down Expand Up @@ -231,6 +238,7 @@ class Player extends Sprite {
100,
);

// TODO add shooting animations and link
// Create the animations
this.#animations = {
spawn_0: this.createAnimation(
Expand Down Expand Up @@ -767,13 +775,21 @@ class Player extends Sprite {
* dashDuration: number,
* tempAnimation: number,
* hoverTimer: number,
* maxHoverTimer: number
* maxHoverTimer: number,
* power: number
* }} description of Player.
*/
get desc() {
return super.desc;
}

/**
* @returns {number}
*/
get power() {
return this.desc.power;
}

/**
* @returns {number} previous player state.
*/
Expand Down Expand Up @@ -830,6 +846,13 @@ class Player extends Sprite {
return this.desc.moveSpeed;
}

/**
* @param v {number}
*/
set power(v) {
this.desc.power = v;
}

/**
* @param v {number} new number of lives.
*/
Expand Down Expand Up @@ -890,6 +913,33 @@ class Player extends Sprite {
]);
}

/**
* Charges the shot.
*/
charge() {
this.states.set(PlayerAttackState, PlayerAttackState.charging);
}

/**
* Fires the shot.
*/
shoot() {
this.states.set(PlayerAttackState, PlayerAttackState.none);

this.game.insertSprite(
new BusterShot(
this.rx,
this.y + this.height / 2,
this.flip,
Math.min(3, Math.ceil(this.power / 12)),
[],
this.scale
)
);

this.power = 1;
}

/**
* Activates the key listeners
*/
Expand Down Expand Up @@ -934,6 +984,9 @@ class Player extends Sprite {
this.states.set(PlayerVerticalDisplacementState, PlayerVerticalDisplacementState.up);
}
break;
case 'x':
this.charge();
break;
}
};

Expand All @@ -958,6 +1011,9 @@ class Player extends Sprite {
case 'ArrowDown':
this.states.set(PlayerVerticalDisplacementState, PlayerVerticalDisplacementState.float);
break;
case 'x':
this.shoot();
break;
}
};

Expand Down Expand Up @@ -1004,13 +1060,6 @@ class Player extends Sprite {
this.game.addEventListener('keyup', keyLiftHandler);
}

/**
* Starts the player nova attack.
*/
nova() {

}

/**
* Draws the rectangle in the 2d context.
*
Expand Down

0 comments on commit c6fbef3

Please sign in to comment.