Skip to content

Commit

Permalink
Add clouds. Home in on pixel style and update most gfx
Browse files Browse the repository at this point in the history
  • Loading branch information
marcheiligers committed Jul 31, 2021
1 parent a9de057 commit 1099d60
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
https://www.pinclipart.com/pindetail/iRJxbJi_underline-design-and-simple-design-hand-drawn-elements/
https://www.pinclipart.com/pindetail/Twbbw_scroll-design-clip-art-corner-designs-clipartfest-clipartix/
https://easings.net

Image by <a href="https://pixabay.com/users/ykman-9016214/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5341640">YK Choi</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5341640">Pixabay</a>
Image by <a href="https://pixabay.com/users/95c-484762/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2421760">95C</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2421760">Pixabay</a>
https://www.pngkey.com/download/u2a9o0u2o0e6e6u2_background-transparent-real-clouds-png-cumulus/


31 changes: 31 additions & 0 deletions app/cloud.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Cloud
CLOUDS = [
{ w: 640, h: 427 },
{ w: 128, h: 64 },
{ w: 64, h: 32 },
{ w: 64, h: 32 },
{ w: 64, h: 32 }
]
def initialize(anywhere: true)
@v = (rand(10) + 1) / 10

i = rand(3) + 2
c = CLOUDS[i]
z = 8
x = anywhere ? (rand(1000) + 140) : -c[:w] * z
y = rand(720) - 50
a = rand(100) + 25
r = 0

@primitive = { x: x, y: y, w: c[:w] * z, h: c[:h] * z, a: a, path: "sprites/cloud#{i}.png", angle: r }.sprite
end

def finished?
@primitive[:x] + @primitive[:w] < 0 || @primitive[:x] > 1280
end

def to_p
@primitive[:x] += @v
@primitive
end
end
47 changes: 43 additions & 4 deletions app/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
MAX_POINT_TICKS = 600
PRIMARY_FONT = 'fonts/BLKCHCRY.TTF'
SECONDARY_FONT = 'fonts/MayflowerAntique.ttf'
CLOUD_CHANCE = 0.003
STARTING_CLOUDS = 3

class Snake
def initialize
Expand Down Expand Up @@ -135,6 +137,7 @@ def reset
@state = :game_starting
@score = 0
@animations = []
STARTING_CLOUDS.times { @animations << Cloud.new }
$gtk.args.outputs.static_primitives.clear
end

Expand All @@ -150,7 +153,8 @@ def to_p
[@map.to_p, head_sprite, fruit_sprite, score, @menu.to_p]
when :game
@animations.reject!(&:finished?)
[@map.to_p] + @body.map { |pos| body_sprite(pos) } + [head_sprite, fruit_sprite, score] + @animations.map(&:to_p)
@animations << Cloud.new(anywhere: false) if rand < CLOUD_CHANCE
[@map.to_p] + @body.map { |pos| body_sprite(pos) } + [head_sprite, wings_sprite, fruit_sprite, score] + @animations.map(&:to_p)
when :game_over
[text('GAME OVER'), text('Press [SPACE] to play again', -50), score]
end
Expand All @@ -163,15 +167,50 @@ def head_sprite
when :up then 180
when :down then 0
end
{ x: @logical_x * GRID_SIZE, y: @logical_y * GRID_SIZE, w: GRID_SIZE, h: GRID_SIZE, path: 'sprites/snake.png', angle: angle }.sprite
{ x: @logical_x * GRID_SIZE, y: @logical_y * GRID_SIZE, w: GRID_SIZE, h: GRID_SIZE, path: 'sprites/head.png', angle: angle }.sprite
end

def body_sprite(pos)
{ x: pos.x * GRID_SIZE, y: pos.y * GRID_SIZE, w: GRID_SIZE, h: GRID_SIZE, path: 'sprites/body.png' }.sprite
{ x: pos.x * GRID_SIZE, y: pos.y * GRID_SIZE, w: GRID_SIZE, h: GRID_SIZE, path: 'sprites/body2.png' }.sprite
end

def wings_sprite
anim = ($args.tick_count / 10).to_i % 3
case @direction
when :left
angle = 180
x = @logical_x + 1
y = @logical_y - 1
when :right
angle = 0
x = @logical_x - 1
y = @logical_y - 1
when :up
angle = 90
x = @logical_x
y = @logical_y - 2
when :down
angle = -90
x = @logical_x
y = @logical_y
end

{
x: x * GRID_SIZE,
y: y * GRID_SIZE,
w: GRID_SIZE,
h: GRID_SIZE * 3,
path: 'sprites/wings.png',
angle: angle,
source_x: anim * 5,
source_y: 0,
source_w: 5,
source_h: 15
}.sprite
end

def fruit_sprite
{ x: @fruit.x * GRID_SIZE, y: @fruit.y * GRID_SIZE, w: GRID_SIZE, h: GRID_SIZE, path: 'sprites/peach.png' }.sprite
{ x: @fruit.x * GRID_SIZE, y: @fruit.y * GRID_SIZE, w: GRID_SIZE, h: GRID_SIZE, path: 'sprites/peach2.png' }.sprite
end

def score
Expand Down
10 changes: 6 additions & 4 deletions app/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ def initialize

rt.primitives << { x: 75, y: 75, w: 1130, h: 570, r: 142, g: 199, b: 241, a: 200 }.solid

rt.primitives << { x: 50, y: 500, w: 1180, h: 218, path: 'sprites/menu_top.png' }.sprite
rt.primitives << { x: 15, y: 15, w: 400, h: 400, path: 'sprites/menu_corner.png' }.sprite
rt.primitives << { x: 865, y: 15, w: 400, h: 400, path: 'sprites/menu_corner.png', flip_horizontally: true }.sprite
rt.primitives << { x: 50, y: 500, w: 1180, h: 218, path: 'sprites/menu_top2.png' }.sprite
rt.primitives << { x: 15, y: 15, w: 400, h: 400, path: 'sprites/menu_corner2.png' }.sprite
rt.primitives << { x: 865, y: 15, w: 400, h: 400, path: 'sprites/menu_corner2.png', flip_horizontally: true }.sprite

rt.primitives << [text('WYRM', 100, 60), text('Press [SPACE] to play', -50, 3, SECONDARY_FONT)]
rt.primitives << { x: 390, y: 360, w: 512, h: 128, path: 'sprites/title.png' }.sprite

rt.primitives << [text('Press [SPACE] to play', -50, 3, SECONDARY_FONT)]

@primitive = { x: 0, y: 0, w: 1280, h: 720, path: TARGET, source_x: 0, source_y: 0, source_w: 1280, source_h: 720 }.sprite
@state = :hidden
Expand Down
1 change: 1 addition & 0 deletions app/requires.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'app/easing.rb'
require 'app/fruit_score_label.rb'
require 'app/cloud.rb'
require 'app/menu.rb'
require 'app/map.rb'
require 'app/game.rb'
Binary file added sprites/body2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/cloud0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/cloud1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/cloud2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/cloud3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/cloud4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/head.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/menu_corner2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/menu_top2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/peach2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/wings.aseprite
Binary file not shown.
Binary file added sprites/wings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1099d60

Please sign in to comment.