a janky init
This commit is contained in:
55
src/1-1-walker.c
Executable file
55
src/1-1-walker.c
Executable file
@@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
|
||||
#define PROJECT_NAME "vecotrs-main"
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
} OBJECT;
|
||||
|
||||
#include <init.h>
|
||||
|
||||
void constructor(int w, int h, OBJECT *obj){
|
||||
obj->x = (float)w/2;
|
||||
obj->y = (float)h/2;
|
||||
}
|
||||
|
||||
OBJECT init_stuffs(int w, int h){
|
||||
OBJECT obj;
|
||||
constructor(w,h,&obj);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
void update(OBJECT *obj){
|
||||
obj->x = obj->x + (rand() % 2 - 0.5);
|
||||
obj->y = obj->y + (rand() % 2 - 0.5);
|
||||
}
|
||||
|
||||
void show(SDL_Renderer* renderer,OBJECT *obj){
|
||||
SDL_SetRenderDrawColor(renderer,150,50,255,255);
|
||||
SDL_RenderDrawPoint(renderer,obj->x,obj->y);
|
||||
}
|
||||
|
||||
void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
|
||||
//SDL_SetRenderDrawColor(renderer,0,0,0,255);
|
||||
//SDL_RenderClear(renderer);
|
||||
|
||||
update(stuff->obj);
|
||||
show(renderer,stuff->obj);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
//SDL_UpdateWindowSurface(window);
|
||||
}
|
||||
|
||||
void mousePressed(STUFFS *stuff){
|
||||
|
||||
}
|
||||
|
||||
#include <init.c>
|
||||
56
src/1-2-vec-math.c
Executable file
56
src/1-2-vec-math.c
Executable file
@@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include "global_objects.c"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
|
||||
#define PROJECT_NAME "vecotrs-main"
|
||||
|
||||
typedef struct {
|
||||
Point pos;
|
||||
Point vel;
|
||||
} OBJECT;
|
||||
|
||||
#include <init.h>
|
||||
|
||||
void constructor(int w, int h, OBJECT *obj){
|
||||
obj->pos.x = (float)w/2;
|
||||
obj->pos.y = (float)h/2;
|
||||
obj->vel.x = 1;
|
||||
obj->vel.y = -1;
|
||||
}
|
||||
|
||||
OBJECT init_stuffs(int w, int h){
|
||||
OBJECT obj;
|
||||
constructor(w,h,&obj);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
void update(OBJECT *obj){
|
||||
point_add(&obj->pos, &obj->vel);
|
||||
}
|
||||
|
||||
void show(SDL_Renderer* renderer,OBJECT *obj){
|
||||
SDL_SetRenderDrawColor(renderer,150,50,255,255);
|
||||
SDL_RenderFillRect(renderer,&(SDL_Rect){.x = obj->pos.x - 5, .y=obj->pos.y - 5, .w = 10, .h = 10});
|
||||
}
|
||||
|
||||
void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
|
||||
SDL_SetRenderDrawColor(renderer,0,0,0,255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
update(stuff->obj);
|
||||
show(renderer,stuff->obj);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
void mousePressed(STUFFS *stuff){
|
||||
|
||||
}
|
||||
|
||||
#include <init.c>
|
||||
65
src/1-3-rand-vec.c
Executable file
65
src/1-3-rand-vec.c
Executable file
@@ -0,0 +1,65 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include "global_objects.c"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
|
||||
#define PROJECT_NAME "vecotrs-main"
|
||||
|
||||
typedef struct {
|
||||
Point pos;
|
||||
} OBJECT;
|
||||
|
||||
#include <init.h>
|
||||
|
||||
float RandomFloat(float min, float max){
|
||||
return ((max - min) * ((float)rand() / RAND_MAX)) + min;
|
||||
}
|
||||
|
||||
void constructor(int w, int h, OBJECT *obj){
|
||||
obj->pos.x = (float)w/2;
|
||||
obj->pos.y = (float)h/2;
|
||||
}
|
||||
|
||||
OBJECT init_stuffs(int w, int h){
|
||||
OBJECT obj;
|
||||
constructor(w,h,&obj);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
void update(STUFFS *stuff){
|
||||
Point rand_point = {RandomFloat(-1, 1),RandomFloat(-1, 1)};
|
||||
point_set_mag(&rand_point, 1);
|
||||
|
||||
float random_mul = RandomFloat(50, 100);
|
||||
point_mul(&rand_point,&(Point){.x = random_mul, .y = random_mul});
|
||||
|
||||
stuff->obj->pos.x = rand_point.x + (float)stuff->width / 2;;
|
||||
stuff->obj->pos.y = rand_point.y + (float)stuff->height / 2;
|
||||
}
|
||||
|
||||
void show(SDL_Renderer* renderer,STUFFS *stuff){
|
||||
SDL_SetRenderDrawColor(renderer,150,50,255,255);
|
||||
//SDL_RenderFillRect(renderer,&(SDL_Rect){.x = obj->pos.x - 5, .y=obj->pos.y - 5, .w = 10, .h = 10});
|
||||
SDL_RenderDrawLine(renderer,stuff->width/2,stuff->height/2,stuff->obj->pos.x,stuff->obj->pos.y);
|
||||
}
|
||||
|
||||
void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
|
||||
//SDL_SetRenderDrawColor(renderer,0,0,0,255);
|
||||
//SDL_RenderClear(renderer);
|
||||
|
||||
update(stuff);
|
||||
show(renderer,stuff);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
void mousePressed(STUFFS *stuff){
|
||||
|
||||
}
|
||||
|
||||
#include <init.c>
|
||||
Reference in New Issue
Block a user