This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[SOLVED] Agar.io clone (help)
Pythonistapro777 last edited by Pythonistapro777
Haven't been using the forum often 'cause of my onslaught of homework, but it's getting better...
I'm making an Agar.io clone. I have the player and "cells" or as I like to call them food in separate scripts (I'll put them together when I'm free).
For any of you who don't know what I'm talking about you can search "agar.io" in the App Store or in google to play the game...
Here is the script for player:
(It's very bad - just trying to get the basics down)
from scene import * class MyScene (Scene): def setup(self): self.layer = Layer(Rect(self.size.w * 0.5, self.size.h * 0.5, 16, 16)) self.layer.background = Color(1, 0, 0) def draw(self): background(0, 0, 0) self.layer.update(self.dt) self.layer.draw() ellipse(self.size.w * 0.5 + 90, self.size.h * 0.5 - 160, 120, 120) def touch_moved(self, touch): new_frame = Rect(touch.location.x -160, touch.location.y + 90, 16, 16) self.layer.animate('frame', new_frame, duration=0.1) fill(1,0,0) run(MyScene(), LANDSCAPE)
And the code for the food:
from scene import * from random import * import time import sys class Particle(object): def __init__(self, wh): self.w = wh.w*4 self.h = wh.h*4 self.x = randint(0, self.w) self.y = randint(0, self.h) self.vx = randint(-10, 20) self.vy = randint(-10, 20) self.colour = Color(random(), random(), random()) def update(self): self.x += self.vx self.y += self.vy self.vx *= 0.98 self.vy *= 0.98 if self.x > self.w: self.x = self.w self.vx *= -1 if self.x < 0: self.x = 0 self.vx *= -1 if self.y > self.h: self.y = self.h self.vy *= -1 if self.y < 0: self.y = 0 self.vy *= -1 def draw(self): fill(*self.colour) ellipse(self.x, self.y, 8, 8) class Intro(Scene): def setup(self): num=100 self.particles =  for p in xrange(num): self.particles.append(Particle(self.size)) def draw(self): background(0.00, 0.05, 0.20) for p in self.particles: p.update() p.draw() for t in self.touches.values(): for p in self.particles: tx, ty = t.location.x, t.location.y d = (p.x - tx)*(p.x - tx)+(p.y - ty)*(p.y - ty) d = sqrt(d) p.vx = p.vx - 5/d*(p.x-tx) p.vy = p.vy - 5/d*(p.y-ty) p.colour = Color(random(), random(), random()) run(Intro(), LANDSCAPE)
(Used the particle script :P)
Now why I need help with if moving the view.. Right now if you are running on iphone you will only see a few "cells" because you are looking at a small part of the full game view (don't know what to call it) ~ on iPad you will see note but they are spread out.
For those who know the game when you put your mouse or press on a certain direction you player will move in that direction. But it's not really moving (it does but a little), the game view is. I need help with making it so that if I were to click on the top right of my screen, the view would move too right, like panning with a camera. I tried making it to that when I clicked somewhere all the particles when the opposite direction, but they ended up all crowding to one point, so my last option and probably the best one is to move the game view.
Thanks in advance!
P.s. Before you hate for this probably being the most vague post ever. It's because I wrote this right before going to bed and I'm really busy with school.
Webmaster4o last edited by
Scene doesn't have any built-in functionality for side-scrolling. You have to update the positions of objects and then delete them when they get to the end, like you did in the gravity guy script but in two directions.
dgelessus last edited by
Layers can be larger than the screen, right? In that case you could have a "game field" area that is as large as the entire field. All cells and food are sublayers of the "game field". Then you can simply change the position of the game field relative to the root layer to change the current view position.
Though I'd imagine this causing framerate issues when many cells (and especially food pellets) are on the field. The real agar.io only renders what the player can see, I'm not sure how
scenehandles off-screen layers.