123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <GL/glut.h>
- #include "cardCharSelect.h"
- #include "cardStageSelect.h"
- #include "cardGame.h"
- #include "brick.h"
- CardCharSelect::CardCharSelect(char gIsSurvival)
- {
- /* Bricks */
- //printf("data/heroes\n");
- //Parse file with stats
- FILE *file = fopen("mod/heroes", "r");
- //Failed to open file
- if (!file)
- {
- printf("Error opening file: mod/heroes\n");
- return;
- }
- //Buffer
- char buffer[256];
- //Start parsing
- while (fscanf(file, "%s", buffer) != EOF)
- {
- //Found comment - skip line
- if ( buffer[0] == '#' )
- fscanf(file, "%*[^\n]"); else
- //Found hero
- if ( buffer[0] == '~' )
- {
- //Position on array
- int pos = brick.size();
- //Current brick
- Brick b;
- //Load its graphic
- fscanf(file, "%s", buffer);
- b.load(buffer, ((pos & 1) == 1 ? 1 : 0));
- //Hp
- int hp;
- fscanf(file, "%d", &hp);
- vecHp.push_back(hp);
- //Sp
- /*int sp;
- fscanf(file, "%d", &sp);
- vecSp.push_back(sp);*/
- //Speed and damage
- fscanf(file, "%f", &b.speed);
- //fscanf(file, "%hhu", &b.damage);
- fscanf(file, "%hhu", &b.damage);
- //Position, even numbers to the left
- if ((pos & 1) == 0)
- b.loc.x = -5.0f;//translateSet(-5.0f, -(pos/2) *1.5f, 0.0f);
- //Odd number to the right
- else
- b.loc.x = 5.0f;//b.translateSet( 5.0f, -(pos/2) *1.5f, 0.0f);
- b.loc.y = -(pos/2) *1.5f;
-
- //Add brick to array
- brick.push_back(b);
- }
- }
- //Close file
- fclose(file);
- /* Bars */
- health.load("obj/stats_board.ply", 0);
- health.loc.y = 3.0f -(0 *2.5f);
- health.loc.z = -5.0f;
- health.max = 255;
- /*
- special.load("obj/stats_board.ply", 0);
- special.loc.y = 4.0f -(1 *2.5f);
- special.loc.z = -5.0f;
- special.max = 255;
- */
- speed.load("obj/stats_board.ply", 0);
- speed.loc.y = 3.0f -(1 *2.5f);
- speed.loc.z = -5.0f;
- speed.max = 8;
-
- damage.load("obj/stats_board.ply", 0);
- damage.loc.y = 3.0f -(2 *2.5f);
- damage.loc.z = -5.0f;
- damage.max = 255;
- //Start selection from first brick
- prevSel = selection = 0;
- sAnim.max = 5;
- statsToBars();
- //Font
- font.setColorFront(0.9f, 0.327f, 0.689f);
- font.setColorBack (0.26f, 0.121f, 0.256f);
- font.setAlign(1);
- //Data to pass on
- isSurvival = gIsSurvival;
- }
- void CardCharSelect::input(unsigned char key, bool pressed)
- {
- //Do not accept input if animation is running
- if (!anim.isRunning())
- //According to key
- switch (key)
- {
- //Left/right
- case 'a':
- case 'd':
- //Pressed
- if (pressed)
- {
- //Current selection is left
- if ((selection & 1) == 0)
- {
- //There is character on right
- if (brick.size() > 0 && selection < brick.size()-1)
- {
- //Move right and change shown stats
- selection++;
- statsToBars();
- }
- }
- //Current selection is right
- else
- {
- //Move selection leftwards (There is always left)
- selection--;
- statsToBars();
- }
- }
- break;
- //Up
- case 'w':
- if (pressed)
- {
- //Selection is greater/equal to 2 (so it can move upwards)
- if (selection >= 2)
- {
- /* Save previous selection (for animation),
- * move selection upwards and start animation
- */
- prevSel = selection;
- selection -= 2;
- sAnim.startFromStart();
- statsToBars();
- }
- }
- break;
- //Down
- case 's':
- if (pressed)
- {
- /* There are more than 2 bricks (so at least 2 rows)
- * and selection is not on the last one
- */
- if (brick.size() > 2
- && selection < brick.size()-2)
- {
- /* Save previous selection (for animation),
- * move selection downwards and start animation
- */
- prevSel = selection;
- selection += 2;
- sAnim.startFromStart();
- statsToBars();
- }
- }
- break;
- //Space
- case '\040':
- //Start animation
- anim.startFromStart();
- break;
- }
- }
- void CardCharSelect::update()
- {
- //Animation updated
- if (anim.update())
- //Animation ended
- if (anim.isAtEnd())
- {
- char isSurv = isSurvival;
- int sel = selection;
- int sel2 = rand() %brick.size();
- //Delete this menu and give selection to next menu
- delete card;
- card = new CardStageSelect(isSurv, sel, sel2);
- }
- //Update selection animation
- sAnim.update();
- }
- void CardCharSelect::draw()
- {
- //Animation's drawing
- Card::draw();
- //Camera movement
- glTranslatef(0.0f, -1.0f, -10.0f);
- //Draw bars
- health .draw();
- //special.draw();
- speed .draw();
- damage .draw();
- //Texts
- glPushMatrix();
- glTranslatef(health.loc.x -2.0f, health.loc.y, health.loc.z);
- glScalef(1.3f, 1.3f, 1.3f);
- font.draw("hp");
- glPopMatrix();
- /*
- glPushMatrix();
- glTranslatef(special.loc.x -2.0f, special.loc.y, special.loc.z);
- glScalef(1.3f, 1.3f, 1.3f);
- font.draw("sp");
- glPopMatrix();
- */
- glPushMatrix();
- glTranslatef(speed.loc.x -2.0f, speed.loc.y, speed.loc.z);
- glScalef(1.3f, 1.3f, 1.3f);
- font.draw("spd");
- glPopMatrix();
- glPushMatrix();
- glTranslatef(damage.loc.x -2.0f, damage.loc.y, damage.loc.z);
- glScalef(1.3f, 1.3f, 1.3f);
- font.draw("dmg");
- glPopMatrix();
- //More camera movement (so it doesn't affect bars and text)
- if (sAnim.isRunning())
- glTranslatef(0, -(brick[prevSel].loc.y
- +sAnim.interpolate(brick[selection].loc.y -brick[prevSel].loc.y)), 0);
- //glTranslatef(0, -(brick[prevSel].y()
- // +sAnim.interpolate(brick[selection].y() -brick[prevSel].y())), 0);
- else
- glTranslatef(0, -brick[selection].loc.y, 0);
- //glTranslatef(0, -brick[selection].y(), 0);
- glRotatef(15.0f, 1.0f, 0.0f, 0.0f);
- //Draw bricks
- unsigned int i;
- for (i = 0; i < brick.size(); i++)
- {
- //Selected brick, quake effect
- if (selection == i)
- {
- //Seperate X and Y
- float tempX = ((rand() +1) %100) /1000.0f;
- float tempY = ((rand() +1) %100) /1000.0f;
- //Apply offset
- //brick[i].translateAdd(tempX, tempY, 0.0f);
- brick[i].loc.x += tempX;
- brick[i].loc.y += tempY;
- //Draw choice
- brick[i].draw();
- //Cancel offset
- //brick[i].translateAdd(-tempX, -tempY, 0.0f);
- brick[i].loc.x -= tempX;
- brick[i].loc.y -= tempY;
- }
- //Other non selected bricks
- else brick[i].draw();
- }
- }
- //Apply current selected hero's stats to bars
- void CardCharSelect::statsToBars()
- {
- //Health
- health.cur = vecHp[selection];
- //special.cur = vecSp[selection];
- speed.cur = brick[selection].speed *10;
- if (brick[selection].damage < 60)
- damage.cur = brick[selection].damage *255 /60;
- else
- damage.cur = 255;
- }
|