1 module field;
2 
3 import unecht;
4 
5 ///
6 final class Field : UEComponent
7 {
8     mixin(UERegisterObject!());
9     
10     static immutable x = 15;
11     static immutable z = 10;
12     static immutable h = 2;
13 
14     @Serialize
15     private UEEntity borderUp;
16     @Serialize
17     private UEEntity borderBotton;
18     @Serialize
19     private UEEntity borderLeft;
20     @Serialize
21     private UEEntity borderRight;
22     
23     override void onCreate() {
24         super.onCreate;
25         
26         if(borderUp is null)
27             borderUp = createBorder(false, vec3(0,h/2,-z), vec3(x,h,1));
28         if(borderBotton is null)
29             borderBotton = createBorder(false, vec3(0,h/2,z), vec3(x,h,1));
30         if(borderRight is null)
31             borderRight = createBorder(true, vec3(-x-1.1f,h/2,0), vec3(1,h,z));
32         if(borderLeft is null)
33             borderLeft = createBorder(true, vec3(x+1.1f,h/2,0), vec3(1,h,z));
34     }
35     
36     UEEntity createBorder(bool _outside, vec3 _pos, vec3 _size)
37     {
38         auto name = "border";
39         if(_outside)
40             name ~="-out";
41         
42         auto newE = UEEntity.create(name,sceneNode);
43         newE.sceneNode.position = _pos;
44         newE.sceneNode.scaling = _size;
45         auto shape = newE.addComponent!UEShapeBox;
46         newE.addComponent!UEPhysicsColliderBox;
47         if(!_outside)
48         {
49             newE.getComponent!(UEMaterial).uniforms.setColor(vec4(0,1,0,1));
50             
51             auto material = newE.addComponent!UEPhysicsMaterial;
52             material.materialInfo.bouncyness = 1.0f;
53             material.materialInfo.friction = 0;
54         }
55 
56         return newE;
57     }
58 
59     bool isLeft(UEEntity entity)
60     {
61         return entity is borderLeft;
62     }
63 }