mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
examples/bounce.v: minor fixes
This commit is contained in:
parent
9782d85709
commit
bdf1717703
@ -10,7 +10,7 @@ import time
|
|||||||
|
|
||||||
struct Game {
|
struct Game {
|
||||||
mut:
|
mut:
|
||||||
vg *gg.GG
|
gg *gg.GG
|
||||||
x int
|
x int
|
||||||
y int
|
y int
|
||||||
dy int
|
dy int
|
||||||
@ -26,7 +26,7 @@ fn main() {
|
|||||||
width := 600
|
width := 600
|
||||||
height := 300
|
height := 300
|
||||||
mut game := &Game{
|
mut game := &Game{
|
||||||
vg: 0
|
gg: 0
|
||||||
dx: 2
|
dx: 2
|
||||||
dy: 2
|
dy: 2
|
||||||
height: height
|
height: height
|
||||||
@ -44,13 +44,13 @@ fn main() {
|
|||||||
game.main_wnd = window
|
game.main_wnd = window
|
||||||
window.make_context_current()
|
window.make_context_current()
|
||||||
gg.init()
|
gg.init()
|
||||||
game.vg = gg.new_context(gg.Cfg {
|
game.gg = gg.new_context(gg.Cfg {
|
||||||
width: width
|
width: width
|
||||||
height: height
|
height: height
|
||||||
font_size: 20
|
font_size: 20
|
||||||
use_ortho: true
|
use_ortho: true
|
||||||
})
|
})
|
||||||
println('Starting game loop...')
|
println('Starting the game loop...')
|
||||||
go game.run()
|
go game.run()
|
||||||
for {
|
for {
|
||||||
gl.clear()
|
gl.clear()
|
||||||
@ -66,19 +66,19 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
[live]
|
[live]
|
||||||
fn (ctx &Game) draw() {
|
fn (game &Game) draw() {
|
||||||
ctx.vg.draw_rect(ctx.x, ctx.y, W, W, gx.rgb(255, 0, 0))
|
game.gg.draw_rect(game.x, game.y, W, W, gx.rgb(255, 0, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (ctx mut Game) run() {
|
fn (game mut Game) run() {
|
||||||
for {
|
for {
|
||||||
ctx.x += ctx.dx
|
game.x += game.dx
|
||||||
ctx.y += ctx.dy
|
game.y += game.dy
|
||||||
if ctx.y >= ctx.height - W || ctx.y <= 0 {
|
if game.y >= game.height - W || game.y <= 0 {
|
||||||
ctx.dy = - ctx.dy
|
game.dy = - game.dy
|
||||||
}
|
}
|
||||||
if ctx.x >= ctx.width - W || ctx.x <= 0 {
|
if game.x >= game.width - W || game.x <= 0 {
|
||||||
ctx.dx = - ctx.dx
|
game.dx = - game.dx
|
||||||
}
|
}
|
||||||
// Refresh
|
// Refresh
|
||||||
time.sleep_ms(17)
|
time.sleep_ms(17)
|
||||||
|
Loading…
Reference in New Issue
Block a user