Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    18
  • comments
    161
  • views
    3783

About this blog

warlords

Entries in this blog

 

plane game

I am making a game where two planes shoot at each other to start with. here is my code so far. #include <stdlib.h> #include <freeglut.h> #include <iostream> #include "SOIL.h" #include <math.h> GLuint texture[8]; const float PI = 3.14159; float rotate = 0.125f, vertical = 0.0001f, horizontal = 0.0001f, horizontal_one = 0.0001f, vertical_one = 0.0001f, rotate_one = 0.125f, up = 0.0001f, angle = 0.0f, screen = 0.001f, up_two=0.0001f; int flag[4] = { 0 }; static int animate; static int animate_two; bool checkCollide(float x, float y, float oWidth, float oHeight, float xTwo, float yTwo, float oTwoWidth, float oTwoHeight) { // AABB 1 float x1Min = x; float x1Max = x + oWidth; float y1Max = y + oHeight; float y1Min = y; // AABB 2 float x2Min = xTwo; float x2Max = xTwo + oTwoWidth; float y2Max = yTwo + oTwoHeight; float y2Min = yTwo; // Collision tests if (x1Max < x2Min || x1Min > x2Max) return false; if (y1Max < y2Min || y1Min > y2Max) return false; return true; } void SetupRC(void) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, 1.0f, -1.0f); } int LoadGLTextures() { texture[0] = SOIL_load_OGL_texture ( "enemyplane.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); if (texture[0] == 0) return false; texture[1] = SOIL_load_OGL_texture ( "enemyplane.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); if (texture[1] == 0) return false; texture[2] = SOIL_load_OGL_texture ( "bullet.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); if (texture[2] == 0) return false; texture[3] = SOIL_load_OGL_texture ( "coll.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); if (texture[3] == 0) return false; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); return true; } void handleSpecialKeypress(int key, int x, int y) { switch (key) { case GLUT_KEY_UP: if (rotate_one == 0.875f) { vertical_one -= 0.25f; horizontal_one -= 0.25f; } if (rotate_one == 0.625f) { vertical_one -= 0.25f; horizontal_one += 0.25f; } if (rotate_one == 0.125f) { vertical_one += 0.25f; horizontal_one -= 0.25f; } if (rotate_one == 0.375f) { vertical_one += 0.25f; horizontal_one += 0.25f; } if (rotate_one == 0.75f) { vertical_one -= 0.25f; } if (rotate_one == 0.25f) { vertical_one += 0.25f; } if (rotate_one == 0.5f) { horizontal_one += 0.25f; } if (rotate_one == 0.0f) { horizontal_one -= 0.25f; } if (vertical_one >= 9.5f) { vertical_one = 9.5f; } if (vertical_one <= -9.5f) { vertical_one = -9.5f; } if (horizontal_one <= -14.5f) { horizontal_one = -14.5f; } if (horizontal_one >= 4.5f) { horizontal_one = 4.5f; } break; case GLUT_KEY_DOWN: if (rotate_one == 0.875f) { vertical_one += 0.25f; horizontal_one += 0.25f; } if (rotate_one == 0.625f) { vertical_one += 0.25f; horizontal_one -= 0.25f; } if (rotate_one == 0.375f) { vertical_one -= 0.25f; horizontal_one -= 0.25f; } if (rotate_one == 0.125f) { vertical_one -= 0.25f; horizontal_one += 0.25f; } if (rotate_one == 0.25f) { vertical_one -= 0.25f; } if (rotate_one == 0.75f) { vertical_one += 0.25f; } if (rotate_one == 0.5f) { horizontal_one -= 0.25f; } if (rotate_one == 0.0f) { horizontal_one += 0.25f; } if (vertical_one >= 9.5f) { vertical_one = 9.5f; } if (vertical_one <= -9.5f) { vertical_one = -9.5f; } if (horizontal_one >= 4.5f) { horizontal_one = 4.5f; } if (horizontal_one <= -14.5f) { horizontal_one = -14.5f; } break; case GLUT_KEY_RIGHT: rotate_one += 0.125f; if (rotate_one >= 1.0f) { rotate_one = 0.0f; } break; case GLUT_KEY_LEFT: rotate_one -= 0.125f; if (rotate_one <= -0.125f) { rotate_one = 0.875f; } break; } glutPostRedisplay(); } void shoot() { up += 0.5f; if (up >= 15.0f) { animate = 0; up = 0.0f; glutIdleFunc(NULL); } glutPostRedisplay(); } void shoot_two() { up_two += 0.5f; if (up_two >= 15.0f) { animate_two = 0; up_two = 0.0f; glutIdleFunc(NULL); } glutPostRedisplay(); } void handleKeypress(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; case 's': if (animate) { glutIdleFunc(shoot); } else { glutIdleFunc(NULL); } break; case ' ': if (animate_two) { glutIdleFunc(shoot_two); } else { glutIdleFunc(NULL); } break; case 97: rotate += 0.125f; if (rotate >= 1.0f) { rotate = 0.0f; } break; case 100: rotate -= 0.125f; if (rotate <= -0.125f) { rotate = 0.875f; } break; case 119: if (rotate == 0.875f) { vertical -= 0.25f; horizontal += 0.25f; } if (rotate == 0.625f) { vertical -= 0.25f; horizontal -= 0.25f; } if (rotate == 0.125f) { vertical += 0.25f; horizontal += 0.25f; } if (rotate == 0.375f) { vertical += 0.25f; horizontal -= 0.25f; } if (rotate == 0.75f) { vertical -= 0.25f; } if (rotate == 0.25f) { vertical += 0.25f; } if (rotate == 0.5f) { horizontal -= 0.25f; } if (rotate == 0.0f) { horizontal += 0.25f; } if (vertical >= 9.5f) { vertical = 9.5f; } if (vertical <= -9.5f) { vertical = -9.5f; } if (horizontal <= -4.5f) { horizontal = -4.5f; } if (horizontal >= 14.5f) { horizontal = 14.5f; } break; case 120: if (rotate == 0.875f) { vertical += 0.25f; horizontal -= 0.25f; } if (rotate == 0.625f) { vertical += 0.25f; horizontal += 0.25f; } if (rotate == 0.375f) { vertical -= 0.25f; horizontal += 0.25f; } if (rotate == 0.125f) { vertical -= 0.25f; horizontal -= 0.25f; } if (rotate == 0.25f) { vertical -= 0.25f; } if (rotate == 0.75f) { vertical += 0.25f; } if (rotate == 0.5f) { horizontal += 0.25f; } if (rotate == 0.0f) { horizontal -= 0.25f; } if (vertical >= 9.5f) { vertical = 9.5f; } if (vertical <= -9.5f) { vertical = -9.5f; } if (horizontal <= -4.5f) { horizontal = -4.5f; } if (horizontal >= 14.5f) { horizontal = 14.5f; } break; } glutPostRedisplay(); } void drawcollision_one() { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_POLYGON); glTexCoord3f(0.0f + screen, 0.0f, 0.0f); glVertex3f(0.5f, -0.5f, 0.0f); glTexCoord3f(0.167f + screen, 0.0f, 0.0f); glVertex3f(0.5f, 0.5f, 0.0f); glTexCoord3f(0.167f + screen, 1.0f, 0.0f); glVertex3f(-0.5f, 0.5f, 0.0f); glTexCoord3f(0.0f + screen, 1.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.0f); glEnd(); glDisable(GL_TEXTURE_2D); } void timer(int val) { screen += 0.1667f; if (screen >= 1.0f) { screen = 1.0f; } glutPostRedisplay(); glutTimerFunc(500, timer, 0); } void coll_plane_one() { //draw bullet float x = 5.0f+horizontal_one; float y = 0.0f+vertical_one; float oWidth = 0.125f; float oHeight = 0.125f; //draw plane float xTwo = -5.0f+horizontal+up_two; float yTwo = 0.0f+vertical; float oTwoWidth = 1.0f; float oTwoHeight = 1.0f; if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1) { drawcollision_one(); } } void drawplane_one() { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_POLYGON); glTexCoord3f(0.0f + rotate, 0.0f, 0.0f); glVertex3f(-5.5f + horizontal, -0.5f + vertical, 0.0f); glTexCoord3f(0.125f + rotate, 0.0f, 0.0f); glVertex3f(-5.5f + horizontal, 0.5f + vertical, 0.0f); glTexCoord3f(0.125f + rotate, 1.0f, 0.0f); glVertex3f(-4.5f + horizontal, 0.5f + vertical, 0.0f); glTexCoord3f(0.0f + rotate, 1.0f, 0.0f); glVertex3f(-4.5f + horizontal, -0.5f + vertical, 0.0f); glEnd(); glDisable(GL_TEXTURE_2D); } void drawplane_two() { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[1]); glBegin(GL_POLYGON); glTexCoord3f(0.0f + rotate_one, 0.0f, 0.0f); glVertex3f(5.5f + horizontal_one, -0.5f + vertical_one, 0.0f); glTexCoord3f(0.125f + rotate_one, 0.0f, 0.0f); glVertex3f(5.5f + horizontal_one, 0.5f + vertical_one, 0.0f); glTexCoord3f(0.125f + rotate_one, 1.0f, 0.0f); glVertex3f(4.5f + horizontal_one, 0.5f + vertical_one, 0.0f); glTexCoord3f(0.0f + rotate_one, 1.0f, 0.0f); glVertex3f(4.5f + horizontal_one, -0.5f + vertical_one, 0.0f); glEnd(); glDisable(GL_TEXTURE_2D); } void drawbullet_one() { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[2]); glPushMatrix(); if (rotate == 0.25f) { angle = PI / 2.0f; } if (rotate == 0.75f) { angle = (3.0f*PI) / 2.0f; glTranslatef(0.0f, -1.0f, 0.0f); } if (rotate == 0.5f) { angle = PI; glTranslatef(-0.55f, -0.5f, 0.0f); } if (rotate == 0.0f) { angle = 0.0f; glTranslatef(0.55f, -0.5f, 0.0f); } if (rotate == 0.125f) { angle = PI / 4.0f; glTranslatef(0.35f, -0.15f, 0.0f); } if (rotate == 0.375f) { angle = (3.0f*PI) / 4.0f; glTranslatef(-0.35f, -0.15f, 0.0f); } if (rotate == 0.625f) { angle = (5.0f*PI) / 4.0f; glTranslatef(-0.35f, -0.75f, 0.0f); } if (rotate == 0.875f) { angle = (7.0f*PI) / 4.0f; glTranslatef(0.35f, -0.75f, 0.0f); } glTranslatef(0.0f, 0.5f, 0.0f); float r = sqrt(pow(1.0f, 2) + pow(1.0f, 2)); glBegin(GL_POLYGON); glTexCoord3f(0.0f, 0.0f, 0.0f); glVertex3f(-4.9375f+cos(angle)*r*up+horizontal, 0.0625f+sin(angle)*r*up+vertical, 0.0f); glTexCoord3f(1.0f, 0.0f, 0.0f); glVertex3f(-5.0625f+cos(angle)*r*up+horizontal, 0.0625f+sin(angle)*r*up+vertical, 0.0f); glTexCoord3f(1.0f, 1.0f, 0.0f); glVertex3f(-5.0625f+cos(angle)*r*up+horizontal, -0.0625f+sin(angle)*r*up+vertical, 0.0f); glTexCoord3f(0.0f, 1.0f, 0.0f); glVertex3f(-4.9375f+cos(angle)*r*up+horizontal, -0.0625f+sin(angle)*r*up+vertical, 0.0f); glEnd(); glPopMatrix(); glDisable(GL_TEXTURE_2D); } void drawbullet_two() { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[2]); glPushMatrix(); if (rotate_one == 0.25f) { angle = PI / 2.0f; } if (rotate_one == 0.75f) { angle = (3.0f*PI) / 2.0f; glTranslatef(0.0f, -1.0f, 0.0f); } if (rotate_one == 0.5f) { angle = 0.0f; glTranslatef(0.55f, -0.5f, 0.0f); } if (rotate_one == 0.0f) { angle = PI; glTranslatef(-0.55f, -0.5f, 0.0f); } if (rotate_one == 0.125f) { angle = (3.0f*PI) / 4.0f; glTranslatef(-0.35f, -0.15f, 0.0f); } if (rotate_one == 0.375f) { angle = PI / 4.0f; glTranslatef(0.35f, -0.15f, 0.0f); } if (rotate_one == 0.625f) { angle = (7.0f*PI) / 4.0f; glTranslatef(0.35f, -0.75f, 0.0f); } if (rotate_one == 0.875f) { angle = (5.0f*PI) / 4.0f; glTranslatef(-0.35f, -0.75f, 0.0f); } glTranslatef(0.0f, 0.5f, 0.0f); float r = sqrt(pow(1.0f, 2) + pow(1.0f, 2)); glBegin(GL_POLYGON); glTexCoord3f(0.0f, 0.0f, 0.0f); glVertex3f(5.0625f + cos(angle)*r*up_two + horizontal_one, 0.0625f + sin(angle)*r*up_two + vertical_one, 0.0f); glTexCoord3f(1.0f, 0.0f, 0.0f); glVertex3f(4.9375f + cos(angle)*r*up_two + horizontal_one, 0.0625f + sin(angle)*r*up_two + vertical_one, 0.0f); glTexCoord3f(1.0f, 1.0f, 0.0f); glVertex3f(4.9375f + cos(angle)*r*up_two + horizontal_one, -0.0625f + sin(angle)*r*up_two + vertical_one, 0.0f); glTexCoord3f(0.0f, 1.0f, 0.0f); glVertex3f(5.0625f + cos(angle)*r*up_two + horizontal_one, -0.0625f + sin(angle)*r*up_two + vertical_one, 0.0f); glEnd(); glPopMatrix(); glDisable(GL_TEXTURE_2D); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glGenTextures(8, &texture[8]); drawplane_one(); drawplane_two(); drawbullet_one(); drawbullet_two(); coll_plane_one(); glutSwapBuffers(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowPosition(500, 300); glutInitWindowSize(800, 600); glutCreateWindow("1945"); glutTimerFunc(500, timer, 0); glutSpecialFunc(handleSpecialKeypress); glutKeyboardFunc(handleKeypress); glutDisplayFunc(display); SetupRC(); LoadGLTextures(); glutMainLoop(); return 0; }  

