Snake: Difference between revisions
m
→{{header|Rust}}: cosmetic
m (added up and down arrow keys, removed unused G variable comment) |
m (→{{header|Rust}}: cosmetic) |
||
Line 4,605:
<syntaxhighlight lang="rust">/* add to file Cargo.toml:
[dependencies]
winsafe = "0.0.8" # IMHO: before the appearance of winsafe="0.1" it is not worth raising the version here
rand = "0.8"
derive-new = "0.5"
Line 4,627:
#[derive(new)]
struct Context {
wnd: gui::WindowMain,
#[new(default) ] snake: Vec<i32>, // [rect_ids] where rect_id = y * TW + x (where x, y: nSTEPs)
#[new(value = "[ID0; 6]")] r: [i32; 6], // ID 6 rect to color in next frame (bg, tail, turn, body, food, head)
Line 4,646:
let wnd = gui::WindowMain::new(gui::WindowMainOpts {
title: "Snake - Start: Space, then press W-A-S-D".to_string(),
size:
class_bg_brush: brushes[bg],
..Default::default()
Line 4,660:
let hdc = ctx.wnd.hwnd().BeginPaint(&mut ps)?;
hdc.SelectObjectPen(HPEN::CreatePen(co::PS::NULL, 0, COLORREF::new(0, 0, 0))?)?;
for (&
hdc.SelectObjectBrush(brush)?;▼
▲ let top = rect_id / TW * STEP - (STEP * GCW + SNAKE_W) / 2;
let rect = RECT { left, top, right: left + SNAKE_W, bottom: top + SNAKE_W };
▲ hdc.SelectObjectBrush(brush)?;
hdc.RoundRect(rect, SIZE::new(SNAKE_W / 2, SNAKE_W / 2))?;
}
|