/**
 * Clicking difficulty from menu, sets stated value as current difficulty
 * for the corresponding player (according to btn position)
 */
int on_select_difficulty(Control* btn) {
	if (btn->i == 0) {
		next_level(&(game->first_player_depth), game->depth_range);
	}
	if (btn->i == 1) {
		next_level(&(game->second_player_depth), game->depth_range);
	}
	return show_arena(get_root(btn));
}
bool pred_transformer::legacy_frames::propagate_to_next_level(unsigned src_level)
{

    ast_manager &m = m_pt.get_ast_manager();
    (void) m;
    if (m_levels.size() <= src_level) { return true; }
    if (m_levels [src_level].empty()) { return true; }

    unsigned tgt_level = next_level(src_level);
    m_pt.ensure_level(next_level(tgt_level));

    TRACE("spacer",
          tout << "propagating " << src_level << " to " << tgt_level;
          tout << " for relation " << m_pt.head()->get_name() << "\n";);
Exemple #3
0
static void
config_data_node_get_recursive(config_data_node *running, config_data_node *candidate, utf8str &result, int level)
{
	utf8str indent;
	for (int i = 0; i < level; ++i) {
		indent += "    ";
	}

	bidir_node<config_data_node> *bn_running = nullptr;
	if (running != nullptr) {
		bn_running = running->children().head();
	}

	bidir_node<config_data_node> *bn_candidate = nullptr;
	if (candidate != nullptr) {
		bn_candidate = candidate->children().head();
	}

	while ((bn_running != nullptr) || (bn_candidate != nullptr)) {
		if ((bn_running != nullptr)
		 && (bn_candidate != nullptr)
		 && (bn_running->v() == bn_candidate->v())) {
			config_data_node_get_begin(result, "  ", indent, bn_running->v());
			config_data_node_get_recursive(&bn_running->v(),
				&bn_candidate->v(), result, next_level(level, bn_running->v()));
			config_data_node_get_end(result, "  ", indent, bn_running->v());
			bn_running = bn_running->next();
			bn_candidate = bn_candidate->next();
		} else if ((bn_candidate == nullptr)
		 || ((bn_running != nullptr)
		  && (bn_candidate != nullptr)
		  && (bn_running->v() < bn_candidate->v()))) {
			config_data_node_get_begin(result, "- ", indent, bn_running->v());
			config_data_node_get_recursive(&bn_running->v(),
				nullptr, result, next_level(level, bn_running->v()));
			config_data_node_get_end(result, "- ", indent, bn_running->v());
			bn_running = bn_running->next();
		} else if ((bn_running == nullptr)
		 || ((bn_running != nullptr)
		  && (bn_candidate != nullptr)
		  && (bn_running->v() > bn_candidate->v()))) {
			config_data_node_get_begin(result, "+ ", indent, bn_candidate->v());
			config_data_node_get_recursive(nullptr,
				&bn_candidate->v(), result, next_level(level, bn_candidate->v()));
			config_data_node_get_end(result, "+ ", indent, bn_candidate->v());
			bn_candidate = bn_candidate->next();
		}
	}
}
Exemple #4
0
void		check_brick(t_game *g)
{
	int		x;
	int		y;
	float	size;

	y = 0;
	if (g->level && g->level[0])
		size = ((float)g->win_x / g->len);
	while (g->level[y])
	{
		x = 0;
		while (g->level[y][x])
		{
			if (g->level[y][x] != ' ')
			{
				if (the_return_ofcheck_brick(g, x, y, size) == 1)
				{
					next_level(g);
					return ;
				}
			}
			x++;
		}
		y++;
	}
}
void genDumpMod_call(int data, int reason)
{
  handle child_handle, module_handle;
  char   *pargs, *ptr, *mod_name;
  int    pargs_found, level;
  char   buf[128];

  pargs = mc_scan_plusargs ("gen_dump_module="); 

  pargs_found = 0;
  if (pargs != (char *)0) {
    strcpy(buf, pargs);
    mod_name = strtok (buf, ":");
    ptr = strtok (NULL, " \n");
    level = atoi (ptr);
    if (level > 0 ) {pargs_found = 1;}
  }

  if (pargs_found == 0) return;
  io_printf ("%s %d\n", mod_name, level);
  
  if ((fp = fopen("dump.mod", "w")) == 0)
    tf_error ("can't open dump.mod file\n");

  acc_initialize();

  module_handle = acc_handle_object (mod_name);
  child_handle = null;

  next_level (module_handle, level);
  acc_close();
  fclose (fp);
  tf_dofinish();
}
Exemple #6
0
//movement and actions
void move_left()
{
	moving_left = 1;
	moving_right = 0;
   if(cur_level == 1)
   {
	if(pos_x != 0 && level1[pos_y][pos_x-1] != TILE && level1[pos_y-1][pos_x-1] != TILE && level1[pos_y+1][pos_x] != 0 &&  level1[pos_y+1][pos_x] != EXIT_COLOR)
	{
		  if(level1[pos_y][pos_x-1] == GREEN)
		  {
			  player_HP--;
		  }
		  
		  if(player_HP == 0)
		  {
			  reset();
		  }
		has_moved = 1;
		level1[pos_y][pos_x] = 0;
		level1[pos_y-1][pos_x] = 0;
		pos_x--;
		level1[pos_y][pos_x] = YELLOW;
		level1[pos_y-1][pos_x] = YELLOW;
	}
	else if(level1[pos_y+1][pos_x-1] == EXIT_COLOR)
	{
	  next_level();
	}
	else if(level1[pos_y+1][pos_x] == 0)
	{
	  fall();
	}
   }
   if(cur_level == 2)
   {
	   if(pos_x != 0 && level2[pos_y][pos_x-1] != TILE && level2[pos_y-1][pos_x-1] != TILE && level2[pos_y+1][pos_x] != 0)
	   {
		   if(level2[pos_y][pos_x-1] == GREEN)
		   {
			   player_HP--;
		   }
		   
		   if(player_HP == 0)
		   {
			   reset();
		   }
		   has_moved = 1;
		   level2[pos_y][pos_x] = 0;
		   level2[pos_y-1][pos_x] = 0;
		   pos_x--;
		   level2[pos_y][pos_x] = YELLOW;
		   level2[pos_y-1][pos_x] = YELLOW;
	   }
	   else if(level2[pos_y+1][pos_x] == 0)
	   {
		fall();   
	   }
   }
   
}
Exemple #7
0
void ram(void)
{
    int c=0, pos=0,del=0;

    struct pos_s tail[MAX_SNAKE_LEN];
    snake.tail = tail;

    // load the highscore
    highscore = highscore_get();

    // initially reset everything
    reset();

    while (1) {
        if(!(++c % snake.speed)) {
            handle_input();

            pos = (snake.t_start+1) % MAX_SNAKE_LEN;
            snake.tail[pos].x = snake.tail[snake.t_start].x;
            snake.tail[pos].y = snake.tail[snake.t_start].y;

            if(snake.dir == 0)
                snake.tail[pos].x++;
            else if(snake.dir == 1)
                snake.tail[pos].y++;
            else if(snake.dir == 2)
                snake.tail[pos].x--;
            else if(snake.dir == 3)
                snake.tail[pos].y--;

            snake.t_start = pos;

            if (pos < snake.len) {
                del = MAX_SNAKE_LEN - (snake.len - pos);
            } else
                del = pos - snake.len;

            // remove last, add first line
            draw_block(snake.tail[del].x, snake.tail[del].y, 0xFF);
            draw_block(snake.tail[pos].x, snake.tail[pos].y, 0b00011000);

            // check for obstacle hit..
            if (hitWall() || hitSelf()) {
                death_anim();
                if (showHighscore())
                    break;
                reset();
            } else if (hitFood())
                next_level();

            lcdDisplay();
        }

#ifdef SIMULATOR
        delayms(50);
#else
        delayms(3);
#endif
    }
}
Exemple #8
0
    static inline void apply(Box const& box,
            InputCollection const& collection,
            index_vector_type const& input,
            std::size_t level,
            std::size_t min_elements,
            Policy& policy, VisitBoxPolicy& box_policy)
    {
        box_policy.apply(box, level);

        Box lower_box, upper_box;
        divide_box<Dimension>(box, lower_box, upper_box);

        index_vector_type lower, upper, exceeding;
        divide_into_subsets<OverlapsPolicy>(lower_box, upper_box, collection,
                    input, lower, upper, exceeding);

        if (boost::size(exceeding) > 0)
        {
            // Get the box of exceeding-only
            Box exceeding_box = get_new_box(collection, exceeding);

            // Recursively do exceeding elements only, in next dimension they
            // will probably be less exceeding within the new box
            next_level(exceeding_box, collection, exceeding, level,
                min_elements, policy, box_policy);

            // Switch to two collections, combine exceeding with lower resp upper
            // but not lower/lower, upper/upper
            next_level2(exceeding_box, collection, exceeding, lower, level,
                min_elements, policy, box_policy);
            next_level2(exceeding_box, collection, exceeding, upper, level,
                min_elements, policy, box_policy);
        }

        // Recursively call operation both parts
        next_level(lower_box, collection, lower, level, min_elements,
                        policy, box_policy);
        next_level(upper_box, collection, upper, level, min_elements,
                        policy, box_policy);
    }
handle next_level(handle h, int l)
{
  handle child_handle;

  if (l == 0) return null;

  child_handle = null;

  while (child_handle = acc_next_child (h, child_handle)) {
    next_level (child_handle, l-1);
    fprintf (fp, "%s\n", acc_fetch_fullname (child_handle));
  }
}
Exemple #10
0
//potential bugs
//jumping out of bounds
//jumping through objects
void jump()
{
		has_moved = 1;
		in_air = 1;
		crouched = 1;
		///LEVEL 1
		if(cur_level == 1)
		{
			if(pos_y >= 4 && level1[pos_y-2][pos_x] == 0)
			{
				level1[pos_y][pos_x] = 0;
				level1[pos_y-1][pos_x] = 0;
				level1[pos_y-3][pos_x] = YELLOW;
				pos_y = pos_y-3;
			}
			else if (pos_y == 3 && level1[pos_y-2][pos_x] == 0) //only jump up 2 otherwise will end up out of range
			{
				level1[pos_y][pos_x] = 0;
				level1[pos_y-1][pos_x] = 0;
				level1[pos_y-3][pos_x] = YELLOW;
				pos_y -= 3;
			}
		}
		//LEVEL 2
		if(cur_level == 2)
		{
			if(pos_y >= 4 && level2[pos_y-2][pos_x] == 0)
			{
				level2[pos_y][pos_x] = 0;
				level2[pos_y-1][pos_x] = 0;
				level2[pos_y-3][pos_x] = YELLOW;
				pos_y = pos_y-3;
			}
			else if (pos_y == 3 && (level2[pos_y-2][pos_x] == EXIT_COLOR || level2[pos_y-3][pos_x] == EXIT_COLOR)) //only jump up 2 otherwise will end up out of range
			{
					next_level();
			}
			else if (pos_y == 3 && level1[pos_y-2][pos_x] == 0) //only jump up 2 otherwise will end up out of range
			{
				level2[pos_y][pos_x] = 0;
				level2[pos_y-1][pos_x] = 0;
				level2[pos_y-2][pos_x] = YELLOW;
				pos_y -= 2;
			}	
		}

}
Exemple #11
0
static void reset()
{
    int i;

    // setup the screen
    lcdClear();
    for (i=MIN_X; i<MAX_X; i++) {
        lcdSetPixel(i,MIN_Y,0b000101011);
        lcdSetPixel(i,MAX_Y,0b000101011);
    }

    for (i=MIN_Y; i<MAX_Y; i++) {
        lcdSetPixel(MIN_X,i,0b000101011);
        lcdSetPixel(MAX_X,i,0b000101011);
    }

    snake.speed = MIN_SPEED;
    snake.len = 3;
    snake.dir = 0;
    snake.t_start = 2;

    points = 0;

    // create snake in the middle of the field
    snake.tail[0].x = SIZE_X/2;
    snake.tail[0].y = SIZE_Y/2;
    snake.tail[1].x = SIZE_X/2 +1;
    snake.tail[1].y = SIZE_Y/2;
    snake.tail[2].x = SIZE_X/2 +2;
    snake.tail[2].y = SIZE_Y/2;

    // print initail tail
    draw_block(snake.tail[0].x, snake.tail[0].y, 0b00011000);
    draw_block(snake.tail[1].x, snake.tail[1].y, 0b00011000);
    draw_block(snake.tail[2].x, snake.tail[2].y, 0b00011000);

    // switch to level one
    next_level();
}
Exemple #12
0
		/*
		a = 1 when the player goes of the left of the screen shifting everything to the right
		a = -1  when the player goes of the right of the screen shifting everything to the left
		*/
		entityV[i]->set_x(entityV[i]->get_x()+(1024*a));//add + or - 1024 dpending on weather the player went left or right off the screen a 


		//if the entity is an enemy or the boss
		if(i >= entities[eEnemy] && i < entities[ePlayer])
		{
			entityV[i]->set_center(1024*a);//change the center to the with the same value as x so the enemies can still move
		}
	}
	//if te player went off the left
	if(a == 1)
	{entityV[entities[ePlayer]]->set_x(990);}//set the players position to right hand side of the screen
	
	//if the player went of the right
	if(a == -1)
	{entityV[entities[ePlayer]]->set_x(2);}//set the players position to the left hand side of the screen
}//end scroll()