phil67rpg

phil67rpg

 

rgg platformer

well I have drawn animated sprite which can move back and  forth across the bottom of the screen just above some grass sprites. here is my code. #include <freeglut.h> #include <iostream> #include<SOIL.h> using namespace std; GLuint texture[8]; float screen = 0.0f; float move_sprite = 0.0f; void update(int value) { screen += 0.125f; if (screen >= 0.875f) { screen = 0.0f; } glutPostRedisplay(); glutTimerFunc(500, update, 0); } void drawSprite() { glEnable(GL_TEXTURE_2D); glPushMatrix(); glBindTexture(GL_TEXTURE_2D, texture[0]); glTranslatef(0.0f, -70.0f, 0.0f); glRotatef(90.0f, 0.0f, 0.0f, 1.0f); glBegin(GL_POLYGON); glTexCoord3f(0.0f + screen, 0.0f, 0.0f); glVertex3f(10.0f, -10.0f+ move_sprite, 0.0f); glTexCoord3f(0.125f + screen, 0.0f, 0.0f); glVertex3f(10.0f, 10.0f+ move_sprite, 0.0f); glTexCoord3f(0.125f + screen, 1.0f, 0.0f); glVertex3f(-10.0f, 10.0f+ move_sprite, 0.0f); glTexCoord3f(0.0f + screen, 1.0f, 0.0f); glVertex3f(-10.0f, -10.0f+ move_sprite, 0.0f); glEnd(); glPopMatrix(); glDisable(GL_TEXTURE_2D); } void drawBkgnd() { glEnable(GL_TEXTURE_2D); glPushMatrix(); glBindTexture(GL_TEXTURE_2D, texture[1]); glTranslatef(0.0f, -90.0f, 0.0f); glRotatef(90.0f, 0.0f, 0.0f, 1.0f); glBegin(GL_POLYGON); glTexCoord3f(0.0f, 0.0f, 0.0f); glVertex3f(10.0f, -50.0f, 0.0f); glTexCoord3f(1.0f, 0.0f, 0.0f); glVertex3f(10.0f, 50.0f, 0.0f); glTexCoord3f(1.0f, 1.0f, 0.0f); glVertex3f(-10.0f, 50.0f, 0.0f); glTexCoord3f(0.0f, 1.0f, 0.0f); glVertex3f(-10.0f, -50.0f, 0.0f); glEnd(); glPopMatrix(); glDisable(GL_TEXTURE_2D); } GLuint loadTex(const char* texname) { /* load an image file directly as a new OpenGL texture */ GLuint texture = SOIL_load_OGL_texture ( texname, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); return texture; } void init() { texture[0] = loadTex("C:\\Users\\Owner\\Desktop\\sprite.png"); texture[1] = loadTex("C:\\Users\\Owner\\Desktop\\bkgnd.png"); } void renderScene(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); drawBkgnd(); drawSprite(); glPopMatrix(); glutSwapBuffers(); } void ChangeSize(GLsizei w, GLsizei h) { GLfloat aspectRatio; if (h == 0) h = 1; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); aspectRatio = (GLfloat)w / (GLfloat)h; if (w <= h) glOrtho(-100.0, 100.0, -100.0 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0); else glOrtho(-100.0*aspectRatio, 100.0*aspectRatio, -100.0, 100.0, 1.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void handleSpecialKeypress(int key, int, int y) { switch (key) { case GLUT_KEY_LEFT: move_sprite++; if (move_sprite >= 125.0f) { move_sprite = 125.0f; } break; case GLUT_KEY_RIGHT: move_sprite--; if (move_sprite <= -125.0f) { move_sprite = -125.0f; } break; } glutPostRedisplay(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(400, 300); glutInitWindowSize(800, 600); glutTimerFunc(500, update, 0); glutCreateWindow("Rpg"); glutDisplayFunc(renderScene); glutReshapeFunc(ChangeSize); glutSpecialFunc(handleSpecialKeypress); init(); glutMainLoop(); return 0; }  

