Skip to content

Commit

Permalink
mouse-control, need more c++
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaxvc committed Apr 11, 2012
1 parent c0ce1a7 commit 8187aa3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 121 deletions.
2 changes: 1 addition & 1 deletion dragon_practice/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class entity
{
protected:
bbox box;
position pos;

virtual void calcBbox()=0;
virtual void calcPos()=0;
public:
position pos;
virtual const bbox & getBbox()=0;
virtual const position & getPos()=0;
virtual void draw()=0;
Expand Down
135 changes: 21 additions & 114 deletions dragon_practice/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#define glError() {GLenum err = glGetError();while (err != GL_NO_ERROR) {fprintf(stderr, "glError: %s caught at %s:%u\n",(char *)gluErrorString(err), __FILE__, __LINE__);err = glGetError();}}

ship s;
/* Dimensions of our window. */
int width = 0;
int height = 0;
int score = 0;
int oldscore=score;

Expand All @@ -31,114 +34,17 @@ static void handle_key_down( SDL_keysym* keysym )
quit_tutorial( 0 );
break;

case SDLK_LEFT:
if( s.tim_x.running() )
{
s.tim_x.pause();
}
else
{
s.tim_x.count_up();
s.tim_x.resume();
}
break;

case SDLK_RIGHT:
if( s.tim_x.running() )
{
s.tim_x.pause();
}
else
{
s.tim_x.count_down();
s.tim_x.resume();
}
break;

case SDLK_DOWN:
if( s.tim_y.running() )
{
s.tim_y.pause();
}
else
{
s.tim_y.count_up();
s.tim_y.resume();
}
break;

case SDLK_UP:
if( s.tim_y.running() )
{
s.tim_y.pause();
}
else
{
s.tim_y.count_down();
s.tim_y.resume();
}
break;

case SDLK_SPACE:
s.expand();
break;

default:
break;
}

}

static void handle_key_up( SDL_keysym* keysym )
{
switch( keysym->sym )
{
case SDLK_LEFT:
if( s.tim_x.running() )
{
s.tim_x.pause();
}
else
{
s.tim_x.count_down();
s.tim_x.resume();
}
break;

case SDLK_RIGHT:
if( s.tim_x.running() )
{
s.tim_x.pause();
}
else
{
s.tim_x.count_up();
s.tim_x.resume();
}
break;

case SDLK_DOWN:
if( s.tim_y.running() )
{
s.tim_y.pause();
}
else
{
s.tim_y.count_down();
s.tim_y.resume();
}
break;

case SDLK_UP:
if( s.tim_y.running() )
{
s.tim_y.pause();
}
else
{
s.tim_y.count_up();
s.tim_y.resume();
}
s.expand();
s.expand();
s.expand();
s.expand();
s.expand();
s.expand();
s.expand();
s.expand();
s.expand();
break;

default:
Expand All @@ -156,9 +62,11 @@ static void process_events( void )
while( SDL_PollEvent( &event ) ) {

switch( event.type ) {
case SDL_KEYUP:
handle_key_up( &event.key.keysym );
break;
case SDL_MOUSEMOTION:
s.pos.x = 30*( event.motion.x - width /2) / (double)width;
s.pos.y = -12*( event.motion.y - height/2) / (double)height;
printf("%f %f\n",s.pos.x,s.pos.y);
break;

case SDL_KEYDOWN:
/* Handle key presses. */
Expand Down Expand Up @@ -231,13 +139,10 @@ static void setup_opengl( int width, int height )
gluPerspective( 60.0, ratio, 1.0, 1024.0 );
}

int main( int argc, char* argv[] )
int main()
{
/* Information about the current video settings. */
const SDL_VideoInfo* info = NULL;
/* Dimensions of our window. */
int width = 0;
int height = 0;
/* Color depth in bits of our window. */
int bpp = 0;
/* Flags we will pass into SDL_SetVideoMode. */
Expand All @@ -251,6 +156,8 @@ int main( int argc, char* argv[] )
quit_tutorial( 1 );
}

SDL_ShowCursor( false );

/* Let's get some video information. */
info = SDL_GetVideoInfo( );

Expand Down Expand Up @@ -315,7 +222,7 @@ int main( int argc, char* argv[] )
* glViewport.
*/
flags = SDL_OPENGL | SDL_FULLSCREEN;
flags = SDL_OPENGL;
// flags = SDL_OPENGL;

/*
* Set the video mode
Expand Down
4 changes: 1 addition & 3 deletions dragon_practice/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <cstdio>
#include "ship.h"

#define MAX_DIST .5
#define MAX_DIST .1

#define WIDTH 1.0
#define HEIGHT 1.0
Expand Down Expand Up @@ -63,8 +63,6 @@ return pos;

void ship::calcPos()
{
pos.x = -8 * tim_x.read();
pos.y = -8 * tim_y.read();
}

ship::ship()
Expand Down
4 changes: 1 addition & 3 deletions dragon_practice/ship.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "position.h"
#include "timer_bidi.h"

class ship : private entity
class ship : public entity
{
private:
void calcPos();
Expand All @@ -17,8 +17,6 @@ class ship : private entity
std::list<position> tail;

public:
timer_bidirectional tim_x;
timer_bidirectional tim_y;

ship();
~ship();
Expand Down

0 comments on commit 8187aa3

Please sign in to comment.