diff --git a/src/Camera.m b/src/Camera.m index cebe2b8..5911662 100644 --- a/src/Camera.m +++ b/src/Camera.m @@ -66,8 +66,7 @@ RayCollision ObjectiveCBugFixRaycast(Camera3D camera, BoundingBox bbox) { } } --(bool) raycast { - BoundingBox bbox = {(Vector3){-1.0f, -1.0f, -1.0f}, (Vector3){2.0f, 2.0f, 2.0f}}; +-(bool) raycast: (BoundingBox) bbox { //i called them both raycast to maximize confusion if ( ObjectiveCBugFixRaycast(camera, bbox).hit ) { @@ -76,14 +75,6 @@ RayCollision ObjectiveCBugFixRaycast(Camera3D camera, BoundingBox bbox) { crosshairColor = WHITE; } - #define DEBUG - - #ifdef DEBUG - BeginMode3D(camera); - //DrawBoundingBox(bbox, BLUE); - #endif - - EndMode3D(); return ObjectiveCBugFixRaycast(camera, bbox).hit; } diff --git a/src/Gravitator.m b/src/Gravitator.m index d9804e3..6fa3665 100644 --- a/src/Gravitator.m +++ b/src/Gravitator.m @@ -16,12 +16,19 @@ static inline Vector3 multFloatVector3(float f, Vector3 v) { //cursed - Vector3 force = multFloatVector3( [(PhysObject *)array[i] mass], acceleration); - printf("%f\n", [(PhysObject *)array[i] mass]); - - [(PhysObject *)array[i] setVelocity: Vector3Add(force, [(PhysObject *)array[i] velocity])]; + //need to check collision + + if ( [array[i] isStatic] ) { + continue; + } + + if ( ![array[i] onSurface] ) { + [array[i] setForce: multFloatVector3( [(PhysObject *)array[i] mass], acceleration)]; + } + + //[array[i] setForce: multFloatVector3( [(PhysObject *)array[i] mass], acceleration)]; + [(PhysObject *)array[i] setVelocity: Vector3Add([array[i] force], [(PhysObject *)array[i] velocity])]; [(PhysObject *)array[i] setPos: Vector3Add( [(PhysObject *)array[i] velocity], [(PhysObject *)array[i] pos] )]; - //printf("%f %f %f\n", force.x, force.y, force.z ); } diff --git a/src/InputHandler.m b/src/InputHandler.m index 640dc31..fcb3737 100644 --- a/src/InputHandler.m +++ b/src/InputHandler.m @@ -22,8 +22,11 @@ [controllable moveLeft]; } else if ( set - IsKeyDown(KEY_D) ) { [controllable moveRight]; + } else if ( set - IsKeyDown(KEY_E) ) { + [controllable activate]; } + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { [controllable attack]; } diff --git a/src/NPC.h b/src/NPC.h new file mode 100644 index 0000000..b718b20 --- /dev/null +++ b/src/NPC.h @@ -0,0 +1,27 @@ +//just going to be a simple npc the player can activate +//and it displays a text box + +#ifndef NPC_H +#define NPC_H + +#import +#import +#import +#import "Activator.h" + +@interface NPC : YSObject { + BoundingBox bbox; + Vector3 pos; + Texture2D texture; +} + +-(id) init; ++(id) new; +-(void) draw: (Camera3D) camera; +-(void) activate; + +-(BoundingBox) bbox; + +@end + +#endif \ No newline at end of file diff --git a/src/NPC.m b/src/NPC.m new file mode 100644 index 0000000..9d211c5 --- /dev/null +++ b/src/NPC.m @@ -0,0 +1,39 @@ +#import "NPC.h" + +@implementation NPC + +-(id) init { + self = [super init]; + + if (self) { + bbox = (BoundingBox){ + (Vector3){-1.0f, -1.0f, -1.0f}, + (Vector3){2.0f, 2.0f, 2.0f} + }; + + pos = (Vector3){0.0f, 1.0f, 0.0f}; + + texture = LoadTexture("resources/textures/star.png"); + printf("%s\n", "initted"); + } + + return self; +} + ++(id) new { + return [[NPC alloc] init]; +} + +-(void) draw: (Camera3D) c { + DrawBillboard(c, texture, pos, 4.0f, WHITE); +} + +-(BoundingBox) bbox { + return bbox; +} + +-(void) activate { + printf("%s\n", "wow i did it"); +} + +@end \ No newline at end of file diff --git a/src/PhysObject.h b/src/PhysObject.h index 6804c2e..39d1fa3 100644 --- a/src/PhysObject.h +++ b/src/PhysObject.h @@ -8,6 +8,9 @@ @public float mass; Vector3 velocity; + Vector3 force; + bool onSurface; + bool isStatic; } -(id) init; @@ -15,6 +18,12 @@ -(void) setVelocity: (Vector3) v; -(float) mass; -(void) setMass: (float) m; +-(Vector3) force; +-(void) setForce: (Vector3) f; +-(bool) onSurface; +-(void) setOnSurface: (bool) s; +-(bool) isStatic; +-(void) setStatic: (bool) s; @end #endif \ No newline at end of file diff --git a/src/PhysObject.m b/src/PhysObject.m index ad33d00..f78ace8 100644 --- a/src/PhysObject.m +++ b/src/PhysObject.m @@ -6,7 +6,7 @@ self = [super init]; if (self) { - mass = 1.0f; + mass = 0.00001f; } return self; @@ -28,4 +28,28 @@ mass = m; } +-(Vector3) force { + return force; +} + +-(void) setForce: (Vector3) f { + force = f; +} + +-(bool) onSurface { + return onSurface; +} + +-(void) setOnSurface: (bool) s { + onSurface = s; +} + +-(bool) isStatic { + return isStatic; +} + +-(void) setStatic: (bool) s { + isStatic = s; +} + @end \ No newline at end of file diff --git a/src/Player.h b/src/Player.h index 633a8c9..3254caa 100644 --- a/src/Player.h +++ b/src/Player.h @@ -6,6 +6,7 @@ #import "Camera.h" #import "SoundPlayer.h" +#import "NPC.h" @class GameCamera; @@ -17,11 +18,13 @@ GameCamera *attachedCamera; SoundPlayer *soundPlayer; Texture2D weapon; + YSArray *activators; //things the player can activate } -(id) init; -(void) showPos; -(void) attack; +-(bool) activate; -(void) moveForward; -(void) moveBack; -(void) moveLeft; diff --git a/src/Player.m b/src/Player.m index ce09f1a..e6eb97b 100644 --- a/src/Player.m +++ b/src/Player.m @@ -6,6 +6,7 @@ if ( (self = [super init] ) ) { pos = (Vector3){0.0f, 2.0f, 0.0f}; height = 1.0f; + activators = [[YSArray alloc] init]; } return self; @@ -17,6 +18,8 @@ DrawText(buffer, 0, 50, 20, BLACK); } + +//dont use this yet -(void) attack { if ( [attachedCamera raycast] ) { @@ -25,6 +28,16 @@ } } +-(bool) activate { + int i; + for (i = 0; i < activators->count; i++) { + if ( [attachedCamera raycast: [activators->array[i] bbox]] ) { + //printf("activators->array[%d] == %p\n", i, activators->array[i]); + [(NPC *)activators->array[i] activate]; + } + } +} + -(void) moveForward { Camera *cam = [attachedCamera addressOfCamera]; Vector3 forward = GetCameraForward( cam ); diff --git a/src/main.m b/src/main.m index 1c2ce6a..5c71090 100644 --- a/src/main.m +++ b/src/main.m @@ -10,8 +10,10 @@ #import "Renderer.h" #import "Gravitator.h" #import "PhysObject.h" +#import "NPC.h" #import "properties.h" + const int winWidth = 800; const int winHeight = 600; @@ -38,6 +40,9 @@ int main(int argc, const char *argv[]) { AssetLoader *assetLoader = [[AssetLoader alloc] init]; Renderer *renderer = [[Renderer alloc] init]; Gravitator *gravitator = [[Gravitator alloc] init]; + NPC *npc = [NPC new]; + + input->controllable = player; gravitator->acceleration = (Vector3){0.0f, -1.0f, 0.0f}; @@ -45,22 +50,32 @@ int main(int argc, const char *argv[]) { //player.soundPlayer = sp; [camera attach: player]; + + [assetLoader loadAssetFile: "assets.al"]; + int i; for (i = 0; i < assetLoader->count; i++) { [assetLoader sendObject: assetLoader->array[i] to: renderer]; [assetLoader sendObject: assetLoader->array[i] to: gravitator]; } + + [player->activators addObject: npc]; + + while (!WindowShouldClose()) { [camera update]; + //hard coded input handler [input handleInput]; [gravitator applyGravity]; + + BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera->camera); @@ -69,15 +84,15 @@ int main(int argc, const char *argv[]) { DrawCube((Vector3){ 16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall DrawCube((Vector3){ 0.0f, 2.5f, 16.0f }, 32.0f, 5.0f, 1.0f, GOLD); DrawCube((Vector3){ 0.0f, 2.5f, -16.0f }, 32.0f, 5.0f, 1.0f, RED); + [npc draw: camera->camera]; [renderer render]; EndMode3D(); - [camera showPos]; [camera showTarget]; [player showPos]; [camera drawCrosshair]; - [camera raycast]; + //[camera raycast]; //[enemy Render: [camera camera]]; //DrawTexture(tex, default_properties.width - tex.width, default_properties.height - tex.height, WHITE);