1
1
Fork 0
Browse Source

Generalise the physics a bit

thread-physics
user 5 years ago
parent
commit
60825079b5
  1. 30
      Makefile (SFConflict mail@alistairmichael.com 2019-08-01-11-07-48)
  2. BIN
      draw.o
  3. 19
      game.c
  4. BIN
      game.o
  5. BIN
      main
  6. BIN
      main.o

30
Makefile (SFConflict mail@alistairmichael.com 2019-08-01-11-07-48)

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
CXX = gcc
SDL_INCLUDE = -lSDL2 -lSDL2_image
CXXFLAGS = $(SDL_INCLUDE)
EXE = main
default: all
run: all
./$(EXE)
all: $(EXE)
$(EXE): main.o logger.o game.o
$(CXX) $(CXXFLAGS) -o $(EXE) main.o game.o logger.o
main.o: main.c logger.h game.h
$(CXX) $(CXXFLAGS) -c main.c
logger.o: logger.c logger.h
$(CXX) $(CXXFLAGS) -c logger.c
game.o: game.c game.h
$(CXX) $(CXXFLAGS) -c game.c
clean:
rm *.o && rm $(EXE)

BIN
draw.o

Binary file not shown.

19
game.c

@ -75,6 +75,18 @@ void set_motor_ms(physics_thing * thing, float x, float y) { @@ -75,6 +75,18 @@ void set_motor_ms(physics_thing * thing, float x, float y) {
logwrite(DEBUG, "set motor thing\n");
}
void add_motor_ms(physics_thing * thing, float x, float y) {
// set motor force in newtons
float x_adj = x;
float y_adj = y;
(*thing).motor_x += (float)y_adj;
(*thing).motor_y += (float)x_adj;
logwrite(DEBUG, "set motor thing\n");
}
int advance_glob(physics_thing * thing) {
logwrite(DEBUG, "Global physics\n");
@ -185,7 +197,7 @@ void add_to_world(world_thing thing) { @@ -185,7 +197,7 @@ void add_to_world(world_thing thing) {
void startgame(SDL_Renderer * ren) {
things_in_world = 0;
player = get_player(100,300);
player = get_player(100,400);
world_thing player_world;
@ -215,7 +227,7 @@ void walk_player(int x, int y) { @@ -215,7 +227,7 @@ void walk_player(int x, int y) {
//set_motor_ms(&player.physics, player.max_walking_speed * 0.01 * x, player.max_walking_speed * 0.01 * y);
set_motor_ms(&player.physics, 100 * y , 100 * x);
add_motor_ms(&player.physics, 100 * y , 100 * x);
// player.physics.x_acc = player.max_walking_speed * 0.00001 * x ;
// player.physics.y_acc = player.max_walking_speed * 0.00001 * y ;
@ -266,7 +278,8 @@ void step(int interval) { @@ -266,7 +278,8 @@ void step(int interval) {
// player.physics.y_acc = 0;
keyboard = SDL_GetKeyboardState(NULL);
walk_player(0,0);
set_motor_ms(&player.physics, 0 ,0);
if (keyboard[SDL_SCANCODE_W]) {
walk_player(0, -1);
} if (keyboard[SDL_SCANCODE_A]) {

BIN
game.o

Binary file not shown.

BIN
main

Binary file not shown.

BIN
main.o

Binary file not shown.
Loading…
Cancel
Save