Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started