diff examples/E10_pong.nim @ 1140:5934c5615f13

did: update all examples to work with latest refactoring
author sam <sam@basx.dev>
date Sat, 08 Jun 2024 15:16:17 +0700
parents 114f395b9144
children
line wrap: on
line diff
--- a/examples/E10_pong.nim	Sat Jun 08 14:58:25 2024 +0700
+++ b/examples/E10_pong.nim	Sat Jun 08 15:16:17 2024 +0700
@@ -4,10 +4,10 @@
 import ../semicongine
 
 let
-  barcolor = toRGBA("5A3F00").toSRGB().colorToHex()
+  barcolor = ToRGBA("5A3F00").ToSRGB().ColorToHex()
   barSize = 0.1'f
   barWidth = 0.01'f
-  ballcolor = toRGBA("B17F08").toSRGB().colorToHex()
+  ballcolor = ToRGBA("B17F08").ToSRGB().ColorToHex()
   ballSize = 0.01'f
   ballSpeed = 60'f
   matDef = MaterialType(name: "default", vertexAttributes: {
@@ -17,39 +17,39 @@
 
 var
   level: Scene
-  ballVelocity = NewVec2f(1, 1).normalized * ballSpeed
+  ballVelocity = NewVec2f(1, 1).Normalized * ballSpeed
 
 when isMainModule:
-  var myengine = initEngine("Pong")
+  var myengine = InitEngine("Pong")
 
-  var player = rect(color = barcolor, width = barWidth, height = barSize)
+  var player = Rect(color = barcolor, width = barWidth, height = barSize)
   player.material = matDef.InitMaterialData(name = "player material")
-  var ball = circle(color = ballcolor)
+  var ball = Circle(color = ballcolor)
   ball.material = matDef.InitMaterialData(name = "player material")
   level = Scene(name: "scene", meshes: @[ball, player])
 
   const
-    shaderConfiguration = createShaderConfiguration(
+    shaderConfiguration = CreateShaderConfiguration(
       name = "default shader",
       inputs = [
-        attr[Vec3f]("position"),
-        attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite),
-        attr[Mat4]("transform", memoryPerformanceHint = PreferFastWrite, perInstance = true),
+        Attr[Vec3f]("position"),
+        Attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite),
+        Attr[Mat4]("transform", memoryPerformanceHint = PreferFastWrite, perInstance = true),
       ],
-      intermediates = [attr[Vec4f]("outcolor")],
-      uniforms = [attr[Mat4]("projection")],
-      outputs = [attr[Vec4f]("color")],
+      intermediates = [Attr[Vec4f]("outcolor")],
+      uniforms = [Attr[Mat4]("projection")],
+      outputs = [Attr[Vec4f]("color")],
       vertexCode = """outcolor = color; gl_Position = vec4(position, 1) * (transform * Uniforms.projection);""",
       fragmentCode = "color = outcolor;",
     )
 
   # set up rendering
-  myengine.initRenderer({matDef: shaderConfiguration})
-  level.addShaderGlobal("projection", Unit4f32)
-  myengine.loadScene(level)
+  myengine.InitRenderer({matDef: shaderConfiguration})
+  level.AddShaderGlobal("projection", Unit4f32)
+  myengine.LoadScene(level)
 
   var
-    winsize = myengine.GetWindow().size
+    winsize = myengine.GetWindow().Size
     height = float32(winsize[1]) / float32(winsize[0])
     width = 1'f
     currentTime = cpuTime()
@@ -69,35 +69,36 @@
     let dt: float32 = cpuTime() - currentTime
     currentTime = cpuTime()
     if WindowWasResized():
-      winsize = myengine.GetWindow().size
+      winsize = myengine.GetWindow().Size
       height = float32(winsize[1]) / float32(winsize[0])
       width = 1'f
-      setShaderGlobal(level, "projection", ortho(0, width, 0, height, 0, 1))
-    if KeyIsDown(Down) and (player.transform.col(3).y + barSize/2) < height:
-      player.transform = player.transform * translate(0'f, 1'f * dt, 0'f)
-    if KeyIsDown(Up) and (player.transform.col(3).y - barSize/2) > 0:
-      player.transform = player.transform * translate(0'f, -1'f * dt, 0'f)
+      SetShaderGlobal(level, "projection", Ortho(0, width, 0, height, 0, 1))
+    if KeyIsDown(Down) and (player.transform.Col(3).y + barSize/2) < height:
+      player.transform = player.transform * Translate(0'f, 1'f * dt, 0'f)
+    if KeyIsDown(Up) and (player.transform.Col(3).y - barSize/2) > 0:
+      player.transform = player.transform * Translate(0'f, -1'f * dt, 0'f)
 
     # bounce level
-    if ball.transform.col(3).x + ballSize/2 > width: ballVelocity[0] = -ballVelocity[0]
-    if ball.transform.col(3).y - ballSize/2 <= 0: ballVelocity[1] = -ballVelocity[1]
-    if ball.transform.col(3).y + ballSize/2 > height: ballVelocity[1] = -ballVelocity[1]
+    if ball.transform.Col(3).x + ballSize/2 > width: ballVelocity[0] = -ballVelocity[0]
+    if ball.transform.Col(3).y - ballSize/2 <= 0: ballVelocity[1] = -ballVelocity[1]
+    if ball.transform.Col(3).y + ballSize/2 > height: ballVelocity[1] = -ballVelocity[1]
 
-    ball.transform = ball.transform * translate(ballVelocity[0] * dt, ballVelocity[1] * dt, 0'f32)
+    ball.transform = ball.transform * Translate(ballVelocity[0] * dt, ballVelocity[1] * dt, 0'f32)
 
     # loose
-    if ball.transform.col(3).x - ballSize/2 <= 0:
-      ball.transform = scale(ballSize, ballSize, 1'f) * translate(30'f, 30'f, 0'f)
-      ballVelocity = NewVec2f(1, 1).normalized * ballSpeed
+    if ball.transform.Col(3).x - ballSize/2 <= 0:
+      ball.transform = Scale(ballSize, ballSize, 1'f) * Translate(30'f, 30'f, 0'f)
+      ballVelocity = NewVec2f(1, 1).Normalized * ballSpeed
 
     # bar
-    if ball.transform.col(3).x - ballSize/2 <= barWidth:
+    if ball.transform.Col(3).x - ballSize/2 <= barWidth:
       let
-        barTop = player.transform.col(3).y - barSize/2
-        barBottom = player.transform.col(3).y + barSize/2
-        ballTop = ball.transform.col(3).y - ballSize/2
-        ballBottom = ball.transform.col(3).y + ballSize/2
+        barTop = player.transform.Col(3).y - barSize/2
+        barBottom = player.transform.Col(3).y + barSize/2
+        ballTop = ball.transform.Col(3).y - ballSize/2
+        ballBottom = ball.transform.Col(3).y + ballSize/2
       if ballTop >= barTop and ballBottom <= barBottom:
         ballVelocity[0] = abs(ballVelocity[0])
 
-    myengine.renderScene(level)
+    myengine.RenderScene(level)
+  myengine.Destroy()