Skip to content

Commit

Permalink
Merge pull request #112 from ateb14/wyy/final
Browse files Browse the repository at this point in the history
道具生成逻辑构造完毕,应该是最终版本了!!
  • Loading branch information
ateb14 authored Jun 30, 2022
2 parents 9996a32 + 242b929 commit 9fbf0ec
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 19 deletions.
9 changes: 5 additions & 4 deletions code/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const int DeadTime = 400; // 4s复活
const double BULLET_SPEED = 7.0;
const double BULLET_MASS = 0.5;
const int BULLET_RADIUS = 15;
const int BULLET_DAMAGE = 20;
const int BULLET_DAMAGE = 10;
const int BULLET_TIME_TO_DESPAWN = 3*100;

//BUFF
Expand Down Expand Up @@ -134,7 +134,8 @@ const char cheers1Src[] = "qrc:///music/cheers1.mp3";
const char cheers2Src[] = "qrc:///music/cheers2.mp3";
const char shootSrc[] = "qrc:///music/shoot.mp3";
const char whistleSrc[] = "qrc:///music/whistle.mp3";
const char victorySrc[] = "qrc:///music/victory.mp3";
const char victorySrc[] = "qrc:///music/victory.mp3";\
const char pickSrc[] = "qrc:///music/pick.wav";
#ifdef MP3
const char dieSrc[] = "qrc:///music/die.mp3";
const char skillSrc[PLAYER_TYPES][64] ={
Expand All @@ -153,7 +154,7 @@ extern const QPixmap *player1Pixmap, *player2Pixmap, *frozenManPMap, *hotManPMap
*ballPixmap, *postPixmap, *bulletPixmap[PLAYER_TYPES], *SSBulletPixmap[PLAYER_TYPES],
*itemPMap[ITEM_NUM];

extern QMediaPlayer *shootPlayer, *skillPlayer[PLAYER_TYPES], *victoryPlayer, *diePlayer, *whistlePlayer;
extern QMediaPlaylist *shootPlaylist, *skillPlaylist[PLAYER_TYPES], *victoryPlaylist, *diePlaylist, *whistlePlaylist;
extern QMediaPlayer *shootPlayer, *skillPlayer[PLAYER_TYPES], *victoryPlayer, *diePlayer, *whistlePlayer, *pickPlayer;
extern QMediaPlaylist *shootPlaylist, *skillPlaylist[PLAYER_TYPES], *victoryPlaylist, *diePlaylist, *whistlePlaylist, *pickPlaylist;

#endif // CONFIG_H
30 changes: 18 additions & 12 deletions code/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

const QPixmap *player1Pixmap, *player2Pixmap,*ballPixmap, *postPixmap, *bulletPixmap[PLAYER_TYPES], *SSBulletPixmap[PLAYER_TYPES],
*frozenManPMap, *hotManPMap, *magnetManPMap, *itemPMap[ITEM_NUM];
QMediaPlayer *shootPlayer, *skillPlayer[PLAYER_TYPES], *victoryPlayer, *diePlayer, *whistlePlayer;
QMediaPlaylist *shootPlaylist, *skillPlaylist[PLAYER_TYPES],*victoryPlaylist, *diePlaylist, *whistlePlaylist;
QMediaPlayer *shootPlayer, *skillPlayer[PLAYER_TYPES], *victoryPlayer, *diePlayer, *whistlePlayer, *pickPlayer;
QMediaPlaylist *shootPlaylist, *skillPlaylist[PLAYER_TYPES],*victoryPlaylist, *diePlaylist, *whistlePlaylist, *pickPlaylist;
double PLAYER_SPEED,PLAYER_ACCELERATION;

int Game::winFreeTime = -1;
Expand Down Expand Up @@ -56,6 +56,12 @@ Game::Game(){
diePlaylist->setPlaybackMode(QMediaPlaylist::CurrentItemOnce);
diePlayer->setPlaylist(diePlaylist);

pickPlaylist = new QMediaPlaylist;
pickPlayer = new QMediaPlayer;
pickPlaylist->addMedia(QUrl(pickSrc));
pickPlaylist->setPlaybackMode(QMediaPlaylist::CurrentItemOnce);
pickPlayer->setPlaylist(pickPlaylist);

for(int i=0;i<PLAYER_TYPES;++i){
skillPlaylist[i] = new QMediaPlaylist;
skillPlayer[i] = new QMediaPlayer;
Expand Down Expand Up @@ -622,15 +628,15 @@ void Game::newObjectCheck(){
}

void Game::createItems(){
if(globalTime > 0 && globalTime % (15*100) == 0){
int type = globalTime % 5;
if(globalTime > 0 && globalTime % (11*100) == 0){
int type = (globalTime/11/100) % 5;
GameItem *item;
switch(type){
case 0:item = new GameItem(WIDTH/2, HEIGHT/2, itemPMap[type],this,SPEED,6*100,3*100);break; //speed
case 1:item = new GameItem(WIDTH/2, HEIGHT/2, itemPMap[type],this,SPEED,6*100,0);break; //health
case 2:item = new GameItem(WIDTH/2, HEIGHT/2, itemPMap[type],this,RAGE,6*100,3*100);break; //rage
case 3:item = new GameItem(WIDTH/2, HEIGHT/2, itemPMap[type],this,MAGNET,6*100,3*100);break; //magnet
case 4:item = new GameItem(WIDTH/2, HEIGHT/2, itemPMap[type],this,SPEED,6*100,0);break; //power
case 0:item = new GameItem(WIDTH/2, HEIGHT/2, itemPMap[type],this,SPEED,5*100,3*100,0,0);break; //speed
case 1:item = new GameItem(WIDTH/2, HEIGHT/2, itemPMap[type],this,SPEED,5*100,0,40,0);break; //health
case 2:item = new GameItem(WIDTH/2, HEIGHT/2, itemPMap[type],this,RAGE,5*100,3*100,0,0);break; //rage
case 3:item = new GameItem(WIDTH/2, HEIGHT/2, itemPMap[type],this,MAGNET,5*100,3*100,0,0);break; //magnet
case 4:item = new GameItem(WIDTH/2, HEIGHT/2, itemPMap[type],this,SPEED,5*100,0,0,40);break; //power
}
gameObjects.push_back(item);
}
Expand Down Expand Up @@ -786,6 +792,9 @@ void Game::updateGame()
// call Function for all object->fetchGeneratedObject() returns vector<GameObject *>
newObjectCheck();

/* Generate Items */
createItems();

/* Update Objects in the scene */
for(GameObject *ptr: this->gameObjects)
{
Expand All @@ -797,9 +806,6 @@ void Game::updateGame()
/* Health Check */
healthCheck();

/* Generate Items */
createItems();

/* ball position */
goalCheck();

Expand Down
Binary file added code/icon.ico
Binary file not shown.
10 changes: 7 additions & 3 deletions code/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ GameItem::GameItem(int x, int y, const QPixmap *pixmap_, QGraphicsScene *scene_,
int gainHP_, int gainSkillPoint_):
GameObject(x, y, ITEM_RADIUS, INFINITE_MASS, pixmap_, scene_)
{
type = ObjectType::Item;
buffType = buffType_;
remainTime = remainTime_;
buffTime = buffTime_;
Expand All @@ -19,10 +20,12 @@ void GameItem::eatenBy(GameObject *obj)
if(obj->type!=ObjectType::Player) return;
GamePlayer *player = (GamePlayer *)obj;
player->addBuff(this->buffType, buffTime);
player->health = max(player->health+this->gainHP,
player->health = min(player->health+this->gainHP,
player->maxHealth);
player->skillPoint = max(player->skillPoint+this->gainSkillPoint,
player->skillPoint = min(player->skillPoint+this->gainSkillPoint,
PLAYER_SKILL_POINT_LIMIT);
isDead = true;
pickPlayer->play();
}

void GameItem::collides(GameObject *obj)
Expand All @@ -40,6 +43,7 @@ void GameItem::updateInGame()
{
// 道具不会动
this->setVelocity(0, 0);

--remainTime;
if(remainTime <= 0) isDead = true;
GameObject::updateInGame();
}
Binary file added code/music/pick.wav
Binary file not shown.
1 change: 1 addition & 0 deletions code/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void GameObject::setVelocity(double vx_, double vy_){vx = vx_, vy = vy_;} // 设

bool GameObject::collideJudge(GameObject *obj) // 检测是否与另一物体碰撞
{
if(type == Item) {std::cout << "judge item" << std::endl;}
double dx = obj->centerX()-this->centerX();
double dy = obj->centerY()-this->centerY();
double dz = sqrt(dx*dx+dy*dy);
Expand Down
1 change: 1 addition & 0 deletions code/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@
<file>art/bottle.png</file>
<file>art/choosevideo.png</file>
<file>art/star.png</file>
<file>music/pick.wav</file>
</qresource>
</RCC>

0 comments on commit 9fbf0ec

Please sign in to comment.