I add screenshots to readme file in github:
https://github.com/zhzhussupovkz/super-beeGameplay is very simple, simple physics and AI.... I think enemy's haven't AI. In the future, I add AI to enemies.
You must kill enemies by weapon, by bomb and collect nectar from flowers. It's all. And sometime you have prizes with stamina, ammo, scores or lives.
Images and icons not mine, free license images.
It's my second game in my life.
Sorry for my English, please.
Hello world! I write a simple platformer where mouse eat cheeses from platforms. My code for mouse
1. Player class:
#class Player
class Player
def initialize window, x, y, left, right
@x, @y = x, y
@left = Gosu::Image.new(window, left, false)
@right = Gosu::Image.new(window, right, false)
@face_left = true
end
attr_reader :x, :y
#move left
def move_left
@face_left = true
@x -= 5.0
@x = 1.0 if @x <= 1.0
end
#move right
def move_right
@face_left = false
@x += 5.0 if @x <= 595.0
end
#up
def up
@y -= 7.0 if @y >= 17.0
end
#move down
def down
@y += 2.5 if @y <= 372.5
end
#move
def move
@x %= 640
@y %= 480
end
#draw
def draw
if @face_left
@left.draw(@x, @y, 1)
else
@right.draw(@x, @y, 1)
end
end
end
2.Mouse class:
#class Mouse - main player
class Mouse < Player
def initialize window, x, y
super window, x, y, "images/mouse.png", "images/mouse-r.png"
@score, @lives = 0, 3
@heart = Gosu::Image.new(window, "images/heart.png", false)
@ui = Gosu::Font.new(window, 'Monaco', 25)
puts "Create mouse..."
@on_ground = false
end
attr_reader :lives, :score
attr_accessor :on_ground
#draw mouse
def draw
super
@ui.draw("Score: #{@score}", 10, 450, 2)
@heart_x = 0
@lives.times do
@heart.draw(600-@heart_x, 450, 2)
@heart_x += 24
end
end
#move down
def down
@y += 2.5 if @y <= 372.5
end
#dead
def dead
@lives -= 1
@lives = 0 if @lives <= 0
end
def dead?
return @lives == 0
end
#add score
def add_score
@score += 100
end
end
3.Level class:
#class Level
class Level
def initialize window
@window, @num = window, 0
@cheeses = []
@bricks = []
@ui = Gosu::Font.new(@window, 'Monaco', 25)
puts "Initialize levels..."
end
attr_reader :ui, :num
attr_accessor :bricks, :cheeses
#starting level
def start
@num += 1
(2+@num).times do
@x_cord = rand(10..550)
@y_cord = rand(50..325)
@cheeses << Cheese.new(@window, @x_cord, @y_cord)
@bricks << Brick.new(@window, @x_cord - 10, @y_cord + 36)
end
puts "Starting level #{@num}."
puts "Go!"
end
#draw
def draw
@cheeses.each do |e| e.draw end
@bricks.each do |e| e.draw end
@ui.draw("Level:#{@num}", 10, 425, 2)
end
#max scores in level
def total_scores
(2*@num + 0.5 * @num * (@num+1))*100
end
#end level
def end_level
@cheeses = []
@bricks = []
end
end
4.Main window:
#main window
class MyWindow < Gosu::Window
def initialize
puts "Start environment..."
super 640, 480, false
self.caption = 'Mouse Game'
@bg = Gosu::Image.new(self, 'images/bg.png', true);
@music = Gosu::Song.new(self, 'sounds/music.ogg')
puts "Create game music..."
@music.play(looping = true)
@mouse = Mouse.new(self, 520, 375)
@level = Level.new(self)
@level.start
end
#game logic
def update
if @mouse.score == @level.total_scores
@level.end_level
@level.start
end
@mouse.move_left if button_down? Gosu::KbLeft
@mouse.move_right if button_down? Gosu::KbRight
@mouse.up if button_down? Gosu::KbUp or button_down? Gosu::KbSpace
@mouse.down if @mouse.on_ground == false
@mouse.move
@level.cheeses.each do |e|
if (e.x - @mouse.x).abs <= 15.0 && (e.y - @mouse.y).abs <= 15.0
e.drawing = false
e.x = e.y = -1
@mouse.add_score
end
end
end
def draw
@level.draw
@mouse.draw
@bg.draw(0, 0, 0)
end
def button_down(key)
case key
when Gosu::KbEscape
@music.stop
close
puts "Exit."
end
end
end
How can I create logic:
Stop falling down mouse if he standing in platform and fall down if he jump from platform?
I try when mouse intersects by x and y with platform but he fall down always
Thanks for all, and sorry for my English! (I'm novice in game development)
Hello world! I need help! I read Gosu documentation, but not found method for delete images from window:
For example:
#class Cheese
class Cheese
def initialize window, x, y
@image = Gosu::Image.new(window, "images/cheese.png", false)
@x, @y = x, y
end
#draw cheese
def draw
@image.draw(@x, @y, 1)
end
def delete
#what I write here for delete image? In Gosu::Image documentation i not found answer for my question
end
end
Thanks for all, and sorry for my English!