who can stop the flickering?
thats my code:
require ‘fox16’
require ‘fox16/colors’
include Fox
class Fahrrad
attr_accessor :col_Rahmen
#draw bike
$fahrrad=1
def initialize(col_background = FXColor::Green)
@col_background = col_background
@col_Rahmen = FXColor::Green
@col_reifen = FXColor::Black
@col_felgen = FXColor::White
end
def draw(dc, pos = FXPoint.new(0,0))
return if dc.nil?
dc.foreground = @col_background
dc.fillCircle(pos.x+12, pos.y+20, 5)
dc.fillCircle(pos.x+32, pos.y+20, 5)
dc.foreground = @col_reifen
dc.fillCircle(pos.x+12, pos.y+20, 4)
dc.fillCircle(pos.x+32, pos.y+20, 4)
dc.foreground = @col_felgen
dc.fillCircle(pos.x+12, pos.y+20, 2)
dc.fillCircle(pos.x+32, pos.y+20, 2)
dc.foreground = @col_Rahmen
dc.drawLine(pos.x+11, pos.y+13, pos.x+32, pos.y+13)
dc.drawLine(pos.x+11, pos.y+13, pos.x+19, pos.y+19)
dc.drawLine(pos.x+19, pos.y+19, pos.x+32, pos.y+13)
dc.drawLine(pos.x+11, pos.y+13, pos.x+5, pos.y+19)
dc.drawLine(pos.x+19, pos.y+19, pos.x+5, pos.y+19)
dc.drawLine(pos.x+32, pos.y+8, pos.x+32, pos.y+19)
dc.drawLine(pos.x+28, pos.y+8, pos.x+32, pos.y+8)
end
end
class RubykidsMainWindow < FXMainWindow
KEY_ARROW_LEFT = 65361
KEY_ARROW_UP = 65362
KEY_ARROW_RIGHT = 65363
KEY_ARROW_DOWN = 65364
def initialize(app)
super(app, “BikeDriver 5”, :opts => DECOR_ALL, :width => 1700,
:height => 990)
@hauptFrame = FXHorizontalFrame.new(
self,
LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y,
:padLeft => 0,
:padRight => 0,
:padTop => 0,
:padBottom => 0
)
@leinwandFrame = FXVerticalFrame.new(
@hauptFrame,
LAYOUT_TOP|LAYOUT_LEFT|LAYOUT_FILL_X|LAYOUT_FILL_Y,
:padLeft => 20,
:padRight => 20,
:padTop => 250,
:padBottom => 240
)
FXLabel.new(
@leinwandFrame,
“Bobs Town”,
:opts => JUSTIFY_CENTER_X|LAYOUT_FILL_X
)
FXHorizontalSeparator.new(
@leinwandFrame,
SEPARATOR_GROOVE|LAYOUT_FILL_X
)
@leinwand = FXCanvas.new(
@leinwandFrame,
:opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT
)
FXHorizontalSeparator.new(
@leinwandFrame,
SEPARATOR_GROOVE|LAYOUT_FILL_X
)
@leinwand.connect(SEL_PAINT, method(:onLeinwandRepaint))
@leinwand.connect(SEL_KEYPRESS, method(:onKeyPressed))
@menuFrame = FXVerticalFrame.new(
@hauptFrame,
LAYOUT_TOP|LAYOUT_LEFT|LAYOUT_FILL_Y,
:padLeft => 20,
:padRight => 20,
:padTop => 250,
:padBottom => 250
)
FXLabel.new(
@menuFrame,
"Menü",
:opts => JUSTIFY_CENTER_X|LAYOUT_FILL_X
)
@farbknopf = FXButton.new(
@menuFrame,
"switch vehicle",
nil,
nil,
if $fahrrad == 1
$fahrrad = 2
else $fahrrad = 1
end,
:opts =>
FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_LEFT,
:padLeft => 10,
:padRight => 10,
:padTop => 5,
:padBottom => 5
)
$b=1
if $b==1
@farbknopf.connect(SEL_COMMAND){@fahrrad.col_Rahmen =
FXColor::Red}
$b=2
elsif $b==2
@farbknopf.connect(SEL_COMMAND){@fahrrad.col_Rahmen =
FXColor::Green}
$b=1
end
FXButton.new(
@menuFrame,
"quit",
nil,
getApp(),
FXApp::ID_QUIT,
:opts =>
FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_LEFT,
:padLeft => 10,
:padRight => 10,
:padTop => 5,
:padBottom => 5
)
@current_pos = FXPoint.new(30, 135)
@move_distance = FXPoint.new(8, 8)
@col_background = FXRGB(255, 255, 255)
@fahrrad =Fahrrad.new(@col_background)
end
#painting
def onLeinwandRepaint(sender, sel, event)
FXDCWindow.new(@leinwand, event) do |dc|
dc.foreground = FXColor::LimeGreen
dc.fillRectangle(0, 0, @leinwand.width, @leinwand.height)
#hauses top
x=10
y=35
while x < 1600 do
dc.foreground = FXColor::SlateGray
dc.fillRectangle(x, 30, 50, 80)
dc.foreground = FXColor::DarkBlue
dc.fillRectangle(x+15, 45, 15, 15)
dc.foreground = FXColor::SandyBrown
dc.fillRectangle(x+15, 80, 15, 30)
dc.foreground = FXColor::Red
dc.drawLine(x-5, 40, y, 0)
dc.drawLine(x+55, 40, y, 0)
dc.foreground = FXColor::SaddleBrown
dc.fillRectangle(x-20, 95, 5, 15)
dc.fillRectangle(x-10, 95, 5, 15)
dc.fillRectangle(x-25, 90, 25, 5)
x = x+75
y= y+75
end
#hauses left
x=15
y=40
while x< 250 do
dc.foreground = FXColor::LightYellow
dc.fillRectangle(x,200, 50, 80)
dc.foreground = FXColor::DarkBlue
dc.fillRectangle(x+15, 215, 15, 15)
dc.foreground = FXColor::SandyBrown
dc.fillRectangle(x+15, 250, 15, 30)
dc.foreground = FXColor::Red
dc.drawLine(x-5, 210, y, 170)
dc.drawLine(x+55, 210, y, 170)
dc.foreground = FXColor::Red
dc.fillRectangle(y-45, 265, 5, 15)
dc.fillRectangle(y-35, 265, 5, 15)
dc.fillRectangle(y-50, 260, 25, 5)
x= x+75
y= y+75
end
#hauses middle
x=365
y=390
while x<1300 do
dc.foreground = FXColor::SlateGray
dc.fillRectangle(x,200, 50, 80)
dc.foreground = FXColor::DarkBlue
dc.fillRectangle(x+15, 215, 15, 15)
dc.foreground = FXColor::SandyBrown
dc.fillRectangle(x+15, 250, 15, 30)
dc.foreground = FXColor::Red
dc.drawLine(x-5, 210, y, 170)
dc.drawLine(x+55, 210, y, 170)
dc.foreground = FXColor::White
dc.fillRectangle(y+30, 265, 5, 15)
dc.fillRectangle(y+40, 265, 5, 15)
dc.fillRectangle(y+25, 260, 25, 5)
x= x+75
y= y+75
end
#hauses right bottom
x=1390
y=1415
while x<1800 do
dc.foreground = FXColor::LightYellow
dc.fillRectangle(x,330, 50, 80)
dc.foreground = FXColor::DarkBlue
dc.fillRectangle(x+15, 345, 15, 15)
dc.foreground = FXColor::SandyBrown
dc.fillRectangle(x+15, 380, 15, 30)
dc.foreground = FXColor::Red
dc.drawLine(x-5, 340, y, 300)
dc.drawLine(x+55, 340, y, 300)
dc.foreground = FXColor::SaddleBrown
dc.fillRectangle(y+30, 395, 5, 15)
dc.fillRectangle(y+40, 395, 5, 15)
dc.fillRectangle(y+25, 390, 25, 5)
x= x+75
y= y+75
end
#strasse top
dc.foreground = FXColor::Black
dc.fillRectangle(0, 120, 1700, 40)
x=5
dc.foreground = FXColor::White
while x < 1700 do
dc.fillRectangle(x, 138, 10, 4)
x= x+20
end
#strasse middle
dc.foreground = FXColor::Black
dc.fillRectangle(0, 290, 1350, 40)
x=5
dc.foreground = FXColor::White
while x < 1350 do
dc.fillRectangle(x, 308, 10, 4)
x= x+20
end
#strasse bottom
dc.foreground = FXColor::Black
dc.fillRectangle(1325, 430, 500, 40)
x=1345
dc.foreground = FXColor::White
while x < 1600 do
dc.fillRectangle(x, 448, 10, 4)
x= x+20
end
#strasse left
dc.foreground = FXColor::Black
dc.fillRectangle(300, 160, 45, 140)
x=160
dc.foreground = FXColor::White
while x < 300 do
dc.fillRectangle(320, x, 4, 10)
x= x+20
end
#street right
dc.foreground = FXColor::Black
dc.fillRectangle(1325, 160, 45, 285)
x=160
dc.foreground = FXColor::White
while x < 460 do
dc.fillRectangle(1345, x, 4, 10)
x= x+20
end
#trees right middle
x=1410
while x < 1800 do
dc.foreground = FXColor::SaddleBrown
dc.fillRectangle(x, 245, 20, 40)
dc.foreground = FXColor::DarkGreen
dc.fillCircle(x+10, 210, 45)
x = x+75
end
#trees left bottom
x=10
while x < 1300 do
dc.foreground = FXColor::SaddleBrown
dc.fillRectangle(x, 425, 20, 40)
dc.foreground = FXColor::DarkGreen
dc.fillCircle(x+10, 390, 45)
x = x+75
end
#bikeposition
pos = FXPoint.new(@current_pos.x, @current_pos.y)
[
[0, 0],
[@leinwand.width, 0],
[0, @leinwand.height],
[@leinwand.width, @leinwand.height]
].each do |off|
pos.x = @current_pos.x - off[0]
pos.y = @current_pos.y - off[1]
@fahrrad.draw(dc, pos)
end
end
end
def onKeyPressed(sender, sel, event)
if event.code == KEY_ARROW_LEFT
if @current_pos.y > 270 && @current_pos.x < 7
elsif @current_pos.y > 135 && @current_pos.y < 270
if @current_pos.x < 300
elsif @current_pos.x > 345 && @current_pos.x < 1320
else
self.move_backward
end
elsif @current_pos.y > 310 && @current_pos.x < 1320
else
self.move_backward
end
elsif event.code == KEY_ARROW_RIGHT
if @current_pos.y > 135 && @current_pos.y < 270
if @current_pos.x < 305
self.move_forward
elsif @current_pos.x > 1315 && @current_pos.x < 1330
self.move_forward
end
elsif @current_pos.y > 270 && @current_pos.x > 1465
elsif @current_pos.y > 270 && @current_pos.y < 415 &&
@current_pos.x > 1330
else
self.move_forward
end
elsif event.code == KEY_ARROW_UP
if @current_pos.y < 105
elsif @current_pos.y < 275 && @current_pos.y > 135
if @current_pos.x < 290
elsif @current_pos.x > 315
if @current_pos.x < 1315
elsif @current_pos.x > 1340
else
self.move_up
end
else
self.move_up
end
else
self.move_up
end
elsif event.code == KEY_ARROW_DOWN
if @current_pos.y > 300 && @current_pos.x < 1315
elsif @current_pos.y > 435
elsif @current_pos.y > 130 && @current_pos.y < 270
if @current_pos.x < 290
elsif @current_pos.x > 315
if @current_pos.x < 1315
elsif @current_pos.x > 1340
else
self.move_down
end
else
self.move_down
end
else
self.move_down
end
end
@leinwand.update
end
def move_forward
@current_pos.x = (@current_pos.x + @move_distance.x) %
@leinwand.width
@current_pos.y = (@current_pos.y ) %
@leinwand.height
end
def move_backward
@current_pos.x = (@current_pos.x - @move_distance.x) %
@leinwand.width
@current_pos.y = (@current_pos.y ) %
@leinwand.height
end
def move_up
@current_pos.x = (@current_pos.x ) %
@leinwand.width
@current_pos.y = (@current_pos.y - @move_distance.y) %
@leinwand.height
end
def move_down
@current_pos.x = (@current_pos.x ) %
@leinwand.width
@current_pos.y = (@current_pos.y + @move_distance.y) %
@leinwand.height
end
def create
super
show(PLACEMENT_SCREEN)
end
end
application = FXApp.new
mainWin = RubykidsMainWindow.new(application)
application.create
application.run