void lobby_host_loop() { struct proto_join_packet packet; static int tick = 0; DARNIT_KEYS keys; keys = d_keys_get(); d_keys_set(keys); d_render_tile_blit(config.menu_background, 0, 0, 0); if(!tick) { packet.type = PROTO_TYPE_JOIN; packet.player_id = -1; strcpy(packet.player_name, config.player_name); network_send(config.server.addr, &packet, sizeof(struct proto_join_packet)); update_player_list(lobby_join.list_players, config.player.player); } server_loop(); if(keys.select) { game_state(GAME_STATE_LOBBY); } if(keys.start) { game_state(GAME_STATE_GAME); } d_text_surface_draw(lobby_join.list_players); d_text_surface_draw(lobby_host.start_game); tick++; tick %= 3; }
int main(int argc, char **argv) { DARNIT_IMAGE_DATA img; DARNIT_TILESHEET *ts; IMG_STRUCT **imgs, **tmp; DARNIT_KEYS keys; int images, image_disp, i; imgs = NULL; images = 0; image_disp = 0; if (argc < 2) { fprintf(stderr, "Usage: %s <image to analyze>\n", argv[0]); return -1; } d_init("algdata", "algdata", NULL); if (!((img = d_img_load_raw(argv[1])).data)) { fprintf(stderr, "Unable to load %s\n", argv[1]); d_quit(); } d_render_clearcolor_set(255, 255, 255); do { i = 0; ts = next_image(img, &i); if (ts) { if (!(tmp = realloc(imgs, sizeof(IMG_STRUCT **) * (images + 1)))) d_quit(); imgs = tmp; imgs[images] = new_image(ts, i); images++; } } while (ts); if (!imgs) d_quit(); sort_image(imgs, images); for (;;) { keys = d_keys_get(); if (keys.start) { image_disp = (image_disp + 1 >= images) ? 0 : image_disp + 1; d_keys_set(keys); } d_render_begin(); d_render_tile_blit(imgs[image_disp]->ts, 0, 0, 0); d_render_end(); d_loop(); } return 0; }
void lobby_loop() { static int tick = 0; DARNIT_KEYS keys; int i; struct List *game = lobby_client.client; d_render_tile_blit(config.menu_background, 0, 0, 0); d_render_line_draw(lobby.line, 1); d_text_surface_draw(lobby.list_players); if(lobby.selected_game > 5) { d_render_offset(0, (lobby.selected_game - 5) * d_font_glyph_hs(config.font_std)); } d_text_surface_draw(lobby.list_games); d_render_offset(0, 0); keys = d_keys_get(); d_keys_set(keys); if(!tick) { update_lists(NULL, lobby_client.client); } if(keys.up) { if(lobby.selected_game > 0) lobby.selected_game--; } else if(keys.down) { if(lobby.selected_game < lobby_client.clients) lobby.selected_game++; } if(keys.select) { game_state(GAME_STATE_MENU); return; } if(keys.start) { if(lobby.selected_game == 0) { game_state(GAME_STATE_LOBBY_HOST); } else { for(i = 0; game; i++, game = game->next) { if(i == lobby.selected_game) { config.server.addr = ((struct LobbyHost *) (game->value))->addr; goto join; } } game_state(GAME_STATE_LOBBY_HOST); return; join: game_state(GAME_STATE_LOBBY_JOIN); } } tick++; tick %= 3; }
void gamestate(GAMESTATE state) { DARNIT_KEYS k; switch(_gamestate) { case GAMESTATE_GAME: if(state!=GAMESTATE_PAUSE) map_cleanup(); case GAMESTATE_MENU: d_keymapping_set(game_keymap); break; default: break; } switch(state) { case GAMESTATE_MENU: if(platform.platform&DARNIT_PLATFORM_HANDHELD) d_keymapping_set(menu_keymap_handheld); else d_keymapping_set(menu_keymap_desktop); break; case GAMESTATE_GAME: memset(&k, 0xFF, sizeof(DARNIT_KEYS)); d_keys_set(k); if(_gamestate==GAMESTATE_PAUSE) break; _gamestate=state; map_load(0); score = 0; break; case GAMESTATE_HIGHSCORE: case GAMESTATE_INSTRUCTIONS: case GAMESTATE_GAMEOVER: case GAMESTATE_PAUSE: memset(&k, 0xFF, sizeof(DARNIT_KEYS)); d_keys_set(k); break; default: break; } _gamestate=state; }
void stageSelectDraw() { DARNIT_KEYS keys; keys = d_keys_get(); if (keys.left) { if ((--s->var.stage.selected_stage) < 0) s->var.stage.selected_stage = 8; d_keys_set(keys); } else if (keys.right) { if ((++s->var.stage.selected_stage) > 8) s->var.stage.selected_stage = 0; d_keys_set(keys); } else if (keys.up) { if ((s->var.stage.selected_stage -= 3) < 0) s->var.stage.selected_stage += 9; d_keys_set(keys); } else if (keys.down) { if ((s->var.stage.selected_stage += 3) > 8) s->var.stage.selected_stage -= 9; d_keys_set(keys); } else if (keys.BUTTON_ACCEPT) { if (s->var.stage.selected_stage == 4 && s->var.progress.stages < 255); else { s->load_level = d_stringtable_entry(s->config, stagename[s->var.stage.selected_stage]); s->newstate = STATE_TESTGAME; } } stageSelectMoveCursor(); d_render_offset(0, 0); d_render_blend_enable(); d_render_tile_draw(s->var.stage.stage, 10); d_render_blend_disable(); return; }
int main(int argc, char **argv) { int i, j; struct GRAPH *g, *tree=NULL; struct VERTEX *v; struct POINT p; DARNIT_KEYS keys; srand(time(NULL)); d_init("Graphs", "uppg8", NULL); for(i=0; i<256; i++) { circle[i]=d_render_circle_new(32, 1); line[i]=d_render_line_new(1, 1); } for(j=0; j<4; j++) for(i=0; i<7; i++) { p.x=i*100+50;//(rand()%80)*10; p.y=j*100+50;//(rand()%48)*10; v=graph_add_vertex(&graph, p); for(g=graph; g; g=g->next) if(!(rand()%6)) graph_add_edge(v, g->vertex, rand()%100, DIRECTION_DOUBLE); } tree=graph_prim(graph); draw_graph(graph); for(g=graph;;) { keys=d_keys_get(); if(keys.start) { g=g==graph?tree:graph; draw_graph(g); } d_keys_set(keys); d_render_begin(); d_render_tint(0xFF, 0xFF, 0xFF, 0xFF); for(i=0; i<vertices; i++) d_render_circle_draw(circle[i]); for(i=0; i<edges; i++) { d_render_tint(length[i], 0x7F, 0x0, 0xFF); d_render_line_draw(line[i], 1); } d_render_end(); d_loop(); } d_quit(); return 0; }
/* Bästa Snyggkoden™ i stan! */ int player_loop(DARNIT_KEYS *keys) { SHAPE_COPY *shape; DARNIT_KEYS set; static int shoot_key=0; static int grenade_key=0; int dir; if (!player) return 0; shape=shapesprite_get_current_shape(player->shape); if(keys->up) player->gun_angle=-200; else if(keys->down) player->gun_angle=200; else player->gun_angle=0; if(keys->a&&!shoot_key) { int x=player->x/1000+28, y=player->y/1000+(player->gun_angle?player->gun_angle/20:0); player->bullet=bullet_add(player->bullet, x, y, player->gun_angle, model.bullet, BULLET_OWNER_PLAYER); d_sound_play(sound.shoot, 0, 127, 127, 0); particle_emitter_new(30, 100, 8000, 10000, 255, 0, 0, PARTICLE_TYPE_PULSE, x, y, 0, player->gun_angle-100, player->gun_angle+100); particle_emitter_new(30, 100, 8000, 10000, 255, 255, 0, PARTICLE_TYPE_PULSE, x, y, 0, player->gun_angle-100, player->gun_angle+100); } if(keys->b&&(!grenade_key)&&player->grenades) grenade_time=d_time_get(); if((grenade_key&&!keys->b)||(grenade_time&&d_time_get()>=GRENADE_LIFE+grenade_time)) { int x=player->x/1000+28, y=player->y/1000+(player->gun_angle?player->gun_angle/20:0); if(player->grenades) { player->grenade=grenade_add(player->grenade, x, y, player->gun_angle, grenade_time+GRENADE_LIFE-d_time_get(), model.grenade); player->grenades--; } grenade_time=0; } shoot_key=keys->a; grenade_key=keys->b; if (keys->left) player->vel_x -= (PLAYER_ACCELERATION * d_last_frame_time()) / 1000; else if (keys->right) player->vel_x += (PLAYER_ACCELERATION * d_last_frame_time()) / 1000; else if (player->vel_x) { if (abs(player->vel_x) < (PLAYER_ACCELERATION * d_last_frame_time()) / 1000) player->vel_x = 0; else player->vel_x += ((player->vel_x < 0 ? 1 : -1) * (PLAYER_FRICTION) * d_last_frame_time()) / 1000; } if (abs(player->vel_x) > PLAYER_SPEED_X_MAX) player->vel_x = (player->vel_x < 0 ? -1 : 1) * PLAYER_SPEED_X_MAX; if (keys->l && !player->vel_y) { set = d_keys_zero(); set.l = 1; d_keys_set(set); player->vel_y -= PLAYER_JUMP_ACCELERATION; } player->vel_y += PLAYER_GRAVITY * d_last_frame_time(); if (abs(player->vel_y) > PLAYER_SPEED_Y_MAX) player->vel_y = (player->vel_y < 0 ? -1 : 1) * PLAYER_SPEED_Y_MAX; dir=map_collide_dir(shape->coord, shape->lines, player->x / 1000, player->y / 1000, player->vel_x); if(dir==MAP_SLOPE_UP) { player->x += player->vel_x * d_last_frame_time()/ 1000; player->y-=abs(player->vel_x) * d_last_frame_time() / 1000; } else if(dir==MAP_SLOPE_VERTICAL) { player->x-=player->vel_x/ 200; player->vel_x*=-1; player->y+=2000; } else if(dir!=MAP_SLOPE_VERTICAL) { if (dir != -1) player->y-=50; player->x += player->vel_x * d_last_frame_time() / 1000; } if (player->x < 32000) player->x = 32000; if (!map_collide(shape->coord, shape->lines, player->x / 1000, player->y / 1000) || player->vel_y < 0) player->y += player->vel_y * d_last_frame_time() / 1000; else { player->vel_y = 0; } if (player->y / 1000 >= PLAYER_KILLZONE||map_enemy_collide(shapesprite_get_current_shape(player->shape), player->x, player->y)) { player_kill(); return -1; } if (player->x < camera_x + 32000) player->x = camera_x + 32000; if(player->vel_x) { shapesprite_animate(player->shape); } if(boss_shooting&&((player->x-camera_x)>300000)&&((boss_shooting-d_time_get())>1000)) { player->health--; if(player->health<0) { player_kill(); return 1; } } map_check_powerup(player->x/1000/*+camera_x/1000*/, player->y/1000); score++; return 1; }