Skip to content

Commit

Permalink
Fixed elastic bounce and added some control keys
Browse files Browse the repository at this point in the history
some other small fixes too :)
  • Loading branch information
evilsetg committed Nov 3, 2018
1 parent 308cc5d commit 3df888d
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 94 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#OBJS specifies which files to compile as part of the project
OBJS = test.cc utility.cc lTexture.o physobj.o bezier.o stickman.o
OBJS = main.cc utility.cc lTexture.o physobj.o bezier.o stickman.o vec2.o
#CC specifies which compiler we're using
CC = g++

Expand All @@ -15,13 +15,17 @@ LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_ttf
OBJ_NAME = stickfight

#This is the target that compiles our executable
stickman.o: stickman.cc bezier.o physobj.o
$(CC) stickman.cc $(COMPILER_FLAGS) $(LINKER_FLAGS) -c -o stickman.o
bezier.o: bezier.cc
OBJS: $(OBJS)
echo done
vec2.o: vec2.cc
$(CC) vec2.cc $(COMPILER_FLAGS) $(LINKER_FLAGS) -c -o vec2.o
bezier.o: bezier.cc vec2.o
$(CC) bezier.cc $(COMPILER_FLAGS) $(LINKER_FLAGS) -c -o bezier.o
physobj.o: physobj.cc
$(CC) physobj.cc $(COMPILER_FLAGS) $(LINKER_FLAGS) -c -o physobj.o
lTexture.o: lTexture.cc
$(CC) lTexture.cc $(COMPILER_FLAGS) $(LINKER_FLAGS) -c -o lTexture.o
stickman.o: stickman.cc bezier.o physobj.o
$(CC) stickman.cc $(COMPILER_FLAGS) $(LINKER_FLAGS) -c -o stickman.o
all : $(OBJS)
$(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)
2 changes: 1 addition & 1 deletion bezier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void polanticlock(std::vector<vec2> & Points)
{
if (Points.at(0).xTo(Points.at(1))<0)
{
Points.crbegin
Points.crbegin();
}
}
}
Expand Down
61 changes: 52 additions & 9 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
* Revision: none
* Compiler: gcc
*
* Author: Finn Krein, [email protected]; Arvid Krein, [email protected]
* Company: -
* Author: Finn Krein, [email protected]; Arvid Krein, [email protected] Company: -
*
* =====================================================================================
*/

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>
Expand All @@ -32,7 +31,7 @@
int KASTENGROSSE = 5;
const int FRAMERATE = 25;

