From e5d46d2f812b88feae205eb542b11ed10e0a219b Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 23 Sep 2024 13:30:22 +0300 Subject: [PATCH] examples: add a consistent background to flappylearning, shown when the height of the view is very high (on Android) --- examples/flappylearning/game.v | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/flappylearning/game.v b/examples/flappylearning/game.v index 7ecb10bd6a..1d7599a289 100644 --- a/examples/flappylearning/game.v +++ b/examples/flappylearning/game.v @@ -1,7 +1,6 @@ module main import gg -import gx import time import math import rand @@ -11,6 +10,8 @@ import os.asset const win_width = 500 const win_height = 512 +const bg_color = gg.Color{0x96, 0xE2, 0x82, 0xFF} + struct Bird { mut: x f64 = 80 @@ -174,7 +175,7 @@ fn (mut app App) update() { fn main() { mut app := &App{} app.gg = gg.new_context( - bg_color: gx.white + bg_color: bg_color width: win_width height: win_height create_window: true @@ -206,15 +207,15 @@ fn (mut app App) init_images_wrapper() { } fn (mut app App) init_images() ! { - app.background = app.gg.create_image_from_byte_array(asset.read_bytes('assets', 'img/background.png')!)! app.bird = app.gg.create_image_from_byte_array(asset.read_bytes('assets', 'img/bird.png')!)! app.pipetop = app.gg.create_image_from_byte_array(asset.read_bytes('assets', 'img/pipetop.png')!)! app.pipebottom = app.gg.create_image_from_byte_array(asset.read_bytes('assets', 'img/pipebottom.png')!)! + app.background = app.gg.create_image_from_byte_array(asset.read_bytes('assets', 'img/background.png')!)! } fn frame(app &App) { app.gg.begin() - app.draw() + app.display() app.gg.end() } @@ -239,16 +240,16 @@ fn (app &App) display() { app.bird) } } + app.gg.draw_rect_filled(0, 510, app.background.width * 3, 5, gg.Color{0x21, 0x19, 0x28, 255}) + app.gg.draw_rect_filled(0, 513, app.background.width * 3, app.background.height, bg_color) + app.gg.draw_rect_filled(550, 0, app.background.width + 50, app.background.height + 20, + bg_color) app.gg.draw_text_def(10, 25, 'Score: ${app.score}') app.gg.draw_text_def(10, 50, 'Max Score: ${app.max_score}') app.gg.draw_text_def(10, 75, 'Generation: ${app.generation}') app.gg.draw_text_def(10, 100, 'Alive: ${app.alives} / ${app.nv.population}') } -fn (app &App) draw() { - app.display() -} - fn on_event(e &gg.Event, mut app App) { if e.typ == .key_down { app.key_down(e.key_code)