Initial commit with working cli uxnmin.ha
This commit is contained in:
+90
@@ -0,0 +1,90 @@
|
||||
use sdl3;
|
||||
use sdl3::image;
|
||||
use sdl3::ttf;
|
||||
use types::c;
|
||||
|
||||
def WIDTH = 640;
|
||||
def HEIGHT = 480;
|
||||
|
||||
export fn main() void = {
|
||||
sdl3::Init(sdl3::InitFlags::VIDEO)!;
|
||||
defer sdl3::Quit();
|
||||
|
||||
const win = sdl3::CreateWindow(
|
||||
c::nulstr("Meadow\0"),
|
||||
WIDTH, HEIGHT, 0)!;
|
||||
defer sdl3::DestroyWindow(win);
|
||||
|
||||
const render = sdl3::CreateRenderer(win, null)!;
|
||||
defer sdl3::DestroyRenderer(render);
|
||||
sdl3::SetRenderDrawColor(render, 0, 0, 128, 255)!;
|
||||
|
||||
const img = image::LoadTexture(render, c::nulstr("./assets/mascot.jpg\0"))!;
|
||||
defer sdl3::DestroyTexture(img);
|
||||
|
||||
ttf::Init()!;
|
||||
defer ttf::Quit();
|
||||
|
||||
let font = ttf::OpenFontIO(
|
||||
sdl3::IOFromConstMem(&tiny_ttf, len(tiny_ttf))!, true, 18.0)!;
|
||||
defer ttf::CloseFont(font);
|
||||
|
||||
let text_color = sdl3::Color { r = 0, g = 255, b = 0, a = 255 };
|
||||
let text = ttf::RenderText_Blended(font, c::nulstr("Hello World!\0"),
|
||||
0, text_color)!;
|
||||
let text_texture = sdl3::CreateTextureFromSurface(render, text)!;
|
||||
sdl3::DestroySurface(text);
|
||||
defer sdl3::DestroyTexture(text_texture);
|
||||
|
||||
let w = 0.0f32, h = 0.0f32;
|
||||
sdl3::GetTextureSize(img, &w, &h)!;
|
||||
sdl3::get_error()!;
|
||||
const w = w: int, h = h: int;
|
||||
|
||||
let x = 0, y = 0;
|
||||
let xd = 1, yd = 1;
|
||||
|
||||
let run = true;
|
||||
let ev = sdl3::Event { ... };
|
||||
for (run) {
|
||||
for (sdl3::PollEvent(&ev)) {
|
||||
if (ev.event_type == sdl3::EventType::QUIT) {
|
||||
run = false;
|
||||
};
|
||||
};
|
||||
|
||||
sdl3::RenderClear(render)!;
|
||||
|
||||
sdl3::RenderTexture(render, img, null, &sdl3::FRect {
|
||||
x = x: f32,
|
||||
y = y: f32,
|
||||
w = w: f32,
|
||||
h = h: f32,
|
||||
})!;
|
||||
|
||||
let dst = sdl3::FRect { y = y: f32, ... };
|
||||
sdl3::GetTextureSize(text_texture, &dst.w, &dst.h)!;
|
||||
dst.x = x: f32 + (w: f32 - dst.w) / 2.0;
|
||||
sdl3::RenderTexture(render, text_texture, null, &dst)!;
|
||||
|
||||
sdl3::RenderPresent(render)!;
|
||||
sdl3::Delay(1000 / 60);
|
||||
|
||||
x += xd;
|
||||
y += yd;
|
||||
if (x + w >= WIDTH) {
|
||||
xd = -1;
|
||||
};
|
||||
if (x <= 0) {
|
||||
xd = 1;
|
||||
};
|
||||
if (y + h >= HEIGHT) {
|
||||
yd = -1;
|
||||
};
|
||||
if (y <= 0) {
|
||||
yd = 1;
|
||||
};
|
||||
|
||||
sdl3::get_error()!;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user