Exemplo n.º 1
0
//player to hard code point
bool checkCollidePH(player P, float ox, float oy, float or)
{
	Point p;
	p.x = ox;
	p.y = oy;

	return theCollide(P.getPosition(), p, P.getRadius(), or);
}
Exemplo n.º 2
0
void drawPlayer()
{
	int x, y;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	//get players position
	x = mainPlayer.getPosition().x;
	y = mainPlayer.getPosition().y;

	//draw our triangle
	glBegin(GL_TRIANGLES);
		glVertex3f(x,y + 20 ,0);
		glVertex3f(x -20, y-10,0);
		glVertex3f(x+20,y -10,0);
	glEnd();
	//glutSwapBuffers();//swap bufferes!!!! Important for animation
	glFlush();
}
Exemplo n.º 3
0
//player to player
bool checkCollidePP(player P1, player P2)
{
	return (theCollide(P1.getPosition(), P2.getPosition(), P1.getRadius(), P2.getRadius()));
}
Exemplo n.º 4
0
//player to unit
bool checkCollidePU(player P, unit U)
{
	return (theCollide(P.getPosition(), U.getPosition(), P.getRadius(), U.getRadius()));
}
Exemplo n.º 5
0
//movement function
void playerMovement ()
{
    if (_move == true)
    {
        //if right clicked in enemy, following enemy
        if (follow == true)
        {
            if (attack_flag == true && clock() >= end_cool_attack)
            {
                attack_flag = false;
                player_animation_select = 0;
                //reset animation
            }
            //take a portion of clock time on cooldown to select animations basically 1 animation per 1/num animtions timeframe

            float pre, post;
            current = clock();

            pre = (float)((float)player_animation_select / (float)player_animation_max);
            post = (float)((float)(player_animation_select + 1) / (float)player_animation_max);

            if (current >= start_cool_attack + (attack_cooldown*pre) && current < start_cool_attack + (attack_cooldown*post) && player_animation_select != player_animation_max  - 1 && attack_flag == true)
            {
                player_animation_select++;
            }

            mouse.x = enemy[chase].getPosition().x;
            mouse.y = enemy[chase].getPosition().y;

            //if not attacking
            if (attack_flag == false)
            {
                float distance = (float)pow(pow(enemy[chase].getPosition().x - mainPlayer.getPosition().x, 2) + pow(enemy[chase].getPosition().y - mainPlayer.getPosition().y, 2), 0.5);
                //if within range of enemy, rememebr we already checked if the enemy was clicked on
                if (distance <= mainPlayer.getRange())
                {
                    //attack the enemy and start the cooldown clock
                    cout<<enemy[chase].getHealth()<<cout<<"\n";
                    attack(chase);
                    start_cool_attack = clock();
                    end_cool_attack = attack_cooldown + start_cool_attack;
                    attack_flag = true;
                    cout<<enemy[chase].getHealth()<<cout<<"\n";
                }
            }

            //stop following if enemy is dead
            if (enemy[chase].getHealth() <= 0 && follow == true)
            {
                follow = false;
                _move = false;
            }
        }

        if (follow == false)
            player_animation_select = 0;
        //move the player to its movepoint
        mainPlayer.move(movepoint.x, movepoint.y);

        //if you reach the mouse click, stop moving
        if (mainPlayer.getPosition().x == mouse.x && mainPlayer.getPosition().y == mouse.y)
            _move = false;
    }
}
Exemplo n.º 6
0
void drawPlayer()
{
    int x, y, r;
    //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //get players position
    x = (int)mainPlayer.getPosition().x;
    y = (int)mainPlayer.getPosition().y;
    r = (int)mainPlayer.getRadius();

    //start drawing the player
    glPushMatrix();
    glEnable(GL_TEXTURE_2D);
    glMatrixMode(GL_MODELVIEW);
    //for rotation
    if (wasclicked_RB == true || follow == true)
    {
        float PI = (float)3.14159265;
        float dy, dx;

        if (follow == true)
        {
            dy = (enemy[chase].getPosition().y - y);
            dx = (enemy[chase].getPosition().x - x);
        }
        else
        {
            dy = (mouse.y - y);
            dx = (mouse.x - x);
        }

        //find angle of rotation, if dx is 0 then you cant divide by 0 so set angle to 180
        if (dx == 0)
        {}
        else
            angle = atan(dy / dx) * 180/PI + 90;

        //if dx is negative then we have to compensate the angle to go left
        if (dx < 0)
            angle += 180;

    }
    //draw the player texture
    glBindTexture(GL_TEXTURE_2D, mainPlayer.getSprites()[player_animation_select]);
    //translate the player to the origin
    glTranslatef((GLfloat)x,(GLfloat)y, (GLfloat)0.0f);
    //rotate player
    glRotatef(angle,0,0,1);

    //draw player
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0);
    glVertex2f((GLfloat)(-r), (GLfloat)(r));
    glTexCoord2f(1, 0);
    glVertex2f((GLfloat)(r), (GLfloat)(r));
    glTexCoord2f(1, 1);
    glVertex2f((GLfloat)(r), (GLfloat)(-r));
    glTexCoord2f(0, 1);
    glVertex2f((GLfloat)(-r), (GLfloat)(-r));
    glEnd();

    glDisable(GL_TEXTURE_2D);
    //reset the screen so only player rotated
    glPopMatrix();
    //flush the buffer
    glFlush();
}
Exemplo n.º 7
0
void playerMovement () 
{
	//rotate player
	//needs to be added in, will come soon
	//move in direction of 
	int col_flag;

	Point P1, P2;
	if (_move == true)
	{
		//move until player hits mouse click
		P1 = mainPlayer.getPosition();
		mainPlayer.move(mouse.x, mouse.y);
		P2 = mainPlayer.getPosition();

		if (checkCollisions() == true)
		{
			//left
			if ((mainPlayer.getPosition().x - mainPlayer.getRadius()) <= enemy[collide_with].getPosition().x + enemy[collide_with].getRadius() && (mainPlayer.getPosition().x - mainPlayer.getRadius()) + mainPlayer.getSpeed() + 1> enemy[collide_with].getPosition().x + enemy[collide_with].getRadius())
				col_flag = 1;
			//right
			else if ((mainPlayer.getPosition().x + mainPlayer.getRadius()) >= enemy[collide_with].getPosition().x - enemy[collide_with].getRadius() && (mainPlayer.getPosition().x + mainPlayer.getRadius()) - mainPlayer.getSpeed() - 1< enemy[collide_with].getPosition().x - enemy[collide_with].getRadius())
				col_flag = 2;
			//none
			else
				col_flag = 3;

			//top
			if ((mainPlayer.getPosition().y - mainPlayer.getRadius()) <= enemy[collide_with].getPosition().y + enemy[collide_with].getRadius() && (mainPlayer.getPosition().y - mainPlayer.getRadius()) + mainPlayer.getSpeed() + 1 > enemy[collide_with].getPosition().y + enemy[collide_with].getRadius())
				col_flag += 10;
			//bottom
			else if ((mainPlayer.getPosition().y + mainPlayer.getRadius()) >= enemy[collide_with].getPosition().y - enemy[collide_with].getRadius() && (mainPlayer.getPosition().y + mainPlayer.getRadius()) - mainPlayer.getSpeed() - 1 < enemy[collide_with].getPosition().y - enemy[collide_with].getRadius())
				col_flag += 20;
			//none
			else
				col_flag += 30;

			mainPlayer.setPosition(P1.x, P1.y);
			switch (col_flag)
			{
				//left top
				case 11:
					P1.x = enemy[collide_with].getPosition().x + enemy[collide_with].getRadius() + mainPlayer.getRadius();
					P1.y = enemy[collide_with].getPosition().y + enemy[collide_with].getRadius() + mainPlayer.getRadius();
					mainPlayer.move(P1.x,P1.y);
					break;
				//left bottom
				case 21:
					P1.x = enemy[collide_with].getPosition().x + enemy[collide_with].getRadius() + mainPlayer.getRadius();
					P1.y = enemy[collide_with].getPosition().y - enemy[collide_with].getRadius() - mainPlayer.getRadius();
					mainPlayer.move(P1.x,P1.y);
					break;
				//left none
				case 31:
					P1.x = enemy[collide_with].getPosition().x + enemy[collide_with].getRadius() + mainPlayer.getRadius();
					P1.y = mouse.y;
					mainPlayer.move(P1.x,P1.y);
					break;
				//right top
				case 12:
					P1.x = enemy[collide_with].getPosition().x - enemy[collide_with].getRadius() - mainPlayer.getRadius();
					P1.y = enemy[collide_with].getPosition().y + enemy[collide_with].getRadius() + mainPlayer.getRadius();
					mainPlayer.move(P1.x,P1.y);
					break;
				//right bottom
				case 22:
					P1.x = enemy[collide_with].getPosition().x - enemy[collide_with].getRadius() - mainPlayer.getRadius();
					P1.y = enemy[collide_with].getPosition().y - enemy[collide_with].getRadius() - mainPlayer.getRadius();
					mainPlayer.move(P1.x,P1.y);
					break;
				//right none
				case 32:
					P1.x = enemy[collide_with].getPosition().x - enemy[collide_with].getRadius() - mainPlayer.getRadius();
					P1.y = mouse.y;
					mainPlayer.move(P1.x,P1.y);
					break;
				//none top
				case 13:
					P1.x = mouse.x;
					P1.y = enemy[collide_with].getPosition().y + enemy[collide_with].getRadius() + mainPlayer.getRadius();
					mainPlayer.move(P1.x,P1.y);
					break;
				//none bottom
				case 23:
					P1.x = mouse.x;
					P1.y = enemy[collide_with].getPosition().y - enemy[collide_with].getRadius() - mainPlayer.getRadius();
					mainPlayer.move(P1.x,P1.y);
					break;
				//none none
				case 33:
					mainPlayer.move(mouse.x,mouse.y);
					break;
				default:
					mainPlayer.move(mouse.x,mouse.y);
					break;
			}
		}
			
		if (mainPlayer.getPosition().x == mouse.x && mainPlayer.getPosition().y == mouse.y)
			_move = false;

		Sleep(10);
	}
}