malc-game-engine 1.0.7 → 1.0.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.
Files changed (3) hide show
  1. package/malc.js +26 -75
  2. package/malc.min.js +4 -9
  3. package/package.json +1 -1
package/malc.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * MALC Game Engine Library
3
- * Version: 1.0.7
3
+ * Version: 1.0.8
4
4
  * Description: A comprehensive 2D game engine for p5.js
5
5
  */
6
6
 
@@ -2575,7 +2575,7 @@ const helpDocs = {
2575
2575
 
2576
2576
  // ========== MALC MAIN OBJECT ==========
2577
2577
  const MALC = {
2578
- version: "1.0.7", // Increment version
2578
+ version: "1.0.8", // Increment version
2579
2579
 
2580
2580
  // Core classes
2581
2581
  gameObject: gameObject,
@@ -2601,7 +2601,7 @@ const MALC = {
2601
2601
  // Utility functions
2602
2602
  generateId: generateId,
2603
2603
  getTimestamp: getTimestamp,
2604
- coloredText: coloredText, // Add this line
2604
+ coloredText: coloredText,
2605
2605
 
2606
2606
  // Gravity constants
2607
2607
  GRAVITY: GRAVITY,
@@ -2691,8 +2691,6 @@ const MALC = {
2691
2691
  return topics;
2692
2692
  },
2693
2693
 
2694
- // Initialize the engine
2695
-
2696
2694
  // Initialize the engine
2697
2695
  init: function(canvasX, canvasY) {
2698
2696
  // Use the p5 instance that was passed to the factory function
@@ -2742,77 +2740,33 @@ const MALC = {
2742
2740
  console.log("MALC Game Engine initialized v" + this.version);
2743
2741
  console.log("Type MALC.help() for documentation");
2744
2742
  },
2743
+
2744
+ // Update all systems (call in draw)
2745
+ update: function() {
2746
+ // This was incorrectly placed in your file - it belongs in the MALC object
2747
+ this.time = new Date();
2748
+ this.timer = this.time - this.startTime;
2745
2749
 
2746
- // Update all systems (call in draw)
2747
- update() {
2748
- if (!this.active) return;
2749
-
2750
- // Apply gravity if enabled
2751
- this.applyGravity();
2752
-
2753
- let vel = this.velocity[0];
2754
- let angle = this.velocity[1];
2755
-
2756
- if (this.velocityMode == "polar") {
2757
- let linked = false;
2758
- if (!/unlinked/i.test(this.rvm) && /linked/i.test(this.rvm)) {
2759
- this.velocity[1] = this.rotation;
2760
- linked = true;
2761
- }
2750
+ if (this.mouse) {
2751
+ this.mouse.rawX = _p5.prototype.mouseX;
2752
+ this.mouse.rawY = _p5.prototype.mouseY;
2753
+ this.mouse.x = this.mouse.rawX + window.camera.getOrientation()[0];
2754
+ this.mouse.y = this.mouse.rawY + window.camera.getOrientation()[1];
2755
+ this.mouse.down = _p5.prototype.mouseIsPressed;
2756
+ }
2762
2757
 
2763
- let rot = linked ?
2764
- (this.rotationMode == "degrees" ? (this.rotation) : this._toRadians(this.rotation)) :
2765
- (this.rotationMode == "degrees" ? (this.velocity[1]) : (this.velocity[1]));
2766
-
2767
- if(isNaN(rot)){
2768
- vel = 0;
2769
- rot = 0;
2770
- }
2771
-
2772
- // SAFELY call p5 math functions
2773
- let vx = 0;
2774
- let vy = 0;
2775
-
2776
- try {
2777
- vx = vel * _p5.prototype.cos(rot);
2778
- vy = vel * _p5.prototype.sin(rot);
2779
- } catch (e) {
2780
- // Fallback if p5 isn't ready
2781
- vx = vel * Math.cos(rot);
2782
- vy = vel * Math.sin(rot);
2783
- }
2758
+ controller.update();
2784
2759
 
2785
- this.velocityMatrix = [vx, vy];
2786
-
2787
- // Don't apply horizontal movement if gravity is enabled and we're grounded with friction
2788
- if (!(this.gravity.enabled && this.gravity.grounded && this.gravity.friction > 0)) {
2789
- this.x += vx;
2790
- }
2791
-
2792
- // Vertical movement is handled by gravity when enabled
2793
- if (!this.gravity.enabled) {
2794
- this.y += vy;
2795
- }
2796
- } else {
2797
- // Cartesian velocity mode
2798
- if (!(this.gravity.enabled && this.gravity.grounded && this.gravity.friction > 0)) {
2799
- this.x += vel;
2800
- }
2801
- if (!this.gravity.enabled) {
2802
- this.y += angle;
2803
- }
2804
- }
2805
-
2806
- // Update parent scene reference
2807
- this.updateParentScene();
2808
-
2809
- MALCgameObjects[this.objectInstance] = this;
2810
- }
2760
+ gameObject.update();
2761
+ Button.updateButton();
2811
2762
 
2812
- // Helper method for radians conversion without p5
2813
- _toRadians(degrees) {
2814
- return degrees * Math.PI / 180;
2763
+ this.fps = fps;
2764
+
2765
+ if (typeof window.camera.render == "function") {
2766
+ window.camera.render();
2815
2767
  }
2768
+ Scene.update();
2769
+ }
2816
2770
  };
2817
2771
 
2818
2772
  // Initialize mouse and keyboard handlers
@@ -2820,7 +2774,4 @@ MALC.mouse = new MouseHandler();
2820
2774
 
2821
2775
  return MALC;
2822
2776
 
2823
- }));
2824
-
2825
-
2826
-
2777
+ }));
package/malc.min.js CHANGED
@@ -284,7 +284,7 @@ const helpDocs={overview:`
284
284
  function draw() {
285
285
  MALC.update(); // Updates all MALC systems
286
286
  }
287
- `};const MALC={version:"1.0.7",gameObject:gameObject,Button:Button,Scene:Scene,UIPlane:UIPlane,Camera:Camera,mouse:null,keyboard:keyboard,controller:controller,fps:fps,getFPS:getFPS,time:new Date(),startTime:new Date().getTime(),timer:0,generateId:generateId,getTimestamp:getTimestamp,coloredText:coloredText,GRAVITY:GRAVITY,TERMINAL_VELOCITY:TERMINAL_VELOCITY,help:function(topic="overview"){if(topic==="overview"){console.log(helpDocs.overview);return helpDocs.overview}
287
+ `};const MALC={version:"1.0.8",gameObject:gameObject,Button:Button,Scene:Scene,UIPlane:UIPlane,Camera:Camera,mouse:null,keyboard:keyboard,controller:controller,fps:fps,getFPS:getFPS,time:new Date(),startTime:new Date().getTime(),timer:0,generateId:generateId,getTimestamp:getTimestamp,coloredText:coloredText,GRAVITY:GRAVITY,TERMINAL_VELOCITY:TERMINAL_VELOCITY,help:function(topic="overview"){if(topic==="overview"){console.log(helpDocs.overview);return helpDocs.overview}
288
288
  if(helpDocs.classes[topic]){console.log(`=== ${topic.toUpperCase()} ===`);console.log(helpDocs.classes[topic].description);console.log("\nConstructor:",helpDocs.classes[topic].constructor);if(helpDocs.classes[topic].properties){console.log("\nProperties:");Object.entries(helpDocs.classes[topic].properties).forEach(([prop,desc])=>{console.log(` ${prop}: ${desc}`)})}
289
289
  if(helpDocs.classes[topic].methods){console.log("\nMethods:");Object.entries(helpDocs.classes[topic].methods).forEach(([method,desc])=>{console.log(` ${method}: ${desc}`)})}
290
290
  if(helpDocs.classes[topic].staticMethods){console.log("\nStatic Methods:");Object.entries(helpDocs.classes[topic].staticMethods).forEach(([method,desc])=>{console.log(` static ${method}: ${desc}`)})}
@@ -293,11 +293,6 @@ if(helpDocs.input[topic]){console.log(`=== ${topic.toUpperCase()} ===`);console.
293
293
  return helpDocs.input[topic]}
294
294
  if(helpDocs.utilities[topic]){console.log(`=== ${topic.toUpperCase()} ===`);console.log(helpDocs.utilities[topic]);return helpDocs.utilities[topic]}
295
295
  if(topic==="quickStart"||topic==="start"){console.log(helpDocs.quickStart);return helpDocs.quickStart}
296
- console.log(`Help topic "${topic}" not found. Try: overview, classes (gameObject, Button, Scene, UIPlane, Camera), input (mouse, keyboard, controller), utilities (coloredText, getFPS), quickStart`);return null},helpTopics:function(){const topics=["overview","classes: "+Object.keys(helpDocs.classes).join(", "),"input: "+Object.keys(helpDocs.input).join(", "),"utilities: "+Object.keys(helpDocs.utilities).join(", "),"quickStart"];console.log("Available help topics:\n"+topics.join("\n"));return topics},init:function(canvasX,canvasY){_p5.prototype.createCanvas(canvasX,canvasY);this.time=new Date();this.startTime=this.time.getTime();window.camera=new Camera(canvasX,canvasY);this.mouse=new MouseHandler();window.mouse=this.mouse;refreshLoop();new Scene("blank",70);new Scene("loading",50,function(self){try{_p5.prototype.textSize(24);let timed=(self.timeActive/250%4);let dots="";if(timed<1)dots=".";else if(timed<2)dots="..";else if(timed<3)dots="...";coloredText(`\\lime|Loading Game${dots}| `,120,200,_p5.prototype.LEFT,_p5.prototype.CENTER);_p5.prototype.textSize(16);let num=(Math.floor(self.timeActive/100)/10);let percentText=`${ Math.round((10 - num) * 10) / 10 + ((num + "").length < 2 ? ".0" : "")}`;coloredText(`\\red|${percentText}|`,200,225,_p5.prototype.CENTER,_p5.prototype.CENTER)}catch(e){_p5.prototype.text(`Loading Game...`,120,200)}});Scene.activeScene="loading";console.log("MALC Game Engine initialized v"+this.version);console.log("Type MALC.help() for documentation")},update(){if(!this.active)return;this.applyGravity();let vel=this.velocity[0];let angle=this.velocity[1];if(this.velocityMode=="polar"){let linked=!1;if(!/unlinked/i.test(this.rvm)&&/linked/i.test(this.rvm)){this.velocity[1]=this.rotation;linked=!0}
297
- let rot=linked?(this.rotationMode=="degrees"?(this.rotation):this._toRadians(this.rotation)):(this.rotationMode=="degrees"?(this.velocity[1]):(this.velocity[1]));if(isNaN(rot)){vel=0;rot=0}
298
- let vx=0;let vy=0;try{vx=vel*_p5.prototype.cos(rot);vy=vel*_p5.prototype.sin(rot)}catch(e){vx=vel*Math.cos(rot);vy=vel*Math.sin(rot)}
299
- this.velocityMatrix=[vx,vy];if(!(this.gravity.enabled&&this.gravity.grounded&&this.gravity.friction>0)){this.x+=vx}
300
- if(!this.gravity.enabled){this.y+=vy}}else{if(!(this.gravity.enabled&&this.gravity.grounded&&this.gravity.friction>0)){this.x+=vel}
301
- if(!this.gravity.enabled){this.y+=angle}}
302
- this.updateParentScene();MALCgameObjects[this.objectInstance]=this}
303
- _toRadians(degrees){return degrees*Math.PI/180}};MALC.mouse=new MouseHandler();return MALC}))
296
+ console.log(`Help topic "${topic}" not found. Try: overview, classes (gameObject, Button, Scene, UIPlane, Camera), input (mouse, keyboard, controller), utilities (coloredText, getFPS), quickStart`);return null},helpTopics:function(){const topics=["overview","classes: "+Object.keys(helpDocs.classes).join(", "),"input: "+Object.keys(helpDocs.input).join(", "),"utilities: "+Object.keys(helpDocs.utilities).join(", "),"quickStart"];console.log("Available help topics:\n"+topics.join("\n"));return topics},init:function(canvasX,canvasY){_p5.prototype.createCanvas(canvasX,canvasY);this.time=new Date();this.startTime=this.time.getTime();window.camera=new Camera(canvasX,canvasY);this.mouse=new MouseHandler();window.mouse=this.mouse;refreshLoop();new Scene("blank",70);new Scene("loading",50,function(self){try{_p5.prototype.textSize(24);let timed=(self.timeActive/250%4);let dots="";if(timed<1)dots=".";else if(timed<2)dots="..";else if(timed<3)dots="...";coloredText(`\\lime|Loading Game${dots}| `,120,200,_p5.prototype.LEFT,_p5.prototype.CENTER);_p5.prototype.textSize(16);let num=(Math.floor(self.timeActive/100)/10);let percentText=`${ Math.round((10 - num) * 10) / 10 + ((num + "").length < 2 ? ".0" : "")}`;coloredText(`\\red|${percentText}|`,200,225,_p5.prototype.CENTER,_p5.prototype.CENTER)}catch(e){_p5.prototype.text(`Loading Game...`,120,200)}});Scene.activeScene="loading";console.log("MALC Game Engine initialized v"+this.version);console.log("Type MALC.help() for documentation")},update:function(){this.time=new Date();this.timer=this.time-this.startTime;if(this.mouse){this.mouse.rawX=_p5.prototype.mouseX;this.mouse.rawY=_p5.prototype.mouseY;this.mouse.x=this.mouse.rawX+window.camera.getOrientation()[0];this.mouse.y=this.mouse.rawY+window.camera.getOrientation()[1];this.mouse.down=_p5.prototype.mouseIsPressed}
297
+ controller.update();gameObject.update();Button.updateButton();this.fps=fps;if(typeof window.camera.render=="function"){window.camera.render()}
298
+ Scene.update()}};MALC.mouse=new MouseHandler();return MALC}))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "malc-game-engine",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "A comprehensive 2D game engine for p5.js",
5
5
  "main": "malc.js",
6
6
  "unpkg": "malc.min.js",