slifer 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.npmignore CHANGED
@@ -7,6 +7,7 @@ yarn-error.log*
7
7
  lerna-debug.log*
8
8
  .pnpm-debug.log*
9
9
  .vs
10
+ .DS_Store
10
11
  Resources
11
12
  .idea
12
13
 
@@ -135,4 +136,4 @@ test.ts
135
136
  char.png
136
137
 
137
138
  .wakatime-project
138
- libs/
139
+ libs/
package/bun.lockb CHANGED
Binary file
package/index.ts CHANGED
@@ -3,6 +3,9 @@ import Image from "./src/engine/image";
3
3
  import Vector2 from "./src/engine/vector2";
4
4
  import Color from "./src/engine/color";
5
5
  import Audio from "./src/engine/audio";
6
+ import Rectangle from "./src/engine/rectangle";
7
+ import Font from "./src/engine/font";
8
+ import Canvas from './src/engine/canvas';
6
9
 
7
10
  const slf = new Slifer();
8
- export { Vector2, Color, Image, Audio, slf as Slifer };
11
+ export { Vector2, Color, Image, Audio, Rectangle, Font, Canvas, slf as Slifer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slifer",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "A game framework made for bun and typescript",
5
5
  "module": "index.ts",
6
6
  "devDependencies": {
package/src/download.ts CHANGED
@@ -1,5 +1,3 @@
1
- import * as https from 'https';
2
- import * as fs from 'fs';
3
1
  import * as path from 'path';
4
2
 
5
3
  const libDir = path.join(__dirname, '../libs/');
@@ -13,11 +11,17 @@ async function downloadLibrary(url: string, filename: string) {
13
11
 
14
12
  if (process.platform == "darwin") {
15
13
  downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2.dylib", "libSDL2.dylib");
16
-
17
-
18
14
  downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_image.dylib", "libSDL2_image.dylib");
19
-
20
15
  downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_mixer.dylib", "libSDL2_mixer.dylib");
21
-
22
16
  downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_ttf.dylib", "libSDL2_ttf.dylib");
17
+ } else if (process.platform == "win32") {
18
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/SDL2.dll", "SDL2.dll");
19
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/SDL2_image.dll", "SDL2_image.dll");
20
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/SDL2_mixer.dll", "SDL2_mixer.dll");
21
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/SDL2_ttf.dll", "SDL2_ttf.dll");
22
+ } else if (process.platform == "linux") {
23
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2.so", "libSDL2.so");
24
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_image.so", "libSDL2_image.so");
25
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_mixer.so", "libSDL2_mixer.so");
26
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_ttf.so", "libSDL2_ttf.so");
23
27
  }
@@ -0,0 +1,58 @@
1
+ import { type Pointer, ptr } from 'bun:ffi';
2
+ import { libsdl } from '../ffi';
3
+ import Image from './image';
4
+ import Render from './render';
5
+ import Color from './color';
6
+
7
+ /** @internal */
8
+ export default class Canvas {
9
+
10
+ private pointer : Pointer;
11
+
12
+ public readonly width;
13
+ public readonly height;
14
+
15
+ constructor(width: number, height: number) {
16
+ const surPointer = libsdl.symbols.SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0)
17
+ if (surPointer == null) throw `Canvas creation failed`;
18
+ this.pointer = surPointer;
19
+ this.width = width;
20
+ this.height = height;
21
+ }
22
+
23
+ private drawBG(color: Color) {
24
+ const rect = new Uint32Array(4);
25
+ rect[0] = 0;
26
+ rect[1] = 0;
27
+ rect[2] = this.width;
28
+ rect[3] = this.height;
29
+
30
+ const _col = ((color.r << 16) + (color.g << 8) + (color.b << 0));
31
+
32
+ libsdl.symbols.SDL_FillRect(this.pointer, ptr(rect), _col);
33
+ }
34
+
35
+ clear() {
36
+ this.drawBG(new Color(0, 0, 0, 0));
37
+ }
38
+
39
+ setBackground(color: Color) {
40
+ this.drawBG(color);
41
+ }
42
+
43
+ draw(drawable: Image | Canvas, x: number, y: number, scaleX?: number, scaleY?: number) : void {
44
+ const destArray = new Uint32Array(4);
45
+ destArray[0] = x;
46
+ destArray[1] = y;
47
+ destArray[2] = drawable.width * (scaleX ? scaleX : 1);
48
+ destArray[3] = drawable.height * (scaleY ? scaleY : 1);
49
+
50
+ libsdl.symbols.SDL_UpperBlitScaled(
51
+ (drawable as any).pointer,
52
+ null,
53
+ this.pointer,
54
+ ptr(destArray)
55
+ );
56
+ }
57
+
58
+ }
@@ -0,0 +1,16 @@
1
+ import { type Pointer } from 'bun:ffi';
2
+ import { libttf } from '../ffi';
3
+
4
+ export default class Font {
5
+ private pointer : Pointer;
6
+
7
+ constructor(path: string, size: number) {
8
+ const fp = libttf.symbols.TTF_OpenFont(Buffer.from(path+"\x00"), size);
9
+ if (fp == null) throw `Font failed to be opened`;
10
+ this.pointer = fp;
11
+ }
12
+
13
+ public destroy() {
14
+ libttf.symbols.TTF_CloseFont(this.pointer);
15
+ }
16
+ }
@@ -1,34 +1,23 @@
1
1
  import { libimage, libsdl } from "../ffi";
2
- import { type Pointer, ptr } from 'bun:ffi';
2
+ import { type Pointer, ptr, toArrayBuffer } from 'bun:ffi';
3
3
  import Render from "./render";
4
4
 
5
5
  /** @internal */
6
6
  export default class Image {
7
7
 
8
8
  private pointer: Pointer;
9
- private destArr: Uint32Array;
10
9
 
11
- public readonly width;
12
- public readonly height;
10
+ public readonly width: number;
11
+ public readonly height: number;
13
12
 
14
13
  constructor(path: string) {
15
14
  const cs = Buffer.from(path+'\x00');
16
- //@ts-expect-error Buffer error;
17
- const texture = libimage.symbols.IMG_LoadTexture(Render.pointer, cs);
18
- if (texture == null) throw `Texture creation failed.`;
19
- this.pointer = texture;
20
-
21
- const wArr = new Uint32Array(1);
22
- const hArr = new Uint32Array(1);
23
- libsdl.symbols.SDL_QueryTexture(texture, null, null, ptr(wArr), ptr(hArr));
24
-
25
- this.width = wArr[0];
26
- this.height = hArr[0];
27
-
28
- this.destArr = new Uint32Array(4);
29
- this.destArr[0] = 0;
30
- this.destArr[1] = 0;
31
- this.destArr[2] = this.width;
32
- this.destArr[3] = this.height;
15
+ //@ts-expect-error
16
+ const surface = libimage.symbols.IMG_Load(cs);
17
+ if (surface == null) throw `Loading ${path} failed`;
18
+ this.pointer = surface;
19
+ const dv = new DataView(toArrayBuffer(this.pointer, 0, 21));
20
+ this.width = dv.getUint8(16);
21
+ this.height = dv.getUint8(20);
33
22
  }
34
- }
23
+ }
@@ -1,4 +1,4 @@
1
- import type Vector2 from "./vector2";
1
+ import Vector2 from "./vector2";
2
2
  import { ptr, type Pointer } from 'bun:ffi';
3
3
 
4
4
  /** @internal */
@@ -12,6 +12,10 @@ export default class Rectangle {
12
12
  this.size = size;
13
13
  }
14
14
 
15
+ static empty() : Rectangle {
16
+ return new Rectangle(new Vector2(0, 0), new Vector2(0, 0));
17
+ }
18
+
15
19
  public isColliding(rectangle: Rectangle) : boolean {
16
20
  if (
17
21
  this.position.x < rectangle.position.x + rectangle.size.x &&
@@ -6,10 +6,14 @@ import Window from "./window";
6
6
  export default class Render {
7
7
 
8
8
  public static pointer : Pointer;
9
+ public static surface: Pointer;
9
10
 
10
- public static createRenderer() {
11
+ public static createRenderer(width: number, height: number) {
11
12
  const renPointer = libsdl.symbols.SDL_CreateRenderer(Window.pointer, -1, 0);
12
13
  if (renPointer == null) throw `Renderer creation failed.`;
13
14
  this.pointer = renPointer;
15
+ const surPointer = libsdl.symbols.SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0)
16
+ if (surPointer == null) throw `Surface creation failed`;
17
+ this.surface = surPointer;
14
18
  }
15
- }
19
+ }
@@ -7,4 +7,20 @@ export default class Vector2 {
7
7
  this.x = x;
8
8
  this.y = y;
9
9
  }
10
+
11
+ static one() : Vector2 {
12
+ return new Vector2(1, 1);
13
+ }
14
+
15
+ static unitX() : Vector2 {
16
+ return new Vector2(1, 0);
17
+ }
18
+
19
+ static unitY() : Vector2 {
20
+ return new Vector2(0, 1);
21
+ }
22
+
23
+ static zero() : Vector2 {
24
+ return new Vector2(0, 0);
25
+ }
10
26
  }
@@ -4,29 +4,32 @@ import { libsdl } from '../ffi';
4
4
 
5
5
  /** @internal */
6
6
  export default class Window {
7
- public static pointer: Pointer;
8
7
 
8
+ public static pointer: Pointer;
9
+ public static size: Vector2;
10
+
9
11
  private static centerPos = 0x2fff0000;
10
12
 
13
+
14
+
11
15
  public static createWindow(title: string, size: Vector2) : void {
12
16
  const winPointer = libsdl.symbols.SDL_CreateWindow(
13
- //@ts-expect-error Buffer error
14
17
  Buffer.from(title + '\x00'),
15
18
  this.centerPos,
16
19
  this.centerPos,
17
20
  size.x,
18
21
  size.y,
19
22
  0
20
- )
23
+ );
21
24
 
22
25
  if (winPointer == null) throw `Window creation failed.`;
23
26
  this.pointer = winPointer;
27
+ this.size = size;
24
28
  }
25
29
 
26
30
  public setTitle(title: string): void {
27
31
  libsdl.symbols.SDL_SetWindowTitle(
28
32
  Window.pointer,
29
- //@ts-expect-error Buffer error
30
33
  Buffer.from(title + "\x00")
31
34
  );
32
35
  }
@@ -46,4 +49,4 @@ export default class Window {
46
49
  public centerWindow() {
47
50
  this.setPosition(new Vector2(Window.centerPos, Window.centerPos));
48
51
  }
49
- }
52
+ }
package/src/ffi.ts CHANGED
@@ -1,19 +1,22 @@
1
1
  import { dlopen, FFIType, suffix } from "bun:ffi";
2
+ import * as path from "path";
2
3
 
3
4
  let libSDLImport;
4
5
  let libImageImport;
5
6
  let libTTFImport;
6
7
  let libMixerImport;
7
8
 
9
+ const libDir = path.join(__dirname, "../libs/");
10
+
8
11
  if (process.platform == "win32") {
9
12
  //@ts-expect-error
10
- libSDLImport = await import("../libs/libSDL2.dll");
13
+ libSDLImport = await import("../libs/SDL2.dll");
11
14
  //@ts-expect-error
12
- libImageImport = await import("../libs/libSDL2_image.dll");
15
+ libImageImport = await import("../libs/SDL2_image.dll");
13
16
  //@ts-expect-error
14
- libTTFImport = await import("../libs/libSDL2_ttf.dll");
17
+ libTTFImport = await import("../libs/SDL2_ttf.dll");
15
18
  //@ts-expect-error
16
- libMixerImport = await import("../libs/libSDL2_mixer.dll");
19
+ libMixerImport = await import("../libs/SDL2_mixer.dll");
17
20
  } else if (process.platform == "darwin") {
18
21
  //@ts-expect-error
19
22
  libSDLImport = await import("../libs/libSDL2.dylib");
@@ -24,14 +27,10 @@ if (process.platform == "win32") {
24
27
  //@ts-expect-error
25
28
  libMixerImport = await import("../libs/libSDL2_mixer.dylib");
26
29
  } else if (process.platform == "linux") {
27
- //@ts-expect-error
28
- libSDLImport = await import("../libs/libSDL2.so");
29
- //@ts-expect-error
30
- libImageImport = await import("../libs/libSDL2_image.so");
31
- //@ts-expect-error
32
- libTTFImport = await import("../libs/libSDL2_ttf.so");
33
- //@ts-expect-error
34
- libMixerImport = await import("../libs/libSDL2_mixer.so");
30
+ libSDLImport = await import(`${libDir}libSDL2.so`);
31
+ libImageImport = await import(`${libDir}libSDL2_image.so`);
32
+ libTTFImport = await import(`${libDir}libSDL2_ttf.so`);
33
+ libMixerImport = await import(`${libDir}libSDL2_mixer.so`);
35
34
  }
36
35
 
37
36
  /** @internal */
@@ -220,6 +219,29 @@ export const libsdl = dlopen(libSDLImport.default, {
220
219
  SDL_GetScancodeFromName: {
221
220
  args: ["cstring"],
222
221
  returns: "int",
222
+ },
223
+ SDL_GetTicks64: {
224
+ returns: 'u64'
225
+ },
226
+ SDL_CreateRGBSurface: {
227
+ args: ['int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'],
228
+ returns: 'pointer'
229
+ },
230
+ SDL_UpperBlitScaled: {
231
+ args: ['pointer', 'pointer','pointer','pointer'],
232
+ returns: 'int'
233
+ },
234
+ SDL_FillRect: {
235
+ args: ['pointer', 'pointer', 'int'],
236
+ returns: 'int'
237
+ },
238
+ SDL_DestroyTexture : {
239
+ args: ['pointer'],
240
+ returns: 'void'
241
+ },
242
+ SDL_MapRGB: {
243
+ args: ['pointer', 'int', 'int', 'int'],
244
+ returns: 'u32'
223
245
  }
224
246
  });
225
247
 
@@ -234,9 +256,9 @@ export const libimage = dlopen(libImageImport.default, {
234
256
  returns: "pointer",
235
257
  },
236
258
  IMG_LoadTexture: {
237
- args: ['pointer', 'cstring'],
238
- returns: 'pointer'
239
- }
259
+ args: ["pointer", "cstring"],
260
+ returns: "pointer",
261
+ },
240
262
  });
241
263
 
242
264
  /** @internal */
@@ -1,78 +1,100 @@
1
1
  import Vector2 from "../engine/vector2";
2
- import { libsdl } from "../ffi";
2
+ import { libsdl, libttf } from "../ffi";
3
3
  import { ptr } from 'bun:ffi';
4
-
4
+ import Font from '../engine/font';
5
5
  import type Image from "../engine/image";
6
6
  import Render from "../engine/render";
7
+ import Window from '../engine/window';
7
8
  import type Color from "../engine/color";
8
- import type Rectangle from "../engine/rectangle";
9
+ import Rectangle from "../engine/rectangle";
10
+ import Canvas from '../engine/canvas';
9
11
 
10
12
  /** @internal */
11
13
  export default class Graphics {
12
14
 
13
- render() : void {
15
+ public render() : void {
16
+ const texture = libsdl.symbols.SDL_CreateTextureFromSurface(Render.pointer, Render.surface);
17
+ if (texture == null) throw `Render texture creation failed`;
18
+ libsdl.symbols.SDL_RenderCopy(
19
+ Render.pointer,
20
+ texture,
21
+ null,
22
+ null
23
+ );
14
24
  libsdl.symbols.SDL_RenderPresent(Render.pointer);
25
+ libsdl.symbols.SDL_DestroyTexture(texture);
15
26
  }
16
27
 
17
- draw(image: Image, position: Vector2) : void {
18
-
19
- (image as any).destArr[0] = position.x;
20
- (image as any).destArr[1] = position.y;
21
-
22
- libsdl.symbols.SDL_RenderCopy(
23
- Render.pointer,
24
- (image as any).pointer,
25
- null,
26
- ptr((image as any).destArr)
27
- );
28
- }
28
+ public draw(drawable: Image | Canvas, x: number, y: number, scaleX?: number, scaleY?: number) : void {
29
29
 
30
- drawEx(image: Image, position: Vector2, rotation?: number, scale?: Vector2, flipH?: boolean) {
31
-
32
- const destArr = (image as any).destArr;
33
- destArr[0] = position.x;
34
- destArr[1] = position.y;
35
- destArr[2] = image.width * (scale ? scale.x : 1);
36
- destArr[3] = image.height * (scale ? scale.y : 1);
37
-
38
- libsdl.symbols.SDL_RenderCopyEx(
39
- Render.pointer,
40
- (image as any).pointer,
41
- null,
42
- ptr(destArr),
43
- rotation ? rotation : 0,
44
- null,
45
- Number(flipH)
30
+ const destArray = new Uint32Array(4);
31
+ destArray[0] = x;
32
+ destArray[1] = y;
33
+ destArray[2] = drawable.width * (scaleX ? scaleX : 1);
34
+ destArray[3] = drawable.height * (scaleY ? scaleY : 1);
35
+
36
+ libsdl.symbols.SDL_UpperBlitScaled(
37
+ (drawable as any).pointer,
38
+ null,
39
+ Render.surface,
40
+ ptr(destArray)
46
41
  );
47
-
48
-
49
42
  }
50
43
 
51
- setBackground(color: Color) : void {
52
- libsdl.symbols.SDL_SetRenderDrawColor(Render.pointer,
53
- color.r,
54
- color.g,
55
- color.b,
56
- color.a
57
- );
58
- libsdl.symbols.SDL_RenderClear(Render.pointer);
59
- }
44
+ public setBackground(color: Color) : void {
45
+ const rect = new Rectangle(
46
+ new Vector2(0, 0),
47
+ new Vector2(Window.size.x, Window.size.y)
48
+ );
49
+ this.drawRect(rect, color);
50
+ }
60
51
 
61
52
  public drawRect(rectangle: Rectangle, color: Color) {
62
- libsdl.symbols.SDL_SetRenderDrawColor(
63
- Render.pointer,
64
- color.r,
65
- color.g,
66
- color.b,
67
- color.a
68
- );
53
+ const _col = ((color.r << 16) + (color.g << 8) + (color.b << 0));
69
54
 
70
55
  const rect = new Uint32Array(4);
71
56
  rect[0] = rectangle.position.x;
72
- rect[1] = rectangle.position.y;
57
+ rect[1] = rectangle.position.y;
73
58
  rect[2] = rectangle.size.x;
74
59
  rect[3] = rectangle.size.y;
75
60
 
76
- libsdl.symbols.SDL_RenderFillRect(Render.pointer, ptr(rect));
61
+ libsdl.symbols.SDL_FillRect(Render.surface, ptr(rect), _col);
62
+ }
63
+
64
+ public print(text: string, x: number, y: number, font: Font, color: Color) {
65
+ const wArr = new Uint32Array(1);
66
+ const hArr = new Uint32Array(1);
67
+
68
+ libttf.symbols.TTF_SizeText(
69
+ (font as any).pointer,
70
+ //@ts-expect-error
71
+ Buffer.from(text+"\x00"),
72
+ ptr(wArr),
73
+ ptr(hArr)
74
+ );
75
+
76
+ const _col = ((color.r << 16) + (color.g << 8) + (color.b << 0));
77
+
78
+ const surface = libttf.symbols.TTF_RenderText_Solid(
79
+ (font as any).pointer,
80
+ //@ts-expect-error
81
+ Buffer.from(text+'\x00'),
82
+ _col
83
+ );
84
+ if (surface == null) throw `Rendering text failed`;
85
+
86
+ const destRect = new Uint32Array(4);
87
+ destRect[0] = x;
88
+ destRect[1] = y;
89
+ destRect[2] = wArr[0];
90
+ destRect[3] = hArr[0];
91
+
92
+ libsdl.symbols.SDL_UpperBlit(
93
+ surface,
94
+ null,
95
+ Render.surface,
96
+ ptr(destRect)
97
+ );
98
+
77
99
  }
78
- }
100
+ }
@@ -4,18 +4,24 @@ import Vector2 from "../engine/vector2";
4
4
 
5
5
  /** @internal */
6
6
  class Mouse {
7
-
8
- private static x : number;
9
- private static y : number;
7
+ private static x: number;
8
+ private static y: number;
10
9
 
11
10
  private static buttonMap = new Map<number, number>();
12
-
11
+
13
12
  static onRelease(button: number) {
14
13
  this.buttonMap.set(button, 0);
15
14
  }
16
15
 
16
+ static onMove(x: number, y: number) {
17
+ this.x = x;
18
+ this.y = y;
19
+ }
20
+
17
21
  static handleState() {
18
- const down = libsdl.symbols.SDL_GetMouseState();
22
+ const xArr = new Uint32Array(1);
23
+ const yArr = new Uint32Array(1);
24
+ const down = libsdl.symbols.SDL_GetMouseState(ptr(xArr), ptr(yArr));
19
25
  const bmGet = this.buttonMap.get(down);
20
26
 
21
27
  if (bmGet == undefined || bmGet == 0) {
@@ -37,27 +43,31 @@ class Mouse {
37
43
  return false;
38
44
  }
39
45
 
40
- isPressed(button: buttons) : boolean {
46
+ isPressed(button: buttons): boolean {
41
47
  switch (button) {
42
- case 'left':
48
+ case "left":
43
49
  return Mouse.getPressMap(1);
44
- case 'middle':
50
+ case "middle":
45
51
  return Mouse.getPressMap(2);
46
- case 'right':
52
+ case "right":
47
53
  return Mouse.getPressMap(3);
48
54
  }
49
55
  }
50
56
 
51
- isDown(button: buttons) : boolean {
57
+ isDown(button: buttons): boolean {
52
58
  switch (button) {
53
- case 'left':
59
+ case "left":
54
60
  return Mouse.getDownMap(1);
55
- case 'middle':
61
+ case "middle":
56
62
  return Mouse.getDownMap(2);
57
- case 'right':
63
+ case "right":
58
64
  return Mouse.getDownMap(3);
59
65
  }
60
66
  }
67
+
68
+ getPosition(): Vector2 {
69
+ return new Vector2(Mouse.x, Mouse.y);
70
+ }
61
71
  }
62
72
 
63
73
  type buttons = "left" | "middle" | "right";
package/src/slifer.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { libsdl } from "./ffi";
2
2
  import Window from "./engine/window";
3
- import Renderer from "./engine/render";
4
3
  import { ptr } from "bun:ffi";
5
4
  import { initLibraries } from "./engine";
6
5
  import { version } from "../package.json";
@@ -9,32 +8,40 @@ import Graphics from "./modules/graphics";
9
8
  import Keyboard from "./modules/keyboard";
10
9
  import Mouse from "./modules/mouse";
11
10
  import Render from "./engine/render";
11
+ import Color from './engine/color';
12
12
 
13
13
  class Slifer {
14
-
15
14
  public isRunning: boolean;
15
+ public deltaTime: number;
16
16
 
17
17
  // Modules
18
18
  public Graphics = new Graphics();
19
19
  public Keyboard = new Keyboard();
20
20
  public Mouse = new Mouse();
21
21
 
22
+ private start = 0;
23
+ private end = 0;
24
+ private black : Color;
25
+
22
26
  constructor() {
23
27
  initLibraries();
24
28
  this.isRunning = true;
29
+ this.deltaTime = 0;
30
+ this.black = new Color(0,0,0,0);
25
31
  }
26
32
 
27
- public createWindow(title: string, size: Vector2) : Window {
33
+ public createWindow(title: string, size: Vector2): Window {
28
34
  Window.createWindow(title, size);
29
- Renderer.createRenderer();
35
+ Render.createRenderer(size.x, size.y);
36
+
37
+ this.start = Number(libsdl.symbols.SDL_GetTicks64());
30
38
 
31
39
  return new Window();
32
40
  }
33
41
 
34
- public shouldClose() : boolean {
35
-
42
+ public shouldClose(): boolean {
36
43
  libsdl.symbols.SDL_RenderClear(Render.pointer);
37
-
44
+
38
45
  const eventArray = new Uint16Array(32);
39
46
  const event = libsdl.symbols.SDL_PollEvent(ptr(eventArray));
40
47
  if (event) {
@@ -42,24 +49,39 @@ class Slifer {
42
49
  case 256:
43
50
  this.isRunning = false;
44
51
  break;
52
+ case 1024:
53
+ Mouse.onMove(eventArray[10], eventArray[12]);
54
+ break;
45
55
  case 1026:
46
56
  Mouse.onRelease(eventArray[8]);
47
57
  break;
48
58
  }
49
59
  }
50
60
 
61
+
51
62
  Keyboard.handleStates();
52
63
 
53
64
  Mouse.handleState();
65
+
66
+ this.end = Number(libsdl.symbols.SDL_GetTicks64());
67
+
68
+ this.deltaTime = (this.end - this.start) / 1000;
69
+
70
+ this.start = this.end;
54
71
 
55
-
72
+
56
73
  return !this.isRunning;
57
74
  }
58
75
 
59
- public getVersion() : string {
60
- return 'v' + version;
76
+ public getVersion(): string {
77
+ return "v" + version;
61
78
  }
62
- }
63
79
 
80
+ public quit(): void {
81
+ libsdl.symbols.SDL_DestroyRenderer(Render.pointer);
82
+ libsdl.symbols.SDL_DestroyWindow(Window.pointer);
83
+ libsdl.symbols.SDL_Quit();
84
+ }
85
+ }
64
86
 
65
87
  export default Slifer;
package/src/Jost-Bold.ttf DELETED
Binary file