Skip to content

Commit

Permalink
wip: add beginning of bobber assets & logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Stan-Stani committed Jan 8, 2024
1 parent 65a2c70 commit a6e17a7
Show file tree
Hide file tree
Showing 9 changed files with 805 additions and 77 deletions.
131 changes: 131 additions & 0 deletions public/bobber/level1.json

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions public/bobber/level1.tmx

Large diffs are not rendered by default.

Binary file added public/bobber/player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/bobber/tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions s
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
diff --git a/src/games/platformerTest.ts b/src/games/platformerTest.ts
index 3db780f..0be6098 100644
--- a/src/games/platformerTest.ts
+++ b/src/games/platformerTest.ts
@@ -1,4 +1,5 @@
-import { Scene, GameObjects} from 'phaser'
+import { Scene, GameObjects } from 'phaser'
+import { stickyMessage, toastMessage } from '../debugging/tools'
const WIDTH = 256
const HEIGHT = 240
const GRAVITY = 128
@@ -407,77 +408,3 @@ export class PlatformerTestScene extends Scene {
// clearStickyMessage()
}
}
-
-function stickyMessage(...messages: any) {
- // console.log(message)
- const prettyMessages: string[] = []
- let identifier
-
- identifier = getStackIdentifier()
- for (const message of messages) {
- if (message.hasOwnProperty('_id')) {
- identifier = message._id
- continue
- }
-
- prettyMessages.push(
- typeof message === 'string' || typeof message === 'number'
- ? String(message)
- : JSON.stringify(message)
- )
- }
-
- if (!stackToDivMap[identifier]) {
- console.log('s')
- // Create a new div for this identifier
- let newDiv = document.createElement('div')
- newDiv.textContent = prettyMessages.join(' ')
- const logDiv = document.getElementById('log')
- const messageDiv = logDiv!.appendChild(newDiv)
- messageDiv.classList.add('log-message', 'fade-in')
- stackToDivMap[identifier] = newDiv
- } else {
- // Update the existing div
- stackToDivMap[identifier].textContent = prettyMessages.join(' ')
- }
-}
-
-function clearStickyMessage() {
- const stickyMessage = document.getElementById('sticky-message')
- if (stickyMessage) {
- stickyMessage.innerHTML = ''
- }
-}
-
-function toastMessage(message: any) {
- console.log(message)
- const prettyMessage =
- typeof message === 'string' || typeof message === 'number'
- ? String(message)
- : JSON.stringify(message)
- const logDiv = document.getElementById('log')
- const messageDiv = document.createElement('div')
- messageDiv.classList.add('log-message', 'fade-in')
- logDiv?.appendChild(messageDiv)
- messageDiv?.append(prettyMessage)
- setTimeout(() => {
- messageDiv.classList.add('fade-out')
- setTimeout(() => messageDiv.remove(), 2000)
- }, 7000)
-}
-
-interface IDictionary {
- [index: string]: HTMLElement
-}
-let stackToDivMap: IDictionary = {}
-
-function getStackIdentifier() {
- let stack = new Error().stack
- if (stack) {
- let stackLines = stack.split('\n')
- // Use a combination of function name and line number as the identifier
- // Adjust the index based on where the relevant information is in your stack trace
- return stackLines[2] + stackLines[3]
- }
- return ''
-}
diff --git a/src/main.ts b/src/main.ts
index 0858908..8b6a0ad 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,5 +1,7 @@
+import './style.css'
import { Game, Scene, WEBGL } from 'phaser'
-import { PlatformerTestScene } from './platformerTest';
+import { PlatformerTestScene } from './games/platformerTest';
+import { BobberScene } from './games/bobber';
interface IMenuScene {
menu: { scene: string; text: string }[]
}
@@ -72,7 +74,7 @@ const config: Phaser.Types.Core.GameConfig = {
// debug: true
},
},
- scene: [MenuScene, PlatformerTestScene],
+ scene: [MenuScene, PlatformerTestScene, BobberScene],
pixelArt: true,
scale: {
parent: 'game-wrapper',
73 changes: 73 additions & 0 deletions src/debugging/tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
export function stickyMessage(...messages: any) {
// console.log(message)
const prettyMessages: string[] = []
let identifier

identifier = getStackIdentifier()
for (const message of messages) {
if (message.hasOwnProperty('_id')) {
identifier = message._id
continue
}

prettyMessages.push(
typeof message === 'string' || typeof message === 'number'
? String(message)
: JSON.stringify(message)
)
}

if (!stackToDivMap[identifier]) {
console.log('s')
// Create a new div for this identifier
let newDiv = document.createElement('div')
newDiv.textContent = prettyMessages.join(' ')
const logDiv = document.getElementById('log')
const messageDiv = logDiv!.appendChild(newDiv)
messageDiv.classList.add('log-message', 'fade-in')
stackToDivMap[identifier] = newDiv
} else {
// Update the existing div
stackToDivMap[identifier].textContent = prettyMessages.join(' ')
}
}

export function clearStickyMessage() {
const stickyMessage = document.getElementById('sticky-message')
if (stickyMessage) {
stickyMessage.innerHTML = ''
}
}

export function toastMessage(message: any) {
console.log(message)
const prettyMessage =
typeof message === 'string' || typeof message === 'number'
? String(message)
: JSON.stringify(message)
const logDiv = document.getElementById('log')
const messageDiv = document.createElement('div')
messageDiv.classList.add('log-message', 'fade-in')
logDiv?.appendChild(messageDiv)
messageDiv?.append(prettyMessage)
setTimeout(() => {
messageDiv.classList.add('fade-out')
setTimeout(() => messageDiv.remove(), 2000)
}, 7000)
}

interface IDictionary {
[index: string]: HTMLElement
}
let stackToDivMap: IDictionary = {}

function getStackIdentifier() {
let stack = new Error().stack
if (stack) {
let stackLines = stack.split('\n')
// Use a combination of function name and line number as the identifier
// Adjust the index based on where the relevant information is in your stack trace
return stackLines[2] + stackLines[3]
}
return ''
}
Loading

0 comments on commit a6e17a7

Please sign in to comment.