@@ -12,312 +12,15 @@ Some things to consider before using Lunar.
1212* Lunar is still being worked on and is nowhere near finished.
1313* Development will slow overtime but will eventually pick back up.
1414
15- Thank you for using Lunar.
15+ # Tutorial
1616
17- # Lunar Tutorial
17+ Looking for a simple tutorial on getting started with Lunar? Check out the [ wiki ] ( https://github.com/Vrekt/Lunar/wiki ) .
1818
19- Lets begin!
19+ # Community
2020
21- The ` Game ` class is where everything in your project starts. It houses the gameloop, window preferences, and much more .
22- Lets start by creating new instance of ` Game ` .
21+ Lunar currently has an official discord you can join [ here ] ( https://discord.gg/UTStd6 ) .
22+ Feel free to join and ask about anything related to Lunar .
2323
24- ``` java
25- Game game = new Game (title, width, height, tickRate);
26- Game game = new Game (title, width, height, GameState , tickRate);
27- Game game = new Game (String title, int width, int height, FramePreferences pref, int tickRate);
28- Game game = new Game (String title, int width, int height, FramePreferences pref, GameState state, int tickRate)
29- ```
24+ # Contributing
3025
31- * ` title ` is the title of the window.
32- * ` tickRate ` is the rate at which the game runs. Something good as a default is ` 60 ` .
33- * ` GameState ` is the default GameStart to start with, this is so you dont have to push one to the stack later.
34- * ` FramePreferences ` is an object which holds all settings for the window.
35-
36- Now we need to 'start' the game.
37- Simply do ` game.start(); ` to start the game.
38-
39- # Game States
40-
41- GameStates are the base of your project. This is where you will store everything preferably.
42- Things like worlds, entities, etc are stored here. GameStates also include two methods:
43- * ` onDraw(Graphics graphics); ` handles drawing things, not automatically though. Its up to you to handle what to call.
44- For example in the constructor of the drawing method you would draw the world.
45-
46- * ` onTick(); ` handles updating things, stuff like entities, maybe the time, etc. This is also not automatic, its up to you.
47- For example in the constructor of the tick method you would update the world and its entities.
48-
49- GameStates also include a priority field. This is the order in which GameStates are called.
50- If I had a GameState with a priority of 0, its getting called first. If I had another GameState with a priority of 3,
51- then everything before that is called first. This is useful for if your GameState isnt as important and doesn't need to be called
52- frequently.
53-
54- Here is an example of a basic GameState.
55-
56- ``` java
57- public class MainState extends GameState {
58- private Player myPlayer;
59- private MyWorld world;
60-
61- public MainState (int priority ) {
62- super (priority);
63-
64- myPlayer = new Player (params);
65- world = new MyWorld (" world1" , 600 , 400 );
66- world. addEntity(player);
67-
68- }
69-
70- @Override
71- public void onDraw (Graphics graphics ) {
72- world. onDraw(graphics);
73- }
74-
75- @Override
76- public void onTick () {
77- player. updateEntity();
78- world. onTick();
79- }
80- }
81- ```
82-
83- # Entities
84- Entities are 'things'. For example this can be a player, monster or for example a chest, item, etc.
85- But living things are defined differently, you don't define them with the entity class.
86- For living things there is ` LivingEntity ` .
87-
88- Entities have the option for sprites/textures.
89- It's not always needed but for living things its required.
90- Lets create a simple player object.
91-
92- ``` java
93- public class MyPlayer extends LivingEntity {
94- public MyPlayer (int x , int y , int width , int height , int entityID , float health , double speed ) {
95- super (x, y, width, height, entityID, health, speed);
96- }
97-
98- /**
99- * Lets draw a simple red box that represents our player.
100- */
101- @Override
102- public void drawEntity (Graphics graphics ) {
103- graphics. setColor(Color . red);
104- graphics. fillRect(x, y, width, height);
105- }
106-
107- @Override
108- public void updateEntity () {
109- // update the entity, for example handle movement, collisions, etc.
110- }
111- }
112- ```
113-
114- Lets go over the params.
115- * ` x ` , ` y ` is the starting coordinates of the player.
116- * ` width ` , ` height ` is the dimensions of the player.
117- * ` entityID ` is the unique ID of the entity. Useful for finding entities, filtering them, etc.
118- * ` health ` is the health of the player.
119- * ` speed ` is how fast the player should move.
120-
121- # Sound
122- Playing sounds is very easy.
123- First start we must create a new ` Sound ` object.
124-
125- ``` java
126- Sound mySound = new Sound (int ID , File audioFile);
127- ```
128- * ` ID ` is the ID of the sound.
129- * ` audioFile ` is the file which contains the audio.
130-
131- Now to play our sound we must create new instance of SoundManager. Its best to have already created one and stored it.
132-
133- ``` java
134- mySoundManager. playAudio(mySound);
135- ```
136-
137- If creating a new Sound object is not feasible you can just use:
138- ``` java
139- mySoundManager. playAudio(audioFile);
140- ```
141-
142- Stopping the playback is easy too.
143- ``` java
144- mySoundManager. stopPlayingSound(sound);
145- ```
146-
147- # Input
148- Lunar provides mouse and keyboard support.
149-
150- To see if a key is pressed do:
151- ``` java
152- InputListener . isKeyPressed(KeyEvent . KEY );
153- ```
154-
155- Checking if the mouse is down is simple too.
156- ``` java
157- MouseInput . isMouseDown();
158- ```
159- Getting the point of the last click goes like this:
160- ``` java
161- MouseInput . getLastClick();
162- ```
163-
164- # Worlds
165- Worlds are essential for handling entities, tiles, etc.
166- Lets create a new World.
167-
168- ``` java
169- public class MyWorld extends World {
170-
171- public MyWorld (String name , int width , int height ) {
172- super (name, width, height);
173- }
174-
175- @Override
176- public void onDraw (Graphics graphics ) {
177-
178- }
179-
180- @Override
181- public void onTick () {
182-
183- }
184- }
185- ```
186- * ` name ` is the name of the world.
187- * ` width ` , height is the dimensions of it.
188-
189- The World class holds many useful methods.
190- These include:
191- * adding/removing entities.
192- * Drawing all entities/tiles at once.
193- * etc.
194-
195- # Tiles/Sprites
196- Tiles are also essential for the game.
197- Tiles hold many values which gives it characteristics.
198- These include the unique ID, texture, dimensions, if its solid, etc.
199-
200- Lets start by creating a new tile with a custom texture.
201- First we must load our SpriteSheet.
202-
203- ``` java
204- SpriteManager sm = new SpriteManager (SpriteManager . load(" pathToSheet.png" ));
205- ```
206-
207- Now we can get our custom texture. My texture is at 0, 0 and its 64x64.
208- ``` java
209- BufferedImage myTexture = sm. getSectionAt(0 , 0 , 64 , 64 );
210- ```
211-
212- Now lets create the tile.
213- ``` java
214- Tile tile = new Tile (myTexture, 0 , true );
215- ```
216-
217- Now we have a tile with the ID 0 and our custom texture we loaded.
218- If we want to store all our tiles we can use the ` AssetManager ` .
219- ``` java
220- AssetManager am = new AssetManager ();
221- ```
222-
223- Lets store our tile:
224-
225- ``` java
226- am. addTile(tile);
227- ```
228-
229- # Animations
230- The AnimationManager handles the animations.
231-
232- Lets create a new SpriteManager with our character spritesheet.
233-
234- ``` java
235- private SpriteManager characters = new SpriteManager (
236- SpriteManager . load(" C:\\ Users\\ Vrekt\\ Desktop\\ characters.png" ));
237- ```
238-
239- Now we can start, lets create an animation for each direction.
240-
241- ``` java
242- private Animation up;
243- private Animation down;
244- private Animation left;
245- private Animation right;
246- ```
247-
248- Now with the SpriteManager we can put the getMultipleSprites method to use.
249-
250- ``` java
251- BufferedImage [] bup = characters. getMultipleSprites(0 , 96 , 32 , 32 , Direction . RIGHT , 3 );
252- BufferedImage [] bdown = characters. getMultipleSprites(0 , 0 , 32 , 32 , Direction . RIGHT , 3 );
253- BufferedImage [] bleft = characters. getMultipleSprites(0 , 32 , 32 , 32 , Direction . RIGHT , 3 );
254- BufferedImage [] bright = characters. getMultipleSprites(0 , 64 , 32 , 32 , Direction . RIGHT , 3 );
255- ```
256-
257- Now we can initialize the Animations.
258-
259- ``` java
260- up = new Animation (bup, 20 , true , 0 );
261- down = new Animation (bdown, 20 , true , 1 );
262- left = new Animation (bleft, 20 , true , 2 );
263- right = new Animation (bright, 20 , true , 3 );
264- ```
265-
266- Lets add them to a list.
267-
268- ``` java
269- List<Animation > animations = new ArrayList<Animation > ();
270- animations. add(up);
271- animations. add(down);
272- animations. add(left);
273- animations. add(right);
274- ```
275-
276- Finally lets initialize the AnimationManager with the animations.
277-
278- ``` java
279- am = new AnimationManager (animations);
280- ```
281-
282- In our player class we have a field named 'playerDirection' which keeps track of which way the player is facing, lets use this for our animation.
283-
284- ``` java
285- Direction d = player. getDirectionFacing();
286- ```
287-
288- Now what we can do is start an animation based on which way we are facing.
289-
290- ``` java
291- am. startAnimation(d == Direction . UP ? up : d == Direction . DOWN ? down : d == Direction . LEFT ? left : right);
292- ```
293-
294- Now lets draw the current frame of the animation.
295-
296- ``` java
297- am. getCurrentPlayingAnimation(). drawCurrentFrame(graphics, player. getX(), player. getY());
298- ```
299-
300- Now in our tick method we can update the animation.
301-
302- ``` java
303- if (am. getCurrentPlayingAnimation() != null ) {
304- am. getCurrentPlayingAnimation(). updateAnimation();
305- }
306- ```
307-
308- # Using the Capture utility.
309- The Capture class provides easy access to getting screenshots.
310- To screenshot do:
311-
312- ``` java
313- Capture . screenshotAndSave(int width, int height, File saveTo, String imageType);
314- ```
315- * ` imageType ` is the extension, for example .png. bmp.
316-
317- This screenshots then it saves it.
318-
319- Say we don't wanna screenshot the whole screen for that we can use ` screenshotPart ` .
320-
321- ``` java
322- Capture . screenshotPart(int x, int y, int width, int height);
323- ```
26+ When contributing and submitting requests for your changes to be merged please make sure to test your code and leave a note if the wiki needs to be updated!
0 commit comments