Skip to content

Instantly share code, notes, and snippets.

void Cannon::Update(float dt)
{
if (m_pTarget != nullptr && m_pSprite != nullptr)
{
cocos2d::Vec2 thisPosition;
thisPosition = m_pSprite->getPosition();
m_TargetPosition = WorldManager::getInstance()->GetCenter(m_pTarget);
float angle = atan2(thisPosition.x - m_TargetPosition.x, thisPosition.y - m_TargetPosition.y);
@uxdxdev
uxdxdev / json_parser.txt
Created December 21, 2016 15:11
RapdiJson writing json data to file example C++
#include <fstream>
#include "external/json/stringbuffer.h"
#include "external/json/writer.h"
void JsonParser::JsonToFile(rapidjson::Document &jsonObject, std::string &fullpath) {
std::ofstream outputFile;
outputFile.open(fullpath);
if(outputFile.is_open()) {
std::string jsonObjectData = JsonToString(jsonObject);
outputFile << jsonObjectData;
@uxdxdev
uxdxdev / panda.py
Created December 21, 2016 15:15
Panda3D Moonwalking Panda Source Code
from math import pi, sin, cos
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import *
from panda3d.core import Point3
class MyApp(ShowBase):
@uxdxdev
uxdxdev / UtilsTest.cpp
Last active January 27, 2023 16:47
Unit tests for Utils class
// Copyright 2016 David Morton. All rights reserved.
// Use of this source code is governed by a license that can be
// found in the LICENSE file.
#include "gtest/gtest.h"
#include "Base/Utils.h"
TEST(UtilsTest, to_strCanConvertIntZeroToString) {
std::string result = Utils::to_str(0);
ASSERT_EQ("0", result);
@uxdxdev
uxdxdev / Utils.h
Created January 7, 2017 15:32
Utils class
// Copyright 2016 David Morton. All rights reserved.
// Use of this source code is governed by a license that can be
// found in the LICENSE file.
#ifndef BASE_UTILS_H
#define BASE_UTILS_H
#include <iostream>
class Utils {
@uxdxdev
uxdxdev / Parity.cpp
Last active January 27, 2023 16:46
EPI C++ 5.1 Computing the parity of a word
#include <iostream>
#include <sstream>
#include <map>
using namespace std;
std::map<unsigned int, short> parityCache;
short parityOf(unsigned long x){
short result = 0;
while(x){
@uxdxdev
uxdxdev / true_if_derived.cpp
Created July 23, 2017 19:36
Implement a template function IsDerivedFrom() that takes class C and class P as template parameters. It should return true when class C is derived from class P and false otherwise.
#include <iostream>
using namespace std;
class B {
};
class A : public B {
};
template<typename D, typename B>
// Command
const InsertCommand = (database, id) => {
return {
execute: () => database.insertRecord(id),
undo: () => database.deleteRecord(id)
};
};
// Receiver
const insertRecord = id => console.log('>>> Database insert', id);
# Command interface
module ICommand
def execute
raise NotImplementedError
end
end
# Concrete commands
class SubmitCommand
// Receiver
class Entity {
String name;
public Entity(String name){
this.name = name;
}
public void jump(){
System.out.println(name + " Jump");
}
public void fire(){