Commits

Mikhail Sidorov committed 35847b6

Initial commit

Comments (0)

Files changed (5)

+syntax: glob
+
+ns.js
+cp.min.js
+*.orig
Added
New image
+<!DOCTYPE html>
+
+<html>
+
+<head>
+	<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
+	<title>ns</title>
+	<script src="http://jawsjs.com/jawsjs/jaws.js"></script>
+	<style type="text/css">
+		body {
+			background-color: #000;
+		}
+	</style>
+</head>
+
+<body>
+	<canvas id="canvas" width="640" height="480"></canvas>
+	<!-- <br /><script src="levels.js"></script> -->
+	<script src="cp.min.js"></script>
+	<script src="ns.js"></script>
+</body>
+
+</html>
+level =
+    ball: {x: 60, y: 100}
+    
+    gradient: [[0, "#304"], [1, "#503"]]
+    
+    static:
+        [
+            [[0, 480], [640, 480], [640, 400], [0, 400]]
+            [[0, 0], [0, 480], [30, 480], [30, 0]]
+            [[0, 180], [100, 170], [100, 160], [95, 150], [85, 140], [30, 130]]
+            [[0, 130], [0, 420], [80, 420], [50, 140]]
+            [[30, 200], [30, 420], [170, 420]]
+            [[30, 300], [30, 420], [250, 420]]
+            [[340, 420], [500, 420], [450, 370], [390, 380]]
+            [[500, 420], [750, 420], [750, 360]]
+        ]
+    
+    dynamic:
+        []
+
+class Ball extends jaws.Sprite
+    constructor: (x, y, space) ->
+        super
+            image: "images/ball.png"
+            x: x
+            y: y
+            anchor: "center"
+        @torque = 20000
+        @body = new cp.Body(1, cp.momentForCircle(1, 0, @width / 2, cp.vzero))
+        @body.setPos(cp.v(x, y))
+        @body.w_limit = 300
+        @shape = new cp.CircleShape(@body, @width / 2, cp.vzero)
+        @shape.setFriction(1)
+        space.addBody(@body)
+        space.addShape(@shape)
+    
+    update: ->
+        @x = @body.p.x
+        @y = @body.p.y
+
+class StaticPlatform
+    constructor: (@verts, space) ->
+        body = new cp.Body(Infinity, Infinity)
+        @shape = new cp.PolyShape(body, [].concat(@verts...), cp.vzero)
+        @shape.setFriction(1)
+        space.addStaticShape(@shape)
+    
+    draw: ->
+        jaws.context.beginPath()
+        jaws.context.fillStyle = "black"
+        jaws.context.lineTo(x, y) for [x, y] in @verts
+        jaws.context.closePath()
+        jaws.context.fill()
+
+class GameState
+    constructor: ->
+        @gradient = jaws.context.createLinearGradient(0, 0, 0, jaws.height)
+        @gradient.addColorStop(pos, color) for [pos, color] in level.gradient
+        
+        @space = new cp.Space()
+        @space.gravity = cp.v(0, 900)
+        
+        @ball = new Ball(level.ball.x, level.ball.y, @space)
+        @static = (new StaticPlatform(verts, @space) for verts in level.static)
+    
+    update: ->
+        if jaws.pressed("left") then @ball.body.t = -@ball.torque
+        else if jaws.pressed("right") then @ball.body.t = @ball.torque
+        else @ball.body.t = 0
+        @space.step(1 / 60)
+        @ball.update()
+    
+    draw: ->
+        jaws.context.fillStyle = @gradient
+        jaws.context.fillRect(0, 0, jaws.width, jaws.height)
+        @ball.draw()
+        platform.draw() for platform in @static
+
+window.onload = ->
+    jaws.assets.add("images/ball.png")
+    jaws.start(GameState)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.