Question: Modify a simple Ruby program to move a shape across the screen by modifying the tasks in the Gosu cycle update ( ) and draw
Modify a simple Ruby program to move a shape across the screen by modifying the tasks in the Gosu cycle update and draw methods.
Enhance the code provided as follows:
Add a variable in the initialize method called shapex with the initial value of zero.
Add code into the update method that will add to shapex
Add code into the draw method that will draw a shape square or circle of any visible colour at the y coordinate of and x coordinate of shapex Regular main compared with GOSU cycle
The GOSU cycle can also be represented as:
require 'gosu'
module ZOrder
BACKGROUND, MIDDLE, TOP
end
class GameWindow Gosu::Window
def initialize
super false
self.caption "Gosu Cycle Example"
@backgroundimage Gosu::Image.newmediaearthpng
@font Gosu::Font.new
@cycle
@shapex
end
def update
@cycle
@shapex
end
def draw
@backgroundimage.draw ZOrder::BACKGROUND
@font.drawtextCycle count: #@cycle ZOrder::TOP, Gosu::Color::BLACK
# Draw a shape in this case, a square at the specified coordinates
Gosu.drawrect@shapex Gosu::Color::GREEN, ZOrder::TOP
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
