aboutsummaryrefslogtreecommitdiff
path: root/main.ha
diff options
context:
space:
mode:
Diffstat (limited to 'main.ha')
-rw-r--r--main.ha44
1 files changed, 31 insertions, 13 deletions
diff --git a/main.ha b/main.ha
index 9035053..09fd30f 100644
--- a/main.ha
+++ b/main.ha
@@ -2,6 +2,9 @@ use fmt;
use sdl2;
use math;
+def CHUNKSIZE = 512;
+def NCHUNKS = 4;
+
export fn main() void = {
sdl2::SDL_Init(sdl2::SDL_INIT_VIDEO)!;
defer sdl2::SDL_Quit();
@@ -11,19 +14,30 @@ export fn main() void = {
const wsurf = sdl2::SDL_GetWindowSurface(win)!;
- const xsurf = sdl2::SDL_CreateRGBSurface(0,
- 512, 512, 32, 0xff0000, 0xff00, 0xff, 0)!;
+ const offs: [_]pos = [
+ (0,0), (0,CHUNKSIZE), (CHUNKSIZE,0), (CHUNKSIZE,CHUNKSIZE),
+ ];
+
+ let pictures: []picture = alloc([],NCHUNKS);
+ for (let i = 0z; i < NCHUNKS; i +=1){
+ const surf = sdl2::SDL_CreateRGBSurface(0,
+ CHUNKSIZE, CHUNKSIZE, 32, 0xff0000, 0xff00, 0xff, 0)!;
+ append(pictures, picture_from_surface(surf, offs[i]));
+ };
let dstate = drawing_state {
drawing = false,
pos = (0,0),
- picture = &picture_from_surface(xsurf)
+ pictures = pictures,
};
let camera_pos: pos = (25, 50);
- clear_picture(dstate.picture, 0xffffff);
- outline_picture(dstate.picture);
+ for (let i = 0z; i < 4; i += 1) {
+ const p = &dstate.pictures[i];
+ clear_picture(p, 0xffffff);
+ outline_picture(p);
+ };
let quit = false;
let n = 0;
@@ -38,22 +52,20 @@ export fn main() void = {
case sdl2::SDL_EventType::MOUSEBUTTONDOWN,
sdl2::SDL_EventType::MOUSEBUTTONUP =>
const edata = ev.button;
- dstate.pos = (edata.x, edata.y);
+ dstate.pos = (edata.x + camera_pos.0, edata.y + camera_pos.1);
if (edata.button == 1)
dstate.drawing = (edata.state == 1);
case sdl2::SDL_EventType::MOUSEMOTION =>
const edata = ev.motion;
- dstate.pos = (edata.x, edata.y);
+ dstate.pos = (edata.x + camera_pos.0, edata.y + camera_pos.1);
case => void;
};
movement(&camera_pos);
-
do_drawing(&dstate);
-
- sdl2::SDL_BlitSurface(xsurf, null, wsurf, &sdl2::SDL_Rect {
- x = camera_pos.0, y = camera_pos.1, ...
- })!;
+
+ for (let i = 0z; i < len(dstate.pictures); i+=1)
+ render_picture(&dstate.pictures[i], wsurf, camera_pos);
sdl2::SDL_UpdateWindowSurface(win)!;
n += 1;
@@ -61,6 +73,13 @@ export fn main() void = {
};
};
+fn render_picture(pic: *picture, winsurf: *sdl2::SDL_Surface, camera_pos: pos) void = {
+ sdl2::SDL_BlitSurface(pic.surf, null, winsurf, &sdl2::SDL_Rect{
+ x = pic.pos.0 - camera_pos.0, y = pic.pos.1 - camera_pos.1, ...
+ })!;
+};
+
+
def SPEED = 17;
def DIAG_SPEED = 12; // thereabouts
@@ -80,4 +99,3 @@ fn movement(pos: *pos) void = {
pos.1 += dy * speed;
};
-