mirror of
https://github.com/vlang/v.git
synced 2025-09-13 06:22:26 +03:00
examples: add a consistent background to flappylearning, shown when the height of the view is very high (on Android)
This commit is contained in:
parent
b79aa0208f
commit
e5d46d2f81
1 changed files with 9 additions and 8 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue