Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Retro2D.h"
- namespace Retro2D
- {
- class Game1 : public Game
- {
- #pragma region Vars
- int _screenW = 640;
- int _screenH = 360;
- bool _pause = false;
- Json _myJson;
- NODE _area;
- ALLEGRO_FONT* _mainFont = nullptr;
- ALLEGRO_SAMPLE* _mySample = nullptr;
- #pragma endregion
- int init() override
- {
- #pragma region Window Setup
- setup
- (
- "DEMO RETRO2D", // Window Title
- Api::OPENGL, // OpenGL API
- _screenW, _screenH, // Screen Size
- 2, 0, // ScaleFull , ScaleWin
- false, // isFullscreen
- false, // isVsync
- false, // isSmooth
- 60, // limitFPS
- true // isLimitFPS
- );
- #pragma endregion
- _mainFont = al_load_font("data/FFFGE___.TTF",8,0);
- _mySample = al_load_sample("data/bubble1.wav");
- SCRIPT demo1Update = CODE{
- ON_FRAME(20)
- {
- PLAY_AT(0);
- }
- IS_PLAY()
- {
- _Y = Easing::value(Easing::backEaseOut, _CURFRAME, -10, 10, 20);
- _X = _Y;
- }
- };
- _node["demo1"] = {
- MAKE_NODE("demo1")
- ->appendTo(_root)
- ->setActive(true)
- ->setSize(_screenW, _screenH)
- ->onInit(CODE{
- })
- ->onUpdate(demo1Update)
- ->onRender(CODE{
- Draw::grid(0, 0, _screenW, _screenH, 16, 16, al_map_rgb(0, 80, 120));
- //Draw::circleFill(Circle{ Input::Mouse::_x, Input::Mouse::_y, 16 }, al_map_rgb(150, 140, 50));
- Draw::circle(Circle{ 320, 180, 16 }, al_map_rgb(250, 140, 50),2);
- Draw::rect(_ABSRECT, al_map_rgb(250,120,0),0);
- _THIS->renderChild();
- })
- ->init()
- };
- _node["demo2"] = {
- MAKE_NODE("demo2")
- ->appendTo(_root)
- ->setActive(true)
- ->setSize(_screenW, _screenH)
- ->attach<Addon::Viewport>()
- ->VIEWPORT->setViewport(_window, 0, Rect{ 0,0,200,200 })
- ->onInit(CODE{
- })
- ->onUpdate(CODE{
- _VIEWPORT->updateViewport(0, Rect{ 0,0,_mouseX,_mouseY });
- float v = 2;
- //if (KEY_DOWN(ALLEGRO_KEY_LEFT)) _X += v;
- //if (KEY_DOWN(ALLEGRO_KEY_RIGHT)) _X += -v;
- //if (KEY_DOWN(ALLEGRO_KEY_UP)) _Y += v;
- //if (KEY_DOWN(ALLEGRO_KEY_DOWN)) _Y += -v;
- })
- ->onRender(CODE{
- _VIEWPORT->beginRenderView(_window, 0);
- al_clear_to_color(al_map_rgb(10,20,10));
- Draw::grid(_ABSX, _ABSY, _screenW, _screenH, 16, 16, al_map_rgb(0, 80, 20));
- Draw::circleFill(Circle{ 320, 180, 32 }, al_map_rgb(250, 140, 50));
- Draw::circle(Circle{ 320, 180, 48 }, al_map_rgb(50, 140, 250),2);
- Draw::rect(_ABSRECT, al_map_rgb(250,120,0),0);
- _THIS->renderChild();
- _VIEWPORT->endRenderView(_window, 0);
- })
- ->init()
- };
- _node["demo3"] = {
- MAKE_NODE("demo3")
- ->appendTo(_root)
- ->setActive(true)
- ->setSize(_screenW,_screenH)
- };
- _node["ball"] = {
- MAKE_NODE("ball")
- ->setActive(true)
- ->appendTo(_node["demo1"])
- ->attach<Addon::Physic>()
- ->onInit(CODE{
- _X = _screenW / 2;
- _Y = _screenH / 2;
- IS(_PHYSIC)
- {
- _PHYSIC->setVelocity(1, 1);
- }
- })
- ->onUpdate(CODE{
- _X += _PHYSIC->_vx;
- _Y += _PHYSIC->_vy;
- if (_X < 0) _PHYSIC->_vx = 1;
- if (_X > _screenW) _PHYSIC->_vx = -1;
- if (_Y < 0) _PHYSIC->_vy = 1;
- if (_Y > _screenH) _PHYSIC->_vy = -1;
- })
- ->onRender(CODE{
- Draw::circleFill(Circle{ _ABSX, _ABSY, 16 }, al_map_rgb(250, 40, 50));
- })
- ->init()
- };
- _node["ball2"] = {
- MAKE_NODE("ball2")
- ->appendTo(_node["demo1"])
- ->setActive(true)
- ->attach<Addon::Draggable>()
- ->DRAGGABLE->setLimitRect(Rect{0,0,(VAR)_screenW,(VAR)_screenH})
- ->setPosition(200,80)
- ->setSize(48,48)
- //->setPivot(CENTER)
- ->onUpdate(CODE{
- _DRAGGABLE->update();
- })
- ->onRender(CODE{
- //Draw::circleFill(Circle{ _ABSX+24, _ABSY+24, 24 }, al_map_rgb(50, 40, 250));
- Draw::rectFill(_ABSRECT, al_map_rgba(50,150,80,150));
- Draw::rect(_ABSRECT, al_map_rgb(250,250,180),0);
- //_DRAGGABLE->render();
- })
- };
- _area = {
- MAKE_NODE("area")
- ->setActive(true)
- ->appendTo(_node["demo1"])
- ->setPosition(320,180)
- ->setSize(24,24)
- ->setPivot(CENTER)
- ->setNumber("speed",12)
- ->onUpdate(CODE{
- if (Input::Button::onPress("aLeft",KEY_DOWN(ALLEGRO_KEY_LEFT),10)) _X += -_NUMBER("speed");
- if (Input::Button::onPress("aRight", KEY_DOWN(ALLEGRO_KEY_RIGHT),10)) _X += _NUMBER("speed");
- if (Input::Button::onPress("aUp", KEY_DOWN(ALLEGRO_KEY_UP),10)) _Y += -_NUMBER("speed");
- if (Input::Button::onPress("aDown", KEY_DOWN(ALLEGRO_KEY_DOWN),10)) _Y += _NUMBER("speed");
- })
- ->onRender(CODE{
- Draw::rectFill(_ABSRECT + Rect{_OX,_OY,0,0}, al_map_rgba(250,150,80,150));
- Draw::rect(_ABSRECT + Rect{ _OX,_OY,0,0 }, al_map_rgb(250,250,180),0);
- _THIS->showPivot(al_map_rgb(255, 0, 0), 2);
- })
- };
- MAKE_CLONE_ALONE(_area, "areaClone")
- ->setActive(true)
- ->appendTo(_node["demo2"]);
- for (int i=0; i<100; ++i)
- {
- MAKE_CLONE_ALONE(_node["ball"], "ball3")
- ->appendTo(_node["demo1"])
- ->onRender(CODE{
- Draw::circleFill(Circle{ _ABSX, _ABSY, 8 }, al_map_rgb(50, 240, 50));
- })
- ->setPosition(Misc::random(0,_screenW), Misc::random(0,_screenH));
- }
- Screen::goTo(_node["demo1"]);
- //Screen::current()->pause();
- Node::showNodeInfo();
- // JSON FILE
- _myJson = File::loadJson("test00.json");
- std::cout << _myJson["array"] << " / ";
- std::cout << _myJson["string"];
- // XML FILE
- pugi::xml_document doc;
- pugi::xml_parse_result result = doc.load_file("test00.xml");
- std::cout << "load result = " << result.description() << "\n";
- pugi::xml_node root_node = doc.child("Root");
- //pugi::xml_node child_node = root_node.first_child();
- for (pugi::xml_node child = root_node.first_child(); child; child = child.next_sibling())
- {
- std::cout << child.name() << std::endl;
- for (pugi::xml_attribute attr = child.first_attribute(); attr; attr = attr.next_attribute())
- {
- std::cout << " " << attr.name() << " = " << attr.value() << std::endl;
- }
- std::cout << "Content = " << child.text().as_string() << "\n";
- std::cout << std::endl;
- }
- return 0;
- }
- int done() override
- {
- al_destroy_font(_mainFont);
- al_destroy_sample(_mySample);
- return 0;
- }
- void update() override
- {
- if (KEY_DOWN(ALLEGRO_KEY_ESCAPE)) _quit = true;
- if (Input::Button::onePress("space", KEY_DOWN(ALLEGRO_KEY_SPACE))) _window->toggleFullScreen(-1);
- if (Input::Button::onePress("tab", KEY_DOWN(ALLEGRO_KEY_TAB))) _window->switchMonitor(-1);
- if (Input::Button::onePress("f1", KEY_DOWN(ALLEGRO_KEY_F1))) Screen::goTo(_node["demo1"]);
- if (Input::Button::onePress("f2", KEY_DOWN(ALLEGRO_KEY_F2))) Screen::goTo(_node["demo2"]);
- if (Input::Button::onePress("f3", KEY_DOWN(ALLEGRO_KEY_F3))) Screen::goTo(_node["demo3"]);
- if (Input::Button::onePress("enter", KEY_DOWN(ALLEGRO_KEY_ENTER)))
- al_play_sample(_mySample, 0.4f, 0.0f, 1.0f, ALLEGRO_PLAYMODE_ONCE, NULL);
- if (Input::Button::onePress("pause", KEY_DOWN(ALLEGRO_KEY_P)))
- {
- (_pause = !_pause) ? Screen::current()->resume(): Screen::current()->pause();
- }
- Screen::current()->update()->updateChild();
- }
- void render() override
- {
- al_clear_to_color(al_map_rgb(0, 20, 50));
- Screen::current()->render();
- Draw::List list;
- Draw::lineBegin(list);
- Draw::sight(list, _mouseX, _mouseY, _screenW, _screenH, al_map_rgb(150, 200, 250));
- Draw::lineEnd(list);
- al_draw_text(_mainFont, al_map_rgb(250, 0, 160), _screenW / 2, _screenH / 2, -1, "- P A U S E -");
- }
- };
- }
- int main()
- {
- Retro2D::Game1 game;
- game.run();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement