Exemplo n.º 1
0
void PHN_Gauge::update() {
  if (_value == _valueReq) {
    return;
  }
  // Draw changes in the needle pointer (avoids having to draw the entire background)
  drawPointer(color(FOREGROUND));
  _value = _valueReq;
  drawPointer(color(CONTENT));
}
Exemplo n.º 2
0
void GaugeCompass::paintEvent(QPaintEvent *)
{
    int width = this->width();
    int height = this->height();
    int side = qMin(width, height);

    //绘制准备工作,启用反锯齿,平移坐标轴中心,等比例缩放
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
    painter.translate(width / 2, height / 2);    
    painter.scale(side / 200.0, side / 200.0);

    //绘制外边框圆
    drawCrownCircle(&painter);
    //绘制背景圆
    drawBgCircle(&painter);
    //绘制刻度
    drawScale(&painter);
    //绘制东南西北标识
    drawScaleNum(&painter);
    //绘制覆盖圆外圆
    drawCoverOuterCircle(&painter);
    //绘制覆盖圆内圆
    drawCoverInnerCircle(&painter);
    //绘制覆盖圆中心圆
    drawCoverCenterCircle(&painter);
    //绘制南北指针
    drawPointer(&painter);
    //绘制中心圆
    drawCenterCircle(&painter);
    //绘制当前值
    drawText(&painter);
}
Exemplo n.º 3
0
// Draw all the Nebulae
void NebulaMgr::draw(StelCore* core)
{
	const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
	StelPainter sPainter(prj);

	StelSkyDrawer* skyDrawer = core->getSkyDrawer();

	Nebula::hintsBrightness = hintsFader.getInterstate()*flagShow.getInterstate();

	sPainter.enableTexture2d(true);
	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ONE);

	// Use a 1 degree margin
	const double margin = 1.*M_PI/180.*prj->getPixelPerRadAtCenter();
	const SphericalRegionP& p = prj->getViewportConvexPolygon(margin, margin);

	// Print all the nebulae of all the selected zones
	float maxMagHints = skyDrawer->getLimitMagnitude()*1.2f-2.f+(hintsAmount*1.2f)-2.f;
	float maxMagLabels = skyDrawer->getLimitMagnitude()-2.f+(labelsAmount*1.2f)-2.f;
	sPainter.setFont(nebulaFont);
	DrawNebulaFuncObject func(maxMagHints, maxMagLabels, &sPainter, core, hintsFader.getInterstate()>0.0001);
	nebGrid.processIntersectingRegions(p, func);

	if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
		drawPointer(core, sPainter);
}
Exemplo n.º 4
0
/*
 Draw our module. This should print name of first PSR in the main window
*/
void Exoplanets::draw(StelCore* core, StelRenderer* renderer)
{
	if (!flagShowExoplanets)
		return;

	StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
	renderer->setFont(font);

	if(NULL == texPointer)
	{
		Q_ASSERT_X(NULL == markerTexture, Q_FUNC_INFO, "Textures need to be created simultaneously");
		texPointer    = renderer->createTexture("textures/pointeur2.png");
		markerTexture = renderer->createTexture(":/Exoplanets/exoplanet.png");
	}
	
	foreach (const ExoplanetP& eps, ep)
	{
		if (eps && eps->initialized)
			eps->draw(core, renderer, prj, markerTexture);
	}

	if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
		drawPointer(core, renderer, prj);

}
Exemplo n.º 5
0
void Engine::render() {
	//Get screen dimensions
	int screen_min_x, screen_min_y, screen_max_x, screen_max_y;
	getbegyx(stdscr, screen_min_y, screen_min_x);
	getmaxyx(stdscr, screen_max_y, screen_max_x);

	//The status bar may exist at some point! Here are some placeholder values.
	int status_bar_size = 0;
	int status_bar_top_size = 0;

	//The view is going to be constantly centered on the player.
	//These variables should help with math.
	int view_offset_x = (screen_max_x - screen_min_x) / 2 - player->getX();
	int view_offset_y = (screen_max_y - screen_min_y) / 2 - player->getY();

	//Draw objects
	for(std::size_t i = 0; i < object_list.size(); i++) {
		//Only draw the object if it's on the screen.
		if(	object_list.at(i)->getY() + view_offset_y < screen_max_y - status_bar_size &&
			object_list.at(i)->getY() + view_offset_y > screen_min_y + status_bar_top_size &&
			object_list.at(i)->getX() + view_offset_x < screen_max_x &&
			object_list.at(i)->getX() + view_offset_x > screen_min_x) {

			mvaddch(
				object_list.at(i)->getY() + view_offset_y,
				object_list.at(i)->getX() + view_offset_x,
				object_list.at(i)->render()
			);
		}
	}

	//Draw cursor
	curs_set(0);
	drawPointer(0, 0);
}
Exemplo n.º 6
0
static void initMain(void){
	// Method for displaying the screen for the main menu
	drawLogo();
	RIT128x96x4StringDraw("Classic", 10, 50, 15);
	RIT128x96x4StringDraw("Continuous", 10, 60, 15);
	RIT128x96x4StringDraw("Instructions", 10, 70, 15);
	RIT128x96x4StringDraw("High Scores", 10, 80, 15);
	drawPointer(50);
}
Exemplo n.º 7
0
/*!
  Draw a compass needle 
*/
void QwtCompassMagnetNeedle::drawThinNeedle(
    QPainter *painter, const QColorGroup &cg,
    const QPoint &center, int length, double direction) 
{
    const int colorOffset = 10;
    const int width = QMAX(qRound(length / 6.0), 3);

    painter->save();

    const QPoint arrowCenter(center.x() + 1, center.y() + 1);

    drawPointer(painter, cg.brush(QColorGroup::Dark), colorOffset, 
        arrowCenter, length, width, direction);
    drawPointer(painter, cg.brush(QColorGroup::Light), -colorOffset, 
        arrowCenter, length, width, direction + 180.0);
    
    drawKnob(painter, arrowCenter, width, 
        cg.brush(QColorGroup::Base), TRUE);

    painter->restore();
}
Exemplo n.º 8
0
void Thermometer::paintEvent(QPaintEvent *)
{
    painter.begin(this);

    drawTitle();
    drawUnit();
    drawLabel();
    drawDisplay();
    drawScale();
    drawMeter();
    drawRange();
    drawPointer();

    painter.end();
}
Exemplo n.º 9
0
/*!
  Draw a compass needle

  \param painter Painter
  \param palette Palette
  \param colorGroup Color group
  \param center Center, where the needle starts
  \param length Length of the needle
  \param direction Direction
*/
void QwtCompassMagnetNeedle::drawThinNeedle( QPainter *painter,
    const QPalette &palette, QPalette::ColorGroup colorGroup,
    const QPoint &center, int length, double direction )
{
    const QBrush darkBrush = palette.brush( colorGroup, QPalette::Dark );
    const QBrush lightBrush = palette.brush( colorGroup, QPalette::Light );
    const QBrush baseBrush = palette.brush( colorGroup, QPalette::Base );

    const int colorOffset = 10;
    const int width = qMax( qRound( length / 6.0 ), 3 );

    painter->save();

    const QPoint arrowCenter( center.x() + 1, center.y() + 1 );

    drawPointer( painter, darkBrush, colorOffset,
        arrowCenter, length, width, direction );
    drawPointer( painter, lightBrush, -colorOffset,
        arrowCenter, length, width, direction + 180.0 );

    drawKnob( painter, arrowCenter, width, baseBrush, true );

    painter->restore();
}
Exemplo n.º 10
0
/*
 Draw our module. This should print name of first SNe in the main window
*/
void Supernovae::draw(StelCore* core)
{
	StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
	StelPainter painter(prj);
	painter.setFont(font);
	
	foreach (const SupernovaP& sn, snstar)
	{
		if (sn && sn->initialized)
			sn->draw(core, painter);
	}

	if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
		drawPointer(core, painter);

}
Exemplo n.º 11
0
void PHN_Gauge::draw() {
  // Draw the gauge background circle
  int radius = width * 0.5;
  display.fillCircle(x + width / 2, y + width / 2, radius, color(FRAME));
  display.fillCircle(x + width / 2, y + width / 2, radius - 1, color(FOREGROUND));
  display.drawCircle(x + width / 2, y + width / 2, radius - 1, color(CONTENT));

  // Draw the pointer and background of value label field
  _value = _valueReq;
  drawPointer(color(CONTENT), true);

  // Draw the tick lines
  int tickCount = 11;
  for (int i = 0; i < tickCount; i++) {
    drawTickLine(radius - 2, radius - 8, (float) i /  (float) (tickCount - 1), color(CONTENT));
  }
}
Exemplo n.º 12
0
/*
 Draw our module. This should print name of first SNe in the main window
*/
void Supernovae::draw(StelCore* core, StelRenderer* renderer)
{
	StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
	renderer->setFont(font);
	
	foreach (const SupernovaP& sn, snstar)
	{
		if (sn && sn->initialized)
		{
			sn->draw(core, renderer, prj);
		}
	}

	if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
	{
		drawPointer(core, renderer, prj);
	}
}
Exemplo n.º 13
0
/*
 Draw our module. This should print name of first PSR in the main window
*/
void Pulsars::draw(StelCore* core)
{
	if (!flagShowPulsars)
		return;

	StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
	StelPainter painter(prj);
	painter.setFont(font);
	
	for (const auto& pulsar : psr)
	{
		if (pulsar && pulsar->initialized)
			pulsar->draw(core, &painter);
	}

	if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
		drawPointer(core, painter);
}
Exemplo n.º 14
0
/*
 Draw our module. This should print name of first Nova in the main window
*/
void Novae::draw(StelCore* core)
{
	StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
	StelPainter painter(prj);
	painter.setFont(font);
	
	foreach (const NovaP& n, nova)
	{
		if (n && n->initialized)
		{
			n->draw(core, &painter);
		}
	}

	if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
	{
		drawPointer(core, painter);
	}
}
Exemplo n.º 15
0
/*
 Draw our module. This should print name of first QSO in the main window
*/
void Quasars::draw(StelCore* core)
{
	if (!flagShowQuasars)
		return;

	StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
	StelPainter painter(prj);
	painter.setFont(font);
	
	foreach (const QuasarP& quasar, QSO)
	{
		if (quasar && quasar->initialized)
			quasar->draw(core, painter);
	}

	if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
		drawPointer(core, painter);

}
Exemplo n.º 16
0
void CLabKnob::drawControl(CDC *pDC, CRect& rect)
{
   CString  valueString;

   // draw control background
   CBrush brush1;
   brush1.CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));      
   pDC->FillRect(rect, &brush1); 

   CPen p(PS_SOLID, 1, _color);
   CPen pw(PS_SOLID, 1, RGB(255,255,255));
   CPen pb(PS_SOLID, 1, RGB(0,0,0));
      
   CRect krect(_borderSize, _borderSize, _borderSize + _radius*2, _borderSize + _radius*2);
   CBrush brush2;
   brush2.CreateSolidBrush(_color);
   CBrush *pOldBrush = pDC->SelectObject(&brush2);
   CPen *pOldPen = pDC->SelectObject(&p);
   pDC->Ellipse(krect);

   //krect.InflateRect(1,1,1,1);
   pDC->SelectObject(&pb);
   pDC->Arc(krect, CPoint(krect.left, krect.bottom),
            CPoint(krect.right, krect.top));
   
   pDC->SelectObject(&pw);
   pDC->Arc(krect, CPoint(krect.right, krect.top),
            CPoint(krect.left, krect.bottom));

   drawPointer(pDC);

   _scale.setBounds(CRect(0, 0, (_borderSize + _radius) * 2, (_borderSize + _radius) * 2));
   _scale.drawScale(pDC);

   pDC->SelectObject(pOldPen);
   pDC->SelectObject(pOldBrush);
}  
Exemplo n.º 17
0
void Render_Gioco(void){

	float tmp;
	
	pointer_pos=cursor_position();

	glutSetCursor(GLUT_CURSOR_NONE);
  
	glDisable(GL_FOG);

    drawSkybox();
	drawGun();
	drawBullet();
    drawScore();
	
    glPushMatrix();
    gluLookAt(0.f,0.f,3.f,0.f,0.f,-5.f,0.f,1.f,0.f);

	tmp = 0.0536414;
	glScalef(tmp, tmp, tmp);
    
	glTranslated(-xpos,0.0f,0.0f);
	
	//SPOSTAMENTO DELLA CAMERA:
	float xx=9,yy=0,zz=42;
	glTranslatef(xx,yy,zz);
	glRotatef(main_camera.getLocRot().y_rot,0.0f,1.0f,0.0f);

	glTranslatef(-xx,-yy,-zz);
	//translo la camera (in realta' translo tutto il resto)
	glTranslatef(main_camera.getLocRot().x, main_camera.getLocRot().y, main_camera.getLocRot().z);


	//Fog----------------------

	glFogi(GL_FOG_MODE, GL_LINEAR);					// Fog Mode
	GLfloat fogColor[4]= {0.6f, 0.5f, 0.3f, 1.0f};
	glFogfv(GL_FOG_COLOR, fogColor);				// Set Fog Color
	glFogf(GL_FOG_DENSITY, 0.45f);					// How Dense Will The Fog Be
	glHint(GL_FOG_HINT, GL_DONT_CARE);				// Fog Hint Value
	glFogf(GL_FOG_START, 3.5f);						// Fog Start Depth
	glFogf(GL_FOG_END, 6.0f);						// Fog End Depth
	glEnable(GL_FOG);								// Enables GL_FOG
	
	//-------------------------

	if(first == TRUE){
		scene_list_case=glGenLists(4);
		scene_list_target=glGenLists(10);
		lista_case(scene_list_case,level1_scene.scene,level2_scene.scene,level3_scene.scene,terreno_scene.scene);
		lista_target(scene_list_target,target_scene.scene);
		pos=scegli_pos(livello,livelli);
		first = FALSE;
	}

	if(m[pos].stato==2){
        m[pos]=reset_motion(m[pos]);
        pos=scegli_pos(livello,livelli);
    }
       
	ch=render_target(livello,scene_list_target,pos,livelli,m[pos],ch,t.v);
	render_case(livello,scene_list_case);

	if(!pause)t=count_time(t);

	m[pos]=scegli_mov(m[pos],livelli,pos,t.tempoi, t.v, ch_index,ch);
    
    glPopMatrix();

	drawPointer(pointer_pos);

	if(pause) DrawMenu(0,0,menuArray[5],true);

}
Exemplo n.º 18
0
void
GPIOEIntHandler(void)
{
	// Method for handling directional pad interrupts. The left and right
	// buttons allow the user to move the alphabet cursor left and right. This
	// behavior is handled here.

	// Clear the GPIO interrupt
	GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

	// Disable Interrupts
	GPIOPinIntDisable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

	if (state==0){
		while(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0)==0 ||
			GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)==0){
			// Increment the counter
			x++;
			if (x>19999){
				if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0)==0){
					if (pointer!=0){
						clearPointer(50+(pointer*10));
						pointer--;
						drawPointer(50+(pointer*10));
					}
					x = 0;
					break;
				}
				if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)==0){
					if (pointer!=3){
						clearPointer(50+(pointer*10));
						pointer++;
						drawPointer(50+(pointer*10));
					}
					x = 0;
					break;
				}
			}
		}
		x = 0;
	}
	else if (state==1 || state==3){
		// Count to 15000 so that we don't move the cursor too fast
		while(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)==0 ||
				GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0){
			// Increment the counter
			x++;
			if (x>14999){
				// Check to see which button was pressed
				if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)==0){
					// Check if the cursor is not in the original position on the
					// top row. If it is, we do nothing
					if (position>0){
						// Check if the cursor is not in the original position on
						// the bottom row
						if (position2>0){
							// Move the cursor one spot to the left
							position2--;
						}
						else {
							// Move the cursor one spot to the left
							position--;
						}
					}
				}
				else if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0){
					// Check if the cursor is at the last possible position on the
					// bottom row. If it is, we do nothing
					if (position2<12){
						// Check if the cursor is at the last spot on the top row
						if (position<13){
							// Move the cursor one spot to the right
							position++;
						}
						else {
							// Move the cursor one spot to the right
							position2++;
						}
					}
				}
				// Update the position of the cursor
				moveCursor();
				break;
			}
		}
		x = 0;
	}

	// Enable Interrupts
	GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
}
Exemplo n.º 19
0
ofVec2f ofxFontStash::drawMultiColumnFormatted(const string &_text, float size, float columnWidth, bool topLeftAlign, bool dryrun){

	float maxX=0;

	string text = _text;
	if (!utf8::is_valid(text.begin(), text.end())){
		text = LocaleToUtf8(text);
	}

	if (stash == NULL || fontIds.empty()) {
		ofLogError("ofxFontStash") << "error: stash not initialized or no font";
		return ofVec2f(0,0);
	}

	//TODO hack!
	//this is to fix the issue where two consecutive \n\n's are ignored
	string localText = text;
	ofStringReplace(localText, "\n", " \n");

	vector<std::string> allWords;
	vector<ofVec2f> wordSizes;
	vector<int> wordFonts;
	vector<ofColor> wordColors;
	vector<float> wordScales;

	int currentFontId = fontIds[0];
	ofColor currentColor = ofGetStyle().color;
	float currentScale = 1;

	// first, calculate the sizes of all the words
	//
	vector<std::string> lines = ofSplitString(localText, "\n");
	for (int i=0; i<lines.size(); i++) {

		vector<std::string> words = ofSplitString(lines[i], " ");

		for (int j=0; j<words.size(); j++) {

			// handle '@' code to change font id
			if (isFontCode(words[j])) {
				currentFontId = fontIds[ofToInt(words[j].substr(1, words[j].length()))];
				continue;
			}

			// handle '#' code to change color
			if (isColorCode(words[j])) {
				currentColor = ofColor::fromHex(ofHexToInt(words[j].substr(1, words[j].length())));
				continue;
			}

			// handle '%' code to change scale
			if (isScaleCode(words[j])) {
				currentScale = ofToFloat(words[j].substr(1, words[j].length()));
				continue;
			}

			std::string word = words[j];

			// add ' ' because we removed it when we did the split
			if (j != words.size()-1) {
				word += " ";
			}

			float x, y, w, h;
			ofx_sth_dim_text( stash, currentFontId, size * currentScale / dpiScale, word.c_str(), &x, &y, &w, &h);

			allWords.push_back(word);
			wordSizes.push_back(ofVec2f(w, h));
			wordFonts.push_back(currentFontId);
			wordColors.push_back(currentColor);
			wordScales.push_back(currentScale);

		}

		// all end of line
		allWords.push_back("\n");
		// a place holder to match indexes
		wordSizes.push_back(ofVec2f(0, 0));
		wordFonts.push_back(currentFontId);
		wordColors.push_back(currentColor);
		wordScales.push_back(currentScale);
	}

	// now draw the text
	//
	ofVec2f drawPointer(0, 0);
	float asc = 0.0f;

	if (topLeftAlign) {
		float desc, lineh;
		ofx_sth_vmetrics(stash, wordFonts[0], size, &asc, &desc, &lineh);

		ofPushMatrix();
		ofTranslate(0, asc);
	}

	if (!dryrun) {
		ofx_sth_begin_draw(stash);
	}

	for (int i=0; i<allWords.size(); i++) {

		// do we need to jump a line?
		if ((drawPointer.x + wordSizes[i].x > columnWidth ||
			allWords[i] == "\n") &&
			drawPointer.x != 0)
		{
			// jump one line down
			drawPointer.y += lineHeight * size * wordScales[i];
			drawPointer.x = 0;
		}

		// we need to flush the vertices if we change the color
		if (!dryrun) {
			if (wordColors[i] != ofGetStyle().color) {
				ofx_sth_end_draw(stash);
				ofx_sth_begin_draw(stash);

				ofSetColor(wordColors[i]);
			}
		}

		float dx = 0;
		if (!dryrun) {
			ofx_sth_draw_text( stash, wordFonts[i], size * wordScales[i], drawPointer.x, drawPointer.y, allWords[i].c_str(), &dx );
		}
		drawPointer.x += wordSizes[i].x;

		// save maxX so we'll return the size
		if (drawPointer.x > maxX) {
			maxX = drawPointer.x;
		}
	}

	if (!dryrun) {
		ofx_sth_end_draw(stash);
	}

	if (topLeftAlign) {
		ofPopMatrix();
	}

	return ofVec2f(maxX, drawPointer.y - (lineHeight * size / dpiScale - asc));
}
Exemplo n.º 20
0
int main(int argc, char *argv[])
{
  int doScale=0; // 0=Undefined, 1=320x240, -1=OpenGL, >1=SwScale
  char* dumpPack=NULL;
  int state=1; //Game, Menu, Editor, Quit
  int sdlVideoModeFlags = SDL_SWSURFACE;

  #ifdef PSP
    //Note to PSP porter, please test if HW is actually faster, Wizznic does a lot of memory-manipulation in the screen-surface, each call might initiate a full copy back/forth from video memory. Remove comment when read. :)
    sdlVideoModeFlags = (SDL_HWSURFACE | SDL_DOUBLEBUF |SDL_HWACCEL);
    SetupCallbacks();//Callbacks actifs
    scePowerSetClockFrequency(333,333,166);
  #endif

//  #ifdef WIN32
//Redirect stdout to console on windows, so we can see what's going in.
//  FILE *stream;
//  stream = freopen("CON", "w", stdout);
//  #endif

  //Print welcome message
  printf( "Wizznic "VERSION_STRING". GPLv3 or newer Copyleft 2010-2013\n\n");

  //initialize path strings
  initUserPaths();

  //Tell where stuff's at.
  printf("Directories:\n    Settings: %s\n    DLC: %s\n    Highscores: %s\n    Editorlevels: %s\n    Datafiles: %s\n\n", \
                            getConfigDir(), getUsrPackDir(), getHighscoreDir(), getUserLevelDir(), (!strlen(DATADIR))?".":DATADIR);

  //Print the command line parameters
  printf("Command-line parameters:\n"STR_VID_OPTIONS);

  //Quit if user wants help
  if( argc > 1 && ( strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-help")==0 ))
  {
    printf("Please see readme.txt or http://wizznic.org/ for more help.\n");
    return(0);
  }

  //Read settings
  printf("Loading settings...\n");
  initSettings();

  #if defined(WITH_OPENGL)
  //We start by enabling glScaling if it was enabled in settings, it can then be overwritten by command line options.
  if( setting()->glEnable && doScale==0 )
    doScale=-1;
  #endif

  //Set scaling
  setting()->scaleFactor=1.0;

  atexit(SDL_Quit);

  //Init SDL
  if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER ) <0 )
  {
    printf("SDL_Init failed: %s\n",SDL_GetError());
    return(-1);
  }

  //Setup display
  #if defined (GP2X) || defined (PSP) || defined (WIZ)
  SDL_Surface* screen = SDL_SetVideoMode(SCREENW,SCREENH,16, sdlVideoModeFlags);
  #else
  SDL_Surface* screen=NULL;

  int i;
  for( i=0; i < argc; i++ )
  {
    if( strcmp( argv[i], "-sw" ) == 0 )
    {
      setting()->glEnable=0;
      doScale=0;
      saveSettings();
    } else
    if( strcmp( argv[i], "-gl" ) == 0 )
    {
      setting()->glEnable=1;
      doScale=-1;
      saveSettings();
    } else
    if( strcmp( argv[i], "-z" ) == 0 )
    {
      if( i+1 < argc )
      {
        doScale = atoi( argv[i+1] );
        setting()->glEnable=0;
        i++;
        saveSettings();
      } else {
        printf(" -z requires zoom level ( -z 2 for example ).\n");
        return(1);
      }
    } else
    if( strcmp( argv[i], "-f" ) == 0 )
    {
        setting()->fullScreen=1;
        saveSettings();
    } else
    if( strcmp( argv[i], "-w" ) == 0 )
      {
        setting()->fullScreen=0;
        saveSettings();
    } else if( strcmp( argv[i], "-glheight" ) == 0 )
    {
      if( i+1 < argc )
      {
        setting()->glHeight = atoi( argv[i+1] );
        setting()->glEnable=1;
        doScale=-1;
        i++;
        printf("Setting OpenGL window height to %i.\n", setting()->glHeight);
        saveSettings();
      } else {
        printf(" -glheight requires an argument (-1 or size in pixels).\n");
        return(1);
      }
    } else if( strcmp( argv[i], "-glwidth" ) == 0 )
    {
      if( i+1 < argc )
      {
        setting()->glWidth = atoi( argv[i+1] );
        setting()->glEnable=1;
        doScale=-1;
        i++;
        printf("Setting OpenGL window width to %i.\n", setting()->glWidth);
        saveSettings();
      } else {
        printf(" -glwidth requires an argument (-1 or size in pixels).\n");
        return(1);
      }
    } else if( strcmp( argv[i], "-glfilter" ) == 0 )
    {
      if( i+1 < argc )
      {
        setting()->glFilter=atoi(argv[i+1]);
        printf("OpenGL texture filtering set to %s.\n", (setting()->glFilter)?"Smooth":"Off");
        i++;
        saveSettings();
      } else {
        printf("-glfilter requires 0 or 1 as argument.\n");
        return(1);
      }
    } else if( strcmp( argv[i] , "-d" ) == 0 )
    {
      if( argc == 3 && i < argc+1 )
      {
        dumpPack = malloc( sizeof(char)*strlen(argv[i+1])+1 );
        strcpy( dumpPack, argv[i+1] );
        doScale=0;
        setting()->glEnable=0;
        i++;
      } else {
        printf("-d requires a packname, and must not be used with other parameters.\n");
        return(1);
      }
    } else if( strcmp( argv[i], "-rift") == 0 )
    {
      setting()->glWidth = 1280;
      setting()->glHeight = 800;
      setting()->glEnable=1;
      setting()->rift=1;
      doScale=-1;
    } else if( i > 0 )
    {
      printf("\nError: Invalid argument '%s', quitting.\n", argv[i]);
      return(1);
    }

  }

  if( setting()->fullScreen )
  {
    sdlVideoModeFlags |= SDL_FULLSCREEN;
  }

  if(doScale)
  {
    //Hardware accelerated scaling
    if( doScale == -1 )
    {
    #ifdef HAVE_ACCELERATION
      printf("Enabling platform specific accelerated scaling.\n");
      screen = platformInitAccel(sdlVideoModeFlags);
      if( !screen )
      {
        printf("Failed to set platform accelerated scaling, falling back to software window.\n");
        screen=swScreen(SDL_SWSURFACE);
        doScale=0;
      }
    #else
      printf("\nError:\n  Not compiled with hardware-scaling support, don't give me -z -1\n  Exiting...\n");
      return(-1);
    #endif
    } else if( doScale > 0 )
    {
    #ifdef WANT_SWSCALE
      //Set up software scaling
      printf("Enabling slow software-based scaling to %ix%i.\n",320*doScale, 240*doScale);
      screen = swScaleInit(sdlVideoModeFlags,doScale);
    #else
      printf("\nError:\n  I don't support software scaling, don't give me any -z options\n  Exiting...\n");
      return(-1);
    #endif
    }
  } else {
    screen=swScreen(sdlVideoModeFlags);
    doScale=0;
  }

  printf("Scaling factor: %f\n", setting()->scaleFactor);

  if( screen == NULL )
  {
    printf("ERROR: Couldn't init video.\n");
    return(-1);
  }


  //Set window title
  SDL_WM_SetCaption("Wizznic!", "Wizznic!");
  //Set window icon
  SDL_Surface* icon = IMG_Load( DATADIR"data/wmicon.png");
  SDL_WM_SetIcon(icon, NULL);
  SDL_FreeSurface(icon);

  #endif

  setting()->bpp = screen->format->BytesPerPixel;
  setAlphaCol( setting()->bpp );

  printf("Screen surface using %i bytes per pixel.\n",setting()->bpp);

  //Open Joysticks (for wiz)
  if (SDL_NumJoysticks() > 0) SDL_JoystickOpen(0);

  //Hide mouse cursor
  SDL_ShowCursor(SDL_DISABLE);

  //Load fonts
  txtInit();

  //Load sounds
  if(!initSound())
  {
    printf("Couldn't init sound.\n");
    return(-1);
  }

  //Menu Graphics
  if(!initMenu(screen))
  {
    printf("Couldn't load menu graphics.\n");
    return(-1);
  }

  //Init controls
  initControls();

  //Init stats
  statsInit();

  //Init packs
  packInit();

  //Scan userlevels dir
  makeUserLevelList(screen);

  //Init particles
  initParticles(screen);

  //Seed the pseudo random number generator (for particles 'n' stuff)
  srand( (int)time(NULL) );

  #if defined(PC)
  //Need to dump level-screenshots?
  if(dumpPack)
  {
    printf("Dumping level-images for pack: %s\n", dumpPack);
    dumplevelimages(screen, dumpPack, 0);
    return(0);
  }
  #endif

  //init starfield
  initStars(screen);

  //Init pointer
  initPointer(screen);

  printf("Applying settings..\n");
  //Apply settings (has to be done after packs are inited)
  applySettings();
  //Set Pack
  packSetByPath( setting()->packDir );

  #if defined( PLATFORM_SUPPORTS_STATSUPLOAD )
  if( (setting()->uploadStats) && !(setting()->firstRun) )
  {
    statsUpload(0,0,0,0,0,"check",1, &(setting()->session) );
    statsUpload(0,0,0,0,0,"q_solved",1, &(setting()->solvedWorldWide) );

    //DLC only works when stats-uploading is enabled so we can use the same nag-screen.
    dlcCheckOnline();
  }
  #endif

  printf("Setting Music...\n");
  //Start playing music (has to be done after readong settings)
  soundSetMusic();

  //Initialize credits
  initCredits(screen);

  initTransition();


#if SCREENW != 320 || SCREENH != 240
  SDL_Rect *borderSrcRect = malloc(sizeof(SDL_Rect));
  SDL_Surface* border = loadImg( BORDER_IMAGE );
  if( border )
  {
    printf("Border image loaded.\n");
    borderSrcRect->x=(border->w-SCREENW)/2;
    borderSrcRect->y=(border->h-SCREENH)/2;
    borderSrcRect->w=SCREENW;
    borderSrcRect->h=SCREENH;
    SDL_BlitSurface( border, borderSrcRect, screen, NULL );
    SDL_FreeSurface(border);
  } else {
    printf("Could not load border image: %s\n", BORDER_IMAGE);
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));
  }
  free(borderSrcRect);
  borderSrcRect=NULL;

