{"id":22028631,"url":"https://github.com/Virus01Official/Object-Library","last_synced_at":"2025-07-23T13:32:42.233Z","repository":{"id":261367757,"uuid":"884100819","full_name":"Virus01Official/Object-Library","owner":"Virus01Official","description":"An Object Library for LOVE2D","archived":false,"fork":false,"pushed_at":"2024-11-16T09:51:17.000Z","size":259,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-16T10:27:17.393Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Virus01Official.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-06T06:21:51.000Z","updated_at":"2024-11-16T09:51:20.000Z","dependencies_parsed_at":"2024-11-06T07:26:20.147Z","dependency_job_id":"56ea1c9d-bb30-4006-8467-4154efbe25f9","html_url":"https://github.com/Virus01Official/Object-Library","commit_stats":null,"previous_names":["virus01official/object-library"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Virus01Official%2FObject-Library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Virus01Official%2FObject-Library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Virus01Official%2FObject-Library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Virus01Official%2FObject-Library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Virus01Official","download_url":"https://codeload.github.com/Virus01Official/Object-Library/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227298647,"owners_count":17760359,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-30T08:01:29.273Z","updated_at":"2024-11-30T08:05:44.019Z","avatar_url":"https://github.com/Virus01Official.png","language":"Lua","funding_links":[],"categories":["Recently Updated","OO"],"sub_categories":["[Nov 29, 2024](/content/2024/11/29/README.md)"],"readme":"# ObjectLibrary\n\n`ObjectLibrary` is a simple library for the LÖVE2D game engine that allows users to create objects with physics, collision detection, and optional textures. If no texture is provided, the object defaults to a simple square shape. This library makes it easy to add basic physics interactions, object rendering, and collision handling to LÖVE2D projects.\n\n## Features\n\n- **Easy Object Creation**: Create objects with customizable positions, sizes, and optional textures.\n- **Collision Detection**: Automatically detects and handles collisions between objects.\n- **Collision Response**: Objects stop overlapping and are separated when colliding.\n- **Simple Rendering**: Objects can be drawn with textures or as default squares if no texture is provided.\n- **Basic Physics**: Objects can have velocity, acceleration, gravity, and friction, allowing for dynamic movement.\n- **Force Application**: Easily apply forces (e.g., gravity or user input) to objects to control their movement.\n\n## Installation\n\n1. Download `ObjectLibrary.lua` and place it in your LÖVE2D project folder.\n2. Include it in your main file (`main.lua` or equivalent) with:\n   ```lua\n   local ObjectLibrary = require(\"ObjectLibrary\")\n   ```\n\n## Usage\n\n### Creating Objects\n\nYou can create an object by calling `ObjectLibrary:new(x, y, width, height, imagePath)`, where:\n- `x` and `y` specify the object's position.\n- `width` and `height` specify its dimensions.\n- `imagePath` is an optional parameter for adding a texture image.\n\nThe object also has the following optional physics properties:\n- **`velocityX`, `velocityY`**: Control the object's velocity in the X and Y directions.\n- **`accelerationX`, `accelerationY`**: Control the object's acceleration.\n- **`gravity`**: Gravity is automatically applied to objects if not overridden.\n- **`mass`**: The mass of the object, which influences how forces like gravity affect it.\n\n#### Example\n\n```lua\nlocal ObjectLibrary = require(\"ObjectLibrary\")\n\nlocal player = ObjectLibrary:new(100, 100, 50, 50, \"player.png\")\nlocal wall = ObjectLibrary:new(200, 100, 50, 50) -- default to white square\n```\n\n### Moving and Updating Objects\n\nIn your `love.update(dt)` function, you can move objects, apply forces, and check for collisions:\n\n```lua\nfunction love.update(dt)\n    -- Store previous position for collision handling\n    local prevX, prevY = player.x, player.y\n\n    -- Apply force (e.g., user input for movement or gravity)\n    if love.keyboard.isDown(\"right\") then\n        player:applyForce(100, 0)  -- Apply force to move right\n    end\n    if love.keyboard.isDown(\"left\") then\n        player:applyForce(-100, 0) -- Apply force to move left\n    end\n    if love.keyboard.isDown(\"up\") then\n        player:applyForce(0, -100) -- Apply force to move up\n    end\n    if love.keyboard.isDown(\"down\") then\n        player:applyForce(0, 100)  -- Apply force to move down\n    end\n\n    -- Update physics (apply gravity, velocity, position)\n    player:update(dt)\n\n    -- Resolve collision\n    player:resolveCollision(wall)\n\n    -- If collision occurs, restore the previous position\n    if player.isColliding then\n        player.x, player.y = prevX, prevY\n    end\nend\n```\n\n### Drawing Objects\n\nTo render your objects, call `draw()` on each object in your `love.draw()` function:\n\n```lua\nfunction love.draw()\n    player:draw()\n    wall:draw()\n    \n    -- Optionally, draw a red border if a collision is detected\n    if player.isColliding then\n        love.graphics.setColor(1, 0, 0) -- red color for collision\n        love.graphics.rectangle(\"line\", player.x, player.y, player.width, player.height)\n        love.graphics.setColor(1, 1, 1) -- reset color\n    end\nend\n```\n\n### Physics and Movement\n\nYou can take advantage of the built-in physics features:\n- **Gravity**: Automatically applied in the `update` method (can be overridden).\n- **Velocity**: Update the object's position based on its velocity.\n- **Acceleration**: Apply forces like gravity, friction, or user input.\n\nUse `applyForce(fx, fy)` to add external forces to objects. For instance, applying gravity or user-controlled movements.\n\n### Example Physics Application\n\n```lua\nfunction love.update(dt)\n    -- Apply gravity force\n    player:applyForce(0, player.gravity)\n\n    -- Optionally, apply other forces like user input\n    if love.keyboard.isDown(\"right\") then\n        player:applyForce(100, 0)\n    end\n\n    -- Update physics (gravity, velocity, position)\n    player:update(dt)\nend\n```\n\n## Example Project Structure\n\n```\nyour_project/\n├── main.lua\n├── ObjectLibrary.lua\n└── assets/\n    └── player.png\n```\n\nIn this example, `main.lua` initializes the library and uses it to create objects. The `assets/` folder holds any textures (like `player.png`) used by objects.\n\n## License\n\nThis library is free to use under the MIT License. See [LICENSE](LICENSE) for more details.\n\n---\n\n## Contributing\n\nFeel free to open issues or submit pull requests with improvements or additional features. All contributions are welcome!\n\n---\n\n## Author\n\nDeveloped by [Virus](https://github.com/Virus01Official).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVirus01Official%2FObject-Library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVirus01Official%2FObject-Library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVirus01Official%2FObject-Library/lists"}