You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include "mover.h"
#include "fighter.h"
#include "drawer.h"
class Pacman
{
private:
int score;
Mover mover;
Fighter fighter;
Drawer drawer;
public:
void SetDir(int dir)
{
mover.SetDir(dir);
}
// 吃豆人行动总控
void Update(Map* map,IMAGE* floor)
{
mover.Move(map);
// 吃,判断坐标所在处是否有豆子/道具
/* 等待完善 */
score++;
// 将被吃的豆子从map和floor中都消除掉
// 吃到金豆子power增加至100因此不要在power持续期间吃道具避免浪费
fighter.SetPower(100);
// power随时间流逝直到降为0
int power = fighter.GetPower();
if (power > 0)
power--;
}
// 吃豆人打败一个怪物获得奖励
void FightGift()
{
// 加分(或者你想到的其他有趣的设定,短时间提高移速,穿墙等)
score++;
}
// 吃豆人死亡
bool IsDead() const { return fighter.GetPower() < 0; }
int GetX() const { return mover.GetX(); }
int GetY() const { return mover.GetY(); }
Fighter& GetFighter() { return fighter; }
void Clear()
{
drawer.Clear(mover.GetOldX(), mover.GetOldY());
}
void Draw(IMAGE* floor)
{
/* 将floor加工为foot image */
IMAGE foot;
SetWorkingImage(floor);
int x = mover.GetX();
int y = mover.GetY();
int w = mover.GetW();
int h = mover.GetH();
getimage(&foot, x, y, w, h);
SetWorkingImage(NULL);
drawer.Draw(x,y, &foot);
}
void Init(int x, int y, int s,int w,int h,int r, int c, const IMAGE* img, const IMAGE* img_h)
{
score = 0;
mover.Init(x, y, s, w, h);
fighter.Init();
drawer.Init(r, c, img, img_h);
}
};