//used to allow the player to input a name to used in the high score table
void CWorldModel::set_name()
{
	HAPI_TKeyboardData data;
	HAPI->GetKeyboardData(&data);

	for(int a=0; a<255; a++)
	{
			//if backpsace or return not pressed
			if (CUserInterface::Inst()->letter(a) && (!CUserInterface::Inst()->back() || !CUserInterface::Inst()->enter()))
			{
				char_input[char_count] = char(a); //cast the int of the number pressed to the relivant char code.
				 if(char_count < 10)
				 char_count++; //move along the array
			}//end if

			//if backspace is pressed
			if (CUserInterface::Inst()->back())
			{
				if (char_count > 0)
				{
					char_count--; //move back one space
					char_input[char_count] = ' '; //replace what was in that place
				}//end if
			}//end if

			//if enter is pressed 
			if(CUserInterface::Inst()->enter())
			{
				game_state=2;//change to to the high score table
			}//end if

			if (CUserInterface::Inst()->escape())
			{
				game_state=0;//exits the program cleanly
			}//end if

	}//end for[a]

if (char_count == 0)
{
	players_name="";
}else{
		players_name = char_input; // convert the char[] to string
	}//end else
}//end set_name()

//sends the high score table to the grapics*/
void CWorldModel::render_scores()
{
	CFiles::Inst()->load_scores();//loads the most recent high score table

	//if the player has a new score
	if(score  > 0)
	{
		CFiles::Inst()->set_high_score(players_name,score);//send to the file class to check if it goes on the high score table
	}//end if
	HAPI->ChangeFont( "Arial", 24, 1000);
	//for all of the scores in the table
	for(int a=0; a<10; a++)
	{
		CGraphics::Inst()->display_score(a,CFiles::Inst()->get_name(a),CFiles::Inst()->get_points(a));//send the name and score to the graphics for rendering
	}//end for [a]
	CGraphics::Inst()->display_title();//asks the graphics to display the name of the game
	CFiles::Inst()->save_scores();//saves the high scores to file via the file class

	level=0;//set level at 0 this screen is seen before the game starts which is why the level is set here

	//if the return key is pressed
	if(CUserInterface::Inst()->enter())
	{
		life=100;
		players_name="";
		lastchange=0;
		score=0;
		char_count=0;//used as players health
		game_state=1;//play game
		next_level();//load the next level
	}//end if

	//if Esc is pressed
	if (CUserInterface::Inst()->escape())
	{
		game_state=0;//exits the program cleanly
	}//end if
}//end render_scores()
Exemple #13
0
    static inline void apply(Box const& box,
            InputCollection1 const& collection1, index_vector_type const& input1,
            InputCollection2 const& collection2, index_vector_type const& input2,
            std::size_t level,
            std::size_t min_elements,
            Policy& policy, VisitBoxPolicy& box_policy)
    {
        box_policy.apply(box, level);

        Box lower_box, upper_box;
        divide_box<Dimension>(box, lower_box, upper_box);

        index_vector_type lower1, upper1, exceeding1;
        index_vector_type lower2, upper2, exceeding2;
        divide_into_subsets<OverlapsPolicy1>(lower_box, upper_box, collection1,
                    input1, lower1, upper1, exceeding1);
        divide_into_subsets<OverlapsPolicy2>(lower_box, upper_box, collection2,
                    input2, lower2, upper2, exceeding2);

        if (boost::size(exceeding1) > 0)
        {
            // All exceeding from 1 with 2:

            if (recurse_ok(exceeding1, exceeding2, min_elements, level))
            {
                Box exceeding_box = get_new_box(collection1, exceeding1,
                            collection2, exceeding2);
                next_level(exceeding_box, collection1, exceeding1,
                                collection2, exceeding2, level,
                                min_elements, policy, box_policy);
            }
            else
            {
                handle_two(collection1, exceeding1, collection2, exceeding2,
                            policy);
            }

            // All exceeding from 1 with lower and upper of 2:

            // (Check sizes of all three collections to avoid recurse into
            // the same combinations again and again)
            if (recurse_ok(lower2, upper2, exceeding1, min_elements, level))
            {
                Box exceeding_box
                    = get_new_box<ExpandPolicy1>(collection1, exceeding1);
                next_level(exceeding_box, collection1, exceeding1,
                    collection2, lower2, level, min_elements, policy, box_policy);
                next_level(exceeding_box, collection1, exceeding1,
                    collection2, upper2, level, min_elements, policy, box_policy);
            }
            else
            {
                handle_two(collection1, exceeding1, collection2, lower2, policy);
                handle_two(collection1, exceeding1, collection2, upper2, policy);
            }
        }

        if (boost::size(exceeding2) > 0)
        {
            // All exceeding from 2 with lower and upper of 1:
            if (recurse_ok(lower1, upper1, exceeding2, min_elements, level))
            {
                Box exceeding_box
                    = get_new_box<ExpandPolicy2>(collection2, exceeding2);
                next_level(exceeding_box, collection1, lower1,
                    collection2, exceeding2, level, min_elements, policy, box_policy);
                next_level(exceeding_box, collection1, upper1,
                    collection2, exceeding2, level, min_elements, policy, box_policy);
            }
            else
            {
                handle_two(collection1, lower1, collection2, exceeding2, policy);
                handle_two(collection1, upper1, collection2, exceeding2, policy);
            }
        }

        if (recurse_ok(lower1, lower2, min_elements, level))
        {
            next_level(lower_box, collection1, lower1, collection2, lower2, level,
                            min_elements, policy, box_policy);
        }
        else
        {
            handle_two(collection1, lower1, collection2, lower2, policy);
        }
        if (recurse_ok(upper1, upper2, min_elements, level))
        {
            next_level(upper_box, collection1, upper1, collection2, upper2, level,
                            min_elements, policy, box_policy);
        }
        else
        {
            handle_two(collection1, upper1, collection2, upper2, policy);
        }
    }
