1+ <!DOCTYPE html>
12< html >
23 < head >
34 < meta charset ="utf-8 ">
45 < title > Map generation demo</ title >
5- < link rel ="stylesheet " href ="style.css ">
6+ < link rel ="stylesheet " href ="style.css " type =" text/css " >
67 </ head >
78 < body >
89 < div id ="main ">
@@ -30,36 +31,68 @@ <h1>Map generation<small> - work in progress</small></h1>
3031 [X] - Find rooms boundaries
3132 [X] - Find all possible pathes (from rooms virtual centers)
3233 [ ] - Create pathes between rooms
33- [ ] - Place random objects
34+ [X ] - Place random objects
3435 [X] - Render the map
3536</ pre >
3637 </ div >
3738
3839 < script src ="https://code.jquery.com/jquery-1.12.3.min.js " integrity ="sha256-aaODHAgvwQW1bFOGXMeX+pC4PZIPsvn2h1sArYOhgXQ= " crossorigin ="anonymous "> </ script >
3940 < script src ="../js/mapgen.js " type ="text/javascript "> </ script >
40- < script src ="../js/room_samples.js " type ="text/javascript "> </ script >
41- < script >
41+ < script src ="../js/mapgen-objects.js " type ="text/javascript "> </ script >
42+ < script src ="../js/mapgen-privates.js " type ="text/javascript "> </ script >
43+ < script src ="../js/mapgen-methods.js " type ="text/javascript "> </ script >
44+ < script src ="../js/demo_base_objects.js " type ="text/javascript "> </ script >
45+ < script src ="../js/demo_room_samples.js " type ="text/javascript "> </ script >
46+ < script type ="text/javascript ">
4247
4348 // Generating the map
44- var map = new MapGen ;
49+ var map = new MapGen ( { cellTypes : cellTypes , cleanLevel : 4 } ) ;
4550 map . createMap ( ) ;
46- //map.createMapFromSample(samples[0 ]);
51+ //map.createMapFromSample(samples[2 ]);
4752 map . createRooms ( ) ;
4853 map . removeSmallRooms ( 50 ) ;
54+
55+ /*
56+ "game" specific "mechanisms" here. This is not included in the class
57+ (beside of map.addItem())
58+ */
59+ // Creating ennemies, taking size of the map in account
60+ createEnnemies ( 'ennemy' , living_things . player . level , map . _getWalkableCells ( true ) . length ) ;
61+ createEnnemies ( 'boss' , living_things . player . level , null , 1 ) ;
62+ // Adding to the map
63+ map . addItems ( living_things , true ) ;
64+ // Creating life potions
65+ createSimpleItem ( 'life_potion' , map . _getWalkableCells ( true ) . length , 2 ) ;
66+ // Creating chests
67+ createSimpleItem ( 'token_strength' , map . _getWalkableCells ( true ) . length , 3 ) ;
68+ createSimpleItem ( 'token_damage' , map . _getWalkableCells ( true ) . length , 3 ) ;
69+ // Adding them to the map.
70+ map . addItems ( dead_things , false ) ; // Can even be in lava !
71+
72+ // Debug
73+ //map.outlineRooms();
4974 map . _findPaths ( ) ;
75+
76+ // Render the map
5077 map . jQueryRender ( '#grid' ) ;
5178
79+ /***************************************************************************
80+ Beside this point, it's only debugging things (room overlays, and paths essay)
81+
82+ */
83+ var cellSize = 14 ;
84+
5285 /*
5386 Rooms overlays... May be included in the class later...
5487 */
5588 for ( let i in map . rooms ) {
56- $ ( '#rooms' ) . append ( '<div class="' + map . cssPrefix + 'room ' + map . cssPrefix + 'room-' + map . rooms [ i ] . id + '-overlay" style="top:' + ( map . rooms [ i ] . box . yMin * 7 )
57- + 'px; left:' + ( map . rooms [ i ] . box . xMin * 7 )
58- + 'px; width :' + ( ( map . rooms [ i ] . box . xMax - map . rooms [ i ] . box . xMin + 1 ) * 7 )
59- + 'px; height :' + ( ( map . rooms [ i ] . box . yMax - map . rooms [ i ] . box . yMin + 1 ) * 7 )
89+ $ ( '#rooms' ) . append ( '<div class="' + map . cssPrefix + 'room ' + map . cssPrefix + 'room-' + map . rooms [ i ] . id + '-overlay" style="top:' + ( map . rooms [ i ] . box . xMin * cellSize )
90+ + 'px; left:' + ( map . rooms [ i ] . box . yMin * cellSize )
91+ + 'px; height :' + ( ( map . rooms [ i ] . box . xMax - map . rooms [ i ] . box . xMin + 1 ) * cellSize )
92+ + 'px; width :' + ( ( map . rooms [ i ] . box . yMax - map . rooms [ i ] . box . yMin + 1 ) * cellSize )
6093 + 'px"><h2>' + map . rooms [ i ] . id + '</h2>' + ( map . rooms [ i ] . box . xMax - map . rooms [ i ] . box . xMin ) + ' x ' + ( map . rooms [ i ] . box . yMax - map . rooms [ i ] . box . yMin ) + '<br>C: ' + map . rooms [ i ] . box . cX + ' x ' + map . rooms [ i ] . box . cY + '</div>' )
6194 }
62- $ ( '#grid' ) . prepend ( '<canvas id="' + map . cssPrefix + 'pathes" width="' + ( map . grid [ 0 ] . length * 7 ) + 'px" height="' + ( map . grid . length * 7 ) + 'px"></canvas>' ) ;
95+ $ ( '#grid' ) . prepend ( '<canvas id="' + map . cssPrefix + 'pathes" width="' + ( map . grid [ 0 ] . length * cellSize ) + 'px" height="' + ( map . grid . length * cellSize ) + 'px"></canvas>' ) ;
6396
6497 /*
6598 Drawing all pathes on the overlay. May be included later as a class function.
@@ -73,14 +106,14 @@ <h1>Map generation<small> - work in progress</small></h1>
73106 for ( let i = 0 ; i < map . distances . length ; i ++ ) {
74107 let idx1 = map . _getRoomIndex ( map . distances [ i ] [ 1 ] [ 0 ] ) ;
75108 let idx2 = map . _getRoomIndex ( map . distances [ i ] [ 1 ] [ 1 ] )
76- ctx . moveTo ( ( map . rooms [ idx1 ] . box . cX * 7 ) , ( map . rooms [ idx1 ] . box . cY * 7 ) ) ;
77- ctx . lineTo ( ( map . rooms [ idx2 ] . box . cX * 7 ) , ( map . rooms [ idx2 ] . box . cY * 7 ) ) ;
109+ ctx . moveTo ( ( map . rooms [ idx1 ] . box . cY * cellSize ) , ( map . rooms [ idx1 ] . box . cX * cellSize ) ) ;
110+ ctx . lineTo ( ( map . rooms [ idx2 ] . box . cY * cellSize ) , ( map . rooms [ idx2 ] . box . cX * cellSize ) ) ;
78111 }
79112 ctx . closePath ( ) ;
80113 ctx . stroke ( ) ;
81114
82115 /**
83- jQuery stuff to handle events
116+ jQuery stuff to handle events on buttons
84117 */
85118 $ ( '#rooms' ) . hide ( ) ;
86119 $ ( '#' + cId ) . hide ( ) ;
0 commit comments