![]() |
#1 | ||
Join Date: Jul 2009
Location: Hungary
Posts: 760
|
![]() 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?
__________________
![]() 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! |
||
![]() ![]() |
|
![]() |
#2 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: May 2005
Location: Nitra, Slovakia
Posts: 6,533
|
![]() Quote:
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
__________________
![]() |
||
![]() ![]() |
|
![]() |
#3 | ||
Join Date: Jul 2009
Location: Hungary
Posts: 760
|
![]() Quote:
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.
__________________
![]() 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! |
||
![]() ![]() |
|
![]() |
#4 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: May 2005
Location: Nitra, Slovakia
Posts: 6,533
|
![]() 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
__________________
![]() |
||
![]() ![]() |
|
![]() |
#5 | ||
Join Date: May 2008
Location: Swan River, Canada
Posts: 842
|
![]() 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. |
||
![]() ![]() |
|
![]() |
#6 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: May 2005
Location: Nitra, Slovakia
Posts: 6,533
|
![]() 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
__________________
![]() |
||
![]() ![]() |
|
![]() |
#7 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2006
Location: ,
Posts: 4,613
|
![]() That diference between subroutine and function was not original from Pascal, both Basic and Fortran had it, I guess it's a tradition created by the latter, but no language designed nowadays (outside the Basic family) keeps it. I never considered it didactic, on the contrary, when I moved from QBasic to C that was one of the things I was happy to see gone. Specially since most versions of most of these languages soon decided to allow you--just like C or other more modern ones, but with more awkward syntax--to call a function as a subroutine, discarding the return value.
Fubb, C++ is one of the languages hardest to understand, that's its major drawback, because its design process was a mess and it was constrained by being a superset of C. (Many languages do many things C++ does with far easier and more elegant syntax.) So if C++ is the language you work most with, I wouldn't worry about not understanding any language that you haven't seen before, that's just to be expected. And there's probably no reason for you to ever try Pascal.
__________________
Life starts every day anew. Prospects not so good... Last edited by Japo; 20-12-2010 at 06:15 PM. |
||
![]() ![]() |
|
![]() |
#8 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2007
Location: Rome, Italy
Posts: 137
|
![]() Quote:
|
||
![]() ![]() |
|
![]() |
#9 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: May 2005
Location: Nitra, Slovakia
Posts: 6,533
|
![]() that's not an issue of a programming language but thinking at all then :P
no, it's a point used for drawing rectangle. Code:
[x,y]--------* | | | | | | *------[x1,y1]
__________________
![]() |
||
![]() ![]() |
|
![]() |
|
![]() |
||||
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 |
|
|
||
  |