Skip to content

Commit

Permalink
FlxCamera Orb Engine
Browse files Browse the repository at this point in the history
The Engine
  • Loading branch information
megalives717 committed Dec 30, 2024
0 parents commit c91541f
Show file tree
Hide file tree
Showing 31 changed files with 843 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"openfl.lime-vscode-extension",
"redhat.vscode-xml"
]
}
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Build + Debug",
"type": "lime",
"request": "launch"
},
{
"name": "Debug",
"type": "lime",
"request": "launch",
"preLaunchTask": null
},
{
"name": "Macro",
"type": "haxe-eval",
"request": "launch"
}
]
}
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"search.exclude": {
"export/**/*.*": true
},
"[haxe]": {
"editor.formatOnSave": true,
"editor.formatOnSaveMode":"modifications",
"editor.formatOnPaste": false,
"editor.codeActionsOnSave": {
"source.sortImports": "explicit"
}
},
"haxe.enableExtendedIndentation": true
}
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "lime",
"command": "test",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
90 changes: 90 additions & 0 deletions Project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://lime.openfl.org/project/1.0.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://lime.openfl.org/project/1.0.4 http://lime.openfl.org/xsd/project-1.0.4.xsd">

<!-- _________________________ Application Settings _________________________ -->

<app title="FlxCamera: Orb Engine" file="OrbEngine" main="Main" version="1.0.0" company="megalives717" />

<!--The flixel preloader is not accurate in Chrome. You can use it regularly if you embed the swf into a html file
or you can set the actual size of your file manually at "FlxPreloaderBase-onUpdate-bytesTotal"!-->
<app preloader="flixel.system.FlxPreloader" />

<!--Minimum without FLX_NO_GAMEPAD: 11.8, without FLX_NO_NATIVE_CURSOR: 11.2 -->
<set name="SWF_VERSION" value="11.8" />

<!-- ____________________________ Window Settings ___________________________ -->

<!--These window settings apply to all targets-->
<window width="640" height="480" fps="60" background="#000000" hardware="true" vsync="false" />

<!--HTML5-specific-->
<window if="html5" resizable="true" />

<!--Desktop-specific-->
<window if="desktop" orientation="landscape" fullscreen="false" resizable="true" />

<!--Mobile-specific-->
<window if="mobile" orientation="landscape" fullscreen="true" width="0" height="0" />

<!-- _____________________________ Path Settings ____________________________ -->

<set name="BUILD_DIR" value="export" />
<source path="source" />
<assets path="assets" exclude="*.ogg" if="web" />
<assets path="assets" exclude="*.mp3" unless="web" />

<!-- _______________________________ Libraries ______________________________ -->

<haxelib name="flixel" />

<!--In case you want to use the addons package-->
<haxelib name="flixel-addons" />

<!--In case you want to use the ui package-->
<!--<haxelib name="flixel-ui" />-->

<!--In case you want to use nape with flixel-->
<haxelib name="nape-haxe4" />

<haxelib name="flxanimate" />

<!-- ______________________________ Haxedefines _____________________________ -->

<!--Remove the legacy health system-->
<haxedef name="FLX_NO_HEALTH" />

<!--Enable the Flixel core recording system-->
<!--<haxedef name="FLX_RECORD" />-->

<!--Disable the right and middle mouse buttons-->
<!--<haxedef name="FLX_NO_MOUSE_ADVANCED" />-->

<!--Disable the Native cursor api for Flash target-->
<!--<haxedef name="FLX_NO_NATIVE_CURSOR" />-->

<!--Optimise inputs, be careful you will get null errors if you don't use conditionals in your game-->
<haxedef name="FLX_NO_MOUSE" if="mobile" />
<haxedef name="FLX_NO_KEYBOARD" if="mobile" />
<haxedef name="FLX_NO_TOUCH" if="desktop" />
<!--<haxedef name="FLX_NO_GAMEPAD" />-->

<!--Disable the Flixel core sound tray-->
<!--<haxedef name="FLX_NO_SOUND_TRAY" />-->

<!--Disable the Flixel sound management code-->
<!--<haxedef name="FLX_NO_SOUND_SYSTEM" />-->

<!--Disable the Flixel core focus lost screen-->
<!--<haxedef name="FLX_NO_FOCUS_LOST_SCREEN" />-->

<!--Disable the Flixel core debugger. Automatically gets set whenever you compile in release mode!-->
<haxedef name="FLX_NO_DEBUG" unless="debug" />

<!--Enable this for Nape release builds for a serious peformance improvement-->
<haxedef name="NAPE_RELEASE_BUILD" unless="debug" />

<!-- _________________________________ Custom _______________________________ -->

<icon path="assets/images/Orb.png" />
</project>
Binary file added assets/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions assets/data/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add other file format(s) data assets
1 change: 1 addition & 0 deletions assets/fonts/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ttf file(s) fonts assets
Binary file added assets/images/Border.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 assets/images/BorderSlice.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 assets/images/FloorTexture.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 assets/images/Orb.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 assets/images/OrbShadow.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 assets/images/OtherOrb.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 assets/images/OtherOrbShadow.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 assets/images/WallLeft.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 assets/images/WallUp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/images/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add png file(s) images assets
1 change: 1 addition & 0 deletions assets/music/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add mp3/ogg file(s) music assets
1 change: 1 addition & 0 deletions assets/sounds/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add mp3/ogg file(s) sounds assets
15 changes: 15 additions & 0 deletions hxformat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"lineEnds": {
"leftCurly": "both",
"rightCurly": "both",
"objectLiteralCurly": {
"leftCurly": "after"
}
},
"sameLine": {
"ifElse": "next",
"doWhile": "next",
"tryBody": "next",
"tryCatch": "next"
}
}
16 changes: 16 additions & 0 deletions source/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package;

