Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 23-11-2010, 10:49 AM   #1
Tracker
Home Sweet Abandonia
 
Tracker's Avatar




 
Join Date: Jul 2009
Location: Hungary
Posts: 760
Default 2D game in Pascal

Oookay, so where do I have to start? First of all, I'd like to let you know that I don't know any programming languages except Pascal, and I'm not even professional in it. However, I managed to make a nice little demo in which you can control a green circle on the screen, and if it reaches the border of the screen then it appears on the other side (a well-known effect from older space shooters, like Asteroids). So, would anyone like to improve it, and create something valuable? Maybe it could be AB-themed! (Directing a ball towards ESA-labelled bricks with a pad, maybe?) Or whatever you desire! The point is to technically improve it. I wouldn't release the source code yet, not because it's valuble but because I wouldn't give it to people who can't do anything useful with it. So, if you'd like to participate in this hobby-level project, feel free to contact me here or in PM. BTW, if I'd be able to make anything interesting, I'll let you take a look at it, just in case you're curious.
__________________


Reverend Preacherbot: Wretched sinner unit! The path to Robot Heaven lies here, in the Good Book 3.0.
Bender: Hey. Do I preach at you when you're lying stoned in the gutter? No!
Tracker is offline                         Send a private message to Tracker
Reply With Quote
Old 27-11-2010, 02:05 AM   #2
_r.u.s.s.
I'm not Russ
but an ex-alektorophobic
 
_r.u.s.s.'s Avatar


 
Join Date: May 2005
Location: Nitra, Slovakia
Posts: 6,533
Default

Quote:
I wouldn't release the source code yet, not because it's valuble but because I wouldn't give it to people who can't do anything useful with it.
a circle moving on screen, spawning on the other side if it reaches the end? what are they gonna do? sell it to the communists?

i mean, anyone could've coded within a day, even if he didn't know the programming language in which he does it (unless you write it in assembler)

why don't you post the code here, maybe we can point out places where you can improve it or tell you what could've been done better and more efficiently
__________________
_r.u.s.s. is offline                         Send a private message to _r.u.s.s.
Reply With Quote
Old 27-11-2010, 01:06 PM   #3
Tracker
Home Sweet Abandonia
 
Tracker's Avatar




 
Join Date: Jul 2009
Location: Hungary
Posts: 760
Default

Quote:
Originally Posted by _r.u.s.s. View Post
why don't you post the code here, maybe we can point out places where you can improve it or tell you what could've been done better and more efficiently
Ooo-kay... I was a bit overloaded with joy 'cause when I showed that little nonsense to some fellow students I heard they jaws loudly dropping to the floor (maybe because they couldn't write anything pascal). The code:

Code:
program keymove;
uses crt,graph;
procedure videoinit;
  var hibakod,gdriver,gmode:integer;
  begin
    gdriver:=detect;
    initgraph(gdriver,gmode,' ');
    hibakod:=graphresult;
    if hibakod<>0 then
      begin
        writeln('GRAFIKUS HIBA: ',grapherrormsg(hibakod));
        halt(1);
      end;
    end;
procedure fall;
  var x,y,x1,y1,xirany,yirany:integer;
  begin
    x:=random(640);
    y:=50;
    x1:=x+50;
    y1:=x-100;
    xirany:=1;
    yirany:=1;
  repeat
    y:=y+yirany;
    y1:=y;
    Setcolor(4);
    rectangle(x,y,x1,y1);
    delay(25);
    Setcolor(0);
    rectangle(x,y,x1,y1);
    if y>469 then y:=0;
  until keypressed;
  end;
var x,y,a:integer; q:char;
begin
  videoinit;
  x:=340;
  y:=280;
  Setcolor(2);
  Circle(x,y,8);
  a:=1;
  fall;
  repeat
  q:=readkey;
  case q of
  'd' : begin Setcolor(0); Circle(x,y,8); Setcolor(2); x:=x+a; Circle(x,y,8); end;
  'a' : begin Setcolor(0); Circle(x,y,8); Setcolor(2); x:=x-a; Circle(x,y,8); end;
  'w' : begin Setcolor(0); Circle(x,y,8); Setcolor(2); y:=y-a; Circle(x,y,8); end;
  's' : begin Setcolor(0); Circle(x,y,8); Setcolor(2); y:=y+a; Circle(x,y,8); end;
  'x' : halt(1);
  '+' : a:=a+10;
  '-' : a:=a-10;
  end;
  if x>640 then begin Setcolor(0); Circle(x,y,8); Setcolor(2); x:=0; end;
  if x<0 then begin Setcolor(0); Circle(x,y,8); Setcolor(2); x:=629; end;
  if y>480 then begin Setcolor(0); Circle(x,y,8); Setcolor(2); y:=0; end;
  if y<0 then begin Setcolor(0); Circle(x,y,8); Setcolor(2); y:=480; end;
  until q=#27;
  readkey;
end.
I wanted to make a red square falling down while I can still move the circle. Later I'd make it like that if the square reaches the circle, the program quits. I guess the algorythm must be a little bit more complicated, and maybe I'd need to use blocks to store variables etc. No idea how to continue this...
__________________


Reverend Preacherbot: Wretched sinner unit! The path to Robot Heaven lies here, in the Good Book 3.0.
Bender: Hey. Do I preach at you when you're lying stoned in the gutter? No!
Tracker is offline                         Send a private message to Tracker
Reply With Quote
Old 28-11-2010, 03:56 PM   #4
_r.u.s.s.
I'm not Russ
but an ex-alektorophobic
 
_r.u.s.s.'s Avatar


 
Join Date: May 2005
Location: Nitra, Slovakia
Posts: 6,533
Default

that's a nice start

however, i see you already noticed the most common problem when people start programing with keyboard events. for example, when you hold one key the dot moves a bit at first, then pauses and then continues moving. you can solve this by remembering states of the keyboard rather than relying on keyboard events directly

example, we have a boolean variable "pressed_left" which is false by default, when a user presses left key you set this variable to true. later in the cycle you check this variable for true or false and move the circle accordingly. when user releases the key you would set the variable to false. that way you can move in more directions at once too.

with this you'd probably notice that you have a lot of variables and it gets kind of big (lines-wise). then you could use arrays. arrays are very useful in programming, you should definitely check them out. for example you could have only one variable which could hold all the key states

also, the code will eventually grow and it's a good to make a clean difference between the action code, calculations and rendering. you can for example try creating a procedure which will register key events and modify positions of the circle (1 up 1 left for example), then a procedure for enemy movement, a procedure which would calculate if something hit something else ... and then, a procedure which will simply draw all this into the scene. the main loop will be cleaner, simpler and much easier to navigate in. ideally, you would use objects and classes, but i don't think that this is a topic for beginner yet, just stick to your procedures and functions for now. and i'm not even sure if pascal supports them anyways
__________________
_r.u.s.s. is offline                         Send a private message to _r.u.s.s.
Reply With Quote
Old 20-12-2010, 03:22 AM   #5
Fubb
GreatCanadianMan
 
Fubb's Avatar


 
Join Date: May 2008
Location: Swan River, Canada
Posts: 842
Default

ohmigosh :S I barely understand C++, Python, and Basic, and Pascal just blew my mind, i have no idea what any of those mean!

Well like, other then the key definitions and what not, but those hibakod, gdriver, gmode thingies, i have no idea what those are lol
__________________
Kugarfang: o hai guiz im trying to find this techno song from the radio and it goes like this:

DUN duuuunnnn dudududududun SPLOOSH duuunnnnn


We ate the horse.
Fubb is offline                         Send a private message to Fubb
Reply With Quote
Old 20-12-2010, 03:44 AM   #6
_r.u.s.s.
I'm not Russ
but an ex-alektorophobic
 
_r.u.s.s.'s Avatar


 
Join Date: May 2005
Location: Nitra, Slovakia
Posts: 6,533
Default

it must be just getting used to it

pascal is syntactically one of the simplest languages for people who learn coding. it was even meant as "the teaching programming language"

you get things like a difference between "function" and "procedure", which is all "function" in every other language. but pascal differences between those two just to make a clean difference between functions that return something and those that only perform something

..and hibakod, gdriver, gmode are just custom variable names
__________________
_r.u.s.s. is offline                         Send a private message to _r.u.s.s.
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Computer Game Quote Quiz Game Zarkumo Forum Games 549 15-08-2010 03:31 AM
Pascal Trouble... The Fifth Horseman Programming 8 05-05-2005 03:02 PM
Need To Learn Turbo Pascal 7... Fast! The Fifth Horseman Programming 17 11-03-2005 02:02 PM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 12:05 PM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.