Free Hero Mesh

Check-in [435ee485bb]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Implement begin_level() and screen_message()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 435ee485bb4e4e9d7fba5fa95be6ae844ba02cef
User & Date: user on 2020-12-02 05:41:38
Other Links: manifest | tags
Context
2020-12-02
08:12
Implement the Broadcast opcode and its variants. check-in: 7b7f59d288 user: user tags: trunk
05:41
Implement begin_level() and screen_message() check-in: 435ee485bb user: user tags: trunk
05:41
Fix several mistakes in exec.c check-in: 646a69c999 user: user tags: trunk
Changes

Modified game.c from [7106f2aed5] to [cdd25f4bc4].

62
63
64
65
66
67
68











69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  }
  snprintf(buf,8,"%2dx%2d",pfwidth,pfheight);
  draw_text(8,32,buf,0xF0,0xFD);
  draw_text(24,32,"x",0xF0,0xF5);
  SDL_UnlockSurface(screen);
  SDL_Flip(screen);
}












static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
  switch(cmd) {
    case '\' ': // Play a move
      return number;
    case '^E': // Edit
      return -2;
    case '^L': // Select level
      load_level(number);
      return 1;
    case '^Q': // Quit
      return -1;
    default:
      return prev;
  }
}







>
>
>
>
>
>
>
>
>
>
>








|







62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  }
  snprintf(buf,8,"%2dx%2d",pfwidth,pfheight);
  draw_text(8,32,buf,0xF0,0xFD);
  draw_text(24,32,"x",0xF0,0xF5);
  SDL_UnlockSurface(screen);
  SDL_Flip(screen);
}

static void begin_level(int id) {
  const char*t;
  t=load_level(id)?:init_level();
  if(t) {
    gameover=-1;
    screen_message(t);
  } else {
    gameover=0;
  }
}

static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
  switch(cmd) {
    case '\' ': // Play a move
      return number;
    case '^E': // Edit
      return -2;
    case '^L': // Select level
      begin_level(number);
      return 1;
    case '^Q': // Quit
      return -1;
    default:
      return prev;
  }
}
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  sqlite3_free(s);
}

void run_game(void) {
  int i;
  SDL_Event ev;
  set_caption();
  load_level(level_id);
  redraw_game();
  while(SDL_WaitEvent(&ev)) {
    switch(ev.type) {
      case SDL_VIDEOEXPOSE:
        redraw_game();
        break;
      case SDL_QUIT:







|







113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  sqlite3_free(s);
}

void run_game(void) {
  int i;
  SDL_Event ev;
  set_caption();
  begin_level(level_id);
  redraw_game();
  while(SDL_WaitEvent(&ev)) {
    switch(ev.type) {
      case SDL_VIDEOEXPOSE:
        redraw_game();
        break;
      case SDL_QUIT:

Modified heromesh.h from [2d7b9d4e3c] to [585a056cca].

85
86
87
88
89
90
91

92
93
94
95
96
97
98
extern Uint16 picture_size;
extern int left_margin;

void draw_picture(int x,int y,Uint16 img);
void draw_text(int x,int y,const unsigned char*t,int bg,int fg);
void draw_cell(int x,int y);
const char*screen_prompt(const char*txt);

void load_pictures(void);

int scrollbar(int*cur,int page,int max,SDL_Event*ev,SDL_Rect*re);

// == class ==

#define CF_PLAYER 0x01







>







85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
extern Uint16 picture_size;
extern int left_margin;

void draw_picture(int x,int y,Uint16 img);
void draw_text(int x,int y,const unsigned char*t,int bg,int fg);
void draw_cell(int x,int y);
const char*screen_prompt(const char*txt);
int screen_message(const char*txt);
void load_pictures(void);

int scrollbar(int*cur,int page,int max,SDL_Event*ev,SDL_Rect*re);

// == class ==

#define CF_PLAYER 0x01

Modified picture.c from [66da19aea7] to [4d5ad5ad22].

195
196
197
198
199
200
201

202
203
204

205
206
207







208
209


210
211
212
213
214
215
216




217
218
219
220
221
222

223
224
225
226
227
228
229
        SDL_LockSurface(screen);
        draw_text(0,8,t,0xF1,0xFF);
        draw_text(n<<3,8,"\xB1",0xF1,0xFB);
        SDL_UnlockSurface(screen);
        SDL_Flip(screen);
    }
  }

}

void screen_message(const char*txt) {

  SDL_Rect r;
  SDL_Event ev;
  







  set_cursor(XC_iron_cross);
  SDL_Flip(screen);


  while(SDL_WaitEvent(&ev)) {
    switch(ev.type) {
      case SDL_QUIT:
        SDL_PushEvent(&ev);
        return;
      case SDL_KEYDOWN:
        




        return;
      case SDL_MOUSEBUTTONDOWN:
        
        return;
    }
  }

}

static Uint16 decide_picture_size(int nwantsize,const Uint8*wantsize,const Uint16*havesize,int n) {
  int i,j;
  if(!nwantsize) fatal("Unable to determine what picture size is wanted\n");
  for(i=0;i<nwantsize;i++) if(havesize[j=wantsize[i]]==n) return j;
  for(i=*wantsize;i;--i) if(havesize[i]) return i;







>


|
>
|

|
>
>
>
>
>
>
>


>
>




|

|
>
>
>
>
|
<
|
|


>







195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240
241
242
243
244
        SDL_LockSurface(screen);
        draw_text(0,8,t,0xF1,0xFF);
        draw_text(n<<3,8,"\xB1",0xF1,0xFB);
        SDL_UnlockSurface(screen);
        SDL_Flip(screen);
    }
  }
  return 0;
}

int screen_message(const char*txt) {
  int n=0;
  SDL_Rect r={0,0,screen->w,16};
  SDL_Event ev;
  SDL_FillRect(screen,&r,0xF4);
  r.y=16;
  r.h=1;
  SDL_FillRect(screen,&r,0xF8);
  SDL_LockSurface(screen);
  draw_text(0,0,txt,0xF4,0xFE);
  draw_text(0,8,"<Push ENTER to continue>",0xF4,0xF7);
  SDL_UnlockSurface(screen);
  set_cursor(XC_iron_cross);
  SDL_Flip(screen);
  r.y=8;
  r.h=8;
  while(SDL_WaitEvent(&ev)) {
    switch(ev.type) {
      case SDL_QUIT:
        SDL_PushEvent(&ev);
        return -1;
      case SDL_KEYDOWN:
        switch(ev.key.keysym.sym) {
          case SDLK_RETURN: case SDLK_KP_ENTER:
            r.y=0;
            r.h=17;
            SDL_FillRect(screen,&r,0xF0);
            return 0;

        }
        break;
    }
  }
  return -1;
}

static Uint16 decide_picture_size(int nwantsize,const Uint8*wantsize,const Uint16*havesize,int n) {
  int i,j;
  if(!nwantsize) fatal("Unable to determine what picture size is wanted\n");
  for(i=0;i<nwantsize;i++) if(havesize[j=wantsize[i]]==n) return j;
  for(i=*wantsize;i;--i) if(havesize[i]) return i;