Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1.compile-games.yml
This is the automatic compilation pipeline of GitHub Actions. When someone requests a PR to the main branch, it automatically finds the modified games in games/. Compile these games across platforms only (Win x86/Linux x86/Linux ARM), then backfill the executable files to compiled-games/< game name >/ in the repository, and finally attach the "compiled" tag to the PR.

2.validate-games.yml
Check and verify the config.txt file of the game in the PR submission. If it does not meet the requirements, the merge is not allowed.
1 change: 1 addition & 0 deletions advanced-game-design-team/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some guidance and cases on developing games using the splashkit framework are provided. We hope you can quickly get started with the framework. There are many excellent teaching cases and guidance
Binary file added games/BelowTheSurface/SDL2.dll
Binary file not shown.
Binary file added games/BelowTheSurface/SDL2_image.dll
Binary file not shown.
Binary file added games/BelowTheSurface/SDL2_mixer.dll
Binary file not shown.
Binary file added games/BelowTheSurface/SDL2_net.dll
Binary file not shown.
Binary file added games/BelowTheSurface/SDL2_ttf.dll
Binary file not shown.
1 change: 1 addition & 0 deletions games/BelowTheSurface/SplashKit.dll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libSplashKit.dylib
Binary file added games/BelowTheSurface/rav1e.dll
Binary file not shown.
Binary file added games/BelowTheSurface/zlib1.dll
Binary file not shown.
39 changes: 39 additions & 0 deletions games/TowerDefense/Manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef _MANAGER_H_
#define _MANAGER_H_

template <typename T>
class Manager
{
public:
static T* instance()//���ȡ��Կ�׵ķ�������instanceԱ����������
{
if (!manager)
manager = new T();//���֮ǰ��û��Կ�ף�����Կ��

return manager;//�մ�����Կ��/�Ѿ���Կ�ף�ֱ�ӷ���Կ��

}

private:
static T* manager;//Կ��ʵ��

protected:
Manager() = default;//����Կ�׷���
~Manager() = default;
Manager(const Manager&) = delete;
Manager& operator=(const Manager&) = delete;

};
template <typename T>//ռλģ�壬����ʱ�����������������T����ģ����д��Tȫ������������Ǹ�
T* Manager<T>::manager = nullptr;
#endif // !_MANAGER_H_

/*
��������ɼ̳е���ģ�壺��һ��������ֻ��һ�ݲ���ȫ�ֹ�����ʵ����Ҳ����˵�����ض��ģ�����������ʹ�����ĵط���ֱ�Ӵ�����ط�������ľ����ˣ�����˵�����ù�˾���˶����Ǹ����������ĸ��ط��ù�˾�˱���Ӧ�ö���
ͬһ�ݣ����������һ��ʵ���������������˱�Ҳ��������ʵ���������ͻ�����������Ե����Ժ���Ҫ��˾�˱�ʱ����ֱ�����ɼ̳е���ģ���������ֱ���þ����ˣ�����Ҫ�㴫������ȵȣ�ֻ��Ҫֱ���ã������ݶ��Ҳ��׳���
�ŵ㻹�кܶ࣬���ﲻ��׸��*/

/*
����ʵ�ֿɼ̳е���ģ�壺instance������Ϊmanager����ڲ�Ա���������Ը㵽�ڲ�manager�ķ�������Ϣ���������Ҫ���ɼ̳е���ģ�壬���Ǿ���������ҪԿ�׵��˶������������Ϳ��԰����õ�ͬһ������Կ�׷ַ��������ˣ�
�������˲���ֱ��ͨ��������Կ�׶�ֻ���������Ա���ã����Կ�׾���������Ҫʵ�ֵĹ��ܣ���������ÿ���˴ӿɼ̳е���ģ���õ��Ķ���ͬ������Ķ���
*/
Binary file added games/TowerDefense/SDL2.dll
Binary file not shown.
Binary file added games/TowerDefense/SDL2_image.dll
Binary file not shown.
Binary file added games/TowerDefense/SDL2_mixer.dll
Binary file not shown.
Binary file added games/TowerDefense/SDL2_ttf.dll
Binary file not shown.
Binary file added games/TowerDefense/TowerDefense.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions games/TowerDefense/animation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#ifndef _ANIMATION_H_
#define _ANIMATION_H_

#include "timer.h"

#include <SDL.h>
#include <vector>
#include <functional>

class Animation
{
public:
typedef std::function<void()> PlayCallback;

public:
Animation()
{
timer.set_one_shot(false);
timer.set_on_timeout(
[&]()
{
idx_frame++;
if (idx_frame >= rect_src_list.size())
{
idx_frame = is_loop ? 0 : rect_src_list.size() - 1;
if (!is_loop && on_finished)
on_finished();
}
}
);
}

~Animation() = default;

void reset()
{
timer.restart();

idx_frame = 0;
}

void set_frame_data(SDL_Texture* texture, int num_h, int num_v, const std::vector<int>& idx_list)
{
int width_tex, height_tex;

this->texture = texture;
SDL_QueryTexture(texture, nullptr, nullptr, &width_tex, &height_tex);
width_frame = width_tex / num_h, height_frame = height_tex / num_v;

rect_src_list.resize(idx_list.size());
for (size_t i = 0; i < idx_list.size(); i++)
{
int idx = idx_list[i];
SDL_Rect& rect_src = rect_src_list[i];

rect_src.x = (idx % num_h) * width_frame;
rect_src.y = (idx / num_h) * height_frame;
rect_src.w = width_frame, rect_src.h = height_frame;
}
}

void set_loop(bool is_loop)
{
this->is_loop = is_loop;
}

void set_interval(double interval)
{
timer.set_wait_time(interval);
}

void set_on_finished(PlayCallback on_finished)
{
this->on_finished = on_finished;
}

void on_update(double delta)
{
timer.on_update(delta);
}

void on_render(SDL_Renderer* renderer, const SDL_Point& pos_dst, double angle = 0) const
{
static SDL_Rect rect_dst;

rect_dst.x = pos_dst.x, rect_dst.y = pos_dst.y;
rect_dst.w = width_frame, rect_dst.h = height_frame;

SDL_RenderCopyEx(renderer, texture, &rect_src_list[idx_frame], &rect_dst, angle, nullptr, SDL_RendererFlip::SDL_FLIP_NONE);
}

private:
Timer timer;
bool is_loop = true;
size_t idx_frame = 0;
PlayCallback on_finished;
SDL_Texture* texture = nullptr;
std::vector<SDL_Rect> rect_src_list;
int width_frame = 0, height_frame = 0;

};


#endif // !_ANIMATION_H_

50 changes: 50 additions & 0 deletions games/TowerDefense/archer_tower.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef _ARCHER_TOWER_H_
#define _ARCHER_TOWER_H_

#include "tower.h"
#include "resources_manager.h"


class ArcherTower : public Tower
{
public:
ArcherTower()
{
static SDL_Texture* tex_archer = ResourcesManager::instance()
->get_texture_pool().find(ResID::Tex_Archer)->second;

static const std::vector<int> idx_list_idle_up = { 3, 4 };
static const std::vector<int> idx_list_idle_down = { 0, 1 };
static const std::vector<int> idx_list_idle_left = { 6, 7 };
static const std::vector<int> idx_list_idle_right = { 9, 10 };
static const std::vector<int> idx_list_fire_up = { 15, 16, 17 };
static const std::vector<int> idx_list_fire_down = { 12, 13, 14 };
static const std::vector<int> idx_list_fire_left = { 18, 19, 20 };
static const std::vector<int> idx_list_fire_right = { 21, 22, 23 };

anim_idle_up.set_frame_data(tex_archer, 3, 8, idx_list_idle_up);
anim_idle_down.set_frame_data(tex_archer, 3, 8, idx_list_idle_down);
anim_idle_left.set_frame_data(tex_archer, 3, 8, idx_list_idle_left);
anim_idle_right.set_frame_data(tex_archer, 3, 8, idx_list_idle_right);
anim_fire_up.set_frame_data(tex_archer, 3, 8, idx_list_fire_up);
anim_fire_down.set_frame_data(tex_archer, 3, 8, idx_list_fire_down);
anim_fire_left.set_frame_data(tex_archer, 3, 8, idx_list_fire_left);
anim_fire_right.set_frame_data(tex_archer, 3, 8, idx_list_fire_right);

size.x = 48, size.y = 48;

tower_type = TowerType::Archer;

fire_speed = 6;
bullet_type = BulletType::Arrow;
}

~ArcherTower() = default;



};


#endif // !_ARCHER_TOWER_H_

54 changes: 54 additions & 0 deletions games/TowerDefense/arrow_bullet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef _ARROW_BULLET_H_
#define _ARROW_BULLET_H_

#include"bullet.h"
#include "resources_manager.h"