phil67rpg

phil67rpg

 

vetical side scroller

well I am able to draw and move the plane and shoot bullets and move the enemy plane from the top to the bottom of the screen. here is my code so far. #include <freeglut.h> #include <iostream> #include<SOIL.h> using namespace std; GLuint textureBrick[8]; float move_plane = 0.0f; float up = 0.0f; float down = 0.0f; GLuint loadTex(const char* texname) { /* load an image file directly as a new OpenGL texture */ GLuint texture = SOIL_load_OGL_texture ( texname, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); return texture; } void init() { textureBrick[0] = loadTex("C:\\Users\\Owner\\Desktop\\plane.png"); textureBrick[1] = loadTex("C:\\Users\\Owner\\Desktop\\bullet.png"); textureBrick[2] = loadTex("C:\\Users\\Owner\\Desktop\\enemy.png"); } void timer(int) { down--; if (down <= -160.0f) { down = 0.0f; } glutPostRedisplay(); glutTimerFunc(1000.0 / 60.0, timer, 0); } void renderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, textureBrick[2]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(-10.0f, 100.0f + down); glTexCoord2f(1.0f, 0.0f); glVertex2f(10.0f, 100.0f + down); glTexCoord2f(1.0f, 1.0f); glVertex2f(10.0f, 80.0f + down); glTexCoord2f(0.0f, 1.0f); glVertex2f(-10.0f, 80.0f + down); glEnd(); glBindTexture(GL_TEXTURE_2D, textureBrick[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(-10.0f+move_plane, -80.0f); glTexCoord2f(1.0f, 0.0f); glVertex2f(10.0f+move_plane, -80.0f); glTexCoord2f(1.0f, 1.0f); glVertex2f(10.0f+move_plane, -100.0f); glTexCoord2f(0.0f, 1.0f); glVertex2f(-10.0f+move_plane, -100.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, textureBrick[1]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(-2.5f+move_plane, -75.0f+up); glTexCoord2f(1.0f, 0.0f); glVertex2f(2.5f+move_plane, -75.0f+up); glTexCoord2f(1.0f, 1.0f); glVertex2f(2.5f+move_plane, -80.0f+up); glTexCoord2f(0.0f, 1.0f); glVertex2f(-2.5f+move_plane, -80.0f+up); glEnd(); glPopMatrix(); glutSwapBuffers(); glDisable(GL_TEXTURE_2D); } void ChangeSize(GLsizei w, GLsizei h) { GLfloat aspectRatio; if (h == 0) h = 1; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); aspectRatio = (GLfloat)w / (GLfloat)h; if (w <= h) glOrtho(-100.0, 100.0, -100.0 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0); else glOrtho(-100.0*aspectRatio, 100.0*aspectRatio, -100.0, 100.0, 1.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void shoot() { up++; if (up >= 175.0f) { up = 0.0f; glutIdleFunc(NULL); } glutPostRedisplay(); } void handleKeypress(unsigned char key, int x, int y) { int animate = 0; switch(key) { case 27: exit(0); break; case 32: animate = !animate; if (animate) glutIdleFunc(shoot); else glutIdleFunc(NULL); break; } glutPostRedisplay(); } void handleSpecialKeypress(int key, int x, int y) { switch (key) { case GLUT_KEY_LEFT: move_plane--; if (move_plane <= -125.0f) { move_plane = -125.0f; } break; case GLUT_KEY_RIGHT: move_plane++; if (move_plane >= 125.0f) { move_plane = 125.0f; } break; } glutPostRedisplay(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(400, 300); glutInitWindowSize(800, 600); glutCreateWindow("Combat"); glutDisplayFunc(renderScene); glutTimerFunc(1000.0 / 60.0, timer, 0); glutReshapeFunc(ChangeSize); glutKeyboardFunc(handleKeypress); glutSpecialFunc(handleSpecialKeypress); init(); glutMainLoop(); return 0; }  

