author | ekku |
Thu, 20 Nov 2008 23:54:41 +0000 | |
changeset 90 | c1a072928790 |
parent 88 | 7431cd0cf900 |
child 91 | 0a6d675099dc |
permissions | -rw-r--r-- |
58 | 1 |
|
2 |
#include "Physics.hh" |
|
3 |
#include "Engine.hh" |
|
4 |
||
45
32c876923cac
I added a couple of lines. This still clearly is not going to work in this state.
saiam
parents:
44
diff
changeset
|
5 |
#include <algorithm> |
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
49
diff
changeset
|
6 |
#include <functional> |
77
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
7 |
#include <cmath> |
45
32c876923cac
I added a couple of lines. This still clearly is not going to work in this state.
saiam
parents:
44
diff
changeset
|
8 |
|
60 | 9 |
PhysicsWorld::PhysicsWorld (Vector gravity, Vector dimensions) |
90 | 10 |
: tick_timer(PHYSICS_TICK_MS), gravity(gravity), dimensions(dimensions), terrain(dimensions.x, std::vector<TerrainType>(dimensions.y, DIRT)) { |
88 | 11 |
|
12 |
generateTerrain(1337); |
|
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
49
diff
changeset
|
13 |
|
54 | 14 |
slots.connect(tick_timer.sig_timer(), this, &PhysicsWorld::tick); |
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
49
diff
changeset
|
15 |
tick_timer.enable(); |
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
49
diff
changeset
|
16 |
} |
44 | 17 |
|
18 |
void PhysicsWorld::addObject (PhysicsObject *object) { |
|
47 | 19 |
objects.push_back(object); |
44 | 20 |
} |
21 |
||
22 |
void PhysicsWorld::tick () { |
|
60 | 23 |
// Engine::log(DEBUG, "physics.apply_force") << "*tick*"; |
58 | 24 |
|
76 | 25 |
for (std::vector<PhysicsObject*>::iterator i = objects.begin(); i != objects.end(); i++) { |
26 |
(*i)->tick(); |
|
27 |
} |
|
48
fa1da22db8a0
It looks like physics could now work, but I doubt it...
saiam
parents:
47
diff
changeset
|
28 |
} |
fa1da22db8a0
It looks like physics could now work, but I doubt it...
saiam
parents:
47
diff
changeset
|
29 |
|
60 | 30 |
PhysicsObject::PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity) |
31 |
: world(world), mass(mass), position(position), velocity(velocity) { |
|
32 |
||
33 |
world.addObject(this); |
|
34 |
} |
|
44 | 35 |
|
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
36 |
/** |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
37 |
* Updates object speed and position. This function organises force |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
38 |
* integration and collision detection. |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
39 |
*/ |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
40 |
void PhysicsObject::updatePosition () { |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
41 |
// Add gravity to the force queue |
85 | 42 |
forceq.push(world.gravity); |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
43 |
|
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
44 |
// Go trough every force in the queue |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
45 |
// TODO: It might be possible to optimize by adding forces together |
84
3cb862028a24
No nyt se toimii v?h?n paremmin. Koodia pit?? kyll? viel? siisti? aika huolella.
saiam
parents:
83
diff
changeset
|
46 |
Force total; |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
47 |
posAfterTick = position; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
48 |
velAfterTick = velocity; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
49 |
while (!forceq.empty()) { |
85 | 50 |
total += forceq.front(); |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
51 |
forceq.pop(); |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
52 |
// Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Current position: " << posAfterTick; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
53 |
} |
85 | 54 |
integrate(total, PHYSICS_TICK_MS); |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
55 |
|
84
3cb862028a24
No nyt se toimii v?h?n paremmin. Koodia pit?? kyll? viel? siisti? aika huolella.
saiam
parents:
83
diff
changeset
|
56 |
Vector newPosition = posAfterTick /*+ (velAfterTick * PHYSICS_TICK_MS)/1000*/; |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
57 |
this->velocity = velAfterTick; |
88 | 58 |
//Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Nopeus: "<<this->velocity; |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
59 |
/* |
60 | 60 |
this->velocity += world.gravity * (PHYSICS_TICK_MS / 1000.0); |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
61 |
|
60 | 62 |
Vector newPosition = position + velocity * (PHYSICS_TICK_MS / 1000.0); |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
63 |
*/ |
44 | 64 |
|
47 | 65 |
//TODO Handle the object as a square or a polygon |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
66 |
|
80 | 67 |
bool collided = false; |
77
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
68 |
|
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
69 |
//goes 1 unit forward every step and check if has hit anything |
80 | 70 |
Vector unitVector = (newPosition-position) / (newPosition-position).length(); |
82 | 71 |
|
72 |
Vector tmpVector = position; |
|
77
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
73 |
Vector reached = position; |
82 | 74 |
int steps = (int) (newPosition-position).length(); |
75 |
for(int i = 0; i < steps; i++) { |
|
77
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
76 |
tmpVector += unitVector; |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
77 |
if(world.getType(tmpVector) != EMPTY) { |
80 | 78 |
//Engine::log(DEBUG, "physics.update_position") << "hit something"; |
77
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
79 |
// Then we have hit something |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
80 |
reached = position + unitVector*(i-1); |
80 | 81 |
collided = true; |
77
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
82 |
break; |
80 | 83 |
} else { |
84 |
//Engine::log(DEBUG, "physics.update_position") << "didnt hit"; |
|
85 |
} |
|
77
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
86 |
} |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
87 |
|
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
88 |
// In case of some float error |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
89 |
if(!collided) { |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
90 |
if(world.getType(newPosition)) { |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
91 |
// There was error, and there is ground |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
92 |
newPosition = tmpVector; |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
93 |
} else { |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
94 |
// This means everything was ok, so no need to do anything |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
95 |
} |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
96 |
} else { |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
97 |
newPosition = reached; |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
98 |
this->velocity = Vector(0, 0); |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
99 |
//TODO: it shouldn't just stop on collision |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
100 |
} |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
101 |
this->position = newPosition; |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
102 |
|
44 | 103 |
} |
104 |
||
73 | 105 |
bool PhysicsWorld::collided (Vector oldPos, Vector newPos) { |
76 | 106 |
int deltaX = oldPos.x - newPos.x; |
107 |
int deltaY = oldPos.y - newPos.y; |
|
108 |
double distance = sqrt(deltaX * deltaX + deltaY * deltaY); |
|
79 | 109 |
double xInc = deltaX / distance; |
110 |
double yInc = deltaY / distance; |
|
73 | 111 |
double currentX = oldPos.x; |
112 |
double currentY = oldPos.y; |
|
113 |
||
76 | 114 |
// This implementation is bit slow since it checks some squares twice. |
73 | 115 |
for(unsigned int i = 1; i < distance; i++) { |
76 | 116 |
currentX += xInc; |
117 |
currentY += yInc; |
|
118 |
if(terrain[(int)currentX][(int)currentY] != EMPTY) |
|
79 | 119 |
return true; |
76 | 120 |
} |
79 | 121 |
return false; |
73 | 122 |
} |
123 |
||
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
124 |
/** |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
125 |
* Integrates given force over time and stores new position to |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
126 |
* posAfterTick and new velocity to velAfterTick. |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
127 |
* @param force Force vector. |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
128 |
* @param dt The time the force is applied (<=PHYSICS_TICK_MS) |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
129 |
*/ |
85 | 130 |
void PhysicsObject::integrate(Force force, TimeMS dt) { |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
131 |
Derivative tmpd; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
132 |
Derivative k1 = evaluate(force, 0, tmpd); |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
133 |
Derivative k2 = evaluate(force, 0.5f*dt, k1); |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
134 |
Derivative k3 = evaluate(force, 0.5f*dt, k2); |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
135 |
Derivative k4 = evaluate(force, dt, k3); |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
136 |
|
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
137 |
|
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
138 |
const Vector dxdt = (k1.dx + (k2.dx + k3.dx) * 2.0f + k4.dx) * 1.0f/6.0f; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
139 |
const Vector dvdt = (k1.dv + (k2.dv + k3.dv) * 2.0f + k4.dv) * 1.0f/6.0f; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
140 |
|
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
141 |
// Engine::log(DEBUG, "PhysicsObject.integrate") << "Changes: "<< dxdt << " " << dvdt << " Time: " <<dt; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
142 |
posAfterTick = posAfterTick + (dxdt * dt)/1000; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
143 |
velAfterTick = velAfterTick + (dvdt * dt)/1000; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
144 |
//Engine::log(DEBUG, "PhysicsObject.integrate") << "velAfterTick: " << velAfterTick; |
70 | 145 |
} |
146 |
||
85 | 147 |
Derivative PhysicsObject::evaluate(Force force, TimeMS dt, Derivative &d) { |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
148 |
Vector curPos = posAfterTick + (d.dx*dt)/1000; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
149 |
Vector curVel = velAfterTick + (d.dv*dt)/1000; |
58 | 150 |
|
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
151 |
Derivative out; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
152 |
out.dx = curVel; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
153 |
out.dv = acceleration(force); |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
154 |
//Engine::log(DEBUG, "PhysicsObject.evaluate") << "Out.dx: " << out.dx; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
155 |
return out; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
156 |
} |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
157 |
|
85 | 158 |
Vector PhysicsObject::acceleration(const Force &force) { |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
159 |
return (force/mass); |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
160 |
} |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
161 |
|
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
162 |
/** |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
163 |
* Adds force to the force queue. Force queue is emptied on each |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
164 |
* tick. Forces that last over one tick are also handled. |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
165 |
* @param force Force vector. |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
166 |
* @param dt The time the force is applied. |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
167 |
*/ |
85 | 168 |
void PhysicsObject::applyForce (Force force, TimeMS dt) { |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
82
diff
changeset
|
169 |
// Add applied force to the queue |
85 | 170 |
forceq.push(force); |
44 | 171 |
} |
172 |
||
60 | 173 |
void PhysicsObject::updatePhysics (Vector position, Vector velocity) { |
47 | 174 |
this->position = position; |
175 |
this->velocity = velocity; |
|
44 | 176 |
} |
177 |
||
178 |
Vector PhysicsObject::getPosition () { |
|
47 | 179 |
return this->position; |
44 | 180 |
} |
181 |
||
182 |
void PhysicsObject::tick () { |
|
47 | 183 |
this->updatePosition(); |
44 | 184 |
} |
185 |
||
75 | 186 |
/** |
187 |
* simple random map generation |
|
188 |
* first fills whole level with dirt |
|
189 |
* then randomizes circles of empty or rock |
|
190 |
* @param seed - seed number for random number generator |
|
191 |
*/ |
|
79 | 192 |
void PhysicsWorld::generateTerrain(int seed) { |
75 | 193 |
// generating should use own random number generator, but didn't find easily how that is done |
194 |
srand(seed); |
|
195 |
||
196 |
// some constants to control random generation |
|
197 |
const int min_range = 10; |
|
198 |
const int max_range = 40; |
|
90 | 199 |
const int num = 30; |
75 | 200 |
const int rock_rarity = 4; // 1 / rock_rarity will be rock circle |
201 |
||
202 |
// loops for amount of circles |
|
203 |
for(int i = 0; i < num; i++) { |
|
204 |
// information of new circle |
|
79 | 205 |
int midx = rand()%(int)dimensions.x; |
206 |
int midy = rand()%(int)dimensions.y; |
|
88 | 207 |
int range = rand()%(max_range-min_range)+min_range; |
79 | 208 |
|
209 |
// put first circle in the middle of the cave |
|
210 |
// so that we have some area we can certainly spawn into |
|
211 |
if(i == 0) { |
|
90 | 212 |
midx = dimensions.x/2; |
213 |
midy = dimensions.y/2; |
|
214 |
range = 150; |
|
79 | 215 |
} |
216 |
||
90 | 217 |
TerrainType type = EMPTY; |
75 | 218 |
if(rand()%rock_rarity == 0) { |
219 |
type = ROCK; |
|
220 |
} |
|
90 | 221 |
|
222 |
Engine::log(DEBUG, "PhysicsObject.generta") << "Dims: " << dimensions.x << " " << dimensions.y; |
|
75 | 223 |
// loops for every pixel of circle |
79 | 224 |
for(int x = std::max(0, midx-range); x < std::min((int)dimensions.x, midx+range); x++) { |
225 |
for(int y = std::max(0, midy-range); y < std::min((int)dimensions.y, midy+range); y++) { |
|
90 | 226 |
if((x-midx) * (x-midx) + (y-midy) * (y-midy) < range*range) { |
75 | 227 |
// and sets it to type |
228 |
terrain[x][y] = type; |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
77
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
234 |
|
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
235 |
/** |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
236 |
* Returns terrainType in given tile. ROCK if tile is out of area |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
237 |
* @param pos - coordinate of tile |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
238 |
*/ |
79 | 239 |
TerrainType PhysicsWorld::getType(Vector pos) const { |
77
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
240 |
int x = (int)(pos.x); |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
241 |
int y = (int)(pos.y); |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
242 |
if(x < 0 || y < 0 || x >= dimensions.x || y >= dimensions.y) { |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
243 |
return ROCK; |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
244 |
} |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
245 |
return terrain[x][y]; |
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
76
diff
changeset
|
246 |
} |