class ArrowBullet : public Bullet
{
public:
ArrowBullet()
{
static SDL_Texture* tex_arrow = ResourcesManager::instance()
->get_texture_pool().find(ResID::Tex_BulletArrow)->second;
static const std::vector<int> idx_list = { 0,1 };

animation.set_loop(true);
animation.set_interval(0.1);
animation.set_frame_data(tex_arrow, 2, 1, idx_list);

can_rotated = true;
size.x = 48, size.y = 48;
}

~ArrowBullet() = default;

void on_collide(Enemy* enemy) override
{
static const ResourcesManager::SoundPool& sound_pool
= ResourcesManager::instance()->get_sound_pool();

switch(rand()%3)
{
case 0:
Mix_PlayChannel(-1,sound_pool.find(ResID::Sound_ArrowHit_1)->second,0);
break;
case 1:
Mix_PlayChannel(-1, sound_pool.find(ResID::Sound_ArrowHit_2)->second, 0);
break;
case 2:
Mix_PlayChannel(-1, sound_pool.find(ResID::Sound_ArrowHit_3)->second, 0);
break;
default:
break;
}
Bullet::on_collide(enemy);
}

private:

};

#endif // !_ARROW_BULLET_H_

60 changes: 60 additions & 0 deletions games/TowerDefense/axe_bullet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef _AXE_BULLET_H_
#define _AXE_BULLET_H_

#include "bullet.h"
#include "resources_manager.h"



class AxeBullet : public Bullet
{
public:
AxeBullet()
{
static SDL_Texture* tex_axe = ResourcesManager::instance()
->get_texture_pool().find(ResID::Tex_BulletAxe)->second;
static const std::vector<int> idx_list = { 0,1,2,3,4,5,6,7,8};

animation.set_loop(true);
animation.set_interval(0.1);
animation.set_frame_data(tex_axe, 4, 2, idx_list);

can_rotated = false;
size.x = 48, size.y = 48;
}

~AxeBullet() = default;
void on_collide(Enemy* enemy) override
{
static const ResourcesManager::SoundPool& sound_pool
= ResourcesManager::instance()->get_sound_pool();

switch (rand() % 3)
{
case 0:
Mix_PlayChannel(-1, sound_pool.find(ResID::Sound_AxeHit_1)->second, 0);
break;
case 1:
Mix_PlayChannel(-1, sound_pool.find(ResID::Sound_AxeHit_2)->second, 0);
break;
case 2:
Mix_PlayChannel(-1, sound_pool.find(ResID::Sound_AxeHit_3)->second, 0);
break;
default:
break;
}

enemy->slow_down();

Bullet::on_collide(enemy);
}
private:

};





#endif // !_AXE_BULLET_H_

48 changes: 48 additions & 0 deletions games/TowerDefense/axeman_tower.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef _AXEMAN_TOWER_H_
#define _AXEMAN_TOWER_H_

#include "tower.h"
#include "resources_manager.h"

class AxemanTower : public Tower
{
public:
AxemanTower()
{
static SDL_Texture* tex_axeman = ResourcesManager::instance()
->get_texture_pool().find(ResID::Tex_Axeman)->second;

static const std::vector<int> idx_list_idle_up = { 3, 4 };
static const std::vector<int> idx_list_idle_down = { 0, 1 };
static const std::vector<int> idx_list_idle_left = { 9, 10 };
static const std::vector<int> idx_list_idle_right = { 6, 7 };
static const std::vector<int> idx_list_fire_up = { 15, 16, 17 };
static const std::vector<int> idx_list_fire_down = { 12, 13, 14 };
static const std::vector<int> idx_list_fire_left = { 21, 22, 23 };
static const std::vector<int> idx_list_fire_right = { 18, 19, 20 };

anim_idle_up.set_frame_data(tex_axeman, 3, 8, idx_list_idle_up);
anim_idle_down.set_frame_data(tex_axeman, 3, 8, idx_list_idle_down);
anim_idle_left.set_frame_data(tex_axeman, 3, 8, idx_list_idle_left);
anim_idle_right.set_frame_data(tex_axeman, 3, 8, idx_list_idle_right);
anim_fire_up.set_frame_data(tex_axeman, 3, 8, idx_list_fire_up);
anim_fire_down.set_frame_data(tex_axeman, 3, 8, idx_list_fire_down);
anim_fire_left.set_frame_data(tex_axeman, 3, 8, idx_list_fire_left);
anim_fire_right.set_frame_data(tex_axeman, 3, 8, idx_list_fire_right);

size.x = 48, size.y = 48;

tower_type = TowerType::Axeman;

fire_speed = 5;
bullet_type = BulletType::Axe;
}

~AxemanTower() = default;

private:

};

#endif // !_AXEMAN_TOWER_H_

Loading