-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc.old
116 lines (106 loc) · 2.66 KB
/
main.cc.old
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* =====================================================================================
*
* 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;
}