Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Challenge: 2D Tank

Name: Anonymous 2010-05-14 15:43

The Challenge:
|---->Program a 2d tank application in the language of your choice that adheres to the following:

#-The tank must rotate using the left and right directional keys.
#-The tank must loosely resemble a tank.
#-The tank must move forward or backward respectively from the direction it is facing using the up and down directional keys.
#-Pressing spacebar must fire a 'shot' in the direction the tank is facing.
#-The perspective of the user must be fixed and facing down at the tank.
#-The tank, shot, and ground must each have their own color. (all shots may have the same color)


<------You have 24 hours!------>
GET TO WORK!

Name: Anonymous 2010-05-18 13:28

>>118
Expert Eclipse user.

Name: Anonymous 2010-05-18 18:50

>>118
I find it interesting that, in the phrase first use in this function, all of the words except for first are highlighted as keywords.

Maybe this is some sort of protest message against the use of first/rest in place of car/cdr in Lisp?

Name: Anonymous 2010-05-18 19:26

car use in this function

Name: Anonymous 2010-05-19 15:58

We need more threads like this. Can we get a date for the next one?

Name: Anonymous 2010-05-19 16:06

>>124
whenever someone thinks up a new one

Name: Anonymous 2010-05-19 17:48

fixed or not, use string in this function

Name: Anonymous 2010-05-19 18:33

>>117
So what about if I install with setup.exe? And if I were to compile it myself, how ought I to configure it?

Name: Anonymous 2010-05-19 19:30


goto register for new and explicit private friend

Name: Anonymous 2010-05-19 19:39


do do do do do do do#########################################
for do do do do goto
do do do do do do do#########################################
for do do do do goto
do do do do do do do#########################################
for do do do do goto
do do do do do do do#########################################

#############################################################

#############################################################

#############################################################

Name: Anonymous 2010-05-19 19:43


____________________________
|                           |
|                           |
|            /**/           |
|          /******/         |
|        /**********/       |
|       /************/      |
|        /**********/       |
|          /******/         |
|            /**/           |
|                           |
|                           |
|___________________________|

Name: Anonymous 2010-05-19 19:45

BONJOUR MY ANUS

reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################
reinterpret_case                ################

Name: Anonymous 2010-05-19 19:46

MERDE! J'AI ULTRAFAIL

reinterpret_cast                ################
reinterpret_cast                ################
reinterpret_cast                ################
reinterpret_cast                ################
reinterpret_cast                ################
reinterpret_cast                ################
reinterpret_cast                ################
reinterpret_cast                ################
reinterpret_cast                ################
reinterpret_cast                ################
reinterpret_cast                ################
reinterpret_cast                ################

Name: Anonymous 2010-05-19 19:47

CIAO MY ANUS

"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS
"HAXMYANUSHAXMYANUS"                  #HAXMYANUSHAXMYANUS

Name: Anonymous 2010-05-19 19:53

Do Vatican City next.

Name: Anonymous 2010-05-19 19:56

>>134
n ou

Name: Anonymous 2010-05-19 21:51

Bump for /prog/scii art. This is a truly innovative art form the likes of which has likely never been seen before.

Name: Anonymous 2010-05-19 23:02

>>132
Oh this is legendary.

Name: Anonymous 2010-05-20 1:43

Ill get right to that, as soon as I figure out how to get this snot off my fingers

Name: Anonymous 2010-05-20 6:53


/**/   extern  /**/ extern    /**/
  /**/   goto  /**/ goto    /**/
if  /**/   if  /**/ if    /**/  if
goto  /**/     /**/     /**/  goto
extern  /**/   /**/   /**/  extern
operator  /**/ /**/ /**/  operator
               /**/
/*********************************/
/*********************************/
               /**/
operator  /**/ /**/ /**/  operator
extern  /**/   /**/   /**/  extern
goto  /**/     /**/     /**/  goto
if  /**/   if  /**/ if    /**/  if
  /**/   goto  /**/ goto    /**/
/**/   extern  /**/ extern    /**/

Name: Anonymous 2010-05-20 6:55

>>139
God save the queen! ಥ_ಥ

Name: Anonymous 2010-05-20 9:53

Fuck America, we got real liberty.

##################################################
##################################################
##################################################
##################################################
##################################################
##################################################
##################################################







reinterpret_cast reinterpret_cast reinterpret_cast
reinterpret_cast reinterpret_cast reinterpret_cast
reinterpret_cast reinterpret_cast reinterpret_cast
reinterpret_cast reinterpret_cast reinterpret_cast
reinterpret_cast reinterpret_cast reinterpret_cast
reinterpret_cast reinterpret_cast reinterpret_cast
reinterpret_cast reinterpret_cast reinterpret_cast

Name: Anonymous 2010-05-20 11:39

>>141
Luxembourg?

Name: Anonymous 2010-05-20 12:12

>>141
Why is the bottom right black?

Name: Anonymous 2010-05-20 12:16


####################################################
####################################################
####################################################
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::
####################################################
####################################################
####################################################

Name: Anonymous 2010-05-20 12:55

It's to show the multicutural society of the Netherlands

Name: Anonymous 2010-05-20 13:10

>>145
or more likey:

BB CODE FAIL

Name: Anonymous 2010-05-20 13:57

Java has saved us all!

Name: Anonymous 2010-05-20 14:21

>>147
Java
saved

I don't think so, Tim!

Name: Anonymous 2010-05-20 15:01

Isn't there any image apart from a flag that's comprised of nothing but red, green, blue, #EFEFEF and black?

Name: Anonymous 2010-05-20 17:26

. /  | /  / /  /  / // / ハ.    ヽ    ヽ. \
/' 丁|'  i l /   /// 〃/  \ ̄ \!     |\|
\/ j|  ,レ' _ / /.///./  _ \  |\. | |/
. /__」ヒ.´_彡'_>=,ニドノ'  //  'ァ,.'ニ=<} '  | | 
/  {{ ̄ { \ #⌒!|  //    "⌒!i ノ ,'   /! /
,/  {ハ..  \__, ゞ冖^  /' !     ̄^` ブ ///
   ハ. \   く             __  ∠ イ ,ノ'
  ,/ ,ハ 7`ト _,>       __,. イ !   /〃/
f´ ̄ヽ ヾ、'.{}ヘ.     `'マ二..__ /   /{}ヽ》
_) >┴=く¨ヽ ヽ.、       --     , イ   }}
/  '´   \レ-、V__. 、      _,. イ/{{ヽ{}/《
  .'      `て{ ヽ\ `  -- /  / {{-- −}}
 '    '    __j| ,ヘ \.  ∧_/  {{ /{}ヽ }}
,'    ,'   (_ |ヽ{i,ハ   ヽ、」.  \ {{.    }}
    ,'     〕|__ __ |/.,二f丑:‐ 、\{ ヽ {} /}}
         ( }}/{}ヽ|/  /ハ 「 \ヽ|{ ー i ‐.}}

Name: Anonymous 2010-05-20 19:03

>>150
Sugoi!

Name: Anonymous 2010-05-20 20:45

>>150
Excellent use of code tags.

Name: Anonymous 2010-05-20 21:48


#include <SDL/SDL.h>
#include <OpenGL/gl.h>
#include <iostream>
#include <list>
#include <math.h>
#include "Sound.h"

#define square(x) ((x) * (x))

enum Type {kSprite, kObstacle, kLaser, kTank};

using namespace std;

list<struct Sprite*> gSprites;
unsigned char *gKeys;
float gTime = 0.0; // time in seconds
float gTimeIncrement;

struct Point{
    float x, y;
    };

// should draw in range -1 to 1
struct Sprite{
    float x, y;
    float oldX, oldY;
    float angle;
    float size;
    float speed;
    float turn;
    int player; // 0 is non-player sprite
    Type type;
    void MoveTo(float newX, float newY){
        oldX = x, oldY = y;
        x = newX, y = newY;
        }
    void UndoMove(){ x = oldX, y = oldY; }
    float Speed() { return speed * gTimeIncrement; }
    float Turn() { return turn * gTimeIncrement; }
    void Forward(float distance) {
        MoveTo(x + distance * sin(angle),
            y + distance * cos(angle));
        }
    // translate to global coordinates
    Point Vector(float pX, float pY){
        Point p;
        float sine = sin(angle), cosine = cos(angle);
        p.x = size * (pY * sine + pX * cosine);
        p.y = size * (pY * cosine - pX * sine);
        return p;
        }
    Point Global(float pX, float pY){
        Point p;
        float sine = sin(angle), cosine = cos(angle);
        p.x = size * (pY * sine + pX * cosine) + x;
        p.y = size * (pY * cosine - pX * sine) + y;
        return p;
        }
    virtual void Draw() {}
    virtual void Move() { Forward(Speed()); }
    virtual void Collision(Sprite *sprite) {}
    Sprite(){
        x = 0, y = 0;
        angle = 0, size = 10;
        speed = 0, turn = 4;
        player = 0, type = kSprite;
        }
    };

struct Maze : Sprite{
   
    virtual void Draw(){
        glLineWidth(10.0);
        glBegin(GL_LINE_STRIP);
        glColor3f(0,1,0);
        glVertex2f(-99,-74);
        glVertex2f(99,-74);
        glVertex2f(99,74);
        glVertex2f(-99,74);
        glVertex2f(-99,-74);
        glEnd();
        }
    Maze(){ size = 1; }
    };

struct Obstacle : Sprite{
    virtual void Draw(){
        float i;
        glLineWidth(3);
        glBegin(GL_LINE_STRIP);
        glColor3f(0,1,0);
        for(i = 0; i < 2 * M_PI; i += .4)
            glVertex2f(cos(i),sin(i));
        glVertex2f(cos(2 * M_PI), sin(2 * M_PI));
        glEnd();
        }
    Obstacle(float pX, float pY, float theSize){
        x = pX, y = pY, size = theSize, type = kObstacle;
        }
    };

struct Laser : Sprite{
    float decay; // invisible once decay == 0
    bool bounced; // only bounces once
    virtual void Move() {
        if(decay <= 0) gSprites.remove(this);
        decay -= gTimeIncrement * (bounced ? .6 : .3);
        Sprite::Move();
        }
    virtual void Draw(){
        glLineWidth(5.0);
        glBegin(GL_LINES);
        glColor4f(1, .5, 0, decay);
        glVertex2f(0,-1);
        glColor4f(1, 1, 0, decay);
        glVertex2f(0,1);
        glEnd();
        }
    virtual void Collision(Sprite *s){
        if(!bounced){
            switch(s->type){
                case kTank:
                    if(s->player != player){
                        Point impact = Vector(0,.02);
                        s->x += impact.x;
                        s->y += impact.y;
                        }
                    else break;
                case kObstacle:
                    angle += M_PI + ((rand() %101) - 50.0) / 50.0;
                    bounced = true;
                };
            }
        }
    Laser(int thePlayer, Point p, float a){
        x = p.x, y = p.y, size = 10,
        angle = a, speed = 80;
        player = thePlayer, type = kLaser;
        decay = 1.0, bounced = false;
       
        }
    };

struct Tank : Sprite{
    int fireAngle; // 0,1, or 2
    int soundChannel;
    void ShootLaser() {
        float laserAngle = ((rand() % 41) - 20.0) / 200.0 + angle;
        gSprites.push_back(new Laser(player,Global(0,.7),laserAngle));
        if(soundChannel == -1 || !IsPlaying(soundChannel));
            soundChannel = PlaySound("laser2");
        }
    virtual void Draw(){
        glBegin(GL_TRIANGLES);
        glColor3f(0, .5, 1);
        glVertex2f(-1, -1);
        glVertex2f(1, -1);
        glColor3f(0,1,1);
        glVertex2f(0,1);
        glEnd();
        }
    virtual void Collision(Sprite *sprite){
        if(sprite->type == kObstacle) UndoMove();
        }
    Tank(){
        size = 7; speed = 40; type = kTank, soundChannel = -1;
        }
    };

struct Player : Tank{
    virtual void Move(){
        if(player == 1){
            if(gKeys[SDLK_RIGHT]) angle += Turn();
            if(gKeys[SDLK_LEFT]) angle -= Turn();
            if(gKeys[SDLK_UP]) Forward(Speed());
            if(gKeys[SDLK_DOWN]) Forward(-Speed());
            if(gKeys[SDLK_SPACE]) ShootLaser();
            }
        if(player == 2){
            if(gKeys[SDLK_e]) angle += Turn();
            if(gKeys[SDLK_a]) angle -= Turn();
            if(gKeys[SDLK_COMMA]) Forward(Speed());
            if(gKeys[SDLK_o]) Forward(-Speed());
            if(gKeys[SDLK_TAB]) ShootLaser();
            }
        }
    Player(int playerNumber){
        player = playerNumber;
        if(player == 1) x = 80, angle -= M_PI / 2.0;
        if(player == 2) x = -80, angle += M_PI / 2.0;
        }
    };

int gDone;// = 0;

void MoveSprites();
void DetectCollisions();
void DrawSprites();

int SDL_main(int argc,char* argv[])
{
SDL_Surface *screen;
SDL_Event event;

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
InitializeSound();
LoadSounds();

screen = SDL_SetVideoMode(800, 600, 32, SDL_OPENGL/* | SDL_FULLSCREEN*/);
glViewport(0, 0, screen->w, screen->h);
glOrtho(-100, 100, -75, 75, 0, 1);
glClearColor(0, 0, 0, 1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_LINE_SMOOTH);

gSprites.push_back(new Maze());
gSprites.push_back(new Obstacle(50,40,20));
gSprites.push_back(new Obstacle(-30,-10,30));
gSprites.push_back(new Obstacle(60,-20,10));

gSprites.push_back(new Player(1));
gSprites.push_back(new Player(2));

while(!gDone){
    if(!SDL_PollEvent(&event)){
        gKeys = SDL_GetKeyState(NULL);
        gTimeIncrement = (double)SDL_GetTicks() / (double)1000.0 - gTime;
        gTime += gTimeIncrement;
       
        MoveSprites();
        DetectCollisions();
        DrawSprites();
        SDL_Delay(15);
        continue;
        }
    switch(event.type){
        case SDL_MOUSEBUTTONDOWN:
            gDone = 1;
            break;
        }
    }

SDL_Quit();

return 0;
}

void MoveSprites()
{
list<Sprite*>::iterator i;

for(i = gSprites.begin(); i != gSprites.end(); ++i)
    (*i)->Move();
}

void DetectCollisions()
{
list<Sprite*>::iterator i;

//cerr << "@";
for(i = gSprites.begin(); i != gSprites.end(); ++i){
    Sprite *sprite = (*i);
    list<Sprite*>::iterator i2 = i;
   
    //cerr << ".";
    for(++i2; i2 != gSprites.end(); ++i2){
        Sprite *sprite2 = (*i2);
        float dx = sprite2->x - sprite->x;
        float dy = sprite2->y - sprite->y;
       
        //cerr << "!";
        // first objects are probably more permanent
        // (bullets might want to delete themselves on collision)
        if(square(dx) + square(dy) <= square(sprite->size + sprite2->size)){
            //cerr << "W";
            sprite->Collision(sprite2);
            sprite2->Collision(sprite);
            }
        }
    }
}

void DrawSprites()
{
list<Sprite*>::iterator i;

glClear(GL_COLOR_BUFFER_BIT);
for(i = gSprites.begin(); i != gSprites.end(); ++i){
    Sprite *sprite = *i;
    float spriteSize = sprite->size;
   
    glPushMatrix();
    glTranslatef(sprite->x, sprite->y, 0);
    glRotatef(180.0 * sprite->angle / M_PI, 0, 0, -1);
    glScalef(spriteSize, spriteSize, spriteSize);
    sprite->Draw();
    glPopMatrix();
    }
SDL_GL_SwapBuffers();
}

Name: Anonymous 2010-05-21 0:19

>>153
It's 2 player!  If only I had friends...

Name: Anonymous 2010-05-21 1:19

>>154
So submit an RFE to include "new friends."

Name: Anonymous 2010-05-21 12:13

>>153
to run on *nix :

--- original.cpp    2010-05-21 18:06:19.913591576 +0200
+++ linux.cpp    2010-05-21 18:11:20.216878465 +0200
@@ -1,9 +1,9 @@
+/* g++ -lSDL -lGL tank.cpp && ./a.out */
 #include <SDL/SDL.h>
-#include <OpenGL/gl.h>
+#include <GL/gl.h>
 #include <iostream>
 #include <list>
 #include <math.h>
-#include "Sound.h"
 
 #define square(x) ((x) * (x))
 
@@ -143,12 +143,9 @@
 
 struct Tank : Sprite{
     int fireAngle; // 0,1, or 2
-    int soundChannel;
     void ShootLaser() {
         float laserAngle = ((rand() % 41) - 20.0) / 200.0 + angle;
         gSprites.push_back(new Laser(player,Global(0,.7),laserAngle));
-        if(soundChannel == -1 || !IsPlaying(soundChannel));
-            soundChannel = PlaySound("laser2");
         }
     virtual void Draw(){
         glBegin(GL_TRIANGLES);
@@ -163,7 +160,7 @@
         if(sprite->type == kObstacle) UndoMove();
         }
     Tank(){
-        size = 7; speed = 40; type = kTank, soundChannel = -1;
+        size = 7; speed = 40; type = kTank;
         }
     };
 
@@ -197,14 +194,12 @@
 void DetectCollisions();
 void DrawSprites();
 
-int SDL_main(int argc,char* argv[])
+int main(int argc,char* argv[])
 {
 SDL_Surface *screen;
 SDL_Event event;
 
 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
-InitializeSound();
-LoadSounds();
 
 screen = SDL_SetVideoMode(800, 600, 32, SDL_OPENGL/* | SDL_FULLSCREEN*/);
 glViewport(0, 0, screen->w, screen->h);

Name: Anonymous 2010-05-21 12:20

>>156
RUN ON MY ANUS

Name: Anonymous 2010-05-21 14:49

I didn't even use any classes.

import sys, os
import pygame
import math
import random
import time
from pygame.locals import *

if not pygame.font : print "Fonts's turned off"
if not pygame.mixer : print "Sound's turned off"
if not pygame.key : print "Input's turned off"

pygame.init ()
pygame.font.init()
clock = pygame.time.Clock()
def input(events):
    for event in events:
        if event.type == QUIT:
            sys.exit (0)
        else :
            print event
           
os.environ['SDL_VIDEO_CENTERED'] = '1'
window = pygame.display.set_mode ((800, 600))
pygame.display.set_caption (' Simple Shooter' )
screen = pygame.display.get_surface ()


tangent = pygame.key.get_pressed
spelare_y = 0
spelare_x = 100
spelare_rect = pygame.Rect (spelare_x, spelare_y, 80, 60 )

pos_x = 400
pos_y = 400
target_rect = pygame.Rect (pos_x, pos_y, 80, 60)

cirkel_y = spelare_y
cirkel_x = spelare_x + 50
cirkel_rect = pygame.Rect (cirkel_x, cirkel_y, 30, 30)
cirkel_aktiv = 0

targetz = 0

font = pygame.font.SysFont (None, 48)
font_2 = pygame.font.SysFont (None, 22)
start_text = font.render ("A GAME!", True, (255,255,255))
score_int = 0
score_str = str(score_int)
score_text = font_2.render ("Score:" + score_str, True, (255,255,255))

screen.blit (start_text, (0,0))
pygame.display.update()
time.sleep (3.0)
screen.fill ((0,0,0))

while True:
    pygame.key.get_pressed()
    input(pygame.event.get())
    clock.tick(60)
    if tangent() [K_ESCAPE] == True:
        pygame.quit()
        sys.exit()
       
    if tangent() [K_UP]== True:
        if spelare_y >= 15 :
            spelare_y = spelare_y - 15
            if cirkel_aktiv == 0:
                cirkel_y = spelare_y
               
    if tangent () [K_DOWN] == True:
        if spelare_y <= 525:
            spelare_y = spelare_y + 15
            if cirkel_aktiv == 0:
                cirkel_y = spelare_y

    if pos_y >= 15:
           
        pos_y = pos_y + random.choice ([-4,-5,-2, -3, +2, +3])
        target_rect = pygame.Rect (pos_x, pos_y, 80, 60)

       
        if pos_y <= 525 +60:
            
            pos_y = pos_y + random.choice ([+8,+4,+3, - 3, -2, -5])
            target_rect = pygame.Rect (pos_x, pos_y, 80, 60)
           
       
    if tangent () [K_SPACE] == True:
        cirkel_aktiv = 1
       
    if cirkel_aktiv == 1:
        cirkel_x = cirkel_x + 10
        pygame.draw.circle(screen, (30,97,200), (cirkel_x, cirkel_y), 20, 0)
        cirkel_rect = pygame.Rect (cirkel_x, cirkel_y, 30, 30)
        pygame.display.update()
       
    if cirkel_x >= 799:
        cirkel_aktiv = 0
        cirkel_y = spelare_y + 30
        cirkel_x = spelare_x + 120
        pygame.draw.circle(screen, (30,97,200), (cirkel_x, cirkel_y), 20, 0)
        cirkel_rect = pygame.Rect (cirkel_x, cirkel_y, 30, 30)
       
    if cirkel_rect.colliderect (target_rect) == True:
        cirkel_aktiv = 0
        cirkel_x = spelare_x +  20
        cirkel_y = spelare_y + 30
        cirkel_rect = pygame.Rect (cirkel_x, cirkel_y, 30, 30)
        score_int = score_int + 10
        score_str = str(score_int)
        score_text = font_2.render ("Score:" + score_str, True, (255,255,255))
       
    screen.fill ((0,0,0))
    pygame.draw.rect (screen, (230,160, 125), (pos_x,pos_y,80,60)) 
    pygame.draw.rect(screen, (200,200,200),(spelare_x, spelare_y, 80, 60))
    screen.blit (score_text, (0,0))
   
    if cirkel_aktiv == 0:
        pygame.display.update()

Name: Anonymous 2010-05-21 14:53

>>158
I didn't even use any [code] tags.
Fixed that for you.

Name: Anonymous 2010-05-21 17:05

>>159
Back to proggit, Please!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List