#endif

  int lastTick;
  while(state!=STATEQUIT)
  {
    lastTick=SDL_GetTicks();

    frameStart();

    if(runControls()) state=STATEQUIT;
    switch(state)
    {
      case STATEPLAY:
        state = runGame(screen);
      break;

      case STATEMENU:
        state = runMenu(screen);
      break;

      case STATEEDIT:
        state=runEditor(screen);
      break;
    }

    drawPointer(screen);

    soundRun(screen,state);

    runTransition(screen);

    if(setting()->showFps)
      drawFPS(screen);

    switch( doScale )
    {
      #if defined(HAVE_ACCELERATION)
      case -1:
        platformDrawScaled(screen);
        break;
      #endif
      case 0:
        SDL_Flip(screen);
        break;
      #if defined(WANT_SWSCALE)
      default:
        swScale(screen,doScale);
        break;
      #else
      default:
        state=STATEQUIT;
      break;
      #endif
    }

    #if defined(CRUDE_TIMING)
    //Oh how I loathe this, is there no better way?
    while(SDL_GetTicks()-lastTick <= PLATFORM_CRUDE_TIMING_TICKS)
    {
      //Burn, burn baby burn!
    }
    #else
    int t=SDL_GetTicks()-lastTick;
    if(t < 20)
    {
      SDL_Delay( 20 -t);
    }
    #endif
  }

  #if defined(PLATFORM_NEEDS_EXIT)
  platformExit();
  #endif

  SDL_Quit();

  return(0);
}
Exemplo n.º 21
0
// the main function
void _main(void) {
    unsigned int difficulty = NORMAL;
    short int key=0;
    short int keys[8];
    unsigned int level_num = 1;
    unsigned short int score = 0;
    int done = 0;
    unsigned int money = 0;
    int cannon_level = 1;
    int missile_level = 0;
    char map[12][MAP_SIZE];

    // seed the random numbers
    randomize();
    // get the key masks
    getKeyMasks(keys);


    INT_HANDLER interrupt1 = GetIntVec(AUTO_INT_1);  // this will save auto int 1

    // draw title screen and wait for keypress
    GrayOn();
    drawTitle(2);
    ngetchx();

    //draw background title screen and menu
    drawTitle(1);
    drawWords(difficulty);
    POSITION pointer = {10,0};
    drawPointer(pointer);
    // the menu loop
    while (1) {
        key = ngetchx();
        if (key == KEY_ENTER && pointer.y != OPTIONS) {
            if (pointer.y == PLAY) break;
            if (pointer.y == HIGH_SCORES) printHiScores();
            if (pointer.y == HELP) doHelp();
            if (pointer.y == ABOUT) {
                SetIntVec(AUTO_INT_1,interrupt1);
                GrayOff();
                exit(0);
            }
            GraySetAMSPlane(LIGHT_PLANE);
            clrscr();
            GraySetAMSPlane(DARK_PLANE);
            clrscr();
            drawTitle(1);
            drawWords(difficulty);
            pointer=(POSITION) {
                10,0
            };
            drawPointer(pointer);
        }
        if (key == KEY_LEFT && pointer.y == OPTIONS && difficulty < VERY_EASY) {
            difficulty+=1;
            GraySetAMSPlane(LIGHT_PLANE);
            clrscr();
            GraySetAMSPlane(DARK_PLANE);
            clrscr();
            drawTitle(1);
            drawPointer(pointer);
            drawWords(difficulty);
        }
        if (key == KEY_RIGHT && pointer.y == OPTIONS && difficulty > IMPOSSIBLE)  {
            difficulty-=1;
            GraySetAMSPlane(LIGHT_PLANE);
            clrscr();
            GraySetAMSPlane(DARK_PLANE);
            clrscr();
            drawTitle(1);
            drawPointer(pointer);
            drawWords(difficulty);
        }
        if (key == KEY_UP || key == KEY_DOWN) drawPointer(pointer);
        if (key == KEY_UP && pointer.y > 0) pointer.y--;
        if (key == KEY_DOWN && pointer.y < 4) pointer.y++;
        if (key == KEY_UP || key == KEY_DOWN) drawPointer(pointer);
    }
    key = 0;
    // turn off gray, so we can destroy auto-int-1 and not mess it up
    GrayOff();

    // DESTROY auto-interrupt 1 so as not to mess up _rowread
    SetIntVec(AUTO_INT_1,DUMMY_HANDLER);

    // turn gray back on
    GrayOn();

    // randomize the map
    randomMap(difficulty, map, level_num);
    //the main game loop
    while (!quit() && !done) {
        done = 0;
        int fin = 0;
        int win = 0;
        int forward = 0;
        int map_x_location = 0;
        int laser = 0;
        int justLaser = 0;
        int missile = 0;
        int justMissile = 0;
        int missileSlow = 2;
        POSITION laserPos;
        POSITION oldLaserPos;
        POSITION missilePos;
        POSITION oldMissilePos;
        POSITION oldShip;
        POSITION ShipPos = {0,5};

        // we need to disable gray temporarily to do the shop screen...
        GrayOff();
        SetIntVec(AUTO_INT_1, interrupt1);
        shop(&money, &cannon_level, &missile_level);
        SetIntVec(AUTO_INT_1, DUMMY_HANDLER);
        GrayOn();

        // draws the level
        Draw_Map(map_x_location, map, ShipPos, laserPos, laser, missilePos, missile);


        // the loop for the action in the level
        while (!quit()) {

            // if the user has a missile out, deal with it
            if (missile && missileSlow == 2) {
                missileSlow = 1;
                oldMissilePos = missilePos;
                missilePos.x++;
                missilePos.y+=missile;
                if (missilePos.x > map_x_location + 20) missile = 0;
                if (missilePos.y < 0 || missilePos.y > 12) {
                    missile = 0;
                    eraseMissile(missilePos, map_x_location);
                }
                if (blowWall(missilePos,map)) {
                    if (map[missilePos.y][missilePos.x] < 4) {
                        map[missilePos.y][missilePos.x]-=3;
                        if (map[missilePos.y][missilePos.x] == 0) {
                            score++;
                            money+=BLOCK_VALUE;
                        }
                    }
                    if (map[missilePos.y][missilePos.x] < 0) map[missilePos.y][missilePos.x] = 0;
                    missile = 0;
                    justMissile = 0;
                    Draw_Map(map_x_location,map,ShipPos,laserPos,laser,missilePos,missile);
                }
                // if the shot was just fired, then there wont be one to erase
                if (!justMissile && missile == 1) {
                    moveMissile(oldMissilePos,missilePos,map_x_location);
                } else if (missile == 1) {
                    drawMissile(missilePos,map_x_location);
                    justMissile = 0;
                } else if (!justMissile && missile == -1) {
                    moveUpMissile(oldMissilePos, missilePos, map_x_location);
                } else if (missile == -1) {
                    drawUpMissile(missilePos, map_x_location);
                    justMissile = 0;
                }

            } else {
                missileSlow++;
            }

            // if the user has a laser shot that is still going, continue it
            if (laser) {
                oldLaserPos = laserPos;
                laserPos.x++;
                if (laserPos.x > map_x_location + 20) laser=0;
                if (blowWall(laserPos,map)) {
                    if (map[laserPos.y][laserPos.x] < 4) {
                        map[laserPos.y][laserPos.x]-=cannon_level;
                        if (map[laserPos.y][laserPos.x] <= 0) {
                            score++;
                            money+=BLOCK_VALUE;
                            map[laserPos.y][laserPos.x] = 0;
                        }
                    } else if (map[laserPos.y][laserPos.x] == 4 && cannon_level == 4) {
                        map[laserPos.y][laserPos.x] = 1;
                    }
                    laser = 0;
                    justLaser = 0;
                    Draw_Map(map_x_location,map,ShipPos,laserPos,laser, missilePos, missile);
                }
                // if the shot was just fired, then there wont be one to erase
                if (!justLaser && laser) {
                    moveLaser(oldLaserPos,laserPos,map_x_location);
                } else if (laser) {
                    drawLaser(laserPos,map_x_location);
                    justLaser = 0;
                }
            }

            // scroll the screen forward one block every (difficulty) time through the main loop
            if (forward == difficulty) {
                map_x_location++;
                ShipPos.x++;
                forward = 0;
                if (map_x_location >= MAP_SIZE - 20) {
                    win = 1;
                    level_num++;
                    break;
                }
                // if you ran into a wall, quit
                if (detectWall(ShipPos,map)) {
                    win = 1;
                    score /= 2 ;
                    break;
                }
                Draw_Map(map_x_location,map,ShipPos,laserPos,laser, missilePos, missile);
            } else {
                forward++;
            }

            // if you ran into a wall, quit
            if (detectWall(ShipPos,map)) {
                win = 1;
                score = 0;
                break;
            }

            if (_rowread(~((short)(1<<1))) & (1<<6) && _rowread(~((short)(1<<2))) & (1<<6)) {
                win = 1;
                level_num++;
                break;
            }

            // get keypresses
            key = _rowread(ARROW_ROW);

            // if the user pressed right, move the ship right
            if (key & keys[RIGHT]) {
                oldShip = ShipPos;
                ShipPos.x++;
                if (ShipPos.x > map_x_location + 18) ShipPos.x--;
                if (!detectWall(ShipPos,map)) {
                    moveShip(oldShip,ShipPos,map_x_location);
                }	else {
                    win = 1;
                    score = 0;
                    break;
                }
            }
            // If the user pressed left, move the ship left
            if (key & keys[LEFT]) {
                oldShip = ShipPos;
                ShipPos.x--;
                if (ShipPos.x < map_x_location) ShipPos.x++;
                if (!detectWall(ShipPos,map)) {
                    moveShip(oldShip,ShipPos,map_x_location);
                } else {
                    win = 1;
                    score = 0;
                    break;
                }
            }

            // if the user pressed up, move the ship up
            if (key & keys[UP]) {
                oldShip = ShipPos;
                if (ShipPos.y - 1 < 0) {
                    ShipPos.y = 0;
                } else {
                    ShipPos.y--;
                }
                if (!detectWall(ShipPos,map))	{
                    moveShip(oldShip,ShipPos,map_x_location);
                } else {
                    win = 1;
                    score = 0;
                    break;
                }
            }

            // if the user pressed down, move the ship down
            if (key & keys[DOWN]) {
                oldShip = ShipPos;
                ShipPos.y++;
                if (ShipPos.y > 10) ShipPos.y = 10;
                if (!detectWall(ShipPos,map)) {
                    moveShip(oldShip,ShipPos,map_x_location);
                } else {
                    win = 1;
                    score = 0;
                    break;
                }
            }

            // if 2nd was pushed, fire the laser
            if (key & keys[SECOND]) {
                if (!laser) {
                    justLaser = 1;
                    laser = 1;
                    laserPos.x = ShipPos.x + 1;
                    laserPos.y = ShipPos.y;
                }
            }

            // if diamond was pushed fire the downward missiles
            if (key & keys[DIAMOND]) {
                if (missile_level == 3 || missile_level == 1) {
                    if (!missile) {
                        justMissile = 1;
                        missile = 1;
                        missileSlow = 2;
                        missilePos.x = ShipPos.x;
                        missilePos.y = ShipPos.y;
                    }
                }
            }

            // if shift was pushed fire the upward missiles
            if (key & keys[SHIFT]) {
                if (missile_level == 2 || missile_level == 3) {
                    if (!missile) {
                        justMissile = 1;
                        missile = -1;
                        missileSlow = 2;
                        missilePos.x = ShipPos.x;
                        missilePos.y = ShipPos.y;
                    }
                }
            }

            /*if (key & keys[ALPHA]) {
            score += 10;
            }*/
            // slow down the program because _rowread is too fast
            delay();
        }



        // back to the overall game loop
        if (win) {
            if (level_num <= LEVEL_NUM) {
                won(difficulty, map, level_num);
            } else {
                fin = 1;
                break;
            }
        }
    }

    // the user left, either by winning or quitting, so make sure everything is reset so the calc will be fine
    GrayOff();
    SetIntVec(AUTO_INT_1,interrupt1);
    hiScoresGo(score, difficulty, level_num);
}