We are about to switch to a new forum software. Until then we have removed the registration on this forum.
PImage gamepic; PImage game; PImage gstartr; import gifAnimation.*; Gif gst; Gif gsti; float x=300; float y=500; int r=50; float m; float rx=200; float ry=0; float rs=10; int scr=0; float px=300; float py=0; float ps=10; int s=0, t=0; int p=-1; void setup() { size(600, 600); gamepic = loadImage("gamer.png"); game = loadImage("retry.png"); gstartr = loadImage("ty.png"); gst=new Gif(this, "gamei.gif"); gsti=new Gif(this, "koki.gif"); } void draw() { startscreen(); if(p==-1) { gst.loop(); image(gst,0,0); textSize(60); } else { gsti.loop(); image(gsti, 0, 0); fill(#00AAC1); rect(x, y, r, r); textSize(40); text(scr, 500, 50); fill(#5112AF); if(s!=-1) { play(); } else { background(0); image(game, 150, 100); textSize(30); fill(#F99F03); text(scr,290,260); textSize(20); text("click space to play again",220,350); if(keyCode==(char)32) { retry(); } } }} void keyPressed() { if (key == CODED) { if (keyCode == LEFT) { if (x>200) { x=x-100; } } if (keyCode == RIGHT) { if (x<400) { x=x+100; } } } } void crect() { if (ry>=height) { scr++; rx=(int)random(2, 5)*100; ry=0; px=(int)random(2, 5)*100; py=0; if (rx==px) { rx=(int)random(2, 5)*100; if (rx==px) { rx=(int)random(2, 5)*100; } } } } void play() { rect(rx, ry, 50, 50); rect(px, py, 50, 50); crect(); gamess(); timef(); tim(); if ((ry<=y+50&&ry+50>=y&&rx>=x&&rx<=x+50)||(py<=y+50&&py+50>=y&&px>=x&&px<=x+50)) { s=-1; } } void retry() { rs=9; ps=9; scr=0; ry=0; py=0; s=0; } void gamess() { ry+=rs; py+=ps; if (scr==10) { rs=11; ps=11; } if (scr==20) { rs=11.5; ps=11.5; } if (scr==30) { rs=12.5; ps=12.5; } if (scr==40) { rs=13; ps=13; } if (scr==50) { rs=13.5; ps=13.5; } if (scr==60) { rs=13.8; ps=13.8; } if (scr==70) { rs=14; ps=14; } if (scr==80) { rs=14.3; ps=14.3; } if (scr==90) { rs=14.5; ps=14.5; } if (scr==100) { rs=14.8; ps=14.8; } if (scr==120) { rs=15; ps=15; } } void timef() { String a=s+"."+t; fill(#F89A1C); rect(52,10,120,60,5); fill(#EB1E23); textSize(40); text(a, 52, 50); } void tim() { t++; if(t>=59) { s++; t=0; } } void startscreen() { if (mousePressed&&mouseButton==LEFT) { background(255); p=0; } }
code with graphics link https://drive.google.com/file/d/0B_0SmP7wVFHXY0xWWU9udW1HSjQ/view?usp=sharing the game goes fine if i use key(left/right) after i die and endscreen show and stays but if i dnt use key after i dies first time the endscreen doesnt stay plz could any1 help me with it
Answers
The variabe "keyCode" will always have the the value of the last key that has been pressed. So when you hit "space" to restart the game and the next game ends before you press a different key, then "keyCode" will still be 32.
You could maybe check for the space-key-press inside of keyPressed() or you could use a boolean like "keyPressedThisGame" and set it to true inside of keyPressed() and to false in retry().
hey tankz it worked could anyone help me with this the game is simple but it took like 35 mb so how to use files that are only necesarry in this game and it reduces size of program