Переглянути джерело

Compressed images. Added movement speed example.

Björn Ritzl 5 роки тому
батько
коміт
a9f879017d

BIN
assets/images/bunny1_ready.png


BIN
assets/images/bunny2_ready.png


BIN
assets/images/carrot.png


BIN
assets/images/close.png


BIN
assets/images/elementMetal001.png


BIN
assets/images/elementStone019.png


BIN
assets/images/elementStone023.png


BIN
assets/images/enemyFloating_1.png


BIN
assets/images/flame.png


BIN
assets/images/grid.png


BIN
assets/images/header.png


BIN
assets/images/laserYellow_burst.png


BIN
assets/images/logo-color.png


BIN
assets/images/logo.png


BIN
assets/images/rainbow.png


BIN
assets/images/red_button12.png


BIN
assets/images/shipBlue_manned.png


BIN
assets/images/shipGreen_manned.png


BIN
assets/images/shipPink_manned.png


BIN
assets/images/smoke.png


BIN
assets/images/spinner.png


BIN
assets/images/tilesheet_complete.png


+ 4 - 16
assets/sprites.atlas

@@ -1,11 +1,3 @@
-images {
-  image: "/assets/images/logo.png"
-  sprite_trim_mode: SPRITE_TRIM_MODE_OFF
-}
-images {
-  image: "/assets/images/grid.png"
-  sprite_trim_mode: SPRITE_TRIM_MODE_OFF
-}
 images {
   image: "/assets/images/spinner.png"
   sprite_trim_mode: SPRITE_TRIM_MODE_OFF
@@ -18,14 +10,6 @@ images {
   image: "/assets/images/elementStone023.png"
   sprite_trim_mode: SPRITE_TRIM_MODE_OFF
 }
-images {
-  image: "/assets/images/close.png"
-  sprite_trim_mode: SPRITE_TRIM_MODE_OFF
-}
-images {
-  image: "/assets/images/header.png"
-  sprite_trim_mode: SPRITE_TRIM_MODE_OFF
-}
 images {
   image: "/assets/images/bunny1_ready.png"
   sprite_trim_mode: SPRITE_TRIM_MODE_OFF
@@ -62,6 +46,10 @@ images {
   image: "/assets/images/logo-color.png"
   sprite_trim_mode: SPRITE_TRIM_MODE_OFF
 }
+images {
+  image: "/assets/images/shipGreen_manned.png"
+  sprite_trim_mode: SPRITE_TRIM_MODE_OFF
+}
 animations {
   id: "bee"
   images {

+ 19 - 0
assets/ui.atlas

@@ -0,0 +1,19 @@
+images {
+  image: "/assets/images/grid.png"
+  sprite_trim_mode: SPRITE_TRIM_MODE_OFF
+}
+images {
+  image: "/assets/images/close.png"
+  sprite_trim_mode: SPRITE_TRIM_MODE_OFF
+}
+images {
+  image: "/assets/images/header.png"
+  sprite_trim_mode: SPRITE_TRIM_MODE_OFF
+}
+images {
+  image: "/assets/images/logo.png"
+  sprite_trim_mode: SPRITE_TRIM_MODE_OFF
+}
+margin: 0
+extrude_borders: 2
+inner_padding: 0

+ 18 - 0
examples/_main/loader.go

@@ -676,3 +676,21 @@ embedded_components {
     w: 1.0
   }
 }
+embedded_components {
+  id: "basics/movement_speed"
+  type: "collectionproxy"
+  data: "collection: \"/examples/basics/movement_speed/movement_speed.collection\"\n"
+  "exclude: false\n"
+  ""
+  position {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+}

+ 5 - 5
examples/_main/menu.gui

@@ -8,8 +8,8 @@ fonts {
   font: "/assets/text64.font"
 }
 textures {
-  name: "sprites"
-  texture: "/assets/sprites.atlas"
+  name: "ui"
+  texture: "/assets/ui.atlas"
 }
 background_color {
   x: 0.0
@@ -104,7 +104,7 @@ nodes {
   }
   type: TYPE_BOX
   blend_mode: BLEND_MODE_ALPHA
-  texture: "sprites/header"
+  texture: "ui/header"
   id: "box"
   xanchor: XANCHOR_NONE
   yanchor: YANCHOR_NONE
@@ -220,7 +220,7 @@ nodes {
   }
   type: TYPE_BOX
   blend_mode: BLEND_MODE_ALPHA
-  texture: "sprites/logo"
+  texture: "ui/logo"
   id: "logo"
   xanchor: XANCHOR_NONE
   yanchor: YANCHOR_NONE
@@ -274,7 +274,7 @@ nodes {
   }
   type: TYPE_BOX
   blend_mode: BLEND_MODE_ALPHA
-  texture: "sprites/close"
+  texture: "ui/close"
   id: "close"
   xanchor: XANCHOR_NONE
   yanchor: YANCHOR_NONE

+ 1 - 1
examples/_main/menu.gui_script

@@ -101,7 +101,7 @@ end
 function init(self)
 	self.index = { "basics", "physics", "animation", "gui", "input", "particles", "sound", "render", "debug", "collection", "sprite", "file", "tilemap" }
 	self.index = {}
-	self.index["basics"] = { "simple_move", "message_passing", "follow", "parent_child", "spawn", "z_order" }
+	self.index["basics"] = { "simple_move", "message_passing", "follow", "parent_child", "spawn", "z_order", "movement_speed" }
 	self.index["physics"] = { "dynamic", "kinematic", "raycast", "trigger" }
 	self.index["animation"] = { "spinner", "flipbook", "chained_tween", "basic_tween", "spine" }
 	self.index["gui"] = { "button", "stencil", "load_texture", "pointer_over", "color"}

+ 3 - 3
examples/_main/ui.gui

@@ -8,8 +8,8 @@ fonts {
   font: "/assets/text64.font"
 }
 textures {
-  name: "sprites"
-  texture: "/assets/sprites.atlas"
+  name: "ui"
+  texture: "/assets/ui.atlas"
 }
 background_color {
   x: 0.0
@@ -50,7 +50,7 @@ nodes {
   }
   type: TYPE_BOX
   blend_mode: BLEND_MODE_ALPHA
-  texture: "sprites/close"
+  texture: "ui/close"
   id: "close"
   xanchor: XANCHOR_NONE
   yanchor: YANCHOR_NONE

+ 57 - 0
examples/basics/movement_speed/movement_speed.collection

@@ -0,0 +1,57 @@
+name: "movement_speed"
+scale_along_z: 0
+embedded_instances {
+  id: "go"
+  data: "components {\n"
+  "  id: \"movement_speed\"\n"
+  "  component: \"/examples/basics/movement_speed/movement_speed.script\"\n"
+  "  position {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "  }\n"
+  "  rotation {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "    w: 1.0\n"
+  "  }\n"
+  "}\n"
+  "embedded_components {\n"
+  "  id: \"sprite\"\n"
+  "  type: \"sprite\"\n"
+  "  data: \"tile_set: \\\"/assets/sprites.atlas\\\"\\n"
+  "default_animation: \\\"shipGreen_manned\\\"\\n"
+  "material: \\\"/builtins/materials/sprite.material\\\"\\n"
+  "blend_mode: BLEND_MODE_ALPHA\\n"
+  "\"\n"
+  "  position {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "  }\n"
+  "  rotation {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "    w: 1.0\n"
+  "  }\n"
+  "}\n"
+  ""
+  position {
+    x: 360.0
+    y: 360.0
+    z: 0.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  scale3 {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+  }
+}

+ 5 - 0
examples/basics/movement_speed/movement_speed.md

@@ -0,0 +1,5 @@
+---
+title: Movement speed
+brief: This example shows how to move a game object with accelerating speed.
+scripts: movement_speed.script
+---

+ 54 - 0
examples/basics/movement_speed/movement_speed.script

@@ -0,0 +1,54 @@
+go.property("acceleration", 100)
+go.property("deceleration", 200)
+go.property("max_speed", 400)
+
+function init(self)
+	-- make sure the script will receive user input
+	msg.post(".", "acquire_input_focus")
+
+	-- movement input
+	self.input = vmath.vector3()
+	
+	-- the current direction of movement
+	self.direction = vmath.vector3()
+
+	-- the current speed (pixels/second)
+	self.speed = 0
+end
+
+function update(self, dt)
+	-- is any key pressed?
+	if vmath.length(self.input) > 0 then
+		-- adjust direction of travel based on input
+		self.direction = vmath.normalize(self.direction + self.input)
+		-- increase speed if we are moving in any direction
+		self.speed = self.speed + self.acceleration * dt
+		-- cap speed
+		self.speed = math.min(self.speed, self.max_speed)
+	else
+		-- stop when no key is pressed
+		self.speed = self.speed - self.deceleration * dt
+		self.speed = math.max(self.speed, 0)
+	end
+
+	-- move the game object
+	local p = go.get_position()
+	p = p + self.direction * self.speed * dt
+	go.set_position(p)
+
+	-- reset input
+	self.input = vmath.vector3()
+end
+
+function on_input(self, action_id, action)
+	-- update direction of movement based on currently pressed keys
+	if action_id == hash("up") then
+		self.input.y = 1
+	elseif action_id == hash("down") then
+		self.input.y = -1
+	elseif action_id == hash("left") then
+		self.input.x = -1
+	elseif action_id == hash("right") then
+		self.input.x = 1
+	end
+end

+ 1 - 1
examples/main.collection

@@ -25,7 +25,7 @@ embedded_instances {
   data: "embedded_components {\n"
   "  id: \"sprite\"\n"
   "  type: \"sprite\"\n"
-  "  data: \"tile_set: \\\"/assets/sprites.atlas\\\"\\n"
+  "  data: \"tile_set: \\\"/assets/ui.atlas\\\"\\n"
   "default_animation: \\\"grid\\\"\\n"
   "material: \\\"/builtins/materials/sprite.material\\\"\\n"
   "blend_mode: BLEND_MODE_ALPHA\\n"