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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added Fifth/resources/sheet#2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
0 Fifth/CBody.h → Third/CBody.h
100644 → 100755
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions Fifth/CGame.h → Third/CGame.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class CGame {
int _frames;
int _updates;

double _deltaTime = 0;
double _timeStart;

// Misc variables
std::stringstream _title;
std::string _intro;
Expand Down
117 changes: 117 additions & 0 deletions Third/CGame_onEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//
// CGame_onEvent.cpp
// Fifth
//
// Created by Didrik Munther on 22/09/15.
// Copyright (c) 2015 Didrik Munther. All rights reserved.
//

#include "CGame.h"
#include "CBackground.h"
#include "CAssetManager.h"

#include "NFile.h"
#include "NMouse.h"

#include "CEntity.h"


void CGame::_handleKeyStates() {

if(!isFocused)
return;

const Uint8* keystate = SDL_GetKeyboardState(NULL);

if(instance.controller)
instance.controller->onKeyStates(&instance, keystate);
if(ignoreEvents) return;
if(instance.player)
instance.player->onKeyStates(&instance, keystate);
}

void CGame::_onEvent(SDL_Event* event) {

//if(event->key.repeat != 0) return;

switch(event->type) {
case SDL_QUIT:
_isRunning = false;
break;

case SDL_WINDOWEVENT:
switch(event->window.event) {
case SDL_WINDOWEVENT_FOCUS_GAINED:
isFocused = true;
break;

case SDL_WINDOWEVENT_FOCUS_LOST:
isFocused = false;
break;
}
break;

case SDL_TEXTINPUT:
if(instance.controller)
instance.controller->onTextInput(&instance, (std::string)event->text.text);
if(ignoreEvents) break;
if(instance.player)
instance.player->onTextInput(&instance, (std::string)event->text.text);
break;

case SDL_KEYDOWN:
if(instance.controller)
instance.controller->onEvent(&instance, event->key.keysym.sym, true);
if(ignoreEvents) break;
if(instance.player)
instance.player->onEvent(&instance, event->key.keysym.sym, true);

switch(event->key.keysym.sym) {

case SDLK_ESCAPE:
_isRunning = false;
break;

// case SDLK_4:
// {
// if(instance.window.newWindow(_intro, 640, 480)) {
// NFile::log(LogType::ERROR, "Window.onInit failed: ", SDL_GetError());
// }
// instance.camera->onInit(&instance.window);
// instance.loadAssets("resources/map/testMap1.assets");
// restart();
// }
// break;

default:
break;

}
break;

case SDL_KEYUP:
if(instance.controller)
instance.controller->onEvent(&instance, event->key.keysym.sym, false);
if(ignoreEvents) break;
if(instance.player)
instance.player->onEvent(&instance, event->key.keysym.sym, false);
break;

default:
break;

case SDL_MOUSEBUTTONDOWN:
{
int x = NMouse::relativeMouseX(instance.camera);
int y = NMouse::relativeMouseY(instance.camera);
auto entities = instance.entityManager.getEntitiesAtCoordinate(x, y);

for(auto& i: entities) {
i->onClick(x, y, &instance);
}

}
break;
}

}
File renamed without changes.
File renamed without changes.
89 changes: 89 additions & 0 deletions Third/CInstance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// CInstance.cpp
// Fifth
//
// Created by Didrik Munther on 06/05/15.
// Copyright (c) 2015 Didrik Munther. All rights reserved.
//

#include "CInstance.h"
#include "NFile.h"
#include "CAssetManager.h"


CInstance::CInstance(CGame* game)
: game(game)
, L(luaL_newstate())
, camera(new CCamera())
, gravity(3.0f)
, isPaused(false)
, doLoadLevel(false)
, levelToLoad("")
, player(nullptr), controller(nullptr)
, loadedMap("")
{

}

CInstance::~CInstance() {
delete camera;
}

void CInstance::onLoop() {
if(doLoadLevel) {
_loadLevel(levelToLoad);
levelToLoad = "";
}
}

void CInstance::loadAssets(std::string path) {
//CAssetManager::onCleanup(CLEAN_FLAGS::NOT_LUA_SCRIPTS);
NFile::loadAssets(path, this);
}

void CInstance::doLine(std::string line) {
luaL_dostring(L, line.c_str());
}

void CInstance::loadLevel(std::string fileName) {
levelToLoad = fileName;
doLoadLevel = true;
}

void CInstance::_loadLevel(std::string fileName) {
entityManager.onCleanup();
player = nullptr;
controller = nullptr;
camera->setTarget(nullptr);
doLoadLevel = false;
if(NFile::loadLevel(fileName, this) == -1) {
NFile::log(LogType::ALERT, "Reverting loaded map to: \"", loadedMap, "\".");
NFile::loadLevel(loadedMap, this);
} else {
loadedMap = fileName;
}
}

std::string CInstance::onSerialize() {
rapidjson::Document d;
d.Parse("{}");

rapidjson::Value values(rapidjson::kObjectType);
entityManager.onSerialize(&values, &d.GetAllocator(), this);

values.AddMember("player", rapidjson::Value(entityManager.getNameOfEntity(player).c_str(), d.GetAllocator()), d.GetAllocator());
values.AddMember("controller", rapidjson::Value(entityManager.getNameOfEntity(controller).c_str(), d.GetAllocator()), d.GetAllocator());

d.AddMember("this", values, d.GetAllocator());

rapidjson::StringBuffer sb;
rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
d.Accept(writer);

return sb.GetString();
}

void CInstance::closeInstance() {
entityManager.onCleanup();
lua_close(L);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
0 Fifth/CText.h → Third/CText.h
100644 → 100755
File renamed without changes.
66 changes: 66 additions & 0 deletions Third/CTile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// CTile.cpp
// Third
//
// Created by Didrik Munther on 02/04/15.
// Copyright (c) 2015 Didrik Munther. All rights reserved.
//

#include "CTile.h"
#include "CAssetManager.h"
#include "CWindow.h"
#include "CCamera.h"

#include "NSurface.h"


CTile::CTile(std::string tileset, int posX, int posY)
: CEntity(Box{posX * TILE_SIZE, posY * TILE_SIZE, TILE_SIZE, TILE_SIZE}, "")
, tileset(CAssetManager::getTileset(tileset))
, tilesetKey(tileset)
, posX(posX), posY(posY)
, tileIndex(0)
{
addProperty(EntityProperty::STATIC);
}

void CTile::onRender(CWindow* window, CCamera* camera, RenderFlags renderFlags) {
if(!camera->collision(this))
return;

int x = posX * TILE_SIZE - camera->offsetX();
int y = posY * TILE_SIZE - camera->offsetY();

if(tileset)
NSurface::renderSprite(x, y, TILE_SIZE, TILE_SIZE, CAssetManager::getSprite((*tileset)[tileIndex]), window, SDL_RendererFlip::SDL_FLIP_NONE);
else
NSurface::renderRect(x, y, TILE_SIZE, TILE_SIZE, window, 255, 0, 255);
}

void CTile::onSerialize(rapidjson::Value* value, rapidjson::Document::AllocatorType* alloc, CInstance* instance) {
value->PushBack(rapidjson::Value(posX), *alloc);
value->PushBack(rapidjson::Value(posY), *alloc);
}

void CTile::updateIndex(std::map<int, std::map<int, CTile*>>* _tiles) {
tileIndex = 0;
if(tileExist(_tiles, posX, posY-1) && (*_tiles)[posX][posY-1]->tilesetKey == tilesetKey)
tileIndex += 1;
if(tileExist(_tiles, posX+1, posY) && (*_tiles)[posX+1][posY]->tilesetKey == tilesetKey)
tileIndex += 2;
if(tileExist(_tiles, posX, posY+1) && (*_tiles)[posX][posY+1]->tilesetKey == tilesetKey)
tileIndex += 4;
if(tileExist(_tiles, posX-1, posY) && (*_tiles)[posX-1][posY]->tilesetKey == tilesetKey)
tileIndex += 8;
}

void CTile::updateAdjecent(std::map<int, std::map<int, CTile*>>* _tiles) {
if(tileExist(_tiles, posX, posY-1))
(*_tiles)[posX][posY-1]->updateIndex(_tiles);
if(tileExist(_tiles, posX+1, posY))
(*_tiles)[posX+1][posY]->updateIndex(_tiles);
if(tileExist(_tiles, posX, posY+1))
(*_tiles)[posX][posY+1]->updateIndex(_tiles);
if(tileExist(_tiles, posX-1, posY))
(*_tiles)[posX-1][posY]->updateIndex(_tiles);
}
59 changes: 59 additions & 0 deletions Third/CTile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// CTile.h
// Third
//
// Created by Didrik Munther on 02/04/15.
// Copyright (c) 2015 Didrik Munther. All rights reserved.
//

#ifndef __Third__CTile__
#define __Third__CTile__

#include <stdio.h>
#include <string>
#include <map>

#include "Define.h"
#include "CEntity.h"


class CWindow;
class CCamera;

struct Tileset {
std::string spriteKeys[16];

std::string operator[](int i) {
if(i <= 15 && i >= 0)
return spriteKeys[i];
else
return "";
}
};

class CTile : public CEntity {

public:
CTile(std::string tileset, int posX, int posY);

void onRender(CWindow* window, CCamera* camera, RenderFlags renderFlags);
void onSerialize(rapidjson::Value* value, rapidjson::Document::AllocatorType* alloc, CInstance* instance);

void updateIndex(std::map<int, std::map<int, CTile*>>* _tiles);
void updateAdjecent(std::map<int, std::map<int, CTile*>>* _tiles);

int posX, posY;

static inline bool tileExist(std::map<int, std::map<int, CTile*>>* tiles, int posX, int posY) {
return tiles->find(posX) != tiles->end() && (*tiles)[posX].find(posY) != (*tiles)[posX].end();
}

std::string tilesetKey;

private:
Tileset* tileset;
int tileIndex;

};

#endif /* defined(__Third__CTile__) */
File renamed without changes.
File renamed without changes.
0 Fifth/Define.h → Third/Define.h
100644 → 100755
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
0 Fifth/NFile.h → Third/NFile.h
100644 → 100755
File renamed without changes.
File renamed without changes.
0 Fifth/NMouse.h → Third/NMouse.h
100644 → 100755
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
0 Fifth/main.cpp → Third/main.cpp
100644 → 100755
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions Third/resources/config/binds.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"binds": [
{"_0": "self.component.instance.camera.cameraSway = self.component.instance.camera.cameraSway + 10"},
{"_9": "camera = self.component.instance.camera; if(camera.cameraSway <= 10) then camera.cameraSway = 1; else camera.cameraSway = camera.cameraSway - 10 end"},
{"_3": "self.parent.entityManager:toggleRenderFlag(RenderFlags.COLLISION_BORDERS)"},
{"_5": "self.component.instance.game:restart()"},
{"_6": "chars = \"abcdefghijklmnopqrstuvxyz \"; toSay = \"\"; for i = 0, 20 do rand = math.random(string.len(chars)); toSay = toSay .. string.sub(chars, rand, rand) end; self.component.instance.player:say(toSay, \"TESTFONT\", ChatBubbleType.YELL)"},
{"_7": "self.component.instance.camera:addCameraShake(100)"},

{"_m": "self.parent.entityManager:toggleRenderFlag(RenderFlags.COLLISION_AREA)"},
{"_n": "self.parent.entityManager:toggleRenderFlag(RenderFlags.COLLISION_GRID)"},
{"_b": "self.parent.entityManager:toggleRenderFlag(RenderFlags.ENTITY_GRID)"},
{"_x": "self.parent.entityManager:toggleRenderFlag(RenderFlags.RENDER_COMBAT_TEXT)"},
{"_RIGHTBRACKET": "self.component.instance.gravity = 0.3"},
{"_LEFTBRACKET": "self.component.instance.gravity = 0"},

{"_j": "mX, mY = self.component:getRelativeMouse(); temp = self.parent.entityManager:createSpriteEntity(Box(mX, mY, 16 * 4, 32 * 4), 'test7'); self.parent.entityManager:addEntity(temp, '');temp:addComponent(self.component.instance, game.getScript('Standard/Living'));temp:addComponent(self.component.instance, game.getScript('Standard/Npc'));temp:addComponent(self.component.instance, game.getScript('Standard/Movable'));temp:getComponent('Standard/Npc').target = self.component.instance.player;temp:getComponent('Standard/Movable'):onDeserialize('{\"walking_movement_speed\":3.0, \"jumpPower\":17.0}')"},

{"_l": "mX, mY = self.component:getRelativeMouse();temp = self.parent.entityManager:createColoredEntity(Box(mX, mY, 40, 40), Color(0, 0, 255, 255));self.parent.entityManager:addEntity(temp, '');temp:addProperty(EntityProperty.STATIC)"}
],

"commands": [
{"_t": "tile dirt"},
{"_y": "tile stone"},
{"_u": "tilearea"}
]
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading