gfx and 2-2 and multi objects
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define global_objects
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define flaot float
|
||||
|
||||
@@ -25,6 +26,11 @@ void point_mul(Point *A, Point *B){
|
||||
A->y = A->y * B->y;
|
||||
}
|
||||
|
||||
void point_div(Point *A, Point *B){
|
||||
A->x = A->x / B->x;
|
||||
A->y = A->y / B->y;
|
||||
}
|
||||
|
||||
float magnitude(flaot x, flaot y) {
|
||||
return sqrt((pow(x,2) + pow(y,2)));
|
||||
}
|
||||
@@ -38,4 +44,23 @@ void point_set_mag(Point *point, float mag){
|
||||
point->y = ry;
|
||||
}
|
||||
|
||||
void point_limit(Point *point, float mag){
|
||||
flaot getmag = magnitude(point->x, point->y);
|
||||
flaot rx, ry;
|
||||
if (getmag > mag){
|
||||
rx = (point->x / getmag) * mag;
|
||||
ry = (point->y / getmag) * mag;
|
||||
} else {
|
||||
rx = point->x;
|
||||
ry = point->y;
|
||||
}
|
||||
|
||||
point->x = rx;
|
||||
point->y = ry;
|
||||
}
|
||||
|
||||
float RandomFloat(float min, float max){
|
||||
return ((max - min) * ((float)rand() / (double)RAND_MAX)) + min;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
71
lib/init-multi.c
Executable file
71
lib/init-multi.c
Executable file
@@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include <init-multi.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
||||
SDL_Log("SDL fails to initialize! %s\n", SDL_GetError());
|
||||
|
||||
int startw=400;
|
||||
int starth=400;
|
||||
|
||||
SDL_Window *window = SDL_CreateWindow(PROJECT_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, startw, starth, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
|
||||
if (!window) {
|
||||
printf("Failed to create window: %s\n", SDL_GetError());
|
||||
}
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_SOFTWARE);
|
||||
if (!renderer) {
|
||||
printf("Failed to create renderer: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
|
||||
srand(time(NULL));
|
||||
OBJECT obj_storage[obj_n];
|
||||
|
||||
init_stuffs(startw,starth,obj_storage);
|
||||
|
||||
STUFFS stuff = {
|
||||
startw,
|
||||
starth,
|
||||
false,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
|
||||
for (int i = 0; i < obj_n; i++)
|
||||
stuff.obj[i] = &obj_storage[i];
|
||||
|
||||
bool quit = false;
|
||||
SDL_Event e;
|
||||
while (!quit) {
|
||||
while (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_QUIT) {
|
||||
quit = true;
|
||||
}
|
||||
else if(e.type == SDL_MOUSEBUTTONDOWN){
|
||||
if(e.button.button==SDL_BUTTON_LEFT){
|
||||
stuff.mousedown=true;
|
||||
} else if(e.button.button==SDL_BUTTON_RIGHT){
|
||||
}
|
||||
} else if(e.type==SDL_MOUSEBUTTONUP){
|
||||
stuff.mousedown=false;
|
||||
}
|
||||
stuff.mx=e.button.x;
|
||||
stuff.my=e.button.y;
|
||||
}
|
||||
draw(renderer,window,&stuff);
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
15
lib/init-multi.h
Executable file
15
lib/init-multi.h
Executable file
@@ -0,0 +1,15 @@
|
||||
#ifndef inithell
|
||||
#define inithell
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct{
|
||||
int width;
|
||||
int height;
|
||||
bool mousedown;
|
||||
int mx;
|
||||
int my;
|
||||
OBJECT *obj[obj_n];
|
||||
} STUFFS;
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include <init.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
@@ -23,12 +24,15 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
srand(time(NULL));
|
||||
OBJECT obj = init_stuffs(startw,starth);
|
||||
|
||||
STUFFS stuff = {
|
||||
startw,
|
||||
starth,
|
||||
false,
|
||||
0,
|
||||
0,
|
||||
&obj,
|
||||
};
|
||||
|
||||
@@ -47,9 +51,11 @@ int main(int argc, char *argv[])
|
||||
} else if(e.type==SDL_MOUSEBUTTONUP){
|
||||
stuff.mousedown=false;
|
||||
}
|
||||
stuff.mx=e.button.x;
|
||||
stuff.my=e.button.y;
|
||||
}
|
||||
draw(renderer,window,&stuff);
|
||||
SDL_Delay(30);
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
|
||||
@@ -8,6 +8,8 @@ typedef struct{
|
||||
int width;
|
||||
int height;
|
||||
bool mousedown;
|
||||
int mx;
|
||||
int my;
|
||||
OBJECT *obj;
|
||||
} STUFFS;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user