Skip to content

Commit ce107c3

Browse files
committed
fixed line drawing in mode-x
1 parent 0395479 commit ce107c3

4 files changed

Lines changed: 80 additions & 52 deletions

File tree

src/mob.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "level.h"
88
#include "util.h"
99
#include "xmath.h"
10+
#include "app.h"
1011

1112
void init_mob(struct mob *mob)
1213
{
@@ -88,6 +89,7 @@ void mob_state(struct mob *mob, int st)
8889
if(mob->state == st) return;
8990

9091
mob->state = st;
92+
mob->state_t = 0;
9193

9294
if(mob->spr.anim[st].seq[0]) {
9395
mob->spr.cur = mob->spr.anim + st;
@@ -142,11 +144,7 @@ void mob_beam(struct mob *mob, int32_t tx, int32_t ty, int dmg)
142144
int32_t hit_dist, t;
143145

144146
/* first delete the previous beam if it's still active */
145-
for(i=0; i<mob->beam.nseg; i++) {
146-
seg = mob->beam.seg + i;
147-
cell_remove_beamseg(seg->cell, seg);
148-
}
149-
mob->beam.nseg = 0;
147+
mob_beamstop(mob);
150148

151149
x = mob->beam.x0 = mob->x;
152150
y = mob->beam.y0 = mob->y;
@@ -225,6 +223,18 @@ void mob_beam(struct mob *mob, int32_t tx, int32_t ty, int dmg)
225223
mob->beam.y1 = ny;
226224
}
227225

226+
void mob_beamstop(struct mob *mob)
227+
{
228+
int i;
229+
struct beamseg *seg;
230+
231+
for(i=0; i<mob->beam.nseg; i++) {
232+
seg = mob->beam.seg + i;
233+
cell_remove_beamseg(seg->cell, seg);
234+
}
235+
mob->beam.nseg = 0;
236+
}
237+
228238
/*
229239
static int32_t ray_pt_sqdist(int32_t ox, int32_t oy, int32_t dx, int32_t dy, int32_t px, int32_t py)
230240
{

src/mob.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct mob {
3838
struct sprite spr;
3939
int hp, dmg; /* hit points, and damage accumulator since last update */
4040
int32_t hitx, hity; /* position of last hit */
41+
long state_t;
4142
struct level *lvl;
4243
struct level_cell *cell;
4344
struct beam beam;
@@ -61,6 +62,7 @@ void mob_state(struct mob *mob, int st);
6162
* it into beam segments, one per cell to be able to draw it correctly
6263
*/
6364
void mob_beam(struct mob *mob, int32_t tx, int32_t ty, int dmg);
65+
void mob_beamstop(struct mob *mob);
6466

6567
int32_t mob_rayhit(struct mob *mob, int32_t ox, int32_t oy, int32_t dx, int32_t dy,
6668
int32_t *hitx, int32_t *hity);

src/rend.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ void draw_line(int x0, int y0, int x1, int y1, uint8_t color)
124124

125125
#ifdef VGA_LFB
126126
if(cur_bpl) return;
127-
#endif
128127

129128
vmem = vga_backbuf + y0 * SCANLEN + x0;
129+
#else
130+
vmem = vga_backbuf + y0 * SCANLEN + (x0 >> 2);
131+
#endif
132+
130133
dx = x1 - x0;
131134
dy = y1 - y0;
132135

@@ -149,22 +152,48 @@ void draw_line(int x0, int y0, int x1, int y1, uint8_t color)
149152
/* x-major */
150153
err = dy2 - dx;
151154
for(i=0; i<=dx; i++) {
155+
#ifdef VGA_LFB
152156
*vmem = color;
157+
#else
158+
if((x0 & 3) == cur_bpl) {
159+
*vmem = color;
160+
}
161+
#endif
153162
if(err >= 0) {
154163
err -= dx2;
155164
vmem += yinc;
156165
}
157166
err += dy2;
167+
#ifdef VGA_LFB
158168
vmem += xinc;
169+
#else
170+
if((x0 & 3) == 3) {
171+
vmem += xinc;
172+
}
173+
x0 += xinc;
174+
#endif
159175
}
160176
} else {
161177
/* y-major */
162178
err = dx2 - dy;
163179
for(i=0; i<=dy; i++) {
180+
#ifdef VGA_LFB
164181
*vmem = color;
182+
#else
183+
if((x0 & 3) == cur_bpl) {
184+
*vmem = color;
185+
}
186+
#endif
165187
if(err >= 0) {
166188
err -= dy2;
189+
#ifdef VGA_LFB
167190
vmem += xinc;
191+
#else
192+
if((x0 & 3) == 3) {
193+
vmem += xinc;
194+
}
195+
x0 += xinc;
196+
#endif
168197
}
169198
err += dx2;
170199
vmem += yinc;

src/scr_game.c

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define BEAM_DMG 8
1515
#define BEAM_COL 253
1616
#define BEAM_HEIGHT 16
17+
#define BEAM_DUR 100
1718

1819
#ifndef NO_SOUND
1920
#include "audio.h"
@@ -192,6 +193,7 @@ static void update(void)
192193
static long prev_upd;
193194
long dt;
194195
int i, j, x, y, dx, dy;
196+
int32_t gx, gy;
195197
struct level_cell *cell;
196198

197199
dt = time_msec - prev_upd;
@@ -213,14 +215,29 @@ static void update(void)
213215
dx += SCROLL_SPEED * dt >> 2;
214216
}
215217

216-
if(mob_move(&player, dx, dy)) {
217-
scrollto(player.x, player.y);
218-
}
219-
220218
if(player.state == MOB_FIRE) {
221-
/* TODO */
219+
if(player.state_t == 0) {
220+
vscr_to_grid(mouse_x + xscroll, mouse_y + yscroll, &gx, &gy);
221+
gx -= 128;
222+
gy -= 128;
223+
mob_lookat(&player, gx, gy);
224+
mob_beam(&player, gx, gy, BEAM_DMG);
225+
226+
} else if(player.state_t >= BEAM_DUR) {
227+
228+
/* fire duration ended, change state and remove beam */
229+
mob_state(&player, MOB_IDLE);
230+
mob_beamstop(&player);
231+
}
232+
233+
} else {
234+
if(mob_move(&player, dx, dy)) {
235+
scrollto(player.x, player.y);
236+
}
222237
}
223238

239+
player.state_t += dt;
240+
224241
/* compute the list of visible cells */
225242
num_vis = 0;
226243
cell = lvl.cells;
@@ -278,10 +295,9 @@ static void scrgame_display(void)
278295

279296
static void draw_bitplane(int bpl)
280297
{
281-
int i, j, x, y, x1, y1, mouse_cx, mouse_cy, mouse_gx, mouse_gy, player_cx, player_cy;
298+
int i, j, x, y, x1, y1, player_cx, player_cy;
299+
int32_t mouse_gx, mouse_gy;
282300
struct level_cell *cell;
283-
struct tileimg *tile;
284-
struct tileseq *seq;
285301
struct beamseg *bseg;
286302
struct mob *mob;
287303

@@ -320,7 +336,6 @@ static void draw_bitplane(int bpl)
320336
draw_line(x + 1, y, x1 + 1, y1, BEAM_COL);
321337
}
322338

323-
/*tiles_blit_rle(balltile, x1, y1, bpl);*/
324339
bseg = bseg->next;
325340
}
326341

