Question: Modify a simple Ruby program to move a shape across the screen by changing the provided code in the Gosu cycle update ( ) method.
Modify a simple Ruby program to move a shape across the screen by changing the provided code in the Gosu cycle update method.
Use the code provided to get started.
You must enhance the code provided as follows:
The shape also can be moved up and down
The shape does not move out of the window area
Upload a screenshot of your program running to the workspace.
require 'gosu'
module ZOrder
BACKGROUND, MIDDLE, TOP
end
WIDTH
HEIGHT
SHAPEDIM
class GameWindow Gosu::Window
def initialize
superWIDTH HEIGHT, false
self.caption "Shape Moving"
@shapey HEIGHT
@shapex WIDTH
end
def update
if buttondown?Gosu::KbRight && @shapex WIDTH SHAPEDIM
@shapex
end
if buttondown?Gosu::KbLeft && @shapex
@shapex
end
if buttondown?Gosu::KbUp && @shapey
@shapey
end
if buttondown?Gosu::KbDown && @shapey HEIGHT SHAPEDIM
@shapey
end
end
def draw
Gosu.drawrect@shapex @shapey SHAPEDIM, SHAPEDIM, Gosu::Color::RED, ZOrder::TOP, mode :default
end
end
window GameWindow.new
window.show
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