phil67rpg

phil67rpg

 

bug invaders

I am  working on a space invaders clone called bug invaders. here is my code. let me know what you think. let me know what to do next. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using System.Windows.Forms; using System.Drawing.Imaging; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void Form1_Load(object sender, EventArgs e) { timer1.Interval = 20; timer1.Start(); timer2.Interval = 100; timer2.Start(); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); } int x = 375, y = 520; Bitmap bug_one = new Bitmap("bug_one.bmp", true); Bitmap ship = new Bitmap("ship.bmp", true); Bitmap bullet = new Bitmap("bullet.bmp", true); Bitmap coll = new Bitmap("coll.bmp", true); private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Left) { x-=5; if(x<=0) { x = 0; } } if(e.KeyCode == Keys.Right) { x+=5; if(x>=725) { x = 725; } } if (e.KeyCode == Keys.Space) { if (y <= 0) { y = 520; } } } public class Bug { public int px; public int py; public int width = 30; public int height = 30; public bool drawflag = true; public bool collision = false; public int timer = 0; }; IList<Bug> bugs = new List<Bug>() { new Bug() { px=120, py=0 }, new Bug() { px=180, py=0 }, new Bug() { px=240, py=0 }, new Bug() { px=300, py=0 }, new Bug() { px=360, py=0 }, new Bug() { px=420, py=0 }, new Bug() { px=480, py=0 }, new Bug() { px=540, py=0 }, new Bug() { px=600, py=0 },}; IList<Bug> bugs_one = new List<Bug>() { new Bug() { px=120, py=40 }, new Bug() { px=180, py=40 }, new Bug() { px=240, py=40}, new Bug() { px=300, py=40 }, new Bug() { px=360, py=40 }, new Bug() { px=420, py=40 }, new Bug() { px=480, py=40 }, new Bug() { px=540, py=40 }, new Bug() { px=600, py=40 },}; IList<Bug> bugs_two = new List<Bug>() { new Bug() { px=120, py=80 }, new Bug() { px=180, py=80 }, new Bug() { px=240, py=80}, new Bug() { px=300, py=80 }, new Bug() { px=360, py=80 }, new Bug() { px=420, py=80 }, new Bug() { px=480, py=80 }, new Bug() { px=540, py=80 }, new Bug() { px=600, py=80 },}; IList<Bug> bugs_three = new List<Bug>() { new Bug() { px=120, py=120 }, new Bug() { px=180, py=120 }, new Bug() { px=240, py=120}, new Bug() { px=300, py=120 }, new Bug() { px=360, py=120 }, new Bug() { px=420, py=120 }, new Bug() { px=480, py=120 }, new Bug() { px=540, py=120 }, new Bug() { px=600, py=120 },}; IList<Bug> bugs_four = new List<Bug>() { new Bug() { px=120, py=160 }, new Bug() { px=180, py=160 }, new Bug() { px=240, py=160}, new Bug() { px=300, py=160 }, new Bug() { px=360, py=160 }, new Bug() { px=420, py=160 }, new Bug() { px=480, py=160 }, new Bug() { px=540, py=160 }, new Bug() { px=600, py=160 },}; public void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawImage(ship, x-25, 530); e.Graphics.DrawImage(bullet, x, y); foreach (Bug bug in bugs) { if (bug.collision==false) { e.Graphics.DrawImage(bug_one, bug.px, bug.py); } } foreach (Bug bug in bugs) { if (x >= bug.px && y >= bug.py && x <= bug.px + bug.width && y <= bug.py + bug.height) { e.Graphics.DrawImage(coll, bug.px, bug.py); bug.collision = true; } } foreach (Bug bug in bugs_one) { if (bug.collision == false) { e.Graphics.DrawImage(bug_one, bug.px, bug.py); } } foreach (Bug bug in bugs_one) { if (x >= bug.px && y >= bug.py && x <= bug.px + bug.width && y <= bug.py + bug.height) { e.Graphics.DrawImage(coll, bug.px, bug.py); bug.collision = true; } } foreach (Bug bug in bugs_two) { if (bug.collision == false) { e.Graphics.DrawImage(bug_one, bug.px, bug.py); } } foreach (Bug bug in bugs_two) { if (x >= bug.px && y >= bug.py && x <= bug.px + bug.width && y <= bug.py + bug.height) { e.Graphics.DrawImage(coll, bug.px, bug.py); bug.collision = true; } } foreach (Bug bug in bugs_three) { if (bug.collision == false) { e.Graphics.DrawImage(bug_one, bug.px, bug.py); } } foreach (Bug bug in bugs_three) { if (x >= bug.px && y >= bug.py && x <= bug.px + bug.width && y <= bug.py + bug.height) { e.Graphics.DrawImage(coll, bug.px, bug.py); bug.collision = true; } } foreach (Bug bug in bugs_four) { if (bug.collision == false) { e.Graphics.DrawImage(bug_one, bug.px, bug.py); } } foreach (Bug bug in bugs_four) { if (x >= bug.px && y >= bug.py && x <= bug.px + bug.width && y <= bug.py + bug.height) { e.Graphics.DrawImage(coll, bug.px, bug.py); bug.collision = true; } } } public void timer1_Tick(object sender, EventArgs e) { y -= 5; Invalidate(); } public void timer2_Tick(object sender, EventArgs e) { Invalidate(); } } }  

