Jump to content
  • Advertisement

phil67rpg

Member
  • Content Count

    1972
  • Joined

  • Last visited

  • Days Won

    2

phil67rpg last won the day on September 1

phil67rpg had the most liked content!

Community Reputation

451 Neutral

2 Followers

About phil67rpg

  • Rank
    Contributor

Personal Information

  • Role
    Programmer
  • Interests
    Programming

Recent Profile Visitors

28650 profile views
  1. phil67rpg

    plane game

    I tweaked my timer function and have figured out my problem, thanks for all the help.
  2. phil67rpg

    plane game

    thanks Euthyphro I will work on my game some more. however I am still stuck on how to draw a collision sprite when the bullet hits the plane, I know this is a small problem.
  3. phil67rpg

    plane game

    well let me explain my blog, I first have drawn two planes using sprites they start on opposite sides of the screen, then they can rotate left and right using either the left or right arrow keys, or the "a" or "d" keys. also the ships can move up and down using the up and down arrow keys or the "w" or "x" keys. furthermore the ships can shoot bullets using the space bar key or the "s" keys. however when a ship gets hit by a bullet I want to draw an animated collision sprite but it does not do this.
  4. phil67rpg

    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; }
  5. 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; }
  6. 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; }
  7. phil67rpg

    C++ win 32 pong

    I am working on a pong game using windows and c++
  8. 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(); } } }
  9. 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.
  10. phil67rpg

    c# bug invaders

    I have made progress. I have drawn a spaceship , a bug and shoot a bullet and a collision bmp when the bullet hits the bug. 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) { timer1.Interval = 20; timer1.Start(); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); } int x = 0, y = 0; 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<=-350) { x = -350; } } if(e.KeyCode == Keys.Right) { x+=5; if(x>=375) { x = 375; } } if (e.KeyCode == Keys.Space) { if (y <= -530) { y = 0; } } } private void timer1_Tick(object sender, EventArgs e) { y -= 5; Invalidate(); } protected override void OnPaintBackground(PaintEventArgs e) { } private void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(this.BackColor); e.Graphics.DrawImage(ship, 350 + x, 530); e.Graphics.DrawImage(bullet, 375 + x, 520 + y); e.Graphics.DrawImage(bug_one, 350, 0); if(y <= -510) { e.Graphics.DrawImage(coll, 350, 0); } } } }
  11. phil67rpg

    c# bug invaders

    well everything works except that the bug flickers. here is my 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(); timer1.Interval = 20; timer1.Start(); } 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) { if (y <= -530) { y = 0; } } } private void timer1_Tick(object sender, EventArgs e) { y -= 5; Invalidate(); } protected override void OnPaintBackground(PaintEventArgs e) { } private void Form1_Paint(object sender, PaintEventArgs e) { Bitmap bug_one = new Bitmap("bug_one.bmp", true); Bitmap ship = new Bitmap("ship.bmp", true); Bitmap bullet = new Bitmap("bullet.bmp", true); e.Graphics.Clear(this.BackColor); e.Graphics.DrawImage(ship, 350 + x, 530); e.Graphics.DrawImage(bullet, 375 + x, 520 + y); e.Graphics.DrawImage(bug_one, 350, 0); e.Graphics.Dispose(); } } }
  12. 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(); } } }
  13. phil67rpg

    c# blackjack graphics

    thanks duke but I think am going to work on a console based blackjack game.
  14. 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) { } } }
  15. phil67rpg

    c# console snake game

    I have made some changes to observers code. I can get the snake to move randomly about the board. here is my updated 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; namespace snakegamegdi { public partial class Form1 : Form { public Form1() { InitializeComponent(); CenterToScreen(); timer1.Interval = 200; timer1.Start(); timer2.Interval = 200; timer2.Start(); } private void Form1_Load(object sender, EventArgs e) { } Random rnd = new Random(); Point food = new Point(385, 275); const int size = 10; Point direction = new Point(size, 0); List<Point> snakelist = new List<Point>() { new Point(380,280) }; private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = this.CreateGraphics(); foreach (var cell in snakelist) { DrawRectangle(g, cell.X, cell.Y, Color.Green); } DrawRectangle(g, food.X, food.Y, Color.Red); g.Dispose(); } private void DrawRectangle(Graphics g, int x, int y, Color color) { SolidBrush brush = new SolidBrush(color); Rectangle rect = new Rectangle(x, y, size, size); g.FillRectangle(brush, rect); brush.Dispose(); } private void timer1_Tick(object sender, EventArgs e) { int newXPos = snakelist[0].X + direction.X; int newYPos = snakelist[0].Y + direction.Y; snakelist.Insert(0, new Point(newXPos, newYPos)); snakelist.RemoveAt(snakelist.Count - 1); if(snakelist[0].X==food.X && snakelist[0].Y==food.Y) { snakelist.Add(new Point(food.X, food.Y)); } Invalidate(); } private void timer2_Tick(object sender, EventArgs e) { int move = rnd.Next(1, 5); switch(move) { case 1: direction.X = size; direction.Y = 0; break; case 2: direction.X = -size; direction.Y = 0; break; case 3: direction.X = 0; direction.Y = -size; break; case 4: direction.X = 0; direction.Y = size; break; } Invalidate(); } } }
  • 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!