@@ -336,37 +351,25 @@ static void draw_bitplane(int bpl)
336351
tiles_blit_rle(seltile, cell->x, cell->y, bpl);
337352

338353
spr_draw(&player.spr, x - xscroll, y - yscroll, player.dir);
339-
340-
if(player.beam.nseg) {
341-
grid_to_vscr(player.beam.x1, player.beam.y1, &x, &y);
342-
tiles_blit_rle(balltile, x - xscroll, y - yscroll, bpl);
343-
}
344354
}
345355
}
346356
}
347357
}
348358

349-
/* mouseover highlight */
350-
/*vscr_to_cell(mouse_x + xscroll, mouse_y + yscroll, &mouse_cx, &mouse_cy);
351-
if(BOUNDCHK(mouse_cx, lvl.size) && BOUNDCHK(mouse_cy, lvl.size)) {
352-
cell_to_vscr(mouse_cx, mouse_cy, &x, &y);
353-
x -= xscroll;
354-
y -= yscroll;
355-
tiles_blit_rle(seltile, x, y, bpl);
356-
}
357-
*/
359+
/*for(i=0; i<4; i++) {
360+
int yoffs = i * 8;
361+
draw_line(100 + i, 100 + yoffs, 140 + i, 180 + yoffs, 0xff);
362+
}*/
363+
358364
vscr_to_grid(mouse_x + xscroll, mouse_y + yscroll, &mouse_gx, &mouse_gy);
359365
mouse_gx -= 128;
360366
mouse_gy -= 128;
361367

362368
tiles_blit_rle(cursors[mouse_mode], mouse_x, mouse_y, bpl);
363369

364370
gprintf(0, 0, fps_text);
365-
/*gprintf(0, 8, "vsync: %s", vsync ? "on" : "off");*/
366371
gprintf(90, 0, "vis:%d", num_vis);
367372
gprintf(160, 0, "cell:%d,%d %s", player_cx, player_cy, strcellflags(player.cell->flags));
368-
/*gprintf(0, 8, "player: %s,%s\n", fixpstr(player.x, 8), fixpstr(player.y, 8));
369-
gprintf(180, 8, "mouse: %s,%s\n", fixpstr(mouse_gx, 8), fixpstr(mouse_gy, 8));*/
370373
}
371374

372375
static void scrgame_keyb(int key, int press)
@@ -393,34 +396,18 @@ static void scrgame_keyb(int key, int press)
393396

394397
static void scrgame_mouse(int bn, int press, int x, int y)
395398
{
396-
int cx, cy, gx, gy;
397-
398399
prev_mx = x;
399400
prev_my = y;
400401

401-
402-
if(press) {
403-
if(bn == 0) {
404-
vscr_to_cell(mouse_x + xscroll, mouse_y + yscroll, &cx, &cy);
405-
406-
vscr_to_grid(mouse_x + xscroll, mouse_y + yscroll, &gx, &gy);
407-
gx -= 128;
408-
gy -= 128;
409-
mob_lookat(&player, gx, gy);
410-
mob_state(&player, MOB_FIRE);
411-
412-
mob_beam(&player, gx, gy, BEAM_DMG);
413-
}
414-
} else {
415-
if(bn == 0) {
416-
mob_state(&player, MOB_IDLE);
417-
}
402+
if(bn == 0 && press) {
403+
mob_state(&player, MOB_FIRE);
418404
}
419405
}
420406

421407
static void scrgame_motion(int x, int y)
422408
{
423-
int dx, dy, gx, gy;
409+
int dx, dy;
410+
int32_t gx, gy;
424411

425412
dx = mouse_x - prev_mx;
426413
dy = mouse_y - prev_my;

0 commit comments

Comments
 (0)