summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-04-25 04:25:57 -0400
committerrealtradam <[email protected]>2021-04-25 04:25:57 -0400
commit505a4735d519253c5f173f47fbe9691bc5d9ce93 (patch)
treea3b2600a87a4285e60165728f48a346a7b05dec3
parent93290fb327f4dac63ac201c4c21e13c60cae0eff (diff)
downloadruby2d-camera-old-505a4735d519253c5f173f47fbe9691bc5d9ce93.tar.gz
ruby2d-camera-old-505a4735d519253c5f173f47fbe9691bc5d9ce93.zip
.
-rw-r--r--assets/alienpls.gifbin112862 -> 0 bytes
-rw-r--r--assets/background.pngbin29939 -> 60142 bytes
-rw-r--r--assets/blobdanceextract/blob1.pngbin797 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob10.pngbin697 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob11.pngbin742 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob12.pngbin753 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob13.pngbin730 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob14.pngbin740 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob15.pngbin803 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob16.pngbin810 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob17.pngbin790 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob18.pngbin790 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob19.pngbin815 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob2.pngbin807 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob20.pngbin814 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob3.pngbin815 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob4.pngbin819 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob5.pngbin807 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob6.pngbin787 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob7.pngbin755 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob8.pngbin769 -> 0 bytes
-rw-r--r--assets/blobdanceextract/blob9.pngbin719 -> 0 bytes
-rw-r--r--assets/blobshadow.pngbin0 -> 5679 bytes
-rw-r--r--assets/dance2.gifbin95393 -> 0 bytes
-rw-r--r--assets/dancer.gifbin34230 -> 0 bytes
-rw-r--r--assets/houseshadow.pngbin0 -> 10856 bytes
-rw-r--r--assets/sprites/alienpls-56.png (renamed from assets/sprites/alienpls.png)bin255710 -> 255710 bytes
-rw-r--r--assets/sprites/blobdance-128.png (renamed from assets/sprites/blobdance.png)bin35825 -> 35825 bytes
-rw-r--r--assets/sprites/dance2-112.png (renamed from assets/sprites/dance2.png)bin214857 -> 214857 bytes
-rw-r--r--assets/sprites/dancer-128.png (renamed from assets/sprites/dancer.png)bin39270 -> 39270 bytes
-rw-r--r--assets/sprites/mainblob-128.pngbin0 -> 94731 bytes
-rw-r--r--assets/sprites/mainblob.pngbin94235 -> 0 bytes
-rw-r--r--assets/sprites/peepocomfy-100.png (renamed from assets/sprites/peepocomfy.png)bin4321 -> 4321 bytes
-rw-r--r--assets/walk.gifbin102604 -> 0 bytes
-rw-r--r--house.rb103
-rw-r--r--lib/camera/camera.rb4
-rw-r--r--lib/camera/wrappers/circle_wrapper.rb4
-rw-r--r--lib/camera/wrappers/line_wrapper.rb4
-rw-r--r--lib/camera/wrappers/quad_wrapper.rb7
-rw-r--r--lib/camera/wrappers/rectangle_wrapper.rb13
-rw-r--r--lib/camera/wrappers/square_wrapper.rb17
-rw-r--r--lib/camera/wrappers/triangle_wrapper.rb4
-rw-r--r--room.rb107
-rw-r--r--run.rb294
44 files changed, 400 insertions, 157 deletions
diff --git a/assets/alienpls.gif b/assets/alienpls.gif
deleted file mode 100644
index af0f7b0..0000000
--- a/assets/alienpls.gif
+++ /dev/null
Binary files differ
diff --git a/assets/background.png b/assets/background.png
index e12baab..f411e96 100644
--- a/assets/background.png
+++ b/assets/background.png
Binary files differ
diff --git a/assets/blobdanceextract/blob1.png b/assets/blobdanceextract/blob1.png
deleted file mode 100644
index 53cb756..0000000
--- a/assets/blobdanceextract/blob1.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob10.png b/assets/blobdanceextract/blob10.png
deleted file mode 100644
index 2641d19..0000000
--- a/assets/blobdanceextract/blob10.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob11.png b/assets/blobdanceextract/blob11.png
deleted file mode 100644
index da8f7a9..0000000
--- a/assets/blobdanceextract/blob11.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob12.png b/assets/blobdanceextract/blob12.png
deleted file mode 100644
index fe2ca88..0000000
--- a/assets/blobdanceextract/blob12.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob13.png b/assets/blobdanceextract/blob13.png
deleted file mode 100644
index 6368c56..0000000
--- a/assets/blobdanceextract/blob13.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob14.png b/assets/blobdanceextract/blob14.png
deleted file mode 100644
index a3457d9..0000000
--- a/assets/blobdanceextract/blob14.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob15.png b/assets/blobdanceextract/blob15.png
deleted file mode 100644
index fc1be85..0000000
--- a/assets/blobdanceextract/blob15.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob16.png b/assets/blobdanceextract/blob16.png
deleted file mode 100644
index a12d60c..0000000
--- a/assets/blobdanceextract/blob16.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob17.png b/assets/blobdanceextract/blob17.png
deleted file mode 100644
index cdb2569..0000000
--- a/assets/blobdanceextract/blob17.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob18.png b/assets/blobdanceextract/blob18.png
deleted file mode 100644
index bcc0bad..0000000
--- a/assets/blobdanceextract/blob18.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob19.png b/assets/blobdanceextract/blob19.png
deleted file mode 100644
index 128fbb6..0000000
--- a/assets/blobdanceextract/blob19.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob2.png b/assets/blobdanceextract/blob2.png
deleted file mode 100644
index 421ef41..0000000
--- a/assets/blobdanceextract/blob2.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob20.png b/assets/blobdanceextract/blob20.png
deleted file mode 100644
index 4ed12cf..0000000
--- a/assets/blobdanceextract/blob20.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob3.png b/assets/blobdanceextract/blob3.png
deleted file mode 100644
index f7cf2f3..0000000
--- a/assets/blobdanceextract/blob3.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob4.png b/assets/blobdanceextract/blob4.png
deleted file mode 100644
index aff67c8..0000000
--- a/assets/blobdanceextract/blob4.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob5.png b/assets/blobdanceextract/blob5.png
deleted file mode 100644
index 1955c91..0000000
--- a/assets/blobdanceextract/blob5.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob6.png b/assets/blobdanceextract/blob6.png
deleted file mode 100644
index ffd08f2..0000000
--- a/assets/blobdanceextract/blob6.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob7.png b/assets/blobdanceextract/blob7.png
deleted file mode 100644
index f6cdb40..0000000
--- a/assets/blobdanceextract/blob7.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob8.png b/assets/blobdanceextract/blob8.png
deleted file mode 100644
index e787bf4..0000000
--- a/assets/blobdanceextract/blob8.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobdanceextract/blob9.png b/assets/blobdanceextract/blob9.png
deleted file mode 100644
index ec097a0..0000000
--- a/assets/blobdanceextract/blob9.png
+++ /dev/null
Binary files differ
diff --git a/assets/blobshadow.png b/assets/blobshadow.png
new file mode 100644
index 0000000..ff981cb
--- /dev/null
+++ b/assets/blobshadow.png
Binary files differ
diff --git a/assets/dance2.gif b/assets/dance2.gif
deleted file mode 100644
index c1381aa..0000000
--- a/assets/dance2.gif
+++ /dev/null
Binary files differ
diff --git a/assets/dancer.gif b/assets/dancer.gif
deleted file mode 100644
index a2fdfef..0000000
--- a/assets/dancer.gif
+++ /dev/null
Binary files differ
diff --git a/assets/houseshadow.png b/assets/houseshadow.png
new file mode 100644
index 0000000..d860b9b
--- /dev/null
+++ b/assets/houseshadow.png
Binary files differ
diff --git a/assets/sprites/alienpls.png b/assets/sprites/alienpls-56.png
index af9452a..af9452a 100644
--- a/assets/sprites/alienpls.png
+++ b/assets/sprites/alienpls-56.png
Binary files differ
diff --git a/assets/sprites/blobdance.png b/assets/sprites/blobdance-128.png
index 6326ec0..6326ec0 100644
--- a/assets/sprites/blobdance.png
+++ b/assets/sprites/blobdance-128.png
Binary files differ
diff --git a/assets/sprites/dance2.png b/assets/sprites/dance2-112.png
index 2d69026..2d69026 100644
--- a/assets/sprites/dance2.png
+++ b/assets/sprites/dance2-112.png
Binary files differ
diff --git a/assets/sprites/dancer.png b/assets/sprites/dancer-128.png
index c3fdbc0..c3fdbc0 100644
--- a/assets/sprites/dancer.png
+++ b/assets/sprites/dancer-128.png
Binary files differ
diff --git a/assets/sprites/mainblob-128.png b/assets/sprites/mainblob-128.png
new file mode 100644
index 0000000..ca78578
--- /dev/null
+++ b/assets/sprites/mainblob-128.png
Binary files differ
diff --git a/assets/sprites/mainblob.png b/assets/sprites/mainblob.png
deleted file mode 100644
index 836e6ff..0000000
--- a/assets/sprites/mainblob.png
+++ /dev/null
Binary files differ
diff --git a/assets/sprites/peepocomfy.png b/assets/sprites/peepocomfy-100.png
index 6d8812d..6d8812d 100644
--- a/assets/sprites/peepocomfy.png
+++ b/assets/sprites/peepocomfy-100.png
Binary files differ
diff --git a/assets/walk.gif b/assets/walk.gif
deleted file mode 100644
index 67638ad..0000000
--- a/assets/walk.gif
+++ /dev/null
Binary files differ
diff --git a/house.rb b/house.rb
new file mode 100644
index 0000000..850bea8
--- /dev/null
+++ b/house.rb
@@ -0,0 +1,103 @@
+# frozen_string_literal: true
+
+# Is a house
+class House
+ def initialize(x, y)
+ @objects = []
+ @x = x
+ @y = y
+ @objects.push Image.new('assets/blobshadow.png',
+ width: 320,
+ height: 250,
+ x: x - 10,
+ y: y + 130,
+ z: 0)
+ @objects.push Image.new('assets/bricktexture.png',
+ x: x,
+ y: y,
+ width: 300,
+ height: 300)
+ @objects.push Square.new(x: 125 + x,
+ y: 230 + y,
+ size: 50,
+ color: 'black')
+ @objects.push Circle.new(x: 125 + x,
+ y: 205 + y,
+ radius: 25,
+ color: 'black')
+ @objects.push Triangle.new(x1: -5 + x,
+ y1: 16 + y,
+ x2: 310 + x,
+ y2: 14 + y,
+ x3: 150 + x,
+ y3: -75 + y,
+ color: 'red')
+ @objects.push Square.new(x: 160 + x,
+ y: 20 + y,
+ size: 100,
+ color: 'brown',
+ z: 1)
+ @objects.push Square.new(x: 170 + x,
+ y: 25 + y,
+ size: 80,
+ opacity: 0.5,
+ color: 'blue',
+ z: 2)
+ @objects.push Rectangle.new(x: 160 + x,
+ y: 105 + y,
+ width: 100,
+ height: 20,
+ color: 'brown',
+ z: 3)
+ @objects.push Line.new(x1: 210 + x,
+ y1: 105 + y,
+ x2: 210 + x,
+ y2: 25 + y,
+ width: 4,
+ color: 'brown',
+ z: 3)
+ @objects.push Line.new(x1: 250 + x,
+ y1: 65 + y,
+ x2: 170 + x,
+ y2: 65 + y,
+ width: 4,
+ color: 'brown',
+ z: 3)
+ @objects.push Sprite.new('./assets/sprites/alienpls-56.png',
+ x: 175 + x,
+ y: 65 + y,
+ width: 56,
+ height: 56,
+ clip_width: 56,
+ loop: true,
+ time: 35,
+ z: 1)
+ @objects.last.play
+ @objects.each do |item|
+ Camera << item
+ end
+ end
+
+ def remove
+ @objects.each do |item|
+ Camera.remove item
+ item.remove
+ end
+ end
+
+ def visted_by?(character)
+ x = @x + 80
+ y = @y + 160
+ if character.x >= x && character.x <= (x + (character.width * 2)) && character.y > y && character.y <= (y + (character.height * 2))
+ Text.new('Press Space To Enter House',
+ x: x - 10,
+ y: y + 20,
+ color: 'white',
+ z: 98,
+ size: 25.0)
+ else
+ nil
+ end
+ end
+end
+
diff --git a/lib/camera/camera.rb b/lib/camera/camera.rb
index 2b94150..6a6dd3d 100644
--- a/lib/camera/camera.rb
+++ b/lib/camera/camera.rb
@@ -59,6 +59,10 @@ module Camera
objects.push(item) unless objects.include?(item)
end
+ def self.remove(item)
+ objects.delete(item) if objects.include?(item)
+ end
+
# Redraw all objects that
# are tracked by the Camera
def self.redraw
diff --git a/lib/camera/wrappers/circle_wrapper.rb b/lib/camera/wrappers/circle_wrapper.rb
index 52a97c0..a7db05a 100644
--- a/lib/camera/wrappers/circle_wrapper.rb
+++ b/lib/camera/wrappers/circle_wrapper.rb
@@ -10,9 +10,9 @@ module Camera
angle = Camera.angle * (Math::PI / 180)
half_width = Window.width * 0.5
half_height = Window.height * 0.5
- @x = (((x - Camera.x) * Math.cos(angle)) - ((y - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
- @y = (((x - Camera.x) * Math.sin(angle)) + ((y - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
@radius = radius * Camera.zoom
+ @x = (((x - Camera.x + radius) * Math.cos(angle)) - ((y - Camera.y + radius) * Math.sin(angle))) * Camera.zoom + half_width
+ @y = (((x - Camera.x + radius) * Math.sin(angle)) + ((y - Camera.y + radius) * Math.cos(angle))) * Camera.zoom + half_height
end
# Methods for moving the shape as well as
diff --git a/lib/camera/wrappers/line_wrapper.rb b/lib/camera/wrappers/line_wrapper.rb
index d2c1801..7d4d944 100644
--- a/lib/camera/wrappers/line_wrapper.rb
+++ b/lib/camera/wrappers/line_wrapper.rb
@@ -19,7 +19,7 @@ module Camera
#Methods for moving the shape
def x
- @x ||= x1
+ @x ||= 0
end
def x=(x)
@@ -27,7 +27,7 @@ module Camera
end
def y
- @y ||= y1
+ @y ||= 0
end
def y=(y)
diff --git a/lib/camera/wrappers/quad_wrapper.rb b/lib/camera/wrappers/quad_wrapper.rb
index 08a2d6c..477dbfd 100644
--- a/lib/camera/wrappers/quad_wrapper.rb
+++ b/lib/camera/wrappers/quad_wrapper.rb
@@ -22,7 +22,7 @@ module Camera
#Methods for moving the shape
def x
- @x ||= x1
+ @x ||= 0
end
def x=(x)
@@ -30,7 +30,7 @@ module Camera
end
def y
- @y ||= y1
+ @y ||= 0
end
def y=(y)
@@ -87,8 +87,9 @@ module Camera
def y3=(y3)
@virtual_y3 = y3
end
+
def x4
- @virtual_x3 ||= @x3
+ @virtual_x4 ||= @x4
end
def x4=(x4)
diff --git a/lib/camera/wrappers/rectangle_wrapper.rb b/lib/camera/wrappers/rectangle_wrapper.rb
index 887ab8b..93e888a 100644
--- a/lib/camera/wrappers/rectangle_wrapper.rb
+++ b/lib/camera/wrappers/rectangle_wrapper.rb
@@ -4,6 +4,15 @@ module Camera
# Wraps existing variables as well as adding new methods
# so that it can be handled by the Camera Module
module RectangleWrapped
+ # Rectangles are part of the exception where
+ # their x and y variables need to be reset
+ # when wrapped
+ def self.extended(obj)
+ obj.instance_exec do
+ @x = 0
+ @y = 0
+ end
+ end
# Recalculates real coordiantes
# Use after changing variables
def redraw
@@ -22,7 +31,7 @@ module Camera
#Methods for moving the shape
def x
- @x ||= x1
+ @x ||= 0
end
def x=(x)
@@ -30,7 +39,7 @@ module Camera
end
def y
- @y ||= y1
+ @y ||= 0
end
def y=(y)
diff --git a/lib/camera/wrappers/square_wrapper.rb b/lib/camera/wrappers/square_wrapper.rb
index 40578e5..2215a30 100644
--- a/lib/camera/wrappers/square_wrapper.rb
+++ b/lib/camera/wrappers/square_wrapper.rb
@@ -1,9 +1,18 @@
# frozen_string_literal: true
module Camera
-# Wraps existing variables as well as adding new methods
-# so that it can be handled by the Camera Module
+ # Wraps existing variables as well as adding new methods
+ # so that it can be handled by the Camera Module
module SquareWrapped
+ # Squares are part of the exception where
+ # their x and y variables need to be reset
+ # when wrapped
+ def self.extended(obj)
+ obj.instance_exec do
+ @x = 0
+ @y = 0
+ end
+ end
# Recalculates real coordiantes
# Use after changing variables
def redraw
@@ -22,7 +31,7 @@ module Camera
#Methods for moving the shape
def x
- @x ||= x1
+ @x ||= 0
end
def x=(x)
@@ -30,7 +39,7 @@ module Camera
end
def y
- @y ||= y1
+ @y ||= 0
end
def y=(y)
diff --git a/lib/camera/wrappers/triangle_wrapper.rb b/lib/camera/wrappers/triangle_wrapper.rb
index b26ef81..0aba2c0 100644
--- a/lib/camera/wrappers/triangle_wrapper.rb
+++ b/lib/camera/wrappers/triangle_wrapper.rb
@@ -20,7 +20,7 @@ module Camera
#Methods for moving the shape
def x
- @x ||= x1
+ @x ||= 0
end
def x=(x)
@@ -28,7 +28,7 @@ module Camera
end
def y
- @y ||= y1
+ @y ||= 0
end
def y=(y)
diff --git a/room.rb b/room.rb
new file mode 100644
index 0000000..5811dc8
--- /dev/null
+++ b/room.rb
@@ -0,0 +1,107 @@
+# frozen_string_literal: true
+
+# Is a house
+class Room
+ def debug
+ @debug
+ end
+ def initialize(x, y)
+ @objects = []
+ @x = x
+ @y = y
+ @objects.push Square.new(x: 125 + x,
+ y: 230 + y,
+ size: 50,
+ color: 'blue')
+ @objects.push Circle.new(x: 125 + x,
+ y: 205 + y,
+ radius: 25,
+ color: 'blue')
+ @objects.push Quad.new(x1: 50 + x,
+ y1: 130 + y,
+ x2: 125 + x,
+ y2: 180 + y,
+ x3: 325 + x,
+ y3: 180 + y,
+ x4: 250 + x,
+ y4: 130 + y,
+ color: 'aqua',
+ z: 1)
+ @objects.push Quad.new(x1: 50 + x,
+ y1: 45 + y,
+ x2: 50 + x,
+ y2: 125 + y,
+ x3: 250 + x,
+ y3: 125 + y,
+ x4: 250 + x,
+ y4: 45 + y,
+ color: 'orange',
+ z: 1)
+ @objects.push Quad.new(x1: 255 + x,
+ y1: 45 + y,
+ x2: 255 + x,
+ y2: 125 + y,
+ x3: 330 + x,
+ y3: 175 + y,
+ x4: 330 + x,
+ y4: 95 + y,
+ color: 'olive',
+ z: 1)
+ @objects.push Sprite.new('./assets/sprites/blobdance-128.png',
+ x: 250 + x,
+ y: 135 + y,
+ width: 40,
+ height: 40,
+ clip_width: 128,
+ loop: true,
+ time: 24,
+ z: 2)
+ @objects.last.play
+ @objects.push Sprite.new('./assets/sprites/dance2-112.png',
+ x: 95 + x,
+ y: 115 + y,
+ width: 40,
+ height: 40,
+ clip_width: 112,
+ loop: true,
+ time: 13,
+ z: 2)
+ @objects.last.play
+ @objects.push Sprite.new('./assets/sprites/dancer-128.png',
+ x: 175 + x,
+ y: 120 + y,
+ width: 45,
+ height: 45,
+ clip_width: 128,
+ loop: true,
+ time: 60,
+ z: 2)
+ @objects.last.play
+ @objects.each do |item|
+ Camera << item
+ end
+ end
+
+ def remove
+ @objects.each do |item|
+ Camera.remove item
+ item.remove
+ end
+ end
+
+ def visted_by?(character)
+ x = @x + 80
+ y = @y + 160
+ if character.x >= x && character.x <= (x + (character.width * 2)) && character.y > y && character.y <= (y + (character.height * 2))
+ Text.new('Press Space To Exit House',
+ x: x - 10,
+ y: y + 20,
+ color: 'white',
+ z: 98,
+ size: 25.0)
+ else
+ nil
+ end
+ end
+end
+
diff --git a/run.rb b/run.rb
index 5554748..3899c83 100644
--- a/run.rb
+++ b/run.rb
@@ -2,223 +2,233 @@
require 'ruby2d'
require_relative 'lib/camera/camera'
-
-#set width: 700, height: 300
+require_relative 'house'
+require_relative 'room'
Window.set(icon: './assets/blobcoolthink.png',
width: 1280,
- height: 720)
+ height: 720,
+ background: 'blue')
-@background = Image.new(
- 'assets/background.png',
- x: 0, y: 0,
- width: (1920 * 0.25), height: (1080 * 0.25),
- z: -1
-)
-Camera << @background
-@line = Line.new(x1: -40,
- y1: -50,
- x2: 60,
- y2: 70,
- width: 35,
- color: 'random')
-Camera << @line
-=begin
-@player = Quad.new(x1: 0,
- y1: 0,
- x2: 0,
- y2: 0 + 25,
- x3: 0 + 25,
- y3: 0 + 25,
- x4: 0 + 25,
- y4: 0,
- size: (10..50).to_a.sample,
- color: 'blue')
-@player = Square.new(x: 0,
- y: 0,
- size: 100,
- color: 'random')
-=end
-@player = Sprite.new('./assets/sprites/blobdance.png',
- x: 0,
- y: 0,
+
+@player = Sprite.new('./assets/sprites/mainblob-128.png',
+ x: 1920 / 1.1,
+ y: 1080 / 1.1,
width: 50,
height: 50,
clip_width: 128,
loop: true,
- time: 17)
-@sprite = Sprite.new('./assets/sprites/blobdance.png',
- x: 300,
- y: 300,
- width: 100,
- height: 100,
- clip_width: 128,
- loop: true,
- time: 17)
-Camera << @sprite
-@text = Text.new('Hello',
- x: 150, y: 150,
- size: 20)
-Camera << @text
-Camera << @player
+ time: 1,
+ z: 99,
+ animations: {
+ walk: 0...60,
+ stand: 60...61
+ })
+@shadow = Image.new(
+ 'assets/blobshadow.png',
+ width: 52,
+ height: 10,
+ z: 1
+)
+Camera << @shadow
[email protected] animation: :walk, loop: true
Camera << @player
Rectangle.new(
width: 350,
height: 135,
- color: 'navy'
+ color: 'navy',
+ z: 100
)
@ui_pos_cam = Text.new(
'pos: 0,0',
x: 10,
y: 10,
- color: 'teal'
+ color: 'teal',
+ z: 101
)
@ui_pos_ply = Text.new(
'pos: 0,0',
x: 10,
y: 40,
- color: 'teal'
+ color: 'teal',
+ z: 101
)
@ui_zoom = Text.new(
'zoom: 0',
x: 10,
y: 70,
- color: 'lime'
+ color: 'lime',
+ z: 101
)
@ui_rotation = Text.new(
'rotation: 0',
x: 10,
y: 100,
- color: 'lime'
+ color: 'lime',
+ z: 101
)
Rectangle.new(
x: (Window.width - 120),
width: 120,
height: 45,
- color: 'navy'
+ color: 'navy',
+ z: 100
)
@ui_fps = Text.new(
'fps: 60.00',
x: (Window.width - 110),
y: 10,
- color: 'teal'
+ color: 'teal',
+ z: 101
)
# How fast the player can move
-@speed = 10
+@speed = 5
# Initializing
-@x_move = 0
-@y_move = 0
-@cam_x_move = 0
-@cam_y_move = 0
-@is_follow = true
-@zoom_by = 1
-@debug1 = 0
-@debug2 = 0
-@debug4 = 0
-@debug3 = 0
+player_movement_x = 0
+player_movement_y = 0
+@pressed_space = false
+@scene_transition_into = false
+@scene_transition_out = false
+@indoors = false
+@house = nil
+@room = nil
on :key do |event|
- if event.key == 'a'
- @y_move += 0
- @x_move += -@speed
- end
- if event.key == 'd'
- @y_move += 0
- @x_move += @speed
- end
if event.key == 'w'
- @y_move += -@speed
- @x_move += 0
+ player_movement_y -= @speed unless @scene_transition_into || @scene_transition_out
end
if event.key == 's'
- @y_move += @speed
- @x_move += 0
- end
- if event.key == 'j'
- @cam_x_move -= @speed
- @is_follow = false
- end
- if event.key == 'l'
- @cam_x_move += @speed
- @is_follow = false
+ player_movement_y += @speed unless @scene_transition_into || @scene_transition_out
end
- if event.key == 'i'
- @cam_y_move -= @speed
- @is_follow = false
- end
- if event.key == 'k'
- @cam_y_move += @speed
- @is_follow = false
+ if event.key == 'd'
+ player_movement_x += @speed unless @scene_transition_into || @scene_transition_out
end
-end
-on :key_down do |event|
- if event.key == 'f'
- @player.flip_sprite(:vertical)
+ if event.key == 'a'
+ player_movement_x -= @speed unless @scene_transition_into || @scene_transition_out
end
- if event.key == 'h'
- @player.flip_sprite(:none)
+ if event.key == 'space'
+ @pressed_space = true unless @scene_transition_into || @scene_transition_out
end
- if event.key == 't'
- Camera.debug_y += 2
+ if event.key == 'q'
+ Camera.angle += 1
end
- if event.key == 'g'
+ if event.key == 'e'
+ Camera.angle -= 1
end
-end
-
-on :key do |event|
if event.key == 'z'
- @zoom_by = 1.015
+ Camera.zoom *= 1.015
end
if event.key == 'x'
- @zoom_by = 0.985
+ Camera.zoom *= 0.985
end
- if event.key == 'c'
- #Camera.zoom_to 1
- end
- if event.key == 'm'
- #Camera.move_to(-10,-10)
+end
+=begin
+Camera << Text.new('rotate me to see how if it works',
+ x: 500,
+ y: 500,
+ z: 99)
+=end
+update do
+ if (@player.x > 2371 && player_movement_x.positive?) || (@player.x.negative? && player_movement_x.negative?)
+ player_movement_x = 0
+ end
+ if (@player.y > 1608 && player_movement_y.positive?) || (@player.y.negative? && player_movement_y.negative?)
+ player_movement_y = 0
+ end
+ if !player_movement_y.zero? == !player_movement_x.zero?
+ player_movement_x /= 1.4141
+ player_movement_y /= 1.4141
+ end
+ @player.x += player_movement_x
+ @player.y += player_movement_y
+ if player_movement_x.negative?
+ @player.play animation: :walk, loop: true
+ elsif player_movement_x.positive? || !player_movement_y.zero?
+ @player.play animation: :walk, loop: true, flip: :vertical
+ else
+ @player.play animation: :stand
end
- if event.key == 'q'
- Camera.angle -= 2
- end
- if event.key == 'e'
- Camera.angle += 2
- end
- if event.key == 'r'
- Camera.angle = 0.0
- Camera.zoom = 1.0
+ if !@scene_transition_into && !@scene_transition_out
+ Camera.zoom = (-[Math.sqrt(((@player.x + (@player.width / 2) - Camera.x)**2) + ((@player.y + (@player.width / 2) - Camera.y)**2)), 350].min * 0.004) + 2
+ Camera.x += (@player.x + (@player.width / 2) - Camera.x) * 0.025
+ Camera.y += (@player.y + (@player.height / 2)- Camera.y) * 0.025
+ elsif @scene_transition_into
+ if Camera.zoom < 250
+ Camera.zoom *= 1.05
+ Camera.angle += 5
+ else
+ @scene_transition_into = false
+ @scene_transition_out = true
+ if @room.nil?
+ @house.remove
+ @house = nil
+ @indoors = true
+ else
+ @room.remove
+ @room = nil
+ @indoors = false
+ end
+ Camera.remove @background
+ @background.remove
+ @background = nil
+ end
+ Camera.x += (@player.x + (@player.width / 2) - Camera.x) * 0.25
+ Camera.y += (@player.y + (@player.height / 2) - Camera.y) * 0.25
+ elsif @scene_transition_out
+ if !(Camera.zoom <= 2.1 && Camera.angle.zero?)
+ Camera.zoom /= 1.05
+ Camera.angle -= 5
+ else
+ @scene_transition_out = false
+ end
end
-end
-update do
- @player.x += @x_move
- @player.y += @y_move
- @x_move = 0
- @y_move = 0
- Camera.zoom *= @zoom_by
- if @is_follow
- Camera.x = @player.x
- Camera.y = @player.y
+ if @house.nil? && !@indoors
+ @house = House.new(750, 300)
+ @background = Image.new(
+ 'assets/background.png',
+ x: 100, y: 100,
+ z: -1
+ )
+ Camera << @background
+ elsif @room.nil? && @indoors
+ @room = Room.new(750,300)
+ @background = Rectangle.new(
+ color: 'black',
+ x: 0,
+ y: 0,
+ width: 1920,
+ height: 1080,
+ z: -1
+ )
+ end
+ @shadow.x = @player.x - 2
+ @shadow.y = @player.y + 42
+
+ Camera.remove @house_text
+ @house_text&.remove
+ if @indoors
+ @house_text = @room.visted_by?(@player)
else
- angle = Camera.angle * (Math::PI / 180)
- Camera.x += (@cam_x_move * Math.cos(-angle)) - (@cam_y_move * Math.sin(-angle))
- Camera.y += (@cam_x_move * Math.sin(-angle)) + (@cam_y_move * Math.cos(-angle))
+ @house_text = @house.visted_by?(@player)
+ end
+ Camera << @house_text unless @house_text.nil?
+ if !@house_text.nil? && @pressed_space
+ @scene_transition_into = true
end
- @cam_x_move = 0
- @cam_y_move = 0
- @zoom_by = 1
@ui_pos_cam.text = "Camera Position: #{Camera.x.round(1)}, #{Camera.y.round(1)}"
@ui_pos_ply.text = "Player Position: #{@player.x.round(1)}, #{@player.y.round(1)}"
@ui_zoom.text = "Zoom: #{Camera.zoom.round(3)}"
@ui_fps.text = "FPS: #{Window.fps.round(2)}"
@ui_rotation.text = "Angle: #{Camera.angle}"
+ player_movement_x = 0
+ player_movement_y = 0
+ @pressed_space = false
Camera.redraw
end