Answered step by step
Verified Expert Solution
Link Copied!

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 shape_x with the initial value of zero.
Add code into the update() method that will add 10 to shape_x.
Add code into the draw() method that will draw a shape (square or circle of any visible colour) at the y coordinate of 30 and x coordinate of shape_x. Regular main() compared with GOSU cycle
The GOSU cycle can also be represented as:
require 'gosu'
module ZOrder
BACKGROUND, MIDDLE, TOP =*0..2
end
class GameWindow Gosu::Window
def initialize
super(200,135, false)
self.caption = "Gosu Cycle Example"
@background_image = Gosu::Image.new("media/earth.png")
@font = Gosu::Font.new(20)
@cycle =0
@shape_x =0
end
def update
@cycle +=1
@shape_x +=10
end
def draw
@background_image.draw(0,0, ZOrder::BACKGROUND)
@font.draw_text("Cycle count: #{@cycle}",10,10, ZOrder::TOP, 1.0,1.0, Gosu::Color::BLACK)
# Draw a shape (in this case, a square) at the specified coordinates
Gosu.draw_rect(@shape_x,30,50,50, Gosu::Color::GREEN, ZOrder::TOP)
end
end
window = GameWindow.new
window.show
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

=+Based on this, what model might you use to predict Log10Price?

Answered: 1 week ago