Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Tank battle
Farzad Nozarian - Vahid Ranaei
Amirkabir university of technology
References
Problem Definition
Tank Movement
Android Devices
 Orientation Sensors
Desktops
 ‘WASD’ Control Keys
VS.
Problem Definition
Tank Movement/Android Devices
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.se...
Problem Definition
Tank Movement/Desktop Devices
inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_H));
inputMa...
Problem Definition
Tank Movement/Desktop Devices
onAction
handler
if (binding.equals("Ups")) {
if (value) {
accelerationVa...
Problem Definition
Tank Movement
Some Abstractions
Fire
Move Forward (Accelerate)
Move Around (Steer)
…
Problem Definition
Tank Movement
vehicle.steer(steeringValue)
vehicle.accelerate(accelerationValue)
applyImpulse
resetSusp...
Pattern Definition
• Decouple an abstraction from its implementation so that
the two can vary independently
• When abstrac...
Pattern Definition
Pattern Solution
Bridge
Problem Definition
Tank Shooting
Shooting In Real World !
Burst mode
Selective fire
Automatic firearm
Bump firing
Same ‘Fi...
Pattern Definition
Tank Shooting
• Many related classes differ only in their behavior
• We need different variant of algor...
Pattern Solution
Strategy
Problem Definition
World of Complexity!
Geometry
polygon mesh
material
specifying its shape
color
texture
opacity/transpar...
Problem Definition
World of Complexity!
Spatial
Purpose:
Abstract data structure that stores user data and transformations...
Pattern Definition
World of Complexity!
• Compose objects into tree structures to represent part-
whole hierarchies
• Clie...
Pattern Solution
World of Complexity!
Problem Definition
Family of Game Entities
Problem Definition
game configuration
Bunch of configurations !!
:
Problem Definition
game configuration
public static class UserBuilder {
private final String firstName;
private final Stri...
Problem Definition
game configuration
public class Configuration {
private int displayResolution;// display resolution
pri...
Problem Definition
game configuration
But it is not all of it ..
Problem Definition
game configuration
Builderton pattern !? :o
Problem Definition
game configuration
public class Configuration {
private static Configuration c;
private int displayReso...
To Be Continue …
Upcoming SlideShare
Loading in …5
×

Tank Battle - A simple game powered by JMonkey engine

461 views

Published on

A simple two player java-based game powered by JMonkey game engine which implements many standard object oriented design patterns such as Singleton, Composite, Strategy and etc.

Published in: Education
  • Login to see the comments

  • Be the first to like this

Tank Battle - A simple game powered by JMonkey engine

  1. 1. Tank battle Farzad Nozarian - Vahid Ranaei Amirkabir university of technology
  2. 2. References
  3. 3. Problem Definition Tank Movement Android Devices  Orientation Sensors Desktops  ‘WASD’ Control Keys VS.
  4. 4. Problem Definition Tank Movement/Android Devices public void onSensorChanged(SensorEvent sensorEvent) { if (sensorEvent.sensor.getType() == Sensor.TYPE_ORIENTATION) { float headingAngle = sensorEvent.values[0]; float pitchAngle = sensorEvent.values[1]; float rollAngle = sensorEvent.values[2]; // TODO Apply the orientation changes to your application. } }
  5. 5. Problem Definition Tank Movement/Desktop Devices inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_H)); inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_K)); inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_U)); inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_J)); inputManager.addListener(this, "Lefts"); inputManager.addListener(this, "Rights");
  6. 6. Problem Definition Tank Movement/Desktop Devices onAction handler if (binding.equals("Ups")) { if (value) { accelerationValue -= 800; } else { accelerationValue += 800; } player.accelerate(accelerationValue); } else if (binding.equals("Rights")) { if (value) { steeringValue += -.5f; } else { steeringValue += .5f; } player.steer(steeringValue); }
  7. 7. Problem Definition Tank Movement Some Abstractions Fire Move Forward (Accelerate) Move Around (Steer) …
  8. 8. Problem Definition Tank Movement vehicle.steer(steeringValue) vehicle.accelerate(accelerationValue) applyImpulse resetSuspension setPhysicsLocation setPhysicsRotation setLinearVelocity
  9. 9. Pattern Definition • Decouple an abstraction from its implementation so that the two can vary independently • When abstractions and implementations should be extensible through subclassing Bridge!
  10. 10. Pattern Definition
  11. 11. Pattern Solution Bridge
  12. 12. Problem Definition Tank Shooting Shooting In Real World ! Burst mode Selective fire Automatic firearm Bump firing Same ‘Fire’ Different Behaviors ?!
  13. 13. Pattern Definition Tank Shooting • Many related classes differ only in their behavior • We need different variant of algorithm • We need run-time shooting variation
  14. 14. Pattern Solution Strategy
  15. 15. Problem Definition World of Complexity! Geometry polygon mesh material specifying its shape color texture opacity/transparency
  16. 16. Problem Definition World of Complexity! Spatial Purpose: Abstract data structure that stores user data and transformations (= translation, rotation, scale) of elements of the 3D Geometry Node Visibility: visible 3D object invisible "handle" for a group of Spatials Purpose: represent an object's look structure and group Geometries and other Nodes Examples: Box, sphere, player, building, terrain, vehicle, missiles … rootNode, audioNode, vehicleNode or shipNode with passengers attached, etc.
  17. 17. Pattern Definition World of Complexity! • Compose objects into tree structures to represent part- whole hierarchies • Clients treat individual objects and compositions of objects uniformly • We want clients to be able to ignore the difference between compositions of objects and individual objects
  18. 18. Pattern Solution World of Complexity!
  19. 19. Problem Definition Family of Game Entities
  20. 20. Problem Definition game configuration Bunch of configurations !! :
  21. 21. Problem Definition game configuration public static class UserBuilder { private final String firstName; private final String lastName; .. public UserBuilder(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } public UserBuilder age(int age) { this.age = age; return this; } .. public User build() { return new User(this); } } } public class User { private final String firstName; // required private final String lastName; // required private final int age; // optional private final String phone; // optional private final String address; // optional private User(UserBuilder builder) { this.firstName = builder.firstName; this.lastName = builder.lastName; .. } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public user getUser(){ return new User.UserBuilder(‘John’,’Doe’) .age(30) .phone(‘3235345) .address(‘’Fake address 33) .build();
  22. 22. Problem Definition game configuration public class Configuration { private int displayResolution;// display resolution private int displayMode;// full screen? private int soundVolume;//Sound volume private int musicVolume; //Music volume //.... private Configuration(ConfigBuilder builder) { this.displayResolution = builder.displayResolution; this.displayMode = builder.displayMode; .. } public int getDisplayResolution() { return displayResolution; } public int getDisplayMode() { return displayMode; } .. public static class ConfigBuilder{ private int displayResolution=0;// display resolution private int displayMode=0;// full screen? private int soundVolume=0;//Sound volume private int musicVolume=0; //Music volume //.... public ConfigBuilder displayResolution(int dr) { this.displayResolution = dr; return this; } public ConfigBuilder displayMode(int dm) { this.displayMode = dm; return this; } .. public Configuration build(){ return new Configuration(this); } } }
  23. 23. Problem Definition game configuration But it is not all of it ..
  24. 24. Problem Definition game configuration Builderton pattern !? :o
  25. 25. Problem Definition game configuration public class Configuration { private static Configuration c; private int displayResolution; // display resolution private int displayMode; // full screen? private int soundVolume; //Sound volume private int musicVolume; //Music volume //.... private Configuration(ConfigBuilder builder) { this.displayResolution = builder.displayResolution; this.displayMode = builder.displayMode; this.soundVolume = builder.soundVolume; this.musicVolume = builder.soundVolume; } public int getDisplayResolution() { return displayResolution; } public int getDisplayMode() { return displayMode; } … public static class ConfigBuilder{ private int displayResolution=0; private int displayMode=0; private int soundVolume=0; private int musicVolume=0; //.... public ConfigBuilder displayResolution(int dr) { this.displayResolution = dr; return this; } public ConfigBuilder displayMode(int dm) { this.displayMode = dm; return this; } … public Configuration build(){ if (c == null) { c=new Configuration(this); return c; } else return c; } } }
  26. 26. To Be Continue …

×