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
please fix the following code:
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 # Add variable to track shape xcoordinate
end
def update
@cycle
@shapex # Add code to increment shape xcoordinate
end
def draw
@backgroundimage.draw ZOrder::BACKGROUND
@font.drawtextCycle count: #@cycle ZOrder::TOP, Gosu::Color::BLACK
# Add code to draw shape at y and xshapex
shapeimage loadshapeimagemediasquarepng
shapeimage.draw@shapex ZOrder::TOP, Gosu::Color::GREEN if shapeimage
end
def loadshapeimageimagepath
begin
Gosu::Image.newimagepath
rescue exception
puts "Error loading image: #exceptionmessage
return nil
end
end
end
window GameWindow.new
window.show The GOSU cycle can also be
represented as:
Window Class
initialize
update
Thece run until the game stops
draw
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