-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
181 lines (171 loc) · 6.84 KB
/
main.cc
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* =====================================================================================
*
* 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, finnkrein@googlemail.com; Arvid Krein, arvid2000@googlemail.com 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 = 30;
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(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)
{
SDL_Delay(1);
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 << vKpointer->getX() << " , " << vKpointer->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);
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 = {0x00,0x00,0x00,0xFF};
vKpointer+=1;
vKpointer->color = {0xFF,0x00,0x00,0xFF};
break;
case SDLK_MINUS:
vKpointer->color = {0x00,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;
case SDLK_3:
world.gravF.Y -= 1;
break;
case SDLK_4:
world.gravF.X += 1;
break;
case SDLK_5:
vKpointer->setMass(vKpointer->getMass() - 2);
break;
case SDLK_6:
vKpointer->setMass(vKpointer->getMass() + 2);
break;
case SDLK_7:
world.bouncetype -=1;
break;
case SDLK_8:
world.bouncetype +=1;
break;
}
}
if (event.type == SDL_MOUSEBUTTONDOWN)
{
SDL_GetMouseState(&mousex, &mousey);
drawnRect.x=mousex-KASTENGROSSE/2;
drawnRect.y=mousey-KASTENGROSSE/2;
}
}
if (!timer.getstatus())
{
for (int i=0; i<1000; i++)
{
//std::cout << timer.get() << "\n";
world.iterate(1e-5);
}
}
if( timer.get() >= (1000/FRAMERATE) )
{
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(gRenderer);
drawobjs(gRenderer, world.vKPartikel, KASTENGROSSE);
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0x00);
SDL_RenderDrawRect(gRenderer, &drawnRect);
SDL_RenderPresent(gRenderer);
timer.reset();
}
}
SDL_DestroyWindow(gWindow);
SDL_DestroyRenderer(gRenderer);
gWindow = NULL;
gRenderer = NULL;
return 0;
}