Permalink
Browse files

- merged old GameBlock into new codebase

Signed-off-by: timgarbos <timgarbos@gmail.com>
  • Loading branch information...
1 parent 2b18c68 commit fabf04da108e65b58dfd6efbb45ed65b37abb72c @timgarbos timgarbos committed Apr 20, 2012
Showing with 164 additions and 12 deletions.
  1. +40 −0 code/GameBlock.cpp
  2. +27 −0 code/GameBlock.h
  3. +47 −0 code/gameScreen.cpp
  4. +33 −0 code/gameScreen.h
  5. +9 −5 code/testApp.cpp
  6. +8 −7 code/testApp.h
View
@@ -0,0 +1,40 @@
+#include "GameBlock.h"
+
+GameBlock::GameBlock()
+{
+}
+
+void GameBlock::Set(int w, int h, int x, int y, int type)
+{
+ this->x = x;
+ this->y = y;
+
+ this->h = h;
+ this->w = w;
+
+ this->type = type;
+}
+
+GameBlock::~GameBlock()
+{
+
+}
+
+void GameBlock::Update(float deltatime)
+{
+
+}
+
+void GameBlock::Draw()
+{
+ ofFill();
+ if(this->type=='w')
+ ofSetColor(100,50,255);
+ if(this->type=='g')
+ ofSetColor(100,255,50);
+ if(this->type=='b')
+ ofSetColor(100,50,255);
+
+
+ ofRect(x*w,y*h,h,w);
+}
View
@@ -0,0 +1,27 @@
+#ifndef GAMEBLOCK_H
+#define GAMEBLOCK_H
+#include "ofMain.h"
+
+class GameBlock
+{
+ public:
+
+ GameBlock();
+
+ void Set(int h, int w, int x, int y, int type);
+ virtual ~GameBlock();
+ void Draw();
+ void Update(float delta);
+
+ int type;
+ int x;
+ int y;
+
+ int h;
+ int w;
+
+ protected:
+ private:
+};
+
+#endif // GAMEBLOCK_H
View
@@ -0,0 +1,47 @@
+#include "gameScreen.h"
+
+gameScreen::gameScreen()
+{
+ blockWidth = ofGetWidth()/GAMEBLOCK_COLS;
+ blockHeight = ofGetHeight()/GAMEBLOCK_ROWS;
+}
+
+gameScreen::~gameScreen()
+{
+ //dtor
+}
+
+void gameScreen::update(float deltatime)
+{
+
+
+ for(int i=0;i<GAMEBLOCK_COLS*GAMEBLOCK_ROWS;i++)
+ {
+ blocks[i].Update(1.1f);
+ }
+
+}
+
+void gameScreen::draw()
+{
+ for(int i=0;i<GAMEBLOCK_COLS*GAMEBLOCK_ROWS;i++)
+ {
+ blocks[i].Draw();
+ }
+}
+
+void gameScreen::keyPressed (int key){
+
+ int x = rand()%GAMEBLOCK_COLS;
+ int y = rand()%GAMEBLOCK_ROWS;
+
+ if (key == 'w'){
+ blocks[y*GAMEBLOCK_COLS+x].Set(blockWidth,blockHeight,x,y,'w');
+ printf("Set new block\n");
+ }
+
+ if (key == 'g'){
+ blocks[y*GAMEBLOCK_COLS+x].Set(blockWidth,blockHeight,x,y,'g');
+ printf("Set new block\n");
+ }
+}
View
@@ -0,0 +1,33 @@
+#ifndef GAMESCREEN_H
+#define GAMESCREEN_H
+
+#define GAMEBLOCK_COLS 8
+#define GAMEBLOCK_ROWS 6
+
+
+#include "ofMain.h"
+#include "GameBlock.h"
+#include "ofMain.h"
+
+using namespace std;
+
+class gameScreen
+{
+ public:
+ gameScreen();
+ virtual ~gameScreen();
+ void update(float delta);
+ void draw();
+ void keyPressed (int key);
+
+ GameBlock blocks[GAMEBLOCK_COLS*GAMEBLOCK_ROWS];
+
+
+ int blockWidth;
+ int blockHeight;
+
+ protected:
+ private:
+};
+
+#endif // GAMESCREEN_H
View
@@ -3,21 +3,25 @@
//--------------------------------------------------------------
void testApp::setup(){
+ ofBackground(255,255,255);
+ ofSetWindowTitle("graphics example");
+ ofSetFrameRate(60);
+
}
//--------------------------------------------------------------
void testApp::update(){
-
+ game.update(1);
}
//--------------------------------------------------------------
void testApp::draw(){
-
+ game.draw();
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
-
+ game.keyPressed(key);
}
//--------------------------------------------------------------
@@ -56,6 +60,6 @@ void testApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
-void testApp::dragEvent(ofDragInfo dragInfo){
+void testApp::dragEvent(ofDragInfo dragInfo){
-}
+}
View
@@ -3,22 +3,23 @@
#include "ofMain.h"
#include "tracker.h"
#include "calibrator.h"
+#include "GameScreen.h"
class testApp : public ofBaseApp{
-
+
public:
void setup();
void update();
void draw();
-
+
//---------------------
-
+
Tracker tracker;
Calibrator calibrator;
-
+ gameScreen game;
//---------------------
-
-
+
+
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
@@ -28,5 +29,5 @@ class testApp : public ofBaseApp{
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
-
+
};

0 comments on commit fabf04d

Please sign in to comment.