Movement lag
in
Programming Questions
•
10 months ago
Hello, i am trying to make this litle games , in witch the player has to move around, for now the player is a red ellipse and the enemie the green one , my problem here is that my wqsd movement is a bit glitchy.
could any one , direct me to a topic where this issue has been solved or help me to get rid of the lag, i would be verry greatfull.
(sorry for the spelling mistakes i'm french.)
- PImage inter;
- int x= 100;
- int y= 100;
- float vie= 150;
- float x1= 900;
- float y1 = 250;
- void setup() {
- size(1000, 500);
- frameRate(300);
- smooth();
- inter = loadImage("inter.png");
- }
- void draw() {
- background (255, 255, 255);
- inter ();
- BH();
- mvmnt();
- vie();
- ennemi();
- }
- void BH() {
- fill(255, 0, 0);
- ellipse(x, y, 25, 50);
- smooth();
- }
- void mvmnt() {
- if (keyPressed) {
- if (y>55) {
- if (key== 'z'||key== 'Z') {
- y=y-1;
- }
- }
- else {
- y=y;
- }
- if (y<445) {
- if (key== 's'||key== 'S') {
- y=y+1;
- }
- }
- else {
- y=y;
- }
- if (x>44.5) {
- if (key== 'Q' || key == 'q') {
- x=x-1;
- }
- }
- else {
- x=x;
- }
- if (x<957.5) {
- if (key == 'd'|| key == 'D') {
- x=x+1;
- }
- }
- else {
- x=x;
- }
- }
- }
- void inter() {
- image(inter, 0, 0);
- }
- void vie() {
- rect(800, 5, vie, 20);
- if (x==x1 && y==y1) {
- if (vie>0) {
- vie = vie-0.2;
- }
- }
- }
- void ennemi() {
- fill (0, 192, 0);
- ellipse (x1, y1, 20, 20);
- if (x1>x) {
- x1=x1-0.25;
- }
- if (x1<x) {
- x1=x1+0.25;
- }
- if (y1<y) {
- y1=y1+0.25;
- }
- if (y1>y) {
- y1=y1-0.25;
- }
- }
1