phil67rpg

phil67rpg

 

c# book

I am studying c# with a book called Microsoft C# 2017 An introduction to object oriented programming. I am on ch7 which deals with methods. wish me all the best in my studies.

phil67rpg

phil67rpg

 

c# bug invaders

well I am working on a space invaders like game. I am using c# and gdi+. I have managed to draw a space ship and have it shoot a bullet, I am just starting. here is my starting code.  using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Drawing.Imaging; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void Form1_Load(object sender, EventArgs e) { } int x = 0, y = 0; private void Form1_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.Left) { x-=5; if(x<=-350) { x = -350; } } if(e.KeyCode == Keys.Right) { x+=5; if(x>=375) { x = 375; } } if (e.KeyCode == Keys.Space) { for(int i=0; i<5;i++) { y -= 5; } if (y <= -530) { y = 0; } } Invalidate(); } private void Form1_Paint(object sender, PaintEventArgs e) { Bitmap ship = new Bitmap("ship.bmp", true); Bitmap bullet = new Bitmap("bullet.bmp", true); Graphics g1 = this.CreateGraphics(); g1.DrawImage(ship, 350+x, 530); g1.DrawImage(bullet, 375, 520 + y); g1.Dispose(); } } }  

phil67rpg

phil67rpg

 

c# blackjack graphics

