contrib/tinks: add VR
[nit.git] / contrib / tinks / src / client / assets.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Client `Assets` and client-only services on game elements
16 module assets is no_warning("attr-in-refinement")
17
18 import app::audio
19
20 import game
21
22 import drawing
23
24 redef class App
25 redef fun load_image(path)
26 do
27 var img = super
28 img.scale = 0.5
29 return img
30 end
31 end
32
33 redef class FeatureRule
34 # Images of different alternatives
35 var images: Array[Image]
36 end
37
38 redef class TankRule
39 # Image of the base tank structure, at different health level
40 var base_images: Array[Image]
41
42 # Image of the turret
43 var turret_image: Image
44 end
45
46 redef class Feature
47 # Rotation angle of this feature
48 var angle: Float = pi.rand
49
50 # Index within `rule.images` of the image of this instance
51 var image_index: Int = rule.images.length.rand is lazy
52 end
53
54 # Collection of assets
55 class Assets
56
57 # Images from the `art/drawing.svg` file
58 var drawing = new DrawingImages
59 init do drawing.load_all(app)
60
61 # Firing sound
62 var turret_fire = new Sound("sounds/turret_fire.wav")
63
64 # Turret is ready to fire sound
65 var turret_ready = new Sound("sounds/turret_ready.mp3")
66
67 # Associate images to the `story` rules
68 fun assign_images_to_story(story: Story)
69 do
70 story.tree.images = drawing.trees
71 story.rock.images = drawing.rock
72 story.debris.images = drawing.debris
73
74 for tank in story.tanks do
75 tank.base_images = drawing.tank_hit
76 tank.turret_image = drawing.turret
77 end
78
79 story.health.images = [drawing.health]
80 end
81 end