diff --git a/mod-list.html b/mod-list.html
index 4f5b7b1d..00566e31 100644
--- a/mod-list.html
+++ b/mod-list.html
@@ -375,7 +375,7 @@
| randomness_but_tick.js | Random experimental elements using the tick function feature | Alice |
| randomness_but_tool.js | Random experimental elements using the tool function feature | Alice |
| randomness.js | Random experimental elements | Alice |
-| scenexe.js | Work-in-progress mod, renders and simulates a bunch of polygons | nousernamefound |
+| scenexe.js | Work-in-progress mod, allows you to move through a simulated field of polygons | nousernamefound |
| structure_test_2.js | Another test for implementing structures into Sandboxels (requires the previous test) | Alice |
| structure_test.js | A test for implementing structures into Sandboxels | Alice |
| test.js | A test mod that adds mayo :) | R74n |
diff --git a/mods/scenexe.js b/mods/scenexe.js
index 9fa9ac32..3b1b0a28 100644
--- a/mods/scenexe.js
+++ b/mods/scenexe.js
@@ -19,6 +19,46 @@ polygonColors = function(sides){
return {r: 0, g: 0, b: 0}
}
}
+isKeyDown = {
+ w: false,
+ a: false,
+ s: false,
+ d: false
+}
+// when wasd keydown, set isKeyDown to true
+document.addEventListener("keydown", (event) => {
+ if (event.key === "w") {
+ isKeyDown.w = true;
+ }
+ if (event.key === "a") {
+ isKeyDown.a = true;
+ }
+ if (event.key === "s") {
+ isKeyDown.s = true;
+ }
+ if (event.key === "d") {
+ isKeyDown.d = true
+ }
+})
+// when wasd keyup, set isKeyDown to false
+document.addEventListener("keyup", (event) => {
+ if (event.key === "w") {
+ isKeyDown.w = false;
+ }
+ if (event.key === "a") {
+ isKeyDown.a = false;
+ }
+ if (event.key === "s") {
+ isKeyDown.s = false;
+ }
+ if (event.key === "d") {
+ isKeyDown.d = false
+ }
+})
+orbitalSpeed = function(sides){
+ return 1/(1.00672*Math.pow(0.344151, sides) + 0.000002)
+}
+shapeNames = ["Triangle", "Square", "Pentagon", "Hexagon", "Heptagon", "Octagon", "Nonagon", "Decagon", "Hendecagon", "Dodecagon", "Triskaidecagon", "Tetrakaidecagon", "Pentakaidecagon", "Hexakaidecagon", "Heptakaidecagon", "Octakaidecagon", "Enneakaidecagon", "Icosagon", "literally just a circle"]
function polygonCount(random){
const thresholds = [0, 0.3, 0.68, 0.77, 0.82, 0.86, 0.88, 0.89, 0.895, 0.8975, 0.898, 0.8982, 1];
const values = [3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 3];
@@ -30,7 +70,7 @@ function polygonCount(random){
}
}
polygonList = []
-zoomLevel = .2
+zoomLevel = 1
polygonSize = function(sides){
return 18 * Math.pow(1.47, sides - 3)
}
@@ -45,6 +85,7 @@ for (var i = 0; i <= 400; i++){
vy: 0,
random: Math.random(),
rotation: Math.random() * 2 * Math.PI,
+ collisionMass: 3+(polygonSize(sides)**2)/6
})
}
function drawPolygon(ctx, polygon){
@@ -80,8 +121,24 @@ function drawPolygon(ctx, polygon){
ctx.lineTo(x+20*vx, y+20*vy)
ctx.strokeStyle = "rgb(255, 0, 0)"
ctx.stroke()
+ // draw some text to represent mass
+ ctx.lineWidth = 2
+ ctx.fillStyle = "rgb(255, 255, 255)"
+ ctx.strokeStyle = "rgb(0, 0, 0)"
+ ctx.font = `bold 30px Helvetica`
+ ctx.fillText(Math.round(polygon.collisionMass), x, y)
+ ctx.strokeText(Math.round(polygon.collisionMass), x, y)
*/
}
+function drawPlayer(ctx, player){
+ ctx.fillStyle = "rgb(63, 153, 255)"
+ ctx.strokeStyle = "rgb(33, 123, 225)"
+ ctx.lineWidth = 5*zoomLevel
+ ctx.beginPath()
+ ctx.arc(player.x, player.y, player.radius, 0, 2*Math.PI)
+ ctx.fill()
+ ctx.stroke()
+}
function zoom(ctx, poly, multiplier){
polyreturn = {...poly}
polyreturn.x = polyreturn.x * multiplier + ctx.canvas.width/2
@@ -89,56 +146,126 @@ function zoom(ctx, poly, multiplier){
polyreturn.radius = polyreturn.radius * multiplier
return polyreturn
}
+function applyCameraPos(ctx, object, x, y){
+ objectreturn = {...object}
+ objectreturn.x = objectreturn.x + x
+ objectreturn.y = objectreturn.y + y
+ return objectreturn
+}
+function cameraZoom(ctx, object, multiplier, camera){
+ objectreturn = {...object}
+ let x = camera[0]
+ let y = camera[1]
+ objectreturn.x = objectreturn.x * multiplier - x + ctx.canvas.width/2
+ objectreturn.y = objectreturn.y * multiplier - y + ctx.canvas.height/2
+ objectreturn.radius = objectreturn.radius * multiplier
+ return objectreturn
+}
+camera = [0, 0]
+scenexeplayer = {
+ x: 0,
+ y: 0,
+ vx: 0,
+ vy: 0,
+ rotation: 0,
+ radius: 40,
+ collisionMass: 520
+}
renderPostPixel(function(ctx){
ctx.fillStyle = "rgb(205, 205, 205)"
ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.strokeStyle = "rgb(200, 200, 200)"
ctx.lineWidth = 5*zoomLevel
- for (var i = 0; i < canvas.width; i += canvas.width/30*zoomLevel){
+ for (var i = 0; i < canvas.width; i += 20*zoomLevel){
ctx.beginPath()
- ctx.moveTo(i, canvas.height)
- ctx.lineTo(i, 0)
+ //ctx.moveTo(i, canvas.height)
+ //ctx.lineTo(i, 0)
+ // add offset depending on mod of camera
+ ctx.moveTo(i-camera[0]%20*zoomLevel, canvas.height)
+ ctx.lineTo(i-camera[0]%20*zoomLevel, 0)
ctx.stroke()
}
- for (var j = 0; j < canvas.height; j += canvas.width/30*zoomLevel){
+ for (var j = 0; j < canvas.height; j += 20*zoomLevel){
ctx.beginPath()
- ctx.moveTo(0, j)
- ctx.lineTo(canvas.width, j)
+ //ctx.moveTo(0, j)
+ //ctx.lineTo(canvas.width, j)
+ // add offset depending on mod of camera
+ ctx.moveTo(0, j-camera[1]%20*zoomLevel)
+ ctx.lineTo(canvas.width, j-camera[1]%20*zoomLevel)
ctx.stroke()
}
//drawPolygon(ctx, Math.round((pixelTicks/20)%13)+3, polygonSize(Math.round((pixelTicks/20)%13)+3), canvas.width/2, canvas.height/2, 0)
for (var poly = 0; poly < polygonList.length; poly++){
- drawPolygon(ctx, zoom(ctx, polygonList[poly], zoomLevel))
+ drawPolygon(ctx, cameraZoom(ctx, polygonList[poly], zoomLevel, camera))
}
- // polygon collision checking
- for (var poly = 0; poly < polygonList.length; poly++){
- for (var poly2 = 0; poly2 < polygonList.length; poly2++){
+ drawPlayer(ctx, cameraZoom(ctx, scenexeplayer, zoomLevel, camera))
+ // collidable collision checking
+ collideList = []
+ collideList = collideList.concat(polygonList)
+ collideList.push(scenexeplayer)
+ for (var poly = 0; poly < collideList.length; poly++){
+ for (var poly2 = 0; poly2 < collideList.length; poly2++){
if (poly != poly2){
- polygon1 = polygonList[poly]
- polygon2 = polygonList[poly2]
+ polygon1 = collideList[poly]
+ polygon2 = collideList[poly2]
distance = Math.sqrt((polygon1.x - polygon2.x)**2 + (polygon1.y - polygon2.y)**2)
- if (distance < polygonSize(polygon1.sides) + polygonSize(polygon2.sides)){
+ if (distance < polygon1.radius + polygon2.radius){
//calculate angle of collision
angle = Math.atan2(polygon2.y - polygon1.y, polygon2.x - polygon1.x)
// update velocity
- polygon1.vx -= (Math.cos(angle) * (polygonSize(polygon1.sides) + polygonSize(polygon2.sides) - distance)/2)/(3+polygonSize(polygon1.sides)/9)
- polygon1.vy -= (Math.sin(angle) * (polygonSize(polygon1.sides) + polygonSize(polygon2.sides) - distance)/2)/(3+polygonSize(polygon1.sides)/9)
+ polygon1.vx -= (Math.cos(angle) * (polygon1.radius + polygon2.radius - distance)/2)/(polygon1.collisionMass/polygon2.collisionMass**(1/2.5))
+ polygon1.vy -= (Math.sin(angle) * (polygon1.radius + polygon2.radius - distance)/2)/(polygon1.collisionMass/polygon2.collisionMass**(1/2.5))
}
}
}
}
// move polygons
- for (var poly = 0; poly < polygonList.length; poly++){
- let polygon = polygonList[poly]
+ for (var poly = 0; poly < collideList.length; poly++){
+ let polygon = collideList[poly]
if (polygon.vx || polygon.vy){
polygon.x += polygon.vx
polygon.y += polygon.vy
polygon.vx *= 0.8
polygon.vy *= 0.8
}
- polygon.rotation += 1.00672*Math.pow(0.344151, polygon.sides) + 0.000002
+ }
+ // orbit polygons
+ for (var poly = 0; poly < polygonList.length; poly++){
+ let polygon = polygonList[poly]
+ polygon.rotation += 1/orbitalSpeed(polygon.sides)
// add some velocity towards wherever its facing
- polygon.vx += Math.sin(polygon.rotation)*(1.00672*Math.pow(0.344151, polygon.sides) + 0.000002)*8
- polygon.vy += Math.cos(polygon.rotation)*(1.00672*Math.pow(0.344151, polygon.sides) + 0.000002)*8
+ polygon.vx += Math.sin(polygon.rotation)/orbitalSpeed(polygon.sides)*8
+ polygon.vy += Math.cos(polygon.rotation)/orbitalSpeed(polygon.sides)*8
+ }
+ camera[0] += (scenexeplayer.x - camera[0])/10
+ camera[1] += (scenexeplayer.y - camera[1])/10
+ // add velocity to player depending on which keys are down
+ if (isKeyDown.w){
+ if (isKeyDown.a + isKeyDown.d == 1){
+ scenexeplayer.vy -= 1/Math.sqrt(2)
+ } else{
+ scenexeplayer.vy -= 1
+ }
+ }
+ if (isKeyDown.s){
+ if (isKeyDown.a + isKeyDown.d == 1){
+ scenexeplayer.vy += 1/Math.sqrt(2)
+ } else{
+ scenexeplayer.vy += 1
+ }
+ }
+ if (isKeyDown.a){
+ if (isKeyDown.w + isKeyDown.s == 1){
+ scenexeplayer.vx -= 1/Math.sqrt(2)
+ } else{
+ scenexeplayer.vx -= 1
+ }
+ }
+ if (isKeyDown.d){
+ if (isKeyDown.w + isKeyDown.s == 1){
+ scenexeplayer.vx += 1/Math.sqrt(2)
+ } else{
+ scenexeplayer.vx += 1
+ }
}
})
\ No newline at end of file