I am starting a blackjack game  using c# graphics. here is my starting code. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Drawing.Imaging; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void Form1_Load(object sender, EventArgs e) { } public static List<T> Shuffle<T>(List<T> list) { Random rnd = new Random(DateTime.Now.Millisecond); var randomised = list.Select(item => new { item, order = rnd.Next() }) .OrderBy(x => x.order) .Select(x => x.item) .ToList(); return randomised; } private void Form1_MouseDown(object sender, MouseEventArgs e) { Bitmap bitmap_ace_club = new Bitmap("c01.bmp", true); Bitmap bitmap_two_club = new Bitmap("c02.bmp", true); Bitmap bitmap_three_club = new Bitmap("c03.bmp", true); Bitmap bitmap_four_club = new Bitmap("c04.bmp", true); Bitmap bitmap_five_club = new Bitmap("c05.bmp", true); Bitmap bitmap_six_club = new Bitmap("c06.bmp", true); Bitmap bitmap_seven_club = new Bitmap("c07.bmp", true); Bitmap bitmap_eight_club = new Bitmap("c08.bmp", true); Bitmap bitmap_nine_club = new Bitmap("c09.bmp", true); Bitmap bitmap_ten_club = new Bitmap("c10.bmp", true); Bitmap bitmap_jack_club = new Bitmap("c11.bmp", true); Bitmap bitmap_queen_club = new Bitmap("c12.bmp", true); Bitmap bitmap_king_club = new Bitmap("c13.bmp", true); Bitmap bitmap_ace_diamond = new Bitmap("d01.bmp", true); Bitmap bitmap_two_diamond = new Bitmap("d02.bmp", true); Bitmap bitmap_three_diamond = new Bitmap("d03.bmp", true); Bitmap bitmap_four_diamond = new Bitmap("d04.bmp", true); Bitmap bitmap_five_diamond = new Bitmap("d05.bmp", true); Bitmap bitmap_six_diamond = new Bitmap("d06.bmp", true); Bitmap bitmap_seven_diamond = new Bitmap("d07.bmp", true); Bitmap bitmap_eight_diamond = new Bitmap("d08.bmp", true); Bitmap bitmap_nine_diamond = new Bitmap("d09.bmp", true); Bitmap bitmap_ten_diamond = new Bitmap("d10.bmp", true); Bitmap bitmap_jack_diamond = new Bitmap("d11.bmp", true); Bitmap bitmap_queen_diamond = new Bitmap("d12.bmp", true); Bitmap bitmap_king_diamond = new Bitmap("d13.bmp", true); Bitmap bitmap_ace_heart = new Bitmap("h01.bmp", true); Bitmap bitmap_two_heart = new Bitmap("h02.bmp", true); Bitmap bitmap_three_heart = new Bitmap("h03.bmp", true); Bitmap bitmap_four_heart = new Bitmap("h04.bmp", true); Bitmap bitmap_five_heart = new Bitmap("h05.bmp", true); Bitmap bitmap_six_heart = new Bitmap("h06.bmp", true); Bitmap bitmap_seven_heart = new Bitmap("h07.bmp", true); Bitmap bitmap_eight_heart = new Bitmap("h08.bmp", true); Bitmap bitmap_nine_heart = new Bitmap("h09.bmp", true); Bitmap bitmap_ten_heart = new Bitmap("h10.bmp", true); Bitmap bitmap_jack_heart = new Bitmap("h11.bmp", true); Bitmap bitmap_queen_heart = new Bitmap("h12.bmp", true); Bitmap bitmap_king_heart = new Bitmap("h13.bmp", true); Bitmap bitmap_ace_spade = new Bitmap("s01.bmp", true); Bitmap bitmap_two_spade = new Bitmap("s02.bmp", true); Bitmap bitmap_three_spade = new Bitmap("s03.bmp", true); Bitmap bitmap_four_spade = new Bitmap("s04.bmp", true); Bitmap bitmap_five_spade = new Bitmap("s05.bmp", true); Bitmap bitmap_six_spade = new Bitmap("s06.bmp", true); Bitmap bitmap_seven_spade = new Bitmap("s07.bmp", true); Bitmap bitmap_eight_spade = new Bitmap("s08.bmp", true); Bitmap bitmap_nine_spade = new Bitmap("s09.bmp", true); Bitmap bitmap_ten_spade = new Bitmap("s10.bmp", true); Bitmap bitmap_jack_spade = new Bitmap("s11.bmp", true); Bitmap bitmap_queen_spade = new Bitmap("s12.bmp", true); Bitmap bitmap_king_spade = new Bitmap("s13.bmp", true); List<int> cards = new List<int>(52); for (int i = 0; i < 52; i++) { cards.Add(i); } cards = Shuffle(cards); if (e.Button == MouseButtons.Left) { Graphics g1 = this.CreateGraphics(); g1.DrawImage(bitmap_king_spade, 360, 20); g1.Dispose(); } } private void Form1_Paint(object sender, PaintEventArgs e) { } } }  

