sandyx86 1 year ago
parent 8a0f249cc1
commit 4f7e0a31b0

@ -66,8 +66,7 @@ RayCollision ObjectiveCBugFixRaycast(Camera3D camera, BoundingBox bbox) {
} }
} }
-(bool) raycast { -(bool) raycast: (BoundingBox) bbox {
BoundingBox bbox = {(Vector3){-1.0f, -1.0f, -1.0f}, (Vector3){2.0f, 2.0f, 2.0f}};
//i called them both raycast to maximize confusion //i called them both raycast to maximize confusion
if ( ObjectiveCBugFixRaycast(camera, bbox).hit ) { if ( ObjectiveCBugFixRaycast(camera, bbox).hit ) {
@ -76,14 +75,6 @@ RayCollision ObjectiveCBugFixRaycast(Camera3D camera, BoundingBox bbox) {
crosshairColor = WHITE; crosshairColor = WHITE;
} }
#define DEBUG
#ifdef DEBUG
BeginMode3D(camera);
//DrawBoundingBox(bbox, BLUE);
#endif
EndMode3D();
return ObjectiveCBugFixRaycast(camera, bbox).hit; return ObjectiveCBugFixRaycast(camera, bbox).hit;
} }

@ -16,12 +16,19 @@ static inline Vector3 multFloatVector3(float f, Vector3 v) {
//cursed //cursed
Vector3 force = multFloatVector3( [(PhysObject *)array[i] mass], acceleration); //need to check collision
printf("%f\n", [(PhysObject *)array[i] mass]);
[(PhysObject *)array[i] setVelocity: Vector3Add(force, [(PhysObject *)array[i] velocity])]; 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] )]; [(PhysObject *)array[i] setPos: Vector3Add( [(PhysObject *)array[i] velocity], [(PhysObject *)array[i] pos] )];
//printf("%f %f %f\n", force.x, force.y, force.z );
} }

@ -22,8 +22,11 @@
[controllable moveLeft]; [controllable moveLeft];
} else if ( set - IsKeyDown(KEY_D) ) { } else if ( set - IsKeyDown(KEY_D) ) {
[controllable moveRight]; [controllable moveRight];
} else if ( set - IsKeyDown(KEY_E) ) {
[controllable activate];
} }
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
[controllable attack]; [controllable attack];
} }

@ -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 <raylib.h>
#import <yeslib.h>
#import <stdio.h>
#import "Activator.h"
@interface NPC : YSObject <Receiver> {
BoundingBox bbox;
Vector3 pos;
Texture2D texture;
}
-(id) init;
+(id) new;
-(void) draw: (Camera3D) camera;
-(void) activate;
-(BoundingBox) bbox;
@end
#endif

@ -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

@ -8,6 +8,9 @@
@public @public
float mass; float mass;
Vector3 velocity; Vector3 velocity;
Vector3 force;
bool onSurface;
bool isStatic;
} }
-(id) init; -(id) init;
@ -15,6 +18,12 @@
-(void) setVelocity: (Vector3) v; -(void) setVelocity: (Vector3) v;
-(float) mass; -(float) mass;
-(void) setMass: (float) m; -(void) setMass: (float) m;
-(Vector3) force;
-(void) setForce: (Vector3) f;
-(bool) onSurface;
-(void) setOnSurface: (bool) s;
-(bool) isStatic;
-(void) setStatic: (bool) s;
@end @end
#endif #endif

@ -6,7 +6,7 @@
self = [super init]; self = [super init];
if (self) { if (self) {
mass = 1.0f; mass = 0.00001f;
} }
return self; return self;
@ -28,4 +28,28 @@
mass = m; 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 @end

@ -6,6 +6,7 @@
#import "Camera.h" #import "Camera.h"
#import "SoundPlayer.h" #import "SoundPlayer.h"
#import "NPC.h"
@class GameCamera; @class GameCamera;
@ -17,11 +18,13 @@
GameCamera *attachedCamera; GameCamera *attachedCamera;
SoundPlayer *soundPlayer; SoundPlayer *soundPlayer;
Texture2D weapon; Texture2D weapon;
YSArray *activators; //things the player can activate
} }
-(id) init; -(id) init;
-(void) showPos; -(void) showPos;
-(void) attack; -(void) attack;
-(bool) activate;
-(void) moveForward; -(void) moveForward;
-(void) moveBack; -(void) moveBack;
-(void) moveLeft; -(void) moveLeft;

