sandyx86 1 year ago
parent 8a0f249cc1
commit 4f7e0a31b0

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

@ -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 );
}

@ -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];
}

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

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

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

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

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

Loading…
Cancel
Save