int main (/*int argc, char* args[])*/)
int main ()
{
SDL_Window* gWindow;
SDL_Renderer* gRenderer;
Expand All @@ -44,12 +43,15 @@ int main (/*int argc, char* args[])*/)
int mousex;
int mousey;
SDL_Rect drawnRect = {SCREEN_WIDTH/2, SCREEN_HEIGHT/2, 4 ,4};
Worldframe world;
world.xsize = SCREEN_WIDTH;
world.ysize = SCREEN_HEIGHT;
world.gravFy = 0;
Worldframe world(40000, 0, 0);
world.size.X = SCREEN_WIDTH;
world.size.Y = SCREEN_HEIGHT;
world.gravF.Y = -0;
std::cout << "xsize: " << world.size.X << "\n" << std::flush;
std::cout << "ysize: " << world.size.Y << "\n" << std::flush;
std::vector<Bezpath> vBpath;
kraftpartikel tempPart;
std::vector<kraftpartikel>::iterator vKpointer = world.vKPartikel.begin();
while (quit!=true)
{
while(SDL_PollEvent(&event)!=0)
Expand Down Expand Up @@ -79,7 +81,45 @@ int main (/*int argc, char* args[])*/)
tempPart.setX(static_cast<float>(mousex));
tempPart.setY(static_cast<float>(SCREEN_HEIGHT - mousey));
world.vKPartikel.push_back(tempPart);
vKpointer = world.vKPartikel.begin();
break;
case SDLK_RIGHT:
vKpointer->setxvel( vKpointer->getxvel() + 5);
break;
case SDLK_LEFT:
vKpointer->setxvel( vKpointer->getxvel() - 5);
break;
case SDLK_UP:
vKpointer->setyvel( vKpointer->getyvel() + 5);
break;
case SDLK_DOWN:
vKpointer->setyvel( vKpointer->getyvel() - 5);
break;
case SDLK_PLUS:
//vKpointer->color = {0xFF,0x00,0x00,0xFF};
vKpointer+=1;
//vKpointer->color = {0xFF,0x00,0x00,0xFF};
break;
case SDLK_MINUS:
//vKpointer->color = {0xFF,0x00,0x00,0xFF};
vKpointer-=1;
//vKpointer->color = {0xFF,0x00,0x00,0xFF};
break;
case SDLK_e:
std::cout << world.getEnergy() << "\n" << std::flush;
break;
case SDLK_t:
std::cout << pow( vKpointer->getyvel(), 2 ) + pow( vKpointer->getxvel(), 2 ) << "\n" << std::flush;
break;
case SDLK_v:
std::cout << vKpointer->vel.X << " , " << vKpointer->vel.Y << "\n" << std::flush;
break;
case SDLK_1:
world.coulombfaktor -= 1000;
break;
case SDLK_2:
world.coulombfaktor += 1000;
break;
}

}
Expand All @@ -92,7 +132,10 @@ int main (/*int argc, char* args[])*/)
}
}
if (!timer.getstatus())
world.iterate(1e-5);
{
//std::cout << timer.get() << "\n";
world.iterate(1e-5);
}
if( timer.get() >= (1000/FRAMERATE) )
{
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
Expand Down
116 changes: 116 additions & 0 deletions main.cc.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* =====================================================================================
*
* Filename: main.cc
*
* Description: A simple fighting game
*
* Version: 1.0
* Created: 21.03.2017 16:39:34
* Revision: none
* Compiler: gcc
*
* Author: Finn Krein, [email protected]; Arvid Krein, [email protected]
* Company: -
*
* =====================================================================================
*/

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>
#include "utility.h"
#include "lTexture.h"
#include "physobj.h"
#include "bezier.h"
#include "stickman.h"

int KASTENGROSSE = 5;
const int FRAMERATE = 25;

int main ()
{
SDL_Window* gWindow;
SDL_Renderer* gRenderer;
init(&gWindow,&gRenderer, SCREEN_HEIGHT, SCREEN_WIDTH);

bool quit=false;
SDL_Event event;
simpleTimer timer;
int mousex;
int mousey;
SDL_Rect drawnRect = {SCREEN_WIDTH/2, SCREEN_HEIGHT/2, 4 ,4};
Worldframe world;
world.xsize = SCREEN_WIDTH;
world.ysize = SCREEN_HEIGHT;
world.gravFy = 0;
std::vector<Bezpath> vBpath;
kraftpartikel tempPart;
while (quit!=true)
{
while(SDL_PollEvent(&event)!=0)
{
if(event.type == SDL_QUIT)
quit=true;
if(event.type == SDL_KEYDOWN)
{
switch (event.key.keysym.sym)
{
case SDLK_b:
vBpath.push_back(createbezierpath(gRenderer));
break;
case SDLK_p:
timer.flip();
break;
case SDLK_o:
timer.reset();
break;
case SDLK_i:
std::cout << timer.get() << "\n" << std::flush;
break;
case SDLK_w:
std::cout << (world.vKPartikel.end()-1)->getX() << " , " << (world.vKPartikel.end()-1)->getY() << "\n" << std::flush;
break;
case SDLK_n:
tempPart.setX(static_cast<float>(mousex));
tempPart.setY(static_cast<float>(SCREEN_HEIGHT - mousey));
world.vKPartikel.push_back(tempPart);
break;
}

}

if (event.type == SDL_MOUSEBUTTONDOWN)
{
SDL_GetMouseState(&mousex, &mousey);
drawnRect.x=mousex-KASTENGROSSE/2;
drawnRect.y=mousey-KASTENGROSSE/2;
}
}
if (!timer.getstatus())
world.iterate(1e-5);
if( timer.get() >= (1000/FRAMERATE) )
{
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(gRenderer);
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
drawobjs(gRenderer, world.vKPartikel, KASTENGROSSE);
SDL_RenderDrawRect(gRenderer, &drawnRect);
SDL_RenderPresent(gRenderer);
timer.reset();
}
}

SDL_DestroyWindow(gWindow);
SDL_DestroyRenderer(gRenderer);
gWindow = NULL;
gRenderer = NULL;

return 0;
}


Loading

0 comments on commit 3df888d

Please sign in to comment.