Permalink
Browse files

versao funcional, porem o javascript nao conhece os objetos ainda

  • Loading branch information...
1 parent 8622d96 commit 21ade2028351a5ffa5c6ec26c4e12b2368b3368b @prsolucoes committed Sep 16, 2012
Showing with 40 additions and 6 deletions.
  1. +1 −0 .gitignore
  2. +8 −3 Character.cpp
  3. +5 −0 Character.h
  4. +17 −1 JSCharacter.cpp
  5. +5 −2 JSCharacter.h
  6. +4 −0 js/robot1.js
View
@@ -14,6 +14,7 @@ build/*
# QtCreator
*.pro.user
+*.autosave
# Build files
.sconsign.dblite
View
@@ -15,13 +15,18 @@ sf::Sprite *Character::getSprite()
return sprite;
}
+void Character::walkForward()
+{
+ sprite->setPosition(90, 90);
+}
+
void Character::loadSprite()
{
- sf::Texture texture;
- if (!texture.loadFromFile(resourcePath() + "images/" + type + ".png"))
+ texture = new sf::Texture();
+ if (!texture->loadFromFile(resourcePath() + "images/" + type + ".png"))
{
throw new std::exception();
}
- sprite = new sf::Sprite(texture);
+ sprite = new sf::Sprite(*texture);
sprite->setPosition(100, 200);
}
View
@@ -2,6 +2,7 @@
#define CHARACTER_H
#include <SFML/Graphics.hpp>
+#include "v8wrap.h"
#if __APPLE__
#include "ResourcePath.hpp"
@@ -12,13 +13,17 @@
class Character
{
+ static v8::Handle<v8::Value> Method_moveForward(const v8::Arguments &args);
+
public:
Character();
void setType(std::string type);
sf::Sprite *getSprite();
+ void walkForward();
private:
sf::Sprite *sprite;
+ sf::Texture *texture;
std::string type;
void loadSprite();
View
@@ -85,8 +85,24 @@ v8::Handle<v8::Value> JSCharacter::Object_delete(const v8::Arguments &args)
v8::Handle<v8::Value> result = v8::Undefined();
MyClass *inst = ((MyClass*)v8::External::Unwrap(args.Holder()->GetInternalField(0)));
bool IsWeak = args.Holder()->GetInternalField(1)->IsTrue();
- if ( IsWeak ) {
+ if ( IsWeak )
+ {
Delete(inst); args.Holder()->SetInternalField(1, v8::Boolean::New(false)); args.Holder()->SetInternalField(0, v8::External::Wrap(NULL));
}
return scope.Close(result);
}
+
+v8::Handle<v8::Value> JSCharacter::Method_walkForward(const v8::Arguments &args)
+{
+ if ( args.Length() == 0 )
+ {
+ MyClass *inst = ((MyClass*)v8::External::Unwrap(args.Holder()->GetInternalField(0)));
+ inst->walkForward();
+ return v8::Undefined();
+ }
+ else
+ {
+ return v8::ThrowException(v8::Exception::Error(v8::String::New(v8wrap::sInvalidArgs)));
+ }
+}
+
View
@@ -7,6 +7,10 @@
class JSCharacter : public v8wrap::V8ClassTemplate<JSCharacter, Character>
{
+ static v8::Handle<v8::Value> Method_walkForward(const v8::Arguments &args);
+ static v8::Handle<v8::Value> Object_copy(const v8::Arguments &args);
+ static v8::Handle<v8::Value> Object_delete(const v8::Arguments &args);
+
public:
static const char *Bases;
static const char *ClassName;
@@ -18,8 +22,7 @@ class JSCharacter : public v8wrap::V8ClassTemplate<JSCharacter, Character>
static void Register(v8::Handle<v8::ObjectTemplate> target);
private:
- static v8::Handle<v8::Value> Object_copy(const v8::Arguments &args);
- static v8::Handle<v8::Value> Object_delete(const v8::Arguments &args);
+
};
View
@@ -4,3 +4,7 @@ var randomnumber2 = Math.floor(Math.random() * 200);
//robot1.setPosition(200, randomnumber);
//robot1.rotate(randomnumber2);
+
+robot1.walkForward();
+
+//var robot1 = new Character();

0 comments on commit 21ade20

Please sign in to comment.