@ -6,6 +6,7 @@
if ( (self = [super init] ) ) { if ( (self = [super init] ) ) {
pos = (Vector3){0.0f, 2.0f, 0.0f}; pos = (Vector3){0.0f, 2.0f, 0.0f};
height = 1.0f; height = 1.0f;
activators = [[YSArray alloc] init];
} }
return self; return self;
@ -17,6 +18,8 @@
DrawText(buffer, 0, 50, 20, BLACK); DrawText(buffer, 0, 50, 20, BLACK);
} }
//dont use this yet
-(void) attack { -(void) attack {
if ( [attachedCamera raycast] ) { 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 { -(void) moveForward {
Camera *cam = [attachedCamera addressOfCamera]; Camera *cam = [attachedCamera addressOfCamera];
Vector3 forward = GetCameraForward( cam ); Vector3 forward = GetCameraForward( cam );

@ -10,8 +10,10 @@
#import "Renderer.h" #import "Renderer.h"
#import "Gravitator.h" #import "Gravitator.h"
#import "PhysObject.h" #import "PhysObject.h"
#import "NPC.h"
#import "properties.h" #import "properties.h"
const int winWidth = 800; const int winWidth = 800;
const int winHeight = 600; const int winHeight = 600;
@ -38,6 +40,9 @@ int main(int argc, const char *argv[]) {
AssetLoader *assetLoader = [[AssetLoader alloc] init]; AssetLoader *assetLoader = [[AssetLoader alloc] init];
Renderer *renderer = [[Renderer alloc] init]; Renderer *renderer = [[Renderer alloc] init];
Gravitator *gravitator = [[Gravitator alloc] init]; Gravitator *gravitator = [[Gravitator alloc] init];
NPC *npc = [NPC new];
input->controllable = player; input->controllable = player;
gravitator->acceleration = (Vector3){0.0f, -1.0f, 0.0f}; gravitator->acceleration = (Vector3){0.0f, -1.0f, 0.0f};
@ -46,21 +51,31 @@ int main(int argc, const char *argv[]) {
[camera attach: player]; [camera attach: player];
[assetLoader loadAssetFile: "assets.al"]; [assetLoader loadAssetFile: "assets.al"];
int i; int i;
for (i = 0; i < assetLoader->count; i++) { for (i = 0; i < assetLoader->count; i++) {
[assetLoader sendObject: assetLoader->array[i] to: renderer]; [assetLoader sendObject: assetLoader->array[i] to: renderer];
[assetLoader sendObject: assetLoader->array[i] to: gravitator]; [assetLoader sendObject: assetLoader->array[i] to: gravitator];
} }
[player->activators addObject: npc];
while (!WindowShouldClose()) { while (!WindowShouldClose()) {
[camera update]; [camera update];
//hard coded input handler //hard coded input handler
[input handleInput]; [input handleInput];
[gravitator applyGravity]; [gravitator applyGravity];
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera->camera); 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){ 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, GOLD);
DrawCube((Vector3){ 0.0f, 2.5f, -16.0f }, 32.0f, 5.0f, 1.0f, RED); DrawCube((Vector3){ 0.0f, 2.5f, -16.0f }, 32.0f, 5.0f, 1.0f, RED);
[npc draw: camera->camera];
[renderer render]; [renderer render];
EndMode3D(); EndMode3D();
[camera showPos]; [camera showPos];
[camera showTarget]; [camera showTarget];
[player showPos]; [player showPos];
[camera drawCrosshair]; [camera drawCrosshair];
[camera raycast]; //[camera raycast];
//[enemy Render: [camera camera]]; //[enemy Render: [camera camera]];
//DrawTexture(tex, default_properties.width - tex.width, default_properties.height - tex.height, WHITE); //DrawTexture(tex, default_properties.width - tex.width, default_properties.height - tex.height, WHITE);

Loading…
Cancel
Save