Permalink
Browse files

more progress

  • Loading branch information...
1 parent 321bf1f commit ddefdf74d2e98399bc8855af76982a7fd0873e64 @smcameron committed Feb 10, 2013
Showing with 886 additions and 6 deletions.
  1. +342 −0 COPYING
  2. +11 −3 Makefile
  3. +67 −3 laser-lander.c
  4. +45 −0 my_point.h
  5. +328 −0 snis_font.c
  6. +36 −0 snis_font.h
  7. +19 −0 snis_typeface.c
  8. +38 −0 snis_typeface.h
View
Oops, something went wrong.
View
@@ -1,8 +1,16 @@
+
+all: laser-lander
+
+snis_font.o: my_point.h snis_font.c snis_font.h
+ $(CC) -g -c snis_font.c
+
+snis_typeface.o: snis_typeface.h snis_typeface.c snis_font.h
+ $(CC) -g -c snis_typeface.c
-laser-lander: laser-lander.c
- $(CC) -g -L. -o laser-lander laser-lander.c -lopenlase
+laser-lander: laser-lander.c snis_font.o snis_typeface.o
+ $(CC) -g -L. -o laser-lander laser-lander.c -lopenlase snis_font.o snis_typeface.o
clean:
- rm -fr laser-lander
+ rm -fr laser-lander *.o
View
@@ -3,8 +3,15 @@
#include <unistd.h>
#include <math.h>
+#include "snis_font.h"
+#include "snis_typeface.h"
#include "libol.h"
+#define XDIM (1000.0)
+#define YDIM (1000.0)
+#define XSCALE (1.0 / (XDIM / 2.0))
+#define YSCALE (-1.0 / (YDIM / 2.0))
+
struct object;
typedef void (*move_function)(struct object *o, float time);
@@ -20,6 +27,61 @@ static struct object {
} o[MAXOBJS];
static int nobjs = 0;
+
+/* Draws a letter in the given font at an absolute x,y coords on the screen. */
+static int abs_xy_draw_letter(struct my_vect_obj **font,
+ unsigned char letter, int x, int y)
+{
+ int i, x1, y1, x2, y2;
+ int minx, maxx, diff;
+
+ if (letter == ' ' || letter == '\n' || letter == '\t' || font[letter] == NULL)
+ return abs(font['Z']->p[0].x - font['Z']->p[1].x);
+
+ for (i = 0; i < font[letter]->npoints-1; i++) {
+ if (font[letter]->p[i+1].x == LINE_BREAK)
+ i += 2;
+ x1 = x + font[letter]->p[i].x;
+ y1 = y + font[letter]->p[i].y;
+ x2 = x + font[letter]->p[i + 1].x;
+ y2 = y + font[letter]->p[i + 1].y;
+
+ if (i == 0) {
+ minx = x1;
+ maxx = x1;
+ }
+
+ if (x1 < minx)
+ minx = x1;
+ if (x2 < minx)
+ minx = x2;
+ if (x1 > maxx)
+ maxx = x1;
+ if (x2 > maxx)
+ maxx = x2;
+
+ if (x1 > 0 && x2 > 0)
+ olLine(x1, y1, x2, y2, C_WHITE);
+ }
+ diff = abs(maxx - minx);
+ /* if (diff == 0)
+ return (abs(font['Z']->p[0].x - font['Z']->p[1].x) / 4); */
+ return diff;
+}
+
+/* Draws a string at an absolute x,y position on the screen. */
+static void abs_xy_draw_string(char *s, int font, int x, int y)
+{
+
+ int i, dx;
+ int deltax = 0;
+
+ for (i=0;s[i];i++) {
+ dx = (font_scale[font]) + abs_xy_draw_letter(gamefont[font], s[i], x + deltax, y);
+ deltax += dx;
+ }
+}
+
static void draw_objs(void)
{
int i;
@@ -62,7 +124,7 @@ static int setup_openlase(void)
olLoadIdentity();
olTranslate(-1,1);
- olScale(2,-2);
+ olScale(XSCALE, YSCALE);
/* window is now 0,0 - 1,1 with y increasing down, x increasing right */
return 0;
@@ -73,20 +135,22 @@ static void openlase_renderframe(float *elapsed_time)
*elapsed_time = olRenderFrame(60);
olLoadIdentity();
olTranslate(-1,1);
- olScale(2,-2);
+ olScale(XSCALE, YSCALE);
/* window is now 0,0 - 1,1 with y increasing down, x increasing right */
}
int main(int argc, char *argv[])
{
float elapsed_time = 0.0;
+ snis_typefaces_init();
+
if (setup_openlase())
return -1;
-
while(1) {
draw_objs();
+ abs_xy_draw_string("LASER LANDER", BIG_FONT, 120, 500);
openlase_renderframe(&elapsed_time);
move_objs(elapsed_time);
}
View
@@ -0,0 +1,45 @@
+#ifndef MY_POINT_H
+#define MY_POINT_H
+/*
+ (C) Copyright 2007,2008,2010,2013 Stephen M. Cameron.
+
+ This file is part of laser-lander.
+
+ Laser-lander is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Space Nerds In Space is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Space Nerds In Space; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+ */
+
+/* special values to do with drawing shapes. */
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0]))
+#endif
+
+#define LINE_BREAK (-9999)
+#define COLOR_CHANGE (-9998) /* note, color change can ONLY follow LINE_BREAK */
+
+struct my_point_t {
+ short x,y;
+};
+
+/* Just a grouping of arrays of points with the number of points in the array */
+struct my_vect_obj {
+ int npoints;
+ struct my_point_t *p;
+};
+
+#define setup_vect(v, a) { v.p = a; v.npoints = ARRAY_SIZE(a); }
+
+#endif
Oops, something went wrong.

0 comments on commit ddefdf7

Please sign in to comment.