phil67rpg

phil67rpg

 

c# console snake game

I have decided to work on a console based snake game, I am doing this because I want to learn basic c# skills before move on to c#  graphics programming. I am able to move the snake from the center to the edge of the screen, it is just a start, but I am learning. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace snakegame { class Program { static void Main(string[] args) { const int board_size = 17; char[,] board = new char[board_size, board_size]; int horizontal = 5, vertical = 8, count = 0; for (int i = 0; i < board_size; i++) { for (int j = 0; j < board_size; j++) { board[i, j] = '.'; } } void draw_board() { for (int i = 0; i < board_size; i++) { for (int j = 0; j < board_size; j++) { Console.Write(board[i, j]); } Console.WriteLine(); } } while (count < 6) { board[vertical, horizontal] = '*'; board[vertical, horizontal + 1] = '*'; board[vertical, horizontal + 2] = '*'; board[vertical, horizontal + 3] = '*'; board[vertical, horizontal + 4] = '*'; board[vertical, horizontal + 5] = '*'; board[vertical, horizontal + 6] = '*'; draw_board(); horizontal++; count++; System.Threading.Thread.Sleep(1000); Console.Clear(); } } } }  

phil67rpg

phil67rpg

 

c# snake game

well like suggested I am going to make a snake game. here is my code so far. I was told it is easier then blackjack. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void Form1_Paint(object sender, PaintEventArgs e) { } int x = 0, y = 0; private void timer1_Tick(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); SolidBrush greenBrush = new SolidBrush(Color.Green); SolidBrush blackBrush = new SolidBrush(Color.Black); Rectangle rect_green = new Rectangle(340 + x, 280 + y, 10, 100); Rectangle rect_black = new Rectangle(340 + x, 180 + y, 10, 100); g.FillRectangle(greenBrush, rect_green); g.FillRectangle(blackBrush, rect_black); if (x >= 340) { x = 340; } y += 5; greenBrush.Dispose(); g.Dispose(); } } }    

phil67rpg

phil67rpg

 

c# blackjack

I am starting on a blackjack game using c#. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { enum suit { C=1, D, H, S}; enum face { J=11, Q, K, A}; static void Main(string[] args) { Random rand = new Random(); int card = rand.Next(2, 15); int card_suit = rand.Next(1, 5); if (card >= 2 && card <=10) { Console.Write(card); } else if(card==11) { Console.Write(face.J); } else if (card == 12) { Console.Write(face.Q); } else if (card == 13) { Console.Write(face.K); } else if (card == 14) { Console.Write(face.A); } if (card_suit == 1) { Console.WriteLine(suit.C); } if (card_suit == 2) { Console.WriteLine(suit.D); } if (card_suit == 3) { Console.WriteLine(suit.H); } if (card_suit == 4) { Console.WriteLine(suit.S); } } } }  

phil67rpg

phil67rpg

 

c# tic tac toe game

here is my code for my tic tac toe game, I am still working on the computer player. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace wintictactoe { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } int [,] board_x=new int[3,3]; int[,] board_o = new int[3, 3]; private void Form1_MouseDown(object sender, MouseEventArgs e) { if(e.Button == MouseButtons.Left) { Random rnd = new Random(); int col = rnd.Next(325, 476); int row = rnd.Next(200, 351); Graphics g1 = this.CreateGraphics(); if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 200 && e.Y - 10 <= 250) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215)); board_x[0, 0] = 1; } if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 200 && e.Y - 10 <= 250) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 215)); board_x[0, 1] = 1; } if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 200 && e.Y - 10 <= 250) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 215)); board_x[0, 2] = 1; } if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 250 && e.Y - 10 <= 300) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 260)); board_x[1, 0] = 1; } if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 250 && e.Y - 10 <= 300) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 260)); board_x[1, 1] = 1; } if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 250 && e.Y - 10 <= 300) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 260)); board_x[1, 2] = 1; } if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 300 && e.Y - 10 <= 350) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 315)); board_x[2, 0] = 1; } if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 300 && e.Y - 10 <= 350) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 315)); board_x[2, 1] = 1; } if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 300 && e.Y - 10 <= 350) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 315)); board_x[2, 2] = 1; } if (col >= 325 && col <= 375 && row >= 200 && row <= 250) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215)); board_o[0, 0] = 1; } if (col >= 375 && col <= 425 && row >= 200 && row <= 250) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 215)); board_o[0, 1] = 1; } if (col >= 425 && col <= 475 && row >= 200 && row <= 250) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 215)); board_o[0, 2] = 1; } if (col >= 325 && col <= 375 && row >= 250 && row <= 300) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 260)); board_o[1, 0] = 1; } if (col >= 375 && col <= 425 && row >= 250 && row <= 300) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 260)); board_o[1, 1] = 1; } if (col >= 425 && col <= 475 && row >= 250 && row <= 300) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 260)); board_o[1, 2] = 1; } if (col >= 325 && col <= 375 && row >= 300 && row <= 350) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 315)); board_o[2, 0] = 1; } if (col >= 375 && col <= 425 && row >= 300 && row <= 350) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 315)); board_o[2, 1] = 1; } if (col >= 425 && col <= 475 && row >= 300 && row <= 350) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 315)); board_o[2, 2] = 1; } g1.Dispose(); } } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen redPen = new Pen(Color.Red,3); g.DrawLine(redPen, 375, 200, 375, 350); g.DrawLine(redPen, 425, 200, 425, 350); g.DrawLine(redPen, 325, 250, 475, 250); g.DrawLine(redPen, 325, 300, 475, 300); g.Dispose(); } } }  