Exemple #14
0
int main(void)
{
#if !SDL
	//wdt_enable(WDTO_1S);

	// I/O ports

	DDRB = 0x17;
	PORTB = 0x00 | (1<<5);
	//input logic disable on adc3
	DIDR0 = (1<<ADC3D);

	//timer0
	
	//set clock divider to 1024
	TCCR0B |= (1<<CS02) | (1<<CS00);
	//compare value 49 -> 20Hz
	//OCR0B = 49;
	OCR0B = 3;
	//enable compare match B interrupt
	TIMSK |= (1<<OCIE0B);

	//timer1

	//      CK/64
	//TCCR1 = (1<<CS12) | (1<<CS11) | (1<<CS10);
	//overflow interrupt
	//TIMSK |= (1<<TOIE1);

	//external interrupts
	
	//enable pin change interrupt
	//GIMSK = (1<<PCIE);
	//enable only on PB3
	//PCMSK = (1<<3);
	
	//adc
	
	//       enable      clk/16
	//ADCSRA = (1<<ADEN) | (1<<ADPS2);
	//       enable      clk/2
	ADCSRA = (1<<ADEN) | (1<<ADPS0);

	/*//if it's a watchdog reset
	if(mcusr_mirror & (1<<WDRF)){
		if(getkey() == DIR_NONE){
			set_sleep_mode(SLEEP_MODE_PWR_DOWN);
			sleep_mode();
		}
	}*/

	//wdt_enable(WDTO_4S);

#else

	SDL_Init(SDL_INIT_VIDEO);
	if (!(screen = SDL_SetVideoMode(80, 48, 32, SDL_SWSURFACE)))
		return EXIT_FAILURE;

	SDL_WM_SetCaption("elladunkku", NULL);

#endif

	/*g_highscore = eeprom_read_byte(0);
	if(g_highscore == 0xff) g_highscore = 0;*/
	/*g_highscore = eeprom_read_word(0);
	if(g_highscore == 0xffff) g_highscore = 0;*/

start:

	lcd_init();

	//lcd_locate(10,2);
	//lcd_locate8((2<<4)+1);
	//lcd_printstrP(PSTR("C55 PRESENTS"));
	//_delay_ms(1000);

	sei();

	for(;;){

		next_level(true);
		draw_game();

		//main loop

		g_counter0 = 0;
		//TCNT0 = 0;
		for(;;){
#if SDL
			++g_counter0;
			SDL_WaitEvent(&g_event);
			if (g_event.type == SDL_QUIT)
				goto quit;
#endif

			// TODO: If nothing happens for a long time, go to sleep

			int8_t key = getkey();
			if(key == DIR_NONE)
				continue;

			uint8_t num_enemy_moves = move_player(key);
			switch(num_enemy_moves){
			case 2:
				step_enemies();
				draw_game();
			case 1:
				step_enemies();
			}
			draw_game();

			if(g_hp <= 0){
				_delay_ms(5000);
				while(getkey() == DIR_NONE);
				next_level(true); // Reset game
				draw_game();
			}

			/*int8_t lastdir_inv = -g_next_dir;
			while(g_counter0 < 6){
			//while(TCNT0 < 6*3){
				int8_t key = getkey();
				if(key == DIR_NONE) continue;
				if(key == lastdir_inv) continue;
				g_next_dir = key;
				g_random += g_counter0;
			}
			TCNT0 = 0;
			g_counter0 = 0;
			uint8_t ret = snake_move_and_draw();
			if(ret == 1){
				snake_draw(0xaa);
				draw_block(g_snake[g_snake_end], 0xff);
				//lcd_locate(83,5);
				lcd_locate8((0<<4)+4);
				if(g_points > g_highscore){
					g_highscore = g_points;
					//eeprom_write_byte(0, g_highscore);
					eeprom_write_word(0, g_highscore);
				}
				_delay_ms(200);
				break;
			}*/
		}

#if !SDL
		while(getkey() != DIR_NONE);
		//TCNT0 = 0;
		g_counter0 = 0;
		while(getkey() == DIR_NONE){
			if(g_counter0 >= 200){
				cli();

				/*lcd_cls();
				lcd_locate8((1<<4)+0);
				lcd_printstrP(PSTR("GREETINGS  ELLA  TEJEEZ  3210"));
				_delay_ms(2000);*/
				/*lcd_locate8((1<<4)+1);
				lcd_printstrP(PSTR("GREETINGS ELLA TEJEEZ"));
				lcd_locate8((2<<4)+1);
				lcd_printstrP(PSTR("ELLA"));
				lcd_locate8((3<<4)+1);
				lcd_printstrP(PSTR("TEJEEZ"));*/
				/*lcd_cls();
				lcd_locate8((1<<4)+3);
				lcd_put5digit(2048);
				lcd_locate8((2<<4)+3);
				lcd_put5digit(128);
				lcd_locate8((3<<4)+3);
				lcd_put5digit(55);
				_delay_ms(2000);*/
				
				lcd_cls();
				lcd_powerdown();

				ADCSRA = 0 | (1<<ADPS0);
				DIDR0 = 0;
				CLKPR = 0x80;
				CLKPR = (1<<CLKPS3); //256
				while(PINB & (1<<3));
				//while(getkey() == DIR_NONE);
				CLKPR = 0x80;
				CLKPR = 0;
				DIDR0 = (1<<ADC3D);
				ADCSRA = (1<<ADEN) | (1<<ADPS0);

				goto start;
			}
		}
#endif
	}

#if SDL
quit:
	SDL_Quit();
#endif
	return 0;
}
Exemple #15
0
void fall()
{
	//level 1
	if(cur_level == 1)
	{
		if(level1[pos_y+1][pos_x] != TILE && level1[pos_y+1][pos_x] != EXIT_COLOR)
		{
			has_moved = 1;
			level1[pos_y-1][pos_x] = 0;
			level1[pos_y][pos_x] = 0;
			pos_y++;
			level1[pos_y-1][pos_x] = YELLOW ;
		}
		else if(level1[pos_y+1][pos_x] == EXIT_COLOR)
		{
			next_level();
		}
		else
		{
			has_moved = 1;
			level1[pos_y][pos_x] = YELLOW;
			level1[pos_y-1][pos_x] = YELLOW;
			in_air = 0;
			crouched = 0;
		}
	}
	//level 2
	if(cur_level == 2)
	{
		if(level2[pos_y+1][pos_x] != TILE && level2[pos_y+1][pos_x] != BLUE)
		{
			has_moved = 1;
			level2[pos_y-1][pos_x] = 0;
			level2[pos_y][pos_x] = 0;
			//level1[pos_y+1][pos_x] = YELLOW;
			pos_y++;
			level2[pos_y-1][pos_x] = YELLOW ;
		}
		else if(level2[pos_y+1][pos_x] == BLUE)//restart section (die)
		{
			pos_y = 2;
			pos_x = 2;
			player_HP--;
			if(player_HP == 0)
			{
				cur_level = 1;
				level_size_index = 0;
				calc_render_range(lvl_sizes[level_size_index]);
				moving_right = 1;
				crouched = 0;
				in_air = 0;
				whipped = 0;
				pos_x = 2;
				pos_y = 6;
				player_HP = 4;
			}
		}
		else
		{
			has_moved = 1;
			level2[pos_y][pos_x] = YELLOW;
			level2[pos_y-1][pos_x] = YELLOW;
			in_air = 0;
			crouched = 0;
		}
	}

}
Exemple #16
0
//used while game_state = game
void CWorldModel::update_game()
{
	/*
	while traversing the vector different letters are used to move through different parts
	k is ued for the bullets
	j is used for the enemies
	i is used for the entities e.g. the walls and floors
	e is used for the explosions
	the player and boss because there is only one of each are called explicitly using ePlayer and eBoss
	*/

	//go through the vector starting at the bullets and stopping when you reach the explosions since they are the next type of entity
	for(int k=entities[eBullet];k<entities[eExplosion];k++)
	{
		//is the bullets side = the playes side e.g a fireball
		if(entityV[k]->get_side() == eSidePlayer)
		{
			//if the player has fired and there is a fireball not being used
			if (entityV[entities[ePlayer]]->get_fired() && !entityV[k]->get_active())
			{
				//shoot the fireball using x,y and direction from the player
				entityV[k]->shoot(entityV[entities[ePlayer]]->get_x(),entityV[entities[ePlayer]]->get_y(),entityV[entities[ePlayer]]->get_dir());
				HAPI->StopSound(CSounds::Inst()->get_sound(entityV[k]->get_id()));
				//stops the player firing two fireballs at the same time
				entityV[entities[ePlayer]]->set_fired(false);
				HAPI->PlayASound(CSounds::Inst()->get_sound(entityV[k]->get_id()));

			}//end if
		}else//if not a player bullet
		{
			//go through the vector with the for loop [k] to find enemies
			for(int j=entities[eEnemy];j<entities[eBoss]; j++)
			{
				/*
				if the enemy is trooper(basic) and the bullet is a laser(least powerful)
				if the enemy is a solider(advanced and the bullet is a rocket(medieum power)
				if the enemy is a marine Elite and the bullet is a plasma orb(most powerful)
				*/
				if ((entityV[j]->get_id() == eEnemyTrooper && entityV[k]->get_id() == eBulletLaser) || (entityV[j]->get_id() == eEnemySoldier && entityV[k]->get_id() == eBulletRocket) || (entityV[j]->get_id() == eEnemyMarine  && entityV[k]->get_id() == eBulletPlasma))
				{
					//if the enemy has fired and there is an inactive bullet
					if (entityV[j]->get_fired() && !entityV[k]->get_active())
					{
						//shoot the fireball using x,y and direction from the selected enemy
						entityV[k]->shoot(entityV[j]->get_x(),entityV[j]->get_y(),entityV[j]->get_dir());
						HAPI->StopSound(CSounds::Inst()->get_sound(entityV[k]->get_id()));
						entityV[j]->set_fired(false);
						HAPI->PlayASound(CSounds::Inst()->get_sound(entityV[k]->get_id()));
					}//end if
				}//end if
			}//end for [j]


			//if the boss has fired and there is a spare rocket
			if (entityV[entities[eBoss]]->get_fired() && !entityV[k]->get_active() && entityV[k]->get_id() == eBulletRocket)
			{
				//shoot the fireball using x,y and direction from the boss
				entityV[k]->shoot(entityV[entities[eBoss]]->get_x(),entityV[entities[eBoss]]->get_y()+20,entityV[entities[eBoss]]->get_dir());
				entityV[entities[eBoss]]->set_fired(false);
				HAPI->StopSound(CSounds::Inst()->get_sound(entityV[k]->get_id()));
				HAPI->PlayASound(CSounds::Inst()->get_sound(entityV[k]->get_id()),true);
			}//end if
		}//end if

	}//end for [k]

		//move through the entire Vector calling the entities update function
		for(unsigned int i=0;i<entityV.size();i++)
		{
			if (entityV[i]->get_active() && i != entities[eBoss])
			entityV[i]->update(); 
		}//end for
		/* 
		if the game has been running for 1 minute then reset the backgound music to the start
		this makes sure then there is always some music playing during the game
		*/
		int gamertime=HAPI->GetTime();
		if(gamertime-lastchange > 60*1000)
		{
			CSounds::Inst()->play_background(level,boss_attack);
			lastchange=gamertime;
		}//end if
	//checks for collisions more on this function later							
	check_collisions();

		//if the player is on screen 5 or the boss is active
		//players can't stop the boss from moving if they leave the screen
		if (screen == 5 || boss_attack)
		{
			entityV[entities[eBoss]]->update();
			boss_attack=true;
		}//end if

		//if the player goes off the right edge of the screen
		if (entityV[entities[ePlayer]]->get_x() > 1024)
		{
			scroll(-1);
			screen++;
			if(screen ==5)//change background music if the player reaches screen 5
				CSounds::Inst()->play_background(level,boss_attack);
		}//end if
			
		//if the player goes off the left side of the screen
		if (entityV[entities[ePlayer]]->get_x() < -32)
		{
			scroll(1);
			screen--;
		}//end if

		//if the boss has no health left
		if (entityV[entities[eBoss]]->get_health() <= 0)
		{	
			score+=100;
			//if the player has killed the level 4 boss
			if (level==4)
			{
				game_state=3;//go to the menu
				HAPI->StopStreamedMedia();
				score+=entityV[entities[ePlayer]]->get_health();//add the remaining players health to the score
				end_cond="YOU WIN";//congratulate the player
			}else//if it is not the level 4 boss which has been killed
				{
					//keep the players health in a sperate variable as the player is abou to go out of scope
					life=entityV[entities[ePlayer]]->get_health();
					//load the next level
					next_level();
				}//end else end if
		}//end if

		//if the players health is reduced to 0
		if (entityV[entities[ePlayer]]->get_health() <=0 )
		{	
			game_state=3;
			HAPI->StopStreamedMedia();//go tot the menu
		}//end if
}//end update_game()
Exemple #17
0
void ram(void)
{
    int c=0, pos=0,del=0;

    struct pos_s tail[MAX_SNAKE_LEN];
    snake.tail = tail;

    // initially reset everything
    reset();

    while (1)
    {
        if(!(++c % snake.speed)) {
            if (handle_input()){ //handle_input returns 1 to quit
                break;
            }

            pos = (snake.t_start+1) % MAX_SNAKE_LEN;
            snake.tail[pos].x = snake.tail[snake.t_start].x;
            snake.tail[pos].y = snake.tail[snake.t_start].y;

            if(snake.dir == 0)
            {
                snake.tail[pos].x++;
                if(snake.tail[pos].x*SNAKE_DIM>=MAX_X) snake.tail[pos].x=MIN_X/SNAKE_DIM+1;
            }
            else if(snake.dir == 1)
            {
                snake.tail[pos].y++;
                if(snake.tail[pos].y*SNAKE_DIM>=MAX_Y) snake.tail[pos].y=MIN_Y/SNAKE_DIM+1;
            }
            else if(snake.dir == 2)
            {
                snake.tail[pos].x--;
                if(snake.tail[pos].x*SNAKE_DIM<=MIN_X) snake.tail[pos].x=MAX_X/SNAKE_DIM-1;
            }
            else if(snake.dir == SNAKE_DIM)
            {
                snake.tail[pos].y--;
                if(snake.tail[pos].y*SNAKE_DIM<=MIN_Y) snake.tail[pos].y=MAX_Y/SNAKE_DIM-1;
            }

            snake.t_start = pos;

            del = pos - snake.len;
            if (pos < snake.len) del += MAX_SNAKE_LEN;

            // remove last, add first line
            draw_block(snake.tail[del].x, snake.tail[del].y, 0xFF);
            draw_block(snake.tail[pos].x, snake.tail[pos].y, 0b00011000);

            // check for obstacle hit..
            if (hitSelf()) {
                death_anim();
                if (showHighscore())
                    break;
                reset();
            }
            else if (hitFood())
                next_level();

            lcdDisplay();
        }

#ifdef SIMULATOR
        delayms(50);
#else
        delayms(3);
#endif
    }
}
Exemple #18
0
// Returns true if move is valid
static uint8_t move_player(int8_t key)
{
	uint8_t x, y;
	to_pos(g_player_position_i, &x, &y);
	uint8_t old_x = x;
	uint8_t old_y = y;
	switch(key){
	case DIR_UP:
		y--;
		break;
	case DIR_DOWN:
		y++;
		break;
	case DIR_LEFT:
		x--;
		break;
	case DIR_RIGHT:
		x++;
		break;
	default:
		return 0; //no move
	}
	g_seed += (x<<4) + y;

	if(y == 255 || x == 255 || y == MAP_H || x == MAP_W)
		return 0; // Map boundaries

	uint8_t i = get_pos(x, y);
	uint8_t t = g_map[i];

	if(t == MOUNTAIN || t == TREE){
		return 0; // Can't walk on these tiles
	}
	if(t == SNAKE || t == GOBLIN || t == ELLA || t == DRAGON){
		// TODO: Require hitting enemy more than once
		g_map[i] = 0;
		return 1;
	}

	// TODO: Enable this
	/*// Immediately erase player
	lcd_locate(2+old_x*8, old_y+1);
	lcd_print_sprite(0);
	
	// Immediately draw player
	lcd_locate(2+x*8, y+1);
	lcd_print_sprite(12);*/

	g_player_position_i = get_pos(x, y);

	if(t == STAIRS){
		next_level(false);
		return 0;
	}
	if(t == BERRY){
		if(g_hp < 254)
			g_hp+=3;
		g_map[i] = EMPTY;
		return 1;
	}
	if(t == STONE || t == BUSH)
		return 2;
	return 1;
}