import flixel.FlxGame;
import flixel.FlxSprite;
import openfl.display.Sprite;

class Main extends Sprite
{
public function new()
{
super();

FlxSprite.defaultAntialiasing = true;
addChild(new FlxGame(640, 480, PlayState));
}
}
161 changes: 161 additions & 0 deletions source/PlayState.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package;

import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.addons.display.FlxBackdrop;
import flixel.addons.nape.FlxNapeSpace;
import flixel.math.FlxMath;
import haxe.EnumTools;
import nape.phys.Material;
import props.BorderSlice;
import props.Orb;
import props.OtherOrb;
import props.PlayerOrb;
import ui.DeadzoneOverlay;
import ui.HUD;

using flixel.util.FlxSpriteUtil;

/**
* @author TiagoLr ( ~~~ProG4mr~~~ )
*/
class PlayState extends FlxState
{
static var followStyles = EnumTools.createAll(FlxCameraFollowStyle);

var player:PlayerOrb;
var hud:HUD;
var deadzoneOverlay:DeadzoneOverlay;

override public function create():Void
{
FlxNapeSpace.init();

// final levelMinX = -FlxG.stage.stageWidth;
// final levelMaxX = FlxG.stage.stageWidth;
// final levelMinY = -FlxG.stage.stageHeight;
// final levelMaxY = FlxG.stage.stageHeight;
final levelMinX = 0;
final levelMaxX = FlxG.stage.stageWidth * 2;
final levelMinY = 0;
final levelMaxY = FlxG.stage.stageHeight * 2;
final levelWidth = levelMaxX - levelMinX;
final levelHeight = levelMaxY - levelMinY;

super.create();

FlxNapeSpace.velocityIterations = 5;
FlxNapeSpace.positionIterations = 5;

// repeating backdrop
final backdrop = new FlxBackdrop("assets/images/FloorTexture.png");
#if debug
backdrop.ignoreDrawDebug = true;
#end
add(backdrop);

// create nape wall colliders
final border = 10;
FlxNapeSpace.createWalls(levelMinX + border, levelMinY + border, levelMaxX - border, levelMaxY - border, border, new Material(1.0, 0.0, 0.0, 1));

// Walls border sprite
final borderSprite = new BorderSlice(levelMinX, levelMinY, levelWidth, levelHeight);
add(borderSprite);

// Player orb
player = new PlayerOrb(levelMinX + levelWidth / 2, levelMinY + levelHeight / 2);
add(player);
// if the player is using a virtual pad, add it to the state
if (player.controls.virtualPad != null)
add(player.controls.virtualPad);

// Other orbs
for (i in 0...5)
{
final orb = new OtherOrb(0, 0, i);
add(orb);
orb.randomizeVelocity();

// randomize spawn position until it's far enough from the player, up to 20 times
var tries = 20;
do orb.randomizePosition(levelMinX, levelMaxX, levelMinY, levelMaxY)
while (Math.abs(orb.x - player.x) < 200 && Math.abs(orb.y - player.y) < 200 && tries-- > 0);
}

hud = new HUD();
add(hud);

// Camera Overlay
deadzoneOverlay = new DeadzoneOverlay();
add(deadzoneOverlay);

FlxG.camera.pixelPerfectRender = false;
FlxG.camera.setScrollBounds(levelMinX, levelMaxX, levelMinY, levelMaxY);
FlxG.worldBounds.set(levelMinX, levelMinY, levelWidth, levelHeight);
FlxG.camera.follow(player, followStyles[0], 1);
deadzoneOverlay.redraw(FlxG.camera); // now that deadzone is present
}

override public function update(elapsed:Float):Void
{
super.update(elapsed);

final justPressed = FlxG.keys.justPressed;

if (justPressed.Y) setStyle(1);
if (justPressed.H) setStyle(-1);

if (justPressed.U) setLerp(.1);
if (justPressed.J) setLerp(-.1);

if (justPressed.I) setLead(.5);
if (justPressed.K) setLead(-.5);

if (justPressed.O) setZoom(.1);
if (justPressed.L) setZoom(-.1);

if (justPressed.M) FlxG.camera.shake();
}

public function setZoom(delta:Float)
{
final newZoom = FlxG.camera.zoom + delta;
FlxG.camera.zoom = FlxMath.bound(Math.round(newZoom * 10) / 10, 0.5, 4);
hud.updateZoom(FlxG.camera.zoom);
}

function setLead(delta:Float)
{
var cam = FlxG.camera;
cam.followLead.x += delta;
cam.followLead.y += delta;

if (cam.followLead.x < 0)
{
cam.followLead.x = 0;
cam.followLead.y = 0;
}

hud.updateCamLead(cam.followLead.x);
}

function setLerp(delta:Float)
{
var cam = FlxG.camera;
cam.followLerp += delta;
cam.followLerp = Math.round(10 * cam.followLerp) / 10; // adding or subtracting .1 causes roundoff errors
hud.updateCamLerp(cam.followLerp);
}

function setStyle(delta:Int)
{
final nextStyleIndex = (followStyles.indexOf(FlxG.camera.style) + delta) % followStyles.length;
FlxG.camera.follow(player, followStyles[nextStyleIndex], FlxG.camera.followLerp);

deadzoneOverlay.redraw(FlxG.camera);

hud.updateStyle(FlxG.camera.style);
}
}
Loading

0 comments on commit c91541f

Please sign in to comment.