Skip to content

Commit

Permalink
whirlwind source IO init
Browse files Browse the repository at this point in the history
  • Loading branch information
jjppof committed Oct 23, 2023
1 parent 160ffed commit aad4d16
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 3 deletions.
21 changes: 21 additions & 0 deletions assets/dbs/interactable_objects_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,5 +399,26 @@
}
}
}
},{
"key_name": "whirlwind_source",
"anchor_x": 0.5,
"anchor_y": 0.75,
"body_radius": 7.0,
"collision_body_bevel": 3,
"initial_action": "whirlwind_source",
"whirlwind_source": true,
"actions": {
"whirlwind_source": {
"frame_rate": 1,
"animations": ["down", "left", "right"],
"frames_count": 1,
"loop": false,
"initial_animation": "down",
"spritesheet": {
"image": "assets/images/interactable_objects/whirlwind_source.png",
"json": "assets/images/interactable_objects/whirlwind_source.json"
}
}
}
}
]
36 changes: 36 additions & 0 deletions assets/images/interactable_objects/whirlwind_source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{"frames": {

"whirlwind_source/down/00":
{
"frame": {"x":1,"y":1,"w":18,"h":32},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":7,"y":0,"w":18,"h":32},
"sourceSize": {"w":32,"h":32}
},
"whirlwind_source/left/00":
{
"frame": {"x":1,"y":35,"w":18,"h":32},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":7,"y":0,"w":18,"h":32},
"sourceSize": {"w":32,"h":32}
},
"whirlwind_source/right/00":
{
"frame": {"x":1,"y":69,"w":18,"h":32},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":7,"y":0,"w":18,"h":32},
"sourceSize": {"w":32,"h":32}
}},
"meta": {
"app": "http://www.codeandweb.com/texturepacker",
"version": "1.0",
"image": "whirlwind_source.png",
"format": "RGBA8888",
"size": {"w":20,"h":102},
"scale": "1",
"smartupdate": "$TexturePacker:SmartUpdate:678addb2c0bc8e04bef7f4a5c08e2e9a:6d7c849f15c547c321bf45e7fbd0ed7a:9fe8a438923bc41c55feea2691152f22$"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions base/Camera.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {GoldenSun} from "./GoldenSun";
import {ControllableChar} from "./ControllableChar";
import {InteractableObjects} from "./interactable_objects/InteractableObjects";

Expand All @@ -9,23 +10,27 @@ export class Camera {
private static readonly SHAKE_INTENSITY = 3;

private game: Phaser.Game;
private data: GoldenSun;
private _target: ControllableChar | InteractableObjects;
private _camera_shake_enable: boolean;
private _following: boolean;
private _unfollow_hero_on_shake: boolean;
private _shake_ref_pos: {
x: number;
y: number;
};

constructor(game: Phaser.Game) {
constructor(game: Phaser.Game, data: GoldenSun) {
this.game = game;
this.data = data;
this._target = null;
this._camera_shake_enable = false;
this._following = false;
this._shake_ref_pos = {
x: 0,
y: 0,
};
this._unfollow_hero_on_shake = false;
}

/** The target that the camera is following. */
Expand Down Expand Up @@ -109,18 +114,26 @@ export class Camera {

/**
* Enables camera shake.
* @param unfollow_hero_on_shake will unfollow the hero while shaking the camera.
*/
enable_shake() {
enable_shake(unfollow_hero_on_shake: boolean = false) {
this._shake_ref_pos.x = this.game.camera.x;
this._shake_ref_pos.y = this.game.camera.y;
this._camera_shake_enable = true;
this._unfollow_hero_on_shake = unfollow_hero_on_shake;
if (this._unfollow_hero_on_shake) {
this.unfollow();
}
}

/**
* Disables camera shake.
*/
disable_shake() {
this._camera_shake_enable = false;
if (this._unfollow_hero_on_shake) {
this.follow(this.data.hero);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion base/GoldenSun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class GoldenSun {
await initialize_bgm_data(this.game, this, this.dbs.bgm_db);

//init camera custom features
this.camera = new Camera(this.game);
this.camera = new Camera(this.game, this);

//initialize managers
this.gamepad = new XGamepad(this);
Expand Down
12 changes: 12 additions & 0 deletions base/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {DjinnGetEvent} from "./game_events/DjinnGetEvent";
import {Breakable} from "./interactable_objects/Breakable";
import {Window} from "./Window";
import {GAME_HEIGHT, GAME_WIDTH} from "./magic_numbers";
import {WhirlwindSource} from "./interactable_objects/WhirlwindSource";

/** The class reponsible for the maps of the engine. */
export class Map {
Expand Down Expand Up @@ -384,6 +385,7 @@ export class Map {
}
this.collision_sprite.body.velocity.y = this.collision_sprite.body.velocity.x = 0;
this.npcs.forEach(npc => npc.update());
this.interactable_objects.forEach(io => io.update());
for (let key in this.events) {
this.events[key].forEach(event => event.update());
}
Expand Down Expand Up @@ -1111,6 +1113,8 @@ export class Map {
io_class = RollablePillar;
} else if (interactable_object_db.breakable) {
io_class = Breakable;
} else if (interactable_object_db.whirlwind_source) {
io_class = WhirlwindSource;
}
const allow_jumping_over_it =
snapshot_info?.allow_jumping_over_it ??
Expand Down Expand Up @@ -1205,6 +1209,12 @@ export class Map {
property_info.dest_pos_after_fall,
property_info.dest_collision_layer
);
} else if (interactable_object.whirlwind_source) {
(interactable_object as WhirlwindSource).intialize_whirlwind_source(
property_info.dest_point,
property_info.emission_interval,
property_info.speed_factor
);
}
this.interactable_objects.push(interactable_object);
if (interactable_object.label) {
Expand Down Expand Up @@ -1238,6 +1248,8 @@ export class Map {
(interactable_object as Breakable).intialize_breakable();
} else if (interactable_object.rollable) {
(interactable_object as RollablePillar).config_rolling_pillar(this);
} else if (interactable_object.whirlwind_source) {
(interactable_object as WhirlwindSource).config_whirlwind_source();
}
if (
(!snapshot_info && interactable_object.base_collision_layer in this._bodies_positions) ||
Expand Down
10 changes: 10 additions & 0 deletions base/interactable_objects/InteractableObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class InteractableObjects {
protected _is_rope_dock: boolean;
protected _rollable: boolean;
protected _breakable: boolean;
protected _whirlwind_source: boolean;
protected _extra_sprites: (Phaser.Sprite | Phaser.Graphics | Phaser.Group)[];
public allow_jumping_over_it: boolean;
public allow_jumping_through_it: boolean;
Expand Down Expand Up @@ -245,6 +246,7 @@ export class InteractableObjects {
this._is_rope_dock = false;
this._rollable = false;
this._breakable = false;
this._whirlwind_source = false;
this.tile_events_info = {};
for (let index in events_info) {
this.tile_events_info[+index] = events_info[index];
Expand Down Expand Up @@ -391,6 +393,9 @@ export class InteractableObjects {
get breakable() {
return this._breakable;
}
get whirlwind_source() {
return this._whirlwind_source;
}
/** When enable is false, the io is on the map, but a char can't interact with it. */
get enable() {
return this._enable;
Expand Down Expand Up @@ -1407,6 +1412,11 @@ export class InteractableObjects {
*/
custom_unset() {}

/**
* Method to be overriden.
*/
update() {}

add_unset_callback(callback: () => void) {
this.on_unset_callbacks.push(callback);
}
Expand Down
Loading

0 comments on commit aad4d16

Please sign in to comment.