Skip to content

Commit f354317

Browse files
IsaacLicAdrijaned
andauthored
force/contact handling (#516)
* Created force and contact events * Separated impulse events from force events * Slight javadoc fix * Fixed an error in ForceEvent's javadoc * Update engine/src/main/java/org/destinationsol/events/ImpulseEvent.java Co-authored-by: Jindřich Dítě <[email protected]> * Cleaned up javadoc I did most of the changes that were suggested, but I haven't looked into the usage of `causesAcceleration` or why impulse is currently a float, so I didn't make those changes yet. * Changed ContactEvent's javadoc to represent its usage more accurately * Cleaned up ForceEvent and added ImmuneToForce component * Updated contact and impulse events to work with existing stuctures * Small addition to ForceEvent doc Co-authored-by: Jindřich Dítě <[email protected]>
1 parent d693cbe commit f354317

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2020 The Terasology Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.destinationsol.components;
17+
18+
import org.destinationsol.game.ship.KnockBack;
19+
import org.terasology.gestalt.entitysystem.component.Component;
20+
21+
/**
22+
* Denotes that an entity should not be affected by forces such as gravity or the {@link KnockBack} ship ability.
23+
*/
24+
public class ImmuneToForce implements Component<ImmuneToForce> {
25+
@Override
26+
public void copy(ImmuneToForce other) {
27+
28+
}
29+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2020 The Terasology Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.destinationsol.events;
17+
18+
import com.badlogic.gdx.math.Vector2;
19+
import com.badlogic.gdx.physics.box2d.Contact;
20+
import org.destinationsol.game.item.Loot;
21+
import org.destinationsol.game.ship.SolShip;
22+
import org.terasology.gestalt.entitysystem.entity.EntityRef;
23+
import org.terasology.gestalt.entitysystem.event.Event;
24+
25+
/**
26+
* Event that represents the contact between two entities. Both entities involved in the contact will be sent separate
27+
* contact events. If the contact should be modified in any way, the {@link Contact} should be changed. For example, if
28+
* a {@link SolShip} comes in contact with {@link Loot}, the contact should handled without generating an impulse.
29+
* <p>
30+
* Long-term forces, such as gravity, should be handled by a {@link ForceEvent}.
31+
*/
32+
public class ContactEvent implements Event {
33+
34+
private EntityRef otherEntity;
35+
private Contact contact;
36+
37+
public ContactEvent(EntityRef otherEntity, Contact contact) {
38+
this.otherEntity = otherEntity;
39+
this.contact = contact;
40+
}
41+
42+
/**
43+
* The other entity involved in the contact.
44+
*/
45+
public EntityRef getOtherEntity() {
46+
return otherEntity;
47+
}
48+
49+
/**
50+
* Returns the {@link Contact} from the physics engine, which contains the information about the contact. This
51+
* should be modified if any aspect of the contact should be changed before it is processed by the physics engine.
52+
*/
53+
public Contact getContact() {
54+
return contact;
55+
}
56+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2020 The Terasology Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.destinationsol.events;
17+
18+
import com.badlogic.gdx.math.Vector2;
19+
import org.terasology.gestalt.entitysystem.event.Event;
20+
21+
/**
22+
* Event that represents a continuous force applied to an entity, like gravity. This does NOT represent anything
23+
* that is a sudden, instantaneous force, like a collision. That type of occurrence is handled by {@link ImpulseEvent}.
24+
* This event is repeatedly sent as long as the force still affects the entity.
25+
* <p>
26+
* This event is sent every timestep for as long as the entity is being affected by the force.
27+
*/
28+
public class ForceEvent implements Event {
29+
30+
private Vector2 force;
31+
32+
public ForceEvent(Vector2 force) {
33+
this.force = force;
34+
}
35+
36+
/**
37+
* The force applied to the entity.
38+
*/
39+
public Vector2 getForce() {
40+
return force;
41+
}
42+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2020 The Terasology Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.destinationsol.events;
17+
18+
import com.badlogic.gdx.math.Vector2;
19+
import com.badlogic.gdx.physics.box2d.Contact;
20+
21+
/**
22+
* Event that represents the magnitude of a sudden, instantaneous force applied to an entity, like the impact of a
23+
* collision. This is only used for calculating damage. This does NOT handle the movement caused - that is handled
24+
* internally by libGDX, and can be modified by a system altering the {@link Contact} in a {@link ContactEvent}.
25+
* <p>
26+
* This does not represent anything that is an application of continuous force, like gravity. That type of occurrence
27+
* is handled by {@link ForceEvent}.
28+
*/
29+
public class ImpulseEvent {
30+
31+
private Vector2 contactPosition;
32+
private float magnitude;
33+
34+
public ImpulseEvent(Vector2 contactPosition, float magnitude) {
35+
this.contactPosition = contactPosition;
36+
this.magnitude = magnitude;
37+
}
38+
39+
/**
40+
* The position where the contact happened.
41+
*/
42+
public Vector2 getContactPosition() {
43+
return contactPosition;
44+
}
45+
46+
/**
47+
* The magnitude of the impulse that was applied to the entity (used for calculating damage).
48+
*/
49+
public float getMagnitude() {
50+
return magnitude;
51+
}
52+
53+
}

0 commit comments

Comments
 (0)