# March 29
Features need to support:
- Notify view when new level started
- Allow controller to set specific level.
Implementation stuff:
- Actions are general and can be called from different triggers,
(i.e clicks, inputs, collisions)
TODO:
- Think about where callbacks for collisions go.
- Configuration file more
- Start thinking about usecases (user clicks start game etc.)
- What APIs would be needed
What want to do:
Jiyang: ECS
Oliver: Configuration
Robert: Model, callbacks n stuff
Liam: Entity Components
Tinglong: Controller
Josh: View stuff
Includes passing the new gameobjects for that level.
```java=
public interface ObservableModel {
+ setOnNewLevel(Consumer<Level> newLevel)
+ setOnNewObject(Consumer<GameObject> object)
+ getController();
}
public interface Level {
+ getObservableObjects() : List<ObservableObjects>
+ getname: String
+ getLevelID: number
}
// What the controller... controls.
public interface Model {
+ nextLevel()
+ setLevel(int);
}
class ConcreteModel {
- int currLevel;
// Level objects created during construction
nextLevel() {
currLevel++;
setLevel(curLevel)
}
setLevel(currLevel) {
currentLevelObject = levels.get(currLevel);
notifynewLevel(currentLevelObject);
}
}
interface Level {
- Configuration config;
- String name;
- int levelNumber;
}
model.setOnNewLevel( e -> {
this.gameObjects = e.getObservabsakfnaObects();
reset();
})
```
```java=
public class View {
ObservableModel model = ModelFactory.createModel();
ModelController con = model.getController();
}
public class ModelController {
- Model
private Map<String, List<Function>> callbacks;
private Map<KeyCode, String> keymaps;
handlePress(KeyEvent e) {
String name = keymaps.get(e.keyCode());
List<Function> c = callbacks.get(name);
for (var cc : c) {
cc.execute();
}
}
}
public class SPAWN_HANDLER {
public GameObject Spawn(String item) {
return new GameObject(item);
}
}
public class GameObject {
public GameObject {
}
}
```
Configuration
```json=
{
game : {
camera : fixed,
levels : [ 1, 2, 3]
}
levels: [
{
name: "nameas",
id: 125412
gravity : 1
objects: [
{
x: 20,
y: 30,
id: 2
}
]
}
]
objects: [
{
name: "JJAISDfgahsdigfa",
id: 2,
height: 300,
width: 0214021,
"components": [
{
compName: "blahblah"
},
{
compName: "RectangleCollider",
offset: [0, 0],
width: 300,
height: 400
onCollide: [
]
},
{
compName: "CircleCollider",
offset: [10, 0],
radius: 10
}
],
onCollide: [
{
position: "top",
payload: "fireGun"
}
]
visible: false;
}
]
}
```
Model says uh oh u hit a thing danggg homie
obj1.collide(obj2);
obj2.collide(obj1);
```java=
public void mian collide(GameObject obj) {
hitX = obj.getX();
hitY = obj.getY();
}
```
```json=
{
"controls" : [
{
"KEYCODE" : "SPACE",
"controls" : {
"ON_PRESS" : {
"payload": "spawn object"
}
}
]
type: "bullet",
...
onCollide: [
{
with: "enemy",
location: "south",
action: "jump"
}
{
with: "any",
location: "south",
action: "st"
}
]
"bullet" : {
INIT_VELOCITY = 20
X = 0
y = 0
}
}
```
or
```json
{
"controls" : [
{
"KEYCODE" : "SPACE",
"controls" : {
"ON_PRESS" : {
"handler": "Player.ShootBullet",
"args": [
"position": Player.getPosition,
"direction": Player.getOrientation
]
}
}
}
]
}
```
```json=
{
type: "cahracte",
inputs: [
{
keycode: "A",
action: "firebullet",
}
}
```