2022-06-25 00:29:43 -05:00
|
|
|
import Matter, { Vector } from "matter-js";
|
2022-06-25 21:47:29 -05:00
|
|
|
import {
|
|
|
|
GameEngineUpdateEventOptionType,
|
|
|
|
TouchEvent,
|
|
|
|
} from "react-native-game-engine";
|
2022-06-25 00:29:43 -05:00
|
|
|
|
|
|
|
import { windowHeight, windowWidth } from "@game";
|
2022-06-25 21:47:29 -05:00
|
|
|
import { Balloon } from "@entities";
|
2022-06-25 00:29:43 -05:00
|
|
|
|
|
|
|
export const GameLoop = (
|
|
|
|
entities: any,
|
|
|
|
{ touches, time, dispatch }: GameEngineUpdateEventOptionType
|
|
|
|
) => {
|
|
|
|
let engine = entities.physics.engine;
|
|
|
|
let world = entities.physics.world;
|
|
|
|
|
|
|
|
touches
|
|
|
|
.filter((t: TouchEvent) => t.type === "press")
|
|
|
|
.forEach((t: TouchEvent) => {
|
2022-06-25 21:47:29 -05:00
|
|
|
const balloonBody = entities.Balloon.body;
|
|
|
|
const balloonPos = balloonBody.position;
|
|
|
|
const { locationX, locationY } = t.event;
|
|
|
|
if (locationX < 50 && locationY < 50) {
|
|
|
|
dispatch({
|
|
|
|
type: "addToScore",
|
|
|
|
});
|
|
|
|
Matter.Events.trigger(engine, "removeBalloon");
|
|
|
|
}
|
2022-06-25 00:29:43 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
Matter.Engine.update(engine, time.delta);
|
|
|
|
return entities;
|
|
|
|
};
|