phil67rpg

phil67rpg

 

c# pong game

I am working on a pong game using c# and gdi+. here is my code so far. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace winpong { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } int move = 0; float comp_move = 0.0f, comp_velocity = 1.0f, screen_height = 250.0f, flag = 0.0f; public void Form1_KeysDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Up)//key up { move-=5; if (move <= -250) { move = -250; } } if (e.KeyCode == Keys.Down)//key down { move+=5; if(move >= 210) { move = 210; } } Invalidate(); } private void timer1_Tick(object sender, EventArgs e) { comp_velocity = (comp_move < screen_height && flag == 0.0f) ? (comp_velocity = 5.0f) : (comp_velocity = -5.0f); comp_move = (comp_velocity == 5.0f) ? (comp_move += 5.0f) : (comp_move -= 5.0f); if(comp_move >= screen_height-40.0f) { flag = 1.0f; } if(comp_move <= -screen_height) { flag = 0.0f; } Invalidate(); } float x = 0.0f, y = 0.0f, xstep = 5.0f, ystep = 5.0f; private void timer2_Tick(object sender, EventArgs e) { if (x >= 395.0f || x <= -390.0f) { xstep = -xstep; } if (y >= 270.0f || y <= -290.0f) { ystep = -ystep; } x += xstep; y += ystep; Invalidate(); } public void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; SolidBrush blueBrush = new SolidBrush(Color.Blue); SolidBrush redBrush = new SolidBrush(Color.Red); SolidBrush whiteBrush = new SolidBrush(Color.White); RectangleF rect1 = new RectangleF(0, 250 + comp_move, 35, 100); //blue paddle Rectangle rect2 = new Rectangle(750, 250 + move, 35, 100); //red paddle RectangleF rect3 = new RectangleF(390+x, 290+y, 10, 10); //white ball g.FillRectangle(blueBrush, rect1); g.FillRectangle(redBrush, rect2); g.FillRectangle(whiteBrush, rect3); g.Dispose(); } } }  

phil67rpg

phil67rpg

 

1942 plane game

Well I have a peculiar problem. When I set my global variable screen=0.0f and I put my drawcollision_one() function in my display function it only draws a static collision sprite. However when I set my screen=0.0001f and I put my drawcollision_one() in my display function it draws an animated collision sprite. Also when I use my screen=-0.0f variable and I put my drawcollision_one() function in my collision detection function it draws a static collision sprite. However when I use my screen=0.0001f variable it does not draw anything when the drawcollision_one() function is in my collision detection function. What I want is to draw the animated collision sprite when the collision detection function is used. Let me know if you need further explanation.I am using freeglut 3.0.0 and SOIL in my program.

phil67rpg

phil67rpg

 

1943 Plane Game

I am still working on my 1943 plane game. I have got the one plane to move and shoot bullets in all directions. I am going to do the same for the second plane.

phil67rpg

phil67rpg

 

1945 game

I am still working on my 1945 plane game. I am stuck on how to rotate the bullet sprite around the plane sprite. I am using trig. functions and some linear algebra which is what I am taking in college classes. here is the code I am using. void drawbullet_one() { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[2]); glPushMatrix(); glTranslatef(-5.0f, 0.5f, 0.0f); glBegin(GL_POLYGON); glTexCoord3f(0.0f, 0.0f, 0.0f); glVertex3f(0.0625f*cos(angle) - 0.0625f*sin(angle), 0.0625f*sin(angle) + 0.0625f*cos(angle)+up, 0.0f); glTexCoord3f(1.0f, 0.0f, 0.0f); glVertex3f(-0.0625f*cos(angle) - 0.0625f*sin(angle), -0.0625f*sin(angle) + 0.0625f*cos(angle)+up, 0.0f); glTexCoord3f(1.0f, 1.0f, 0.0f); glVertex3f(-0.0625f*cos(angle) + 0.0625f*sin(angle), -0.0625f*sin(angle) + -0.0625f*cos(angle)+up, 0.0f); glTexCoord3f(0.0f, 1.0f, 0.0f); glVertex3f(0.0625f*cos(angle) + 0.0625f*sin(angle), 0.0625f*sin(angle) + -0.0625f*cos(angle)+up, 0.0f); glEnd(); glTranslatef(5.0f, -0.5f, 0.0f); glPopMatrix(); glDisable(GL_TEXTURE_2D); }  

phil67rpg

phil67rpg

 

plane game

well I have drawn two plane sprites and have them move around the screen using keys. one them can also shoot bullets, I have drawn an animated collision sprite

phil67rpg

phil67rpg

Sign in to follow this  
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!