filled background
This commit is contained in:
parent
8a189a9523
commit
fc8e190d0a
BIN
~/.assets/fondo para itchio.png
Normal file
BIN
~/.assets/fondo para itchio.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.0 KiB |
42
~/V/example_window/draw.v
Normal file
42
~/V/example_window/draw.v
Normal file
@ -0,0 +1,42 @@
|
||||
import gg
|
||||
import gx
|
||||
|
||||
fn (game &Game) draw() {
|
||||
game.gg.begin()
|
||||
|
||||
// draw filled texture
|
||||
game.draw_bg_texture()
|
||||
|
||||
// draw ui
|
||||
game.draw_text(gg.window_size().width - 10, 0, 'Lives: ${game.player.lives}', 36,
|
||||
gx.white, 'right', 'top', true)
|
||||
|
||||
// draw image
|
||||
game.gg.draw_image(0, game.gg.window_size().height - game.player.image.height, game.player.image.width,
|
||||
game.player.image.height, game.player.image)
|
||||
|
||||
game.gg.end()
|
||||
}
|
||||
|
||||
fn (game &Game) draw_bg_texture() {
|
||||
game.gg.draw_image(game.bg_texture.pos_x - game.bg_texture.image.width, game.bg_texture.pos_y,
|
||||
game.bg_texture.image.width, game.bg_texture.image.height, game.bg_texture.image)
|
||||
|
||||
for x in 0 .. gg.window_size().width / game.bg_texture.image.width + 3 {
|
||||
game.gg.draw_image(x * game.bg_texture.image.width + game.bg_texture.pos_x, game.bg_texture.pos_y - game.bg_texture.image.height,
|
||||
game.bg_texture.image.width, game.bg_texture.image.height, game.bg_texture.image)
|
||||
|
||||
game.gg.draw_image(game.bg_texture.pos_x - game.bg_texture.image.width, game.bg_texture.pos_y - game.bg_texture.image.height,
|
||||
game.bg_texture.image.width, game.bg_texture.image.height, game.bg_texture.image)
|
||||
|
||||
for y in 0 .. gg.window_size().height / game.bg_texture.image.height + 3 {
|
||||
game.gg.draw_image(x * game.bg_texture.image.width + game.bg_texture.pos_x,
|
||||
y * game.bg_texture.image.height + game.bg_texture.pos_y, game.bg_texture.image.width,
|
||||
game.bg_texture.image.height, game.bg_texture.image)
|
||||
|
||||
game.gg.draw_image(game.bg_texture.pos_x - game.bg_texture.image.width,
|
||||
y * game.bg_texture.image.height + game.bg_texture.pos_y, game.bg_texture.image.width,
|
||||
game.bg_texture.image.height, game.bg_texture.image)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import gg
|
||||
import gx
|
||||
@ -12,8 +10,16 @@ const (
|
||||
|
||||
struct Game {
|
||||
mut:
|
||||
gg &gg.Context = unsafe { nil }
|
||||
player Player
|
||||
gg &gg.Context = unsafe { nil }
|
||||
player Player
|
||||
bg_texture BgTexture
|
||||
}
|
||||
|
||||
struct BgTexture {
|
||||
mut:
|
||||
image gg.Image
|
||||
pos_x f32
|
||||
pos_y f32
|
||||
}
|
||||
|
||||
struct Player {
|
||||
@ -25,19 +31,8 @@ mut:
|
||||
}
|
||||
|
||||
fn frame(mut game Game) {
|
||||
game.gg.begin()
|
||||
|
||||
game.gg.draw_rect_filled(game.player.pos_x, game.player.pos_y, 50, 50, gx.hex(0x5C7A56FF))
|
||||
|
||||
// draw ui
|
||||
game.draw_text(gg.window_size().width - 10, 0, 'Lives: ${game.player.lives}', 36,
|
||||
gx.white, 'right', 'top', true)
|
||||
|
||||
// draw image
|
||||
game.gg.draw_image(0, game.gg.window_size().height - game.player.image.height, game.player.image.width,
|
||||
game.player.image.height, game.player.image)
|
||||
|
||||
game.gg.end()
|
||||
game.update()
|
||||
game.draw()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -65,6 +60,13 @@ fn main() {
|
||||
lives: 3
|
||||
}
|
||||
|
||||
game.bg_texture = &BgTexture{
|
||||
pos_x: 0
|
||||
pos_y: 0
|
||||
}
|
||||
|
||||
game.bg_texture.image = game.gg.create_image(os.resource_abs_path(os.join_path('..',
|
||||
'..', '.assets', 'fondo para itchio.png'))) or { panic(err) }
|
||||
game.player.image = game.gg.create_image(os.resource_abs_path(os.join_path('..', '..',
|
||||
'.assets', 'v-logo.png'))) or { panic(err) }
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
module main
|
||||
|
||||
import gx
|
||||
|
||||
fn (game &Game) text_format(color gx.Color, size int, h_align gx.HorizontalAlign, v_align gx.VerticalAlign) gx.TextCfg {
|
||||
|
15
~/V/example_window/update.v
Normal file
15
~/V/example_window/update.v
Normal file
@ -0,0 +1,15 @@
|
||||
// import gg
|
||||
|
||||
fn (mut game Game) update() {
|
||||
if game.bg_texture.pos_x >= game.bg_texture.image.width {
|
||||
game.bg_texture.pos_x = 0
|
||||
} else {
|
||||
game.bg_texture.pos_x += .5
|
||||
}
|
||||
|
||||
if game.bg_texture.pos_y >= game.bg_texture.image.height {
|
||||
game.bg_texture.pos_y = 0
|
||||
} else {
|
||||
game.bg_texture.pos_y += .5
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user