1 /* ground.c - implement the ground to drive on
2 *
3 * Copyright 1999 Jochen Voss */
4
5 static const char rcsid[] = "$Id: ground.c 4839 2003-04-13 16:50:02Z voss $";
6
7
8 #ifdef HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <string.h>
13 #include <stdlib.h>
14
15 #include "moon-buggy.h"
16
17
18 int *bonus; /* points to get, if we drive over them */
19 char *ground1, *ground2;
20 static int ground_width;
21
22
23 void
resize_ground(int clear_it)24 resize_ground (int clear_it)
25 {
26 int cols, i, old;
27
28 cols = COLS;
29 if (ground_width != cols) {
30 bonus = xrealloc (bonus, cols*sizeof(int));
31 ground1 = xrealloc (ground1, cols);
32 ground2 = xrealloc (ground2, cols);
33 }
34 for (i=(clear_it ? 0 : ground_width); i<cols; ++i) {
35 bonus[i] = 0;
36 ground1[i] = '#';
37 ground2[i] = '#';
38 }
39 ground_width = cols;
40 old = car_base;
41 car_base = (cols > 80 ? 80 : cols) - 12;
42 car_x += (car_base-old);
43 }
44
45 void
print_ground(void)46 print_ground (void)
47 {
48 mvwaddnstr (moon, LINES-4, 0, ground2, ground_width);
49 mvwaddnstr (moon, LINES-3, 0, ground1, ground_width);
50 wnoutrefresh (moon);
51 }
52
53 static void
print_level(void)54 print_level (void)
55 {
56 mvwprintw (status, 0, car_base-32, "level: %d", current_level () + 1);
57 wnoutrefresh (status);
58 }
59
60 static void
scroll_handler(game_time t,void * client_data)61 scroll_handler (game_time t, void *client_data)
62 {
63 if (crash_detected <= 2) {
64 scroll_meteors ();
65
66 memmove (bonus+1, bonus, (ground_width-1)*sizeof(int));
67 memmove (ground2+1, ground2, ground_width-1);
68 level_tick (t);
69 print_ground ();
70 print_level ();
71
72 stakes += bonus[car_x + 7];
73
74 if (crash_detected) shift_buggy (1);
75 }
76
77 if (crash_detected || crash_check ()) {
78 ++crash_detected;
79 if (crash_detected > 35) mode_change (crash_mode, 1);
80 }
81
82 if (can_jump () && stakes) {
83 adjust_score (stakes);
84 stakes = 0;
85 }
86
87 add_event (t+TICK(1), scroll_handler, NULL);
88 }
89
90 void
start_scrolling(double t)91 start_scrolling (double t)
92 {
93 add_event (t, scroll_handler, NULL);
94 }
95