summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/models/cube.cgmodelbin0 -> 952 bytes
-rw-r--r--test/models/tetrahedron.cgmodelbin0 -> 376 bytes
-rw-r--r--test/src/main.rb64
-rw-r--r--test/src/mode/collision.rb87
-rw-r--r--test/textures/color_texture.pngbin0 -> 3594 bytes
5 files changed, 60 insertions, 91 deletions
diff --git a/test/models/cube.cgmodel b/test/models/cube.cgmodel
new file mode 100644
index 0000000..1cb35a0
--- /dev/null
+++ b/test/models/cube.cgmodel
Binary files differ
diff --git a/test/models/tetrahedron.cgmodel b/test/models/tetrahedron.cgmodel
new file mode 100644
index 0000000..7a1f9b9
--- /dev/null
+++ b/test/models/tetrahedron.cgmodel
Binary files differ
diff --git a/test/src/main.rb b/test/src/main.rb
index 9e37faa..31affb8 100644
--- a/test/src/main.rb
+++ b/test/src/main.rb
@@ -12,14 +12,70 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+ROTATION_SPEED = Math::PI/45;
+TRANSLATION_SPEED = 0.5;
+
def init()
- $mode = Mode::Collision.new();
+ $texture = CandyGear::Texture.from_image("textures/color_texture.png");
+ $model = CandyGear::Model.new("models/cube.cgmodel", $texture);
+
+ $instances = [
+ CandyGear::Model::Instance.new(
+ $model,
+ 5.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0),
+ CandyGear::Model::Instance.new(
+ $model,
+ -5.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0),
+ CandyGear::Model::Instance.new(
+ $model,
+ 0.0, 5.0, 0.0,
+ 0.0, 0.0, 0.0),
+ CandyGear::Model::Instance.new(
+ $model,
+ 0.0, -5.0, 0.0,
+ 0.0, 0.0, 0.0),
+ CandyGear::Model::Instance.new(
+ $model,
+ 0.0, 0.0, 5.0,
+ 0.0, 0.0, 0.0),
+ CandyGear::Model::Instance.new(
+ $model,
+ 0.0, 0.0, -5.0,
+ 0.0, 0.0, 0.0)
+ ];
+
+ $camera = CandyGear::Camera.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
+ $camera.use();
end
-def key_down(key) = $mode.controller.key_down(key);
+def key_down(key)
+ case key
+ when CandyGear::Key::I
+ $camera.rotate(ROTATION_SPEED, 0.0, 0.0);
+ when CandyGear::Key::K
+ $camera.rotate(-ROTATION_SPEED, 0.0, 0.0);
+ when CandyGear::Key::J
+ $camera.rotate(0.0, ROTATION_SPEED, 0.0);
+ when CandyGear::Key::L
+ $camera.rotate(0.0, -ROTATION_SPEED, 0.0);
+ when CandyGear::Key::E
+ $camera.translate_by_rotation(0.0, 0.0, -TRANSLATION_SPEED);
+ when CandyGear::Key::D
+ $camera.translate_by_rotation(0.0, 0.0, TRANSLATION_SPEED);
+ when CandyGear::Key::S
+ $camera.translate_by_rotation(-TRANSLATION_SPEED, 0.0, 0.0);
+ when CandyGear::Key::F
+ $camera.translate_by_rotation(TRANSLATION_SPEED, 0.0, 0.0);
+ end
+end
-def key_up(key) = $mode.controller.key_up(key);
+def key_up(key)
+end
def quit() = CandyGear.quit();
-def tick() = $mode.tick();
+def tick()
+ $instances.each {|i| i.draw();};
+end
diff --git a/test/src/mode/collision.rb b/test/src/mode/collision.rb
deleted file mode 100644
index dddfd5a..0000000
--- a/test/src/mode/collision.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-# Copyright 2022 Frederico de Oliveira Linhares
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-module Mode
- class Collision
- WINDOW_WIDTH = 640;
- WINDOW_HEIGHT = 360;
-
- class Square
- attr_reader(:rect);
-
- def initialize(x, y, vertical_direction, horizontal_direction)
- @rect = CandyGear::Rect.new(x, y, 16, 16);
- @vertical_direction = vertical_direction;
- @horizontal_direction = horizontal_direction;
- end
-
- def x() = @rect.x;
- def y() = @rect.y;
-
- def draw() = @rect.draw_fill();
-
- def tick()
- case @vertical_direction
- when :left
- @rect.x -= 2;
- @vertical_direction = :right if @rect.x < 0;
- when :right
- @rect.x += 2;
- if @rect.x > WINDOW_WIDTH - @rect.width() then
- @vertical_direction = :left;
- end
- end
-
- case @horizontal_direction
- when :up
- @rect.y -= 2;
- @horizontal_direction = :down if @rect.y < 0;
- when :down
- @rect.y += 2;
- if @rect.y > WINDOW_HEIGHT - @rect.height() then
- @horizontal_direction = :up;
- end
- end
- end
- end
-
- def initialize()
- @normal_color = CandyGear::Color.new(0x99, 0x99, 0x99);
- @collision_color = CandyGear::Color.new(0x99, 0x33, 0x33);
- @vertical_align_color = CandyGear::Color.new(0x33, 0x99, 0x33);
- @horizontal_align_color = CandyGear::Color.new(0x33, 0x33, 0x99);
-
- @square1 = Square.new(213, 120, :left, :down);
- @square2 = Square.new(427, 240, :right, :down);
- end
-
- def tick()
- @square1.tick();
- @square2.tick();
-
- if @square1.rect.collide?(@square2.rect) then
- CandyGear::Graphic.set_color(@collision_color);
- elsif @square1.rect.align_horizontally?(@square2.rect) then
- CandyGear::Graphic.set_color(@horizontal_align_color);
- elsif @square1.rect.align_vertically?(@square2.rect) then
- CandyGear::Graphic.set_color(@vertical_align_color);
- else
- CandyGear::Graphic.set_color(@normal_color);
- end
-
- @square1.draw();
- @square2.draw();
- end
- end
-end
diff --git a/test/textures/color_texture.png b/test/textures/color_texture.png
new file mode 100644
index 0000000..2c02811
--- /dev/null
+++ b/test/textures/color_texture.png
Binary files differ