Permalink
Browse files

Make planets not intersect with one another.

This is done with collision detection and random movement.
  • Loading branch information...
1 parent 82e81c2 commit 2f248dae4aa3a756857cf7a5f68c2558109a9a49 @imbstack committed Jan 14, 2012
View
@@ -27,7 +27,7 @@ <h1 class="main">BITSpace | <small>AI based game</small></h1>
attached. In addition, you create a commander AI that sets a general strategy for
your force. Click below to try it out.
</p>
- <a href="/play.html">Play the Game!</a>
+ <a href="/play.html">Go to the Game!</a>
<a href="/learn.html">How To</a>
</div>
<footer>
View
@@ -19,15 +19,37 @@
<div id="home">
<h1>BITSpace | <small>AI based game</small></h1>
<span class="action play">Play</span>
+ <span class="action setup">Fleet</span>
<span class="action options">Options</span>
<a href="/">Go to index</a>
</div>
+
<div id="options" style="display:none">
+ <h1>BITSpace | <small>AI based game</small></h1>
+ <span class="action home">Home</span>
+ <h2>Options</h2>
<p>
Options and more options
</p>
+ </div>
+
+ <div id="setup" style="display:none">
+ <h1>BITSpace | <small>AI based game</small></h1>
<span class="action home">Home</span>
+ <h2>Setup</h2>
+ <ol class="menu left">
+ <li class="equip" draggable="true">CRUISER</li>
+ <li class="equip" draggable="true">FRIGATE</li>
+ <li class="equip" draggable="true">FRIGATE</li>
+ <li class="equip" draggable="true">CRUISER</li>
+ <li class="equip" draggable="true">DESTROYER</li>
+ <li class="equip" draggable="true">CRUISER</li>
+ <li class="equip" draggable="true">SUPPORT</li>
+ </ol>
+ <ol class="menu right">
+ </ol>
</div>
+
<div id="play" style="display:none"></div>
</div>
</body>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -21,6 +21,7 @@ class Game
home = $("#home")
play = $("#play")
options = $("#options")
+ setup = $("#setup")
canvas = $("<canvas id='game' width=#{@width} height=#{@height}></canvas>")
play.append(canvas)
@@ -36,11 +37,22 @@ class Game
options.show()
)
+ home.find(".setup").click( ->
+ home.hide()
+ setup.show()
+ )
+
options.find(".home").click( ->
options.hide()
home.show()
)
+ setup.find(".home").click( ->
+ setup.hide()
+ home.show()
+ )
+
+
start: ->
console.log "Loading assets..."
jaws.assets.add(Planet.assets)
@@ -1,12 +1,19 @@
class Planet extends jaws.Sprite
-
+
+ @MAX_RADIUS = 50
+ @PLANET_COUNT = 0
@assets = ["resources/images/planet.png"]
- constructor: (x, y, @radius) ->
+ constructor: (x, y, @radius, @state) ->
+ @id = Planet.PLANET_COUNT++
super({image: "resources/images/planet.png", x: x, y: y, anchor: "center"})
+ @scaleTo(@radius/Planet.MAX_RADIUS)
+ scatterX = if Math.random() > 0.5 then 1 else -1
+ scatterY = if Math.random() > 0.5 then 1 else -1
+ while jaws.collideOneWithMany(this, @state.planets).length != 0
+ @move(10 * scatterX, 10 * scatterY)
update: ->
- @move(0.5,0.5)
module.exports = Planet
@@ -8,11 +8,11 @@ class PlayState
@planets = new jaws.SpriteList()
- for num in [0..3]
- r = 20 + 40 * Math.random()
+ for num in [1..20]
+ r = 20 + (Planet.MAX_RADIUS - 20) * Math.random()
x = Math.floor(Math.random() * (game.width))
y = Math.floor(Math.random() * (game.height))
- @planets.push( new Planet x,y,r )
+ @planets.push( new Planet(x,y,r,this))
@viewport = new jaws.Viewport({max_x: 50000, max_y: 50000})
View
@@ -70,6 +70,30 @@ footer {
}
}
+
+.menu {
+ border: 2px dotted @text;
+ min-height: 400px;
+}
+
+.left {
+ width: 45%;
+ float: left;
+}
+
+.right {
+ width: 45%;
+ float: right;
+}
+
+.equip {
+ height: 40px;
+ line-height: 40px;
+ padding-left: 10px;
+ margin: 7px;
+ border: 3px solid @text;
+}
+
#game {
}

0 comments on commit 2f248